• (nodebb)

    So, it's bad code done badly, and worse than that?

  • LZ79LRU (unregistered)

    SQL: Here comes trouble! PHP: And we'll make it double!

  • (nodebb) in reply to Steve_The_Cynic

    Not only that, I'd say it's probably commonly done bad code done badly, which makes it worse. Most PHP "applications" would probably handle this stuff in a similar way.

  • dusoft (unregistered) in reply to LZ79LRU

    Good joke, but as we know, it's all about programmer and not the language,

  • TheCPUWizard (unregistered)

    Agree on the error handling. And not going to even mention PHP..... But would be interested in thinking what would be believed to be a better solution that provided all of the capabilities of this...

  • LZ79LRU (unregistered) in reply to dusoft

    True that. Much like a certain machine from one of my favorite songs, when it comes to bad developers "you wouldn't believe the things they do."

    Which is why I referenced a quote from a pair whose incompetence is legendary. :)

  • Sauron (unregistered)

    Normal people during Halloween season: Watch horror movies.

    Me during Halloween season: Read CodeSOD on TheDailyWTF.

  • Jonathan (unregistered)

    This looks like one where the complexity is in the problem, not just in the code. If you have to handle a bunch of different messy cases, your code is going to be a bit messy. I.e. like TheCPUWizard commented, I "would be interested in thinking what would be believed to be a better solution that provided all of the capabilities of this."

    The only alternative I can immediately imagine is having the input be one big SQL string - if you're giving the caller this much power, why not just give them SQL?

    (Also, worrying about SQL injection in the front-end to an HPC cluster? Oy. Rewriting this with bind variables sounds like a huge waste of time.)

  • dusoft (unregistered) in reply to LZ79LRU

    You mean similar incompetence as those in Javascript or Java? I agree. Democratization of programming is a good thing. And first tries are often painful.

  • LZ79LRU (unregistered) in reply to dusoft

    I was referring to Team Rocket. The two comic relief bandits from the Pokemon series who are known for their utter incompetence (which even gets recognized in the later series by their commanders) who are renowned for announcing their attempts at stealing a little boys pet electric mouse by proudly stepping out in front of him and doing a dramatic montage with the same text.

    Basically my point was that who ever did this was the Team Rocket of developers. :)

  • (author) in reply to Jonathan

    I mean, the simple answer is "use a query builder library, specifically one that manages an AST or token stream and renders it out to SQL once the query is built". This code would be much simpler if it was just describing the required query, and not also generating the text of the query at the same time. Code generation should always be a two step process: describe the code to be generated as tokens or syntax, then generate text based on that description.

  • (nodebb)

    The "simple" solution if you have any idea what an AST is. For somebody whose dev skills begin and end at iteration, branching, arrays, string diddling, and maybe regexes as a fancy form of string diddling, well, an AST may as well be a warp drive for all the ability those sorts of devs have to handle it.

  • (nodebb)

    PHP echo with \n... Been there, done that.

    When I used to do PHP in an earlier decade, I always looked at the output via raw HTML, thus I always ended echo errors with \n.

    PHP is like bad drugs. You've got to teach the kids to just say no.

  • HonkHonk (unregistered) in reply to TheCPUWizard

    Eloquent, bundled with Laravel, would do this in a much more ... eloquent way:

    Table::select('id', 'name') ->where(...) ->groupBy(...) ->orderBy(...) ->take(...) ->get()

  • NEWZPROZ (unregistered)

    Hey there, Author!

    I just finished reading your article on The Daily WTF, and I couldn't resist dropping a comment. Your take on high-performance queries was not only informative but also incredibly amusing. I've been in the IT industry for quite some time, and I can relate to the "hair-pulling" experiences you described when dealing with poorly optimized database queries. Your writing style, laced with humor, made the topic both entertaining and educational. It's refreshing to see someone who can tackle technical subjects with such wit and charm.

Leave a comment on “High Performance Query”

Log In or post as a guest

Replying to comment #:

« Return to Article