The New TODO and More

  • HAL 2012-11-28 08:04
    Return "Need to fix this"
    I'm sorry, Dave. I'm afraid I can't do that.
  • Larry 2012-11-28 08:09
    The problem with regexen is a lot like the problem with library functions: you can never be entirely sure what they're doing. So, in cases like this where the results are important, it is safest to write your own.
  • Smug Unix User 2012-11-28 08:14
    If you comment your code you can get a good idea of what the function should be doing. If you didn't get the arcane syntax of a regular expression just right then the next developer will at least know what you are trying to do and make the appropriate adjustments. Sometimes code need to have the bugs removed and the same is true of regular expression. A lot of developers will simply look at the expression guess at what it was trying to do and either replace it with something like this example or somehow work around the problem. Writing code is a lot easier than reading it.
  • Herman 2012-11-28 08:19
    I'm actually interested in the execution path of the searchstring when the database server is able to parallelize the unions and each of the searchfields are indexed.
  • VB_adict 2012-11-28 08:21
    "turning option strict on for a large project"

    Ha! There is the TRWTF.

    Or maybe its Visual Basic (someone had to say this)
  • asdf 2012-11-28 08:25
    > the existence of the OR operator

    Some people learn what OR operator does (on certain databases) with indices sooner, some later. Union still has a place in SQL as a poor's man OR.
  • Quosek 2012-11-28 08:33
    in same cases using unions instead of OR really makes a sense - sometimes it's better from performance point of view use unions ....
  • planB 2012-11-28 08:35
    Nonody noticed the order by only has an efect on the last select of the unions. i guess that's not the effect the developer was going for
  • recently departed colleague 2012-11-28 08:36
    Hey Chris,
    sorry for all the injections, but please think a bit and may be you will realize that on old systems UNION worked faster than OR.

    captcha valid
    lol
  • planB 2012-11-28 08:37
    Nonody = Nobody
  • lanmind 2012-11-28 08:42
    Herman:
    I'm actually interested in the execution path of the searchstring when the database server is able to parallelize the unions and each of the searchfields are indexed.


    I think, in the case of SQL Server, that the optimizer really only looks at the first query in UNIONs to do its magic, so I gotta believe that ORs would make for a better query plan - unless the vast majority of the results are caught by the first query. It may be unavoidable, but likely the bigger problem is the LIKE operators.
  • lanmind 2012-11-28 08:45
    planB:
    Nonody noticed the order by only has an efect on the last select of the unions. i guess that's not the effect the developer was going for


    Not on SQL Server:

    SELECT Field01 = 1
    
    UNION
    SELECT 2
    UNION
    SELECT 0
    UNION
    SELECT 4
    ORDER BY Field01

    Field01
    0
    1
    2
    4
  • Ralph 2012-11-28 08:49
    Most databases have these things called query optimizers these days. Writing an arcane overly complex query to make the computer's work easier is premature optimization, like trying to outsmart your compiler. Don't forget that 99.9% of the ongoing costs are developer maintenance time, not CPU time.

    Oh, this is MS SQL?

    Never mind.
  • Bob 2012-11-28 08:50
    Larry:
    The problem with regexen is a lot like the problem with library functions: you can never be entirely sure what they're doing. So, in cases like this where the results are important, it is safest to write your own.


    Ha!
  • n9ds 2012-11-28 08:52
    "The problem with regexen is a lot like the problem with library functions: you can never be entirely sure what they're doing. So, in cases like this where the results are important, it is safest to write your own. "

    That sounds like the "Not Invented Here" argument to me.
  • Cantabrigian 2012-11-28 08:57
    "regex scares me a little, OK, alot actually"

    Aaaaargh! It's "a lot" - two words. You wouldn't write "afew", would you? Then again, it's probably better than writing "allot" (when meaning "a lot", not "share out"). </petpeeve>
  • Peteris 2012-11-28 08:59
    The OR solution would have different results in cases where a record matches multiple search criteria - in that case, the current solution would include duplicate rows.

    I'm not entirely sure why returning duplicate rows would be desired, but that's a different WTF.
  • Quango 2012-11-28 09:03
    Larry:
    The problem with regexe is a lot like the problem with library functions: you can never be entirely sure what they're doing. So, in cases like this where the results are important, it is safest to write your own.


    So by this logic the entire application framework and operating system would have to be replaced. And the hardware, and the drivers.

    Or you could write some unit tests on the regex expression that validate what it's doing.
  • MySQL geek 2012-11-28 09:07
    Actually, here UNION is the same as OR, but in the MySQL point of view, presents a better performance ;)
  • @Deprecated 2012-11-28 09:09
    Larry:
    The problem with regexen is a lot like the problem with library functions: you can never be entirely sure what they're doing. So, in cases like this where the results are important, it is safest to write your own.


    In many cases it is safest NOT to write your own! EG., encryption. Or did I just win a "whooosh"?

    Did he really have to use charAt for two linear ranges?
    I think that if (c >= 'a' && c <= 'z') is less error-prone than "abcdefghijklmnpqrstuvwxyz".chartAt(c) != -1
    Quick, spot the error!
  • Brillant 2012-11-28 09:11
    TRWTF is to say that regular expressions are tidy and save processing power :-)))
  • TGV 2012-11-28 09:20
    Larry:
    The problem with regexen is a lot like the problem with library functions: you can never be entirely sure what they're doing. So, in cases like this where the results are important, it is safest to write your own.

    Since you write "regexen", as in one VAX, two VAXen, I'm assuming you're trolling. Congratulations!
  • Mike Woodhouse 2012-11-28 09:24
    Need also to fix incorrect use of non-existent words.

    http://www.grammar-monster.com/easily_confused/alot_a_lot_allot.htm
  • anonymouse 2012-11-28 09:25
    Larry:
    The problem with regexen is a lot like the problem with library functions: you can never be entirely sure what they're doing. So, in cases like this where the results are important, it is safest to write your own.

    10/10 would rage again
  • the beholder 2012-11-28 09:32
    @Deprecated:


    In many cases it is safest NOT to write your own! EG., encryption. Or did I just win a "whooosh"?
    I'm pretty sure you did. Congratulations!

    @Deprecated:
    Did he really have to use charAt for two linear ranges?
    I think that if (c >= 'a' && c <= 'z') is less error-prone than "abcdefghijklmnpqrstuvwxyz".chartAt(c) != -1
    Quick, spot the error!
    You mean other than the absence of 'o', or the fact the original did account for uppercase letters while you didn't bother going that far?
  • mozbo 2012-11-28 09:37
    Dave's not here, man.
  • Larry 2012-11-28 09:47
    Quango:
    Larry:
    The problem with regexe is a lot like the problem with library functions: you can never be entirely sure what they're doing. So, in cases like this where the results are important, it is safest to write your own.


    So by this logic the entire application framework and operating system would have to be replaced. And the hardware, and the drivers.
    Well frankly I've never cared for the leading OS options all that much, so yeah. And drivers, aren't they the things that create fatal crashes all the time?

    As for hardware, I suppose you're still buying yours from China? Hmmm?

    If you're in a situation where results matter, safest bet is to make your own. If you want it done right, do it yourself.

    You know how free trade is always destroying local economies? Buy from your own town, not online? Well get more local. Only trade with people on your own block. In your own house. Your own bedroom. See where this is going?
  • Herr Otto Flick 2012-11-28 09:48
    TRWTF is Whitesmiths braces, amiright. Allman or bust, that's what I say.
  • Bernie The Bernie 2012-11-28 09:53
    How does it come that you do not know what's the num variable for? Has following function been deleted:
    function checkNum(sStr)
    
    {
    var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var num = '0123456789';
    var Char;
    var isNum = true;
    for (var i=0;(i<sStr.length) && (isNum==true);i++)
    {
    Char = sStr.charAt(i);
    if (num.indexOf(Char)==-1)
    {
    isNum=false;
    }
    }
    return isNum;
    } //end function

    Please add it back to the code base!
  • Jack 2012-11-28 09:54
    Quango:
    So by this logic the entire application framework and operating system would have to be replaced. And the hardware, and the drivers.
    True story: My first computer was from Atari, and I had to write my own modem driver and printer driver. I even separated the print formatting commands from the document formatting codes so that I could buy a different printer someday and not have to modify all my documents.

    At least it came with a disk driver. But I had to add a layer on top of that so that a single file could be larger than a whole floppy disk.

    It's not that hard. You can do it if you want.
  • Cyberzombie 2012-11-28 09:55
    "^\w*$"

    Simple enough.
  • Captcha:sino 2012-11-28 09:55
  • Tom 2012-11-28 09:59
    Cyberzombie:
    "^\w*$"

    Simple enough.
    What if you're using a language where $" is a built-in variable, and double-quoted strings interpolate $Vars? Oh, and newline doesn't necessarily mean end of statement?

    It's never as simple as it looks.
  • Delve 2012-11-28 10:00
    Because there will be a time when it's a good idea to write more code for simple tasks that have been done a million times over like confirming a string is composed only of the basic Latin alphabet.

    When results are important you go with what works rather than ginning up your own solutions with all the inherent human error that new code implies.
  • Cyberzombie 2012-11-28 10:03
    Tom:
    Cyberzombie:
    "^\w*$"

    Simple enough.
    What if you're using a language where $" is a built-in variable, and double-quoted strings interpolate $Vars? Oh, and newline doesn't necessarily mean end of statement?

    It's never as simple as it looks.

    If somebody knows how to use a regex, then they better know how to program in that language - though this is TDWTF...so ignore what I typed :)
  • DCRoss 2012-11-28 10:27
    Tom:
    Cyberzombie:
    "^\w*$"

    Simple enough.
    What if you're using a language where $" is a built-in variable, and double-quoted strings interpolate $Vars? Oh, and newline doesn't necessarily mean end of statement?

    It's never as simple as it looks.

    And what if your compiler only produces eight bit code and both of your legs are broken? Then how would you solve the problem?
  • chris 2012-11-28 10:32
    Peteris:
    The OR solution would have different results in cases where a record matches multiple search criteria - in that case, the current solution would include duplicate rows.

    I don't think it would. Assuming that SQL Server and the w3schools page I just read follow standard practice, UNION ALL concatenates the results of the queries, including duplicates, but UNION returns a unique set.
  • Geoff 2012-11-28 11:00
    That is problem with query optimize though. If your application *needs* the performance right now okay, sometimes you have to code around the ugly. In general though I'd say if your database is not stressed and performance is alright, I'd rather right clean code, at least when it ought to be possible for an optimizer to deal with well, than stick in some ugly workaround.

    If you have to use multiple selects and UNION to get reasonable execution plans for *simple* OR conditions, the problem is your database software.
  • Leander 2012-11-28 11:00
    String searchString="select * from ProjectAndTask_view";
    if (searchWhere !=""){
    searchString=searchString + " where ProjectCode like '" + searchWhere + "%' union " ;
    searchString=searchString + "select * from ProjectAndTask_view where ProjectDesc like '" + searchWhere + "%' union " ;
    searchString=searchString + "select * from ProjectAndTask_view where TaskCode like '" + searchWhere + "%' union " ;
    searchString=searchString + "select * from ProjectAndTask_view where TaskDesc like '" + searchWhere + "%'" ;
    }
    searchString = searchString + " ORDER BY sortval";


    Actually, this is very possible.
    I had todo a similar things for performance issues.
    A union sometimes will perform aster then combining multiple ORs.

    In my case though the query was created at runtime, and it could not be predicted at coding time. The ORsolution was sometimes fast, sometimes very slow.
    Using the UNION alternative was "not to slow, not to fast" (almost) all of the time.
  • me 2012-11-28 11:03
    It is also faster in MSSQL
  • Neil 2012-11-28 11:04
    Cyberzombie:
    "^\w*$"

    Simple enough.
    1. Inside a double quoted string, \ is typically an escape character. Even if there is no special meaning for \w you will still lose the \.

    2. Inside a regex, \w typically matches underscores too.
  • Geoff 2012-11-28 11:06
    They usually do save processing over say a mess of split(),join(),mid$(),left$(),right$(),For i = 0 to len(str); if str[i] = .... EndFor

    stuff
  • Tristram 2012-11-28 11:33
    TRWTF with the last one is using a boolean variable to indicate that it's time to break out of the loop, instead of using GOTO, like God intended.
  • Jim 2012-11-28 11:47
    DCRoss:
    And what if your compiler only produces eight bit code and both of your legs are broken? Then how would you solve the problem?
    I think at that point I'd have to interview at another employer, so thank you for your time.
  • Unicorn #2816 2012-11-28 11:47
    Tristram:

    goto TRWTF
    FIX:
    use GOTO, like God intended.
    goto DONE
    TRWTF:
    using a boolean variable to indicate that it's time to break out of the loop
    goto FIX
    DONE:

    FTFY
  • Frak 2012-11-28 11:49
    Geoff:
    I'd rather right clean code
    and dirty English. Or did you left your brain home today?
  • Will 2012-11-28 12:00
    DCRoss:
    And what if your compiler only produces eight bit code
    If you're as good as you think you are, you ought to be able to get the complier to output the desired 16-bit instruction by tricking it into emitting two unrelated 8-bit instructions.
  • Steve The Cynic 2012-11-28 12:09
    Frak:
    Geoff:
    I'd rather right clean code
    and dirty English. Or did you left your brain home today?

    It's perfectly good English. To right something means to set it upright after it has fallen on one side (or even upside down). The RNLI (the UK's lifeboat-operating organisation, about the only UK charity I'd consider giving money to) has a stock of long-range shore-to-ship lifeboats that can right themselves.
  • Bob 2012-11-28 12:11
    Will:
    DCRoss:
    And what if your compiler only produces eight bit code
    If you're as good as you think you are, you ought to be able to get the complier to output the desired 16-bit instruction by tricking it into emitting two unrelated 8-bit instructions.
    This could be automated. You could develop a table of those "unrelated 8-bit instructions" that produce the required 16 bit codes. Then, as you write what you want in 16-bit, this utility pulls together the table entries and assembles them for you.

    You could call it an assembler.
  • Yank 2012-11-28 12:12
    Steve The Cynic:
    Frak:
    Geoff:
    I'd rather right clean code
    and dirty English. Or did you left your brain home today?

    It's perfectly good English. To right something means to set it upright after it has fallen on one side (or even upside down). The RNLI (the UK's lifeboat-operating organisation, about the only UK charity I'd consider giving money to) has a stock of long-range shore-to-ship lifeboats that can right themselves.
    So you're one of those who likes to think the UK knows anything about good English?
  • Andy 2012-11-28 12:12
    Neil:
    Cyberzombie:
    "^\w*$"

    Simple enough.
    1. Inside a double quoted string, \ is typically an escape character. Even if there is no special meaning for \w you will still lose the \.

    2. Inside a regex, \w typically matches underscores too.

    And in JavaScript, \w only matches non-accented Latin word characters.

    http://blog.stevenlevithan.com/archives/javascript-regex-and-unicode

    captcha: facilisi
    JS lacks the facilisi to match ελληνικές λέξεις
  • Pete 2012-11-28 12:22
    chris:
    Peteris:
    The OR solution would have different results in cases where a record matches multiple search criteria - in that case, the current solution would include duplicate rows.

    I don't think it would. Assuming that SQL Server and the w3schools page I just read follow standard practice, UNION ALL concatenates the results of the queries, including duplicates, but UNION returns a unique set.


    Tru, my bad - looked at my old sql code, and it's UNION ALL where needed. But even then the statements are not identical - if the table contains multiple identical rows, then UNION would throw out duplicates, but OR criteria would return as many rows as there were in the original dataset.
  • Fyrilin 2012-11-28 12:26
    Cyberzombie :

    "^\w*$"

    Simple enough.


    Word, yo.

    captcha: ingenium - quite so
  • Cbuttius 2012-11-28 12:37
    Assuming the last one is Javascript, and it looks like it, it isn't so trivial. Can be done with a regex.

    See http://stackoverflow.com/questions/6800536/isalpha-replacement-for-javascript
  • JAPH 2012-11-28 12:40
    HAL:
    Return "Need to fix this"
    I'm sorry, Dave. I'm afraid I can't do that.

    That comment is so 2001.
  • Chris 2012-11-28 12:40
    I'm the one who submitted that or/union sample.
    I can appreciate that sometimes less logical SQL can be faster, but I can assure you that that though would never have entered this guy's head. The query completes close to instantly either way.
  • Alex 2012-11-28 12:52
    Not only MySQL. Also in some specific cases in Sybase (which Mssql derives from). So this might "just" be premature optimization ;)
  • Mason Wheeler 2012-11-28 13:00
    Brillant:
    TRWTF is to say that regular expressions are tidy and save processing power :-)))

    This. When you run a regular expression over a string, you are running a script interpreter. Coding out what you are actually doing will always be faster, and more readable to boot.
  • DaveK 2012-11-28 13:09
    Cantabrigian:
    "regex scares me a little, OK, alot actually"

    Aaaaargh! It's "a lot" - two words.
    No, it's the alot, which is better than you at everything.
  • F 2012-11-28 13:13
    Mason Wheeler:
    Brillant:
    TRWTF is to say that regular expressions are tidy and save processing power :-)))

    This. When you run a regular expression over a string, you are running a script interpreter. Coding out what you are actually doing will always be faster, and more readable to boot.


    Except, of course, when you're using a language that compiles regexes, in which case it will most likely produce faster code. And in this particular case the regex will be more readable and certainly easier to check (are you sure the uppercase O hasn't been miskeyed as a zero?)
  • da Doctah 2012-11-28 13:14
    JAPH:
    HAL:
    Return "Need to fix this"
    I'm sorry, Dave. I'm afraid I can't do that.

    That comment is so 2001.

    Dave's not here, man.

    That comment is so 1971.
  • fa2k 2012-11-28 13:20
    Need to fix this
  • Victor 2012-11-28 13:26
    Has anyone considered turning option strict on for comments?
  • Herp 2012-11-28 13:32
    Larry:
    The problem with regexen is a lot like the problem with library functions: you can never be entirely sure what they're doing. So, in cases like this where the results are important, it is safest to write your own.


    I really like how this was chosen as a featured comment so that it would immediately piss of anybody who views the article. Hilarious!
  • Uhh 2012-11-28 13:41
    I was under impression that modern regex libs compiled the regex to a provably optimal version - so if you're really good, you may code a version that's as fast in processing and lacks some initialization overhead; but if you're not perfect, then your code will be slower.
  • Coyne 2012-11-28 14:12
    MySQL geek:
    Actually, here UNION is the same as OR, but in the MySQL point of view, presents a better performance ;)


    Actually, while UNION and OR yield the same result in this example, the UNION requires a sort to remove duplicate rows (because it returns DISTINCT rows). It will not perform as well as an OR.

    (My basis for this conclusion is based on IBM host DB2, but I confirmed similar behavior for MYSQL; see UNION vs UNION ALL performance.)

    As he notes in the link, UNION ALL will perform much better (because no sort is required) but it is not exactly the same as OR, since overlapping predicates could cause a row to be returned more than once.


    Addendum (2012-11-28 14:22):
    Oh, and a side-case for UNION (UNION DISTINCT):

    Suppose a table exists where there is no unique key, such that duplicate rows could exist (that is, multiple rows having exactly the same value in each column). On a table of that type, UNION is not the same as OR either, since OR would return all matching rows, but UNION would delete the duplicate rows.

    That's because UNION operates on the distinct data value of the whole row. So if two rows have the same values in all columns, UNION will remove the second row.

    This can't happen if the table has a unique key because no duplicate rows can exist.
  • itzac 2012-11-28 14:13
    The problem with prepackaged CPUs is that you can't never be sure how the gates are wired. So in cases like this, where the results are important, it is safest to layout your own IC.
  • Coyne 2012-11-28 14:18
    And as for "EntityTypeDescription", I don't think it's enterprise-y enough. He also needs "EntityTypeMetaType", "EntityTypeMetaTypeDescription", "EntityMetaEntityType", "EntityMetaEntityTypeDescription", "EntityMetaEntityTypeMetaType", and "EntityMetaEntityTypeMetaTypeDescription". Just to achieve that full enterprise flavor.
  • Auction_God 2012-11-28 15:44
    Also true for Oracle, provided the referenced columns are indexed...
  • Alistair 2012-11-28 16:09
    @Deprecated:


    Did he really have to use charAt for two linear ranges?
    I think that if (c >= 'a' && c <= 'z') is less error-prone than "abcdefghijklmnpqrstuvwxyz".chartAt(c) != -1
    Quick, spot the error!


    Gives false positives in EBCDIC.
  • chubertdev 2012-11-28 17:24
    After playing around with UNIONs and ORs in SSMS, it's interesting to note that the ORDER BY clause has a bigger performance hit on the UNION version than the OR version. At least in my tests.
  • grokpg 2012-11-28 17:52
    recently departed colleague:
    Hey Chris,
    sorry for all the injections, but please think a bit and may be you will realize that on old systems UNION worked faster than OR.

    captcha valid
    lol


    a) That's only a valid excuse if the code is running on one of these alleged old systems.
    b) "Think a bit" is bullshit - this isn't something you could magically figure out just by thinking if you didn't already know it worked like that.

    Conclusion: you're a worthless retard.
  • Mark 2012-11-28 18:15
    Maybe if the results needed to be ranked by the number of criteria matches? Group the results and sort by highest count of duplicates. Then filter out the duplicates and you have a list sorted by relevancy. Probably a better way though.
  • chubertdev 2012-11-28 18:21
    Larry:
    The problem with regexen is a lot like the problem with library functions: you can never be entirely sure what they're doing. So, in cases like this where the results are important, it is safest to write your own.


    It's not limited to using regular expressions, though. I have seen a massive amount of code where the developer definitely was not entirely sure what they were doing.
  • Some guy 2012-11-28 18:49
    > Actually, here UNION is the same as OR, but in the MySQL point of view, presents a better performance ;)

    Same with IBM DB2. I once re-wrote a large query with 20 ORed predicates into 20 UNIONed queries. Massive performance gain - due to each sub-query being run in parallel.

    The bigger WTF is the use of 'SELECT *'.
  • Barf 4Eva 2012-11-28 18:51
    Not sure how I feel about the UNION issue. That could very well be valid, if the OR statement is going to cause the RDBMS to generate a bad exec plan per not being able to logically choose the right indexes. In the example shown here, the UNION might make sense. However, if we had something that would filter down a majority of rows from the table such that it would read as follows:

    WHERE bestFilter = _some_value_
    and (something1 like 'abc%'
    or something2 like 'abc%'
    or something3 like 'abc%'
    )

    The UNION will end up being more costly, most likely. I have already filtered out most rows with an index that will certainly be used.

    Whether or not it will be a WTF, well... It just depends. :)
  • Barf 4Eva 2012-11-28 18:59
    Then again, if the example here is close to the orginal, the querying of three different attributes for the same data seems a bit flaky. :)

    Perhaps the UNION is not the WTF, but everything leading up to it is... More information is needed?
  • Barf 4Eva 2012-11-28 19:01
    Some guy:
    > Actually, here UNION is the same as OR, but in the MySQL point of view, presents a better performance ;)

    Same with IBM DB2. I once re-wrote a large query with 20 ORed predicates into 20 UNIONed queries. Massive performance gain - due to each sub-query being run in parallel.

    The bigger WTF is the use of 'SELECT *'.


    It is, but I think for ease of writing views that need to expose everything to the sql developer, it's not all that bad as long as you rebuild your views nightly to capture any schema changes that won't be picked up otherwise...
  • Norman Diamond 2012-11-28 19:21
    @Deprecated:
    Larry:
    The problem with regexen is a lot like the problem with library functions: you can never be entirely sure what they're doing. So, in cases like this where the results are important, it is safest to write your own.
    In many cases it is safest NOT to write your own! EG., encryption. Or did I just win a "whooosh"?
    Yes, you just won a "whoosh". Larry's irony was obvious and well done.

    @Deprecated:
    Did he really have to use charAt for two linear ranges?
    I think that if (c >= 'a' && c <= 'z') is less error-prone than "abcdefghijklmnpqrstuvwxyz".chartAt(c) != -1
    Quick, spot the error!
    Which error? Treating é as a non-alphabetic? Treating some funny EBCDIC characters as alphabetic when running on a mainframe? Treating a as non-alphabetic? Treating α as non-alphabetic (where did the "alpha" in "alphabetic" come from anyway?)? Treating A as non-alphabetic? Or misspelling charAt as chartAt?
  • Norman Diamond 2012-11-28 19:42
    Yank:
    Steve The Cynic:
    Frak:
    Geoff:
    I'd rather right clean code
    and dirty English. Or did you left your brain home today?
    It's perfectly good English. To right something means to set it upright after it has fallen on one side (or even upside down). The RNLI (the UK's lifeboat-operating organisation, about the only UK charity I'd consider giving money to) has a stock of long-range shore-to-ship lifeboats that can right themselves.
    So you're one of those who likes to think the UK knows anything about good English?
    Well they know how to right it.

    The Linux makefile used to right clean code (not sure if it still does or not):
    make mrproper
  • 4c's A.G.N 2012-11-28 19:45
    Cantabrigian:
    "regex scares me a little, OK, alot actually"

    Aaaaargh! It's "a lot" - two words. You wouldn't write "afew", would you? Then again, it's probably better than writing "allot" (when meaning "a lot", not "share out"). </petpeeve>

    Oh, great, another grammar nazi. As if we needed more here, you guys are diamond dozen.
  • JustSomeGuy 2012-11-28 19:59
    Yank:
    Steve The Cynic:
    Frak:
    Geoff:
    I'd rather right clean code
    and dirty English. Or did you left your brain home today?

    It's perfectly good English. To right something means to set it upright after it has fallen on one side (or even upside down). The RNLI (the UK's lifeboat-operating organisation, about the only UK charity I'd consider giving money to) has a stock of long-range shore-to-ship lifeboats that can right themselves.
    So you're one of those who likes to think the UK knows anything about good English?


    Och aye the noo

    CAPTCHA: conventio : fellatio at a convention?
  • Friedrice the Great 2012-11-28 19:59
    Frak:
    Geoff:
    I'd rather right clean code
    and dirty English. Or did you left your brain home today?

    Yes, I left my brain at home today, that's why I'm reading the daily WTF. Makes it easier to learn kewl programming tricks.
  • jarfil 2012-11-28 22:48
    var isChar = true; 

    Obvious WTF apart, I really HATE it when people state things in their code that are just not true.

    Do you know it's a Char? NO, not yet. So don't freaking set "isChar" to true! Make your checks, use whatever temporal variables you need, but for god's sake, don't name them "isChar" like it was the actual result... like it IS the actual result, and then you get on and on checking it on each iteration of the loop... WTF!

    Oh, right, you have to be able to break out of the look somehow. Let me guess, maybe "break" would work? Maybe setting the counter out-of-bounds so the loop condition is no longer met? But oh no, you had to use "isChar", the freaking result variable, to break out of the loop.

    Give me a break.
  • savar 2012-11-28 23:22
    Coded Smorgasbord:
    No word on who "Dave" is though.


    I read that as text directed *at* Dave, not written by Dave. When attributing something to myself I usually use a double dash at the end. -- Mark

    MySQL geek:
    Actually, here UNION is the same as OR, but in the MySQL point of view, presents a better performance ;)


    The smiley face makes me think you're kidding, but I can't parse any humor out of your statement, so I'm not 100% sure.

    Coded Smorgasbord:
    I don't mind using fairly simple regex in my code. It's tidy and saves processing power.


    Which processor are you talking about? A regex engine certainly doesn't save any CPU power when compared against a purpose-built parser. I'm surprised when engineers can't understand that terse code isn't necessarily fast code, and vice-versa.

    It may save some processing power in your wetware, however, which is entirely the point of using abstractions like regex in the first place.

    lanmind:
    ...likely the bigger problem is the LIKE operators.


    Probably not. The LIKE operator can theoretically use an index if the wildcard is at the end of the query string. Of course, the likely SQL injection means a user can submit "%" in their query string in order to force a full table scan.

    lanmind:
    Not on SQL Server:


    SELECT Field01 = 1
    UNION
    SELECT 2
    UNION
    SELECT 0
    UNION
    SELECT 4
    ORDER BY Field01



    I almost choked on a Frito when I read this. I had to try this myself to believe it.

    Interestingly, SQL Server will also sort the results even if you omit the ORDER BY clause. You can't make this stuff up.

    Peteris:
    The OR solution would have different results in cases where a record matches multiple search criteria - in that case, the current solution would include duplicate rows.


    It shouldn't. UNION is a set operator, and as such, it should deduplicate results.

    http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.commands/html/commands/commands89.htm

    Ralph:
    Writing an arcane overly complex query to make the computer's work easier is premature optimization, like trying to outsmart your compiler.


    +1

    Tom:
    It's never as simple as it looks.


    +1

    Victor:
    Has anyone considered turning option strict on for comments?


  • Paul F 2012-11-29 00:50
    My preferred way of doing this is to return false within the loop and just have return true at the end of the function.
  • Mark 2012-11-29 01:09
    jarfil:
    Give me a break.


    Or just return false within the loop itself and return true immediately after. No need for temporal or result variable and no extra condition to check during iteration. In the case of this function, the intent would be perfectly clear.
  • A. Nonymous 2012-11-29 01:19
    planB:
    Nonody noticed the order by only has an efect on the last select of the unions. i guess that's not the effect the developer was going for


    Because they know SQL?
  • Kakan 2012-11-29 02:42
    Actually, the variable iSChar isn't needed at all.
    Just return false for the first char that's not in alpha.
    If the loop ends, return true.

    Like :
    for (var i=0;(i<sStr.length);i++)
    {
    Char = sStr.charAt(i);
    if (alpha.indexOf(Char)==-1)
    {
    return false;
    }
    }
    return true;

  • Steve The Cynic 2012-11-29 03:11
    Yank:
    So you're one of those who likes to think the UK knows anything about good English?

    Well, I wouldn't want to speak for the Welsh, the Scots, nor the Northern Irish, because I'm English, and they're not. I think England might know something about English. You know, like being where the language actually comes from...

    (Cue Spike Milligan:
    The English, The English, The English are best.
    I wouldn't give tuppence for all the rest.
    )

    ("tuppence": Two pence, that is £0.02, which is worth more than your feeble $0.02, but still not worth all that much.)
  • Cbuttius 2012-11-29 04:33
    jarfil:
    var isChar = true; 

    Obvious WTF apart, I really HATE it when people state things in their code that are just not true.

    Do you know it's a Char? NO, not yet. So don't freaking set "isChar" to true! Make your checks, use whatever temporal variables you need, but for god's sake, don't name them "isChar" like it was the actual result... like it IS the actual result, and then you get on and on checking it on each iteration of the loop... WTF!

    Oh, right, you have to be able to break out of the look somehow. Let me guess, maybe "break" would work? Maybe setting the counter out-of-bounds so the loop condition is no longer met? But oh no, you had to use "isChar", the freaking result variable, to break out of the loop.

    Give me a break.


    yeah, you should initialise it to FileNotFound
  • chris 2012-11-29 04:35
    Yank:
    So you're one of those who likes to think the UK knows anything about good English?

    Sure we do. It's just that we also know about French and ancient Greek and we like our spelling to reflect our broad cultural background.;-)
  • Cbuttius 2012-11-29 04:37
    Steve The Cynic:
    Yank:
    So you're one of those who likes to think the UK knows anything about good English?

    Well, I wouldn't want to speak for the Welsh, the Scots, nor the Northern Irish, because I'm English, and they're not. I think England might know something about English. You know, like being where the language actually comes from...

    (Cue Spike Milligan:
    The English, The English, The English are best.
    I wouldn't give tuppence for all the rest.
    )

    ("tuppence": Two pence, that is £0.02, which is worth more than your feeble $0.02, but still not worth all that much.)


    If Spike Milligan made this quote before 1971 then tuppence was 2d not 2p and was worth 1/120th of a pound as there were 240 pence in the old pound.

    Therefore for 2d to be worth more than 2 US cents, the exchange rate GBPUSD would have to have been more than 2.4 (2.4 US dollars to the pound sterling). I'm not sure it ever got that high, even before 1971.

    Of course, back in those days, 2d was worth something, more than 2p is worth now.
  • pencilcase 2012-11-29 04:55
    Steve The Cynic:
    [...(Cue Spike Milligan:
    The English, The English, The English are best.
    I wouldn't give tuppence for all the rest.
    )

    ("tuppence": Two pence, that is £0.02, which is worth more than your feeble $0.02, but still not worth all that much.)

    Actually, that song was by Flanders and Swann, not Milligan. And it was written firmly tongue-in-cheek, not as an actual Yank-bashing exercise. And, since it was written in the 1950s, tuppence was actually worth £0.008333 (12 pennies in a shilling, 20 shillings in a pound).
    3/10 Could Do Better.
  • Nick 2012-11-29 04:58
    (Cue Spike Milligan:
    The English, The English, The English are best.
    I wouldn't give tuppence for all the rest.
    )


    I thought that was part of a song by Flanders and Swann. Basic googling didn't show any connection to Spike Milligan.
  • beano 2012-11-29 04:59
    Cbuttius:
    Steve The Cynic:
    Yank:
    So you're one of those who likes to think the UK knows anything about good English?

    Well, I wouldn't want to speak for the Welsh, the Scots, nor the Northern Irish, because I'm English, and they're not. I think England might know something about English. You know, like being where the language actually comes from...

    (Cue Spike Milligan:
    The English, The English, The English are best.
    I wouldn't give tuppence for all the rest.
    )

    ("tuppence": Two pence, that is £0.02, which is worth more than your feeble $0.02, but still not worth all that much.)


    If Spike Milligan made this quote before 1971 then tuppence was 2d not 2p and was worth 1/120th of a pound as there were 240 pence in the old pound.

    Therefore for 2d to be worth more than 2 US cents, the exchange rate GBPUSD would have to have been more than 2.4 (2.4 US dollars to the pound sterling). I'm not sure it ever got that high, even before 1971.

    Of course, back in those days, 2d was worth something, more than 2p is worth now.


    Before 1970 the pound sterling regularly traded at above $2.40 to the pound.
  • Steve The Cynic 2012-11-29 06:09
    pencilcase:
    Actually, that song was by Flanders and Swann, not Milligan. And it was written firmly tongue-in-cheek, not as an actual Yank-bashing exercise. And, since it was written in the 1950s, tuppence was actually worth £0.008333 (12 pennies in a shilling, 20 shillings in a pound).
    3/10 Could Do Better.

    Bah. Shows the superiority of basic googling versus long-term (i.e. decades since I last heard it) human memory.

    And yes, I know about pounds, shillings, and pence. I was born before the old system was abandoned. As opposed to my youngest colleagues, who weren't even born when the UK stopped putting "NEW PENCE" on coins, in favour of the simpler "PENCE".
  • pencilcase 2012-11-29 06:21
    Steve The Cynic:
    pencilcase:
    Actually, that song was by Flanders and Swann, not Milligan. And it was written firmly tongue-in-cheek, not as an actual Yank-bashing exercise. And, since it was written in the 1950s, tuppence was actually worth £0.008333 (12 pennies in a shilling, 20 shillings in a pound).
    3/10 Could Do Better.

    Bah. Shows the superiority of basic googling versus long-term (i.e. decades since I last heard it) human memory.

    And yes, I know about pounds, shillings, and pence. I was born before the old system was abandoned. As opposed to my youngest colleagues, who weren't even born when the UK stopped putting "NEW PENCE" on coins, in favour of the simpler "PENCE".

    No googling required - I am in my 50th year, and remember "New Pence", or "New Pee" and all this oldie stuff. Hence why I put "pennies", not "pence". But I couldn't see the English song being attributed to SM without reacting. Mind you, if your memory's half as bad as mine is, I'm not surprised at you being a little off the mark. Now, where did I leave my specs...?
  • faoileag 2012-11-29 07:48
    jarfil:
    I really HATE it when people state things in their code that are just not true

    Are they not? I'd say the approach is: "The character at position i is a char until proven otherwise".

    jarfil:
    Oh, right, you have to be able to break out of the look somehow. Let me guess, maybe "break" would work?

    It would work nicely, but a "break" is a "goto" and "gotos" are not allowed in a lot of coding rules.

    jarfil:
    Maybe setting the counter out-of-bounds so the loop condition is no longer met?

    Violates the single-responsibility-principle - the job of "i" is to express the position in the string and not whether the last tested character was not a char.

    jarfil:
    But oh no, you had to use "isChar", the freaking result variable, to break out of the loop

    Yes, because in quite a few circumstances this is the cleanest way to write that test!

    What I really HATE is people ranting about how the style is wrong of otherwise bug-free code.
  • Bart Fargo 2012-11-29 07:51
    Cantabrigian:
    "regex scares me a little, OK, alot actually"

    Aaaaargh! It's "a lot" - two words. You wouldn't write "afew", would you? Then again, it's probably better than writing "allot" (when meaning "a lot", not "share out"). </petpeeve>


    Frankly, my dear, I don't give adamn.
  • faoileag 2012-11-29 07:53
    Mark:
    jarfil:
    Give me a break.
    Or just return false within the loop itself and return true immediately after.

    That would violate the principle of a single exit point for functions, which some coding styles mandate.

    Yes, it can make for ugly code. It nevertheless can be found in a lot of rule books because it has a nice effect on cyclomatic complexity.
  • Tinctorius 2012-11-29 08:06
    What they meant was `allPreviousElementsWereAlpha`, but anyone with a brain would see what `isChar` means.
  • Jason 2012-11-29 13:29
    I almost choked on a Frito when I read this. I had to try this myself to believe it.

    Interestingly, SQL Server will also sort the results even if you omit the ORDER BY clause. You can't make this stuff up.


    UNION doesn't guarantee ordering, but it is likely that the DBMS will sort the intermediate results in order to de-duplicate them. The observed ordering in this case is just a side effect of the implementation, and shouldn't be relied upon (as the specification will probably say that the order of results returned is arbitrary)
  • JJ 2012-11-29 13:41
    4c's A.G.N:
    Cantabrigian:
    "regex scares me a little, OK, alot actually"

    Aaaaargh! It's "a lot" - two words. You wouldn't write "afew", would you? Then again, it's probably better than writing "allot" (when meaning "a lot", not "share out"). </petpeeve>

    Oh, great, another grammar nazi. As if we needed more here, you guys are diamond dozen.

    For all intensive purposes, you're correct.
  • chubertdev 2012-11-29 13:58
    Jason:
    UNION doesn't guarantee ordering, but it is likely that the DBMS will sort the intermediate results in order to de-duplicate them. The observed ordering in this case is just a side effect of the implementation, and shouldn't be relied upon (as the specification will probably say that the order of results returned is arbitrary)


    yeah, sounds like the order of an identity field. tends to appear in order, but no guarantee.

    JJ:
    For all intensive purposes, you're correct.


    troll bait?
  • David 2012-11-29 13:59
    [quote user=Peteris]The OR solution would have different results in cases where a record matches multiple search criteria - in that case, the current solution would include duplicate rows.[/quote]

    No OR and UNION should give the same result. You are thinking of UNION ALL. UNION is the same as "select DISTINCT * from (select UNION ALL select)".
  • Paul Neumann 2012-11-29 16:58
    planB:
    Nonody != Nobody
  • Paul Neumann 2012-11-29 17:52
    Cantabrigian:
    "regex scares me a little, OK, alot actually"

    ]b]<petpeeve>[/b]Aaaaargh! It's "a lot" - two words. You wouldn't write "afew", would you? Then again, it's probably better than writing "allot" (when meaning "a lot", not "share out"). </petpeeve>
    Please use proper markup.
  • Norman Diamond 2012-11-29 18:29
    Steve The Cynic:
    Yank:
    So you're one of those who likes to think the UK knows anything about good English?
    I think England might know something about English.
    Spike Milligan:
    The English, The English, The English are best.
    I wouldn't give tuppence for all the rest.
    ("tuppence": Two pence, that is £0.02, which is worth more than your feeble $0.02, but still not worth all that much.)
    If you're English you oughta know that Spike Milligan's tuppence were 2/240 of a pound not 2/100 of a pound.
  • Norman Diamond 2012-11-29 18:34
    Cbuttius:
    If Spike Milligan made this quote before 1971 then tuppence was 2d not 2p and was worth 1/120th of a pound as there were 240 pence in the old pound.
    Yes, you beat me to it.
    Cbuttius:
    Therefore for 2d to be worth more than 2 US cents, the exchange rate GBPUSD would have to have been more than 2.4 (2.4 US dollars to the pound sterling). I'm not sure it ever got that high, even before 1971.
    You mean like when 1 GBP was 5 USD? The US copied the dollar from Spanish Mexico. England copied some too: two kings' heads weren't worth a crown.
  • Norman Diamond 2012-11-29 18:39
    pencilcase:
    I'm not surprised at you being a little off the mark.
    OF COURSE he is. They've converted to the euro now. (Though not the part that still uses pounds.)
    pencilcase:
    Now, where did I leave my specs...?
    WTF? We're computer professionals here, you know? We don't get no stinking specs.
  • Ben Vail 2012-11-29 20:40
    Indeed, union means the individual parts of the query can use indexes, whereas an OR would prevent any index, so it's not actually a bad idea here, :)
  • Ben Vail 2012-11-29 20:42
    chubertdev:

    JJ:
    For all intensive purposes, you're correct.


    troll bait?


    It's an eggcorn. I used to think this was the phrase too... :)
  • Meep 2012-11-30 00:33
    MySQL geek:
    Actually, here UNION is the same as OR, but in the MySQL point of view, presents a better performance ;)


    Bullshit.

    There is no way
    select x from foo where a = 1 union select x from foo where a = 2
    is more performant than
    select x from foo where a = 1 or a = 2
    .

    You simply can't do multiple table scans and beat a single one; aside from the redundant IO, your UNION requires a hash join to toss duplicate rows.

    And if MySQL's optimizer is not complete shit, the two should have an identical query plans.
  • W. 2012-11-30 08:33
    jarfil:
    for god's sake, don't name them "isChar" like it was the actual result...


    Thanks! I've spent the last two days redoing all my code to include as many premature assertions as possible :)
  • nuby 2012-11-30 09:27
    @Deprecated:
    Larry:
    The problem with regexen is a lot like the problem with library functions: you can never be entirely sure what they're doing. So, in cases like this where the results are important, it is safest to write your own.


    In many cases it is safest NOT to write your own! EG., encryption. Or did I just win a "whooosh"?

    Did he really have to use charAt for two linear ranges?
    I think that if (c >= 'a' && c <= 'z') is less error-prone than "abcdefghijklmnpqrstuvwxyz".chartAt(c) != -1
    Quick, spot the error!


    the error seems to be that in your keyboard the 'o' key is malfunctioning
  • Josh Lange 2012-11-30 17:23
    The union query makes a lot of sense in this situation. It is an optimization over the OR.

    Most database engines don't do a very good job with OR, especially if it is the only condition (there are no columns which can be used as the first column in an index to make the data returned more selective), the table has a lot of rows, and the data is very sparse.

    The OR will be downgraded into a table scan. If there are millions of records, that means millions of compares, and a lot of disk IO.

    In the union query, since the like condition is bounded on the left side (and assuming each of these columns are the first column in at least one index), each sub query will be very selective. The union would then sort and filter out the duplicates (which shouldn't be expensive, as long as the query was very selective).
  • Barf 4Eva 2012-11-30 18:47
    Meep:
    MySQL geek:
    Actually, here UNION is the same as OR, but in the MySQL point of view, presents a better performance ;)


    Bullshit.

    There is no way
    select x from foo where a = 1 union select x from foo where a = 2
    is more performant than
    select x from foo where a = 1 or a = 2
    .

    You simply can't do multiple table scans and beat a single one; aside from the redundant IO, your UNION requires a hash join to toss duplicate rows.

    And if MySQL's optimizer is not complete shit, the two should have an identical query plans.


    This is not an example of the problem in the query listed by the OP. Granted, I feel for the OP's example it is due to a lot of "WTF?", but here the filter is an OR on _different_ columns checking for the same attribute data.. Sometimes these scenarios lend themselves to exlcuding use of an index, depending on the complexity and index setups of course.
  • ledtvreviews 2012-12-01 03:55
    Thank you, very much.................................


  • TOuchy 2012-12-02 17:07
    jarfil:
    var isChar = true; 

    Obvious WTF apart, I really HATE it when people state things in their code that are just not true.

    Do you know it's a Char? NO, not yet. So don't freaking set "isChar" to true! Make your checks, use whatever temporal variables you need, but for god's sake, don't name them "isChar" like it was the actual result... like it IS the actual result, and then you get on and on checking it on each iteration of the loop... WTF!

    Oh, right, you have to be able to break out of the look somehow. Let me guess, maybe "break" would work? Maybe setting the counter out-of-bounds so the loop condition is no longer met? But oh no, you had to use "isChar", the freaking result variable, to break out of the loop.

    Give me a break.
    Other than the naming of the variable, I think your wrong - a LOT.....

    The boolean is used to indicate whether we have found something that invalidates our string from an alpha-only perspective. Assuming you agree NULL/Empty strings are ok, there is little issue startiing in the TRUE state.

    I also have no issue with is being used as a loop condition. If it were better named, it adds clarity that we might shortcut the loop.

    Of course it might have been better to simply return false rather than play with a var, a'la...:

    for (var i=0;(i<sStr.length);i++)
    {
    Char = sStr.charAt(i);
    if (alpha.indexOf(Char)==-1)
    {
    // This is not an alpa
    return false;
    }
    }
    return true;
    //oops, forgot to use num

  • JimFin 2012-12-03 04:11
    jarfil:
    var isChar = true;


    Obvious WTF apart, I really HATE it when people state things in their code that are just not true.

    Do you know it's a Char? NO, not yet. So don't freaking set "isChar" to true.

    OK, what do you suggest?

    function checkAlpha(sStr)
    {
    var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var Char;
    var isSoFarAssumedToBeAlpha = true;
    for (var i=0;(i<sStr.length) && (isChar==true);i++)
    {
    Char = sStr.charAt(i);
    if (alpha.indexOf(Char)==-1)
    {
    isSoFarAssumedToBeAlpha=false;
    }
    }
    return isSoFarAssumedToBeAlpha;
    } //end function

    Bummer. That, too, states something that is not true. It's no longer assumption within the test, it's a fact there.

    Let's try again.

    function checkAlpha(sStr)
    {
    var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var Char;
    var isSoFarAssumedToBeAlpha = true;
    for (var i=0;(i<sStr.length) && (isChar==true);i++)
    {
    Char = sStr.charAt(i);
    if (alpha.indexOf(Char)==-1)
    {
    isSoFarAssumedToBeAlpha=false;
    }
    }
    var isReallyAlpha = isSoFarAssumedToBeAlpha;
    return isReallyAlpha.
    } //end function

    There. Now, we have explicitly coded the transition from assumption to a fact. But, there's still a problem. Assumption actually changed inside the loop, not after it. How do you state something that should always be true when it comes to meaning of the works?

    So, once more.

    function checkAlpha(sStr)
    {
    var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var Char;
    var isReallyAlphaDuringAndBeforeLoop = true;
    for (var i=0;(i<sStr.length) && (isChar==true);i++)
    {
    Char = sStr.charAt(i);
    if (alpha.indexOf(Char)==-1)
    {
    isReallyAlphaDuringAndBeforeLoop=false;
    }
    }
    var isReallyAlpha = isReallyAlphaDuringAndBeforeLoop;
    return isReallyAlpha.
    } //end function

    There, we nailed it! And now that we see what's really going on, we can start fixing the actual bugs there. Also, that is why regexes are so wrong: you really don't know if there are such assumptions, too.
  • G 2012-12-03 06:39
    I can imagine with a too-dumb query planner it will not use the indexes in the "OR" version... do you mean to say MySQL is in fact that dumb though?

    But the "UNION" version is not in fact equivalent in its result, it will return the same row multiple times if it matches on multiple fields. To fix that he would need to add "DISTINCT" or "GROUP BY", and that may very well kill any performance advantage there was...
  • shinyemptyhead 2012-12-03 12:37
    Or, you know, _test_ it.
  • shinyemptyhead 2012-12-03 12:38
    shinyemptyhead:
    Or, you know, _test_ it.


    Bah, was intended to be a reply to the "you can't know what regexen do" comment, but hit reply instead of quote.
  • Paul W 2012-12-06 07:59
    You're an idiot. If that logic were applied, nobody would ever use library functions, but would write *everything* themselves. How is that safe, or a good idea? Library functions have, we assume, been checked a lot more thoroughly than your ad-hoc code!
  • AllThatJazz 2012-12-11 13:47
    The EntityTypeDescription should have been 'AE35'
  • old mysql user 2013-04-19 19:09
    Meep:
    MySQL geek:
    Actually, here UNION is the same as OR, but in the MySQL point of view, presents a better performance ;)


    Bullshit.

    There is no way
    select x from foo where a = 1 union select x from foo where a = 2
    is more performant than
    select x from foo where a = 1 or a = 2
    .

    You simply can't do multiple table scans and beat a single one; aside from the redundant IO, your UNION requires a hash join to toss duplicate rows.

    And if MySQL's optimizer is not complete shit, the two should have an identical query plans.


    Mysql before 5.0 had a limitation of 1 index (you are using indexes, right?) per table per query. So if you had an index on (ProjectCode), an index on (ProjectDesc), an index on (TaskCode), and an index on (TaskDesc), doing the query as written would be much faster because it could use each index once, and merge the results together. Otherwise, with the OR clauses, you'd be looking at a single table scan.

    e.g. http://www.mysqlperformanceblog.com/2012/12/14/the-optimization-that-often-isnt-index-merge-intersection/