• fruey (unregistered)

    It's only fetching the current item_id... not the whole table, unless I'm very much mistaken...

  • Kluge Doctor (unregistered)

    With a computers, we can bring OCD to the next level!

  • Kluge Doctor (unregistered) in reply to fruey
    fruey:
    It's only fetching the current item_id... not the whole table, unless I'm very much mistaken...
    It's the whole table of item_id, every record!
  • (cs)

    Select $WTF From Comments Where TRWTF = 'Stupid Developer';

  • anon-e moose (unregistered)

    better to be safe than sorry

  • (cs)

    For a while I was playing an online (American) football sim. Rather than buying forum software (which they could have easily afforded) they decided to write their own. Their justification came down to about 7 different ways of saying "because we want to."

    Anyway, one of the things they heard constantly was that their forums ran too slow. Turns out they were calculating # of posts on every page load. The turned off post count (instead of just fixing the bug) and forums sped up by several orders of magnitude.

  • (cs)

    So ... the real WTF is the forum software? That has never happened before.

  • PleegWat (unregistered)

    Isn't TRWTF the forum software on THIS site?

  • (cs)

    They're allocating 100 characters for the item_id? What are they putting in there, the item's full name and postal address?

  • benza (unregistered) in reply to PleegWat

    Too bad we don't have the full query, I'm pretty sure it does not even add the item_id and item_lang columns.

  • (cs)

    Brillant!

  • (cs) in reply to fruey
    fruey:
    It's only fetching the current item_id... not the whole table, unless I'm very much mistaken...

    It executes an SQL query that would fetch all rows (no LIMIT). PHP probably fetches the resulting rows, and even if it doesn't, the poor database server has its work cut out.

  • Mike (unregistered)

    And here I thought that the WTF was the "item cache" which is slower than what it's intended to cache...

  • D2oris (unregistered) in reply to gabba
    gabba:
    So ... the real WTF is the forum software? That has never happened before.

    Win.

  • blah (unregistered)

    This code reminds me of a certain interview WTF.

    "The alter statements lead you to run the CREATE TABLE query, but there is no CREATE TABLE in SQL. What do you do?"

  • Thomas P (unregistered) in reply to gabba

    Google code search gives the answer:

    http://anotherraid.googlecode.com/svn/trunk/ar/itemstats/includes/itemcache.php

    The software home page: http://code.google.com/p/anotherraid/ A World of Warcraft raid tracking, planning and in the future dkp-point system.

  • (cs) in reply to taylonr
    taylonr:
    The turned off post count (instead of just fixing the bug) and forums sped up by several orders of magnitude.
    That is quite impressive. Let's say it now takes one second to load a page. Before they disabled the count, it was taking one thousand seconds (three orders of magnitude), which is sixteen minutes and forty seconds. I admire your patience to wait that long for a single page!
  • (cs)

    What could have possibly been the intention of the developer who wrote this? After the first time it runs, the table is there. End of story!

    It would have been more efficient to simply catch a database error (which you should be doing anyway) and notify someone there was a problem.

    {Forgive me if I simply stated the obvious}

  • alx (unregistered) in reply to gabba

    This just checks to see if items are cached. if not they are added in the cache table.

    My understanding is that the code above should increase performance

  • Anon (unregistered) in reply to dpm
    dpm:
    taylonr:
    The turned off post count (instead of just fixing the bug) and forums sped up by several orders of magnitude.
    That is quite impressive. Let's say it now takes one second to load a page. Before they disabled the count, it was taking one thousand seconds (three orders of magnitude), which is sixteen minutes and forty seconds. I admire your patience to wait that long for a single page!

    I'd assume taylonr measures their orders of magnitude as powers of 2 instead of powers of 10. Therefore, 3 orders of magnitude would only be 8 seconds (still longer than I'd be willing to wait).

  • silent d (unregistered)

    They need to talk to Aaron from this WTF to learn about “WHERE clauses and other optimization techniques.”

    Also, am I the only one that thinks ALTERing db tables on the fly is a bad idea?

  • Waffle (unregistered) in reply to Thomas P
    Thomas P:
    Google code search gives the answer:

    http://anotherraid.googlecode.com/svn/trunk/ar/itemstats/includes/itemcache.php

    The software home page: http://code.google.com/p/anotherraid/ A World of Warcraft raid tracking, planning and in the future dkp-point system.

    RAS Syndrome !

  • orv (unregistered)

    Is the real WTF that you're using a hunk of opensource code and you didn't file that as a bug or submit a fix?

  • (cs) in reply to ParkinT
    ParkinT:
    What could have possibly been the intention of the developer who wrote this?

    Well, it makes perfect sense if you look at how they purge the cache:

    function PurgeItemCache($bNewConnection = false)
    {
       $this->sql = new SqlHelper(dbhost, dbname, dbuser, dbpass, $bNewConnection);
       $this->connected = $this->sql->connected;
    
       $query = "DROP TABLE item_cache";
       $this->sql->query($query);
    }
  • (cs)

    TRWTF is that noone has mentioned the blatantly incorrect use of ALTER TABLE within application code...

  • (cs)

    It's good practise to make sure the table is still there.

    After all, if it wasn't there, what would you take pictures against?

  • (cs) in reply to snoofle
    snoofle:
    Select $WTF From Comments Where TRWTF = 'Stupid Developer';
    This should be a featured comment.
  • SawFred (unregistered) in reply to FredSaw
    FredSaw:
    snoofle:
    Select $WTF From Comments Where TRWTF = 'Stupid Developer';
    This should be a featured comment.
    This should be a featured comment.
  • Morasique (unregistered)

    The real WTF is the app apparently has full privileges on the database instead of SELECT/UPDATE. Forget the massive SELECT being run all the time, if you're creating/altering tables at runtime you're doing something wrong

  • skin (unregistered) in reply to Morasique

    agreed!

  • (cs) in reply to Morasique
    Morasique:
    The real WTF is the app apparently has full privileges on the database instead of SELECT/UPDATE. Forget the massive SELECT being run all the time, if you're creating/altering tables at runtime you're doing something wrong
    This code is just waiting for Bobby Tables to come around...
  • AlanGriffiths (unregistered) in reply to SawFred
    SawFred:
    FredSaw:
    snoofle:
    Select $WTF From Comments Where TRWTF = 'Stupid Developer';
    This should be a featured comment.
    This should be a featured comment.
    This is not a featured comment!
  • fruey (unregistered) in reply to Kluge Doctor

    Sorry my bad.

    SELECT item_id FROM item_cache

    there's no WHERE clause at all, you are totally right. WTF?

  • (cs)

    look at the bright side: at least its not creating a new SQL connection every time its called ;D

  • (cs)

    I was sooo disappointed when this post had nothing to do with a wooden table!

  • (cs) in reply to PerdidoPunk
    PerdidoPunk:
    TRWTF is that noone has mentioned the blatantly incorrect use of ALTER TABLE within application code...
    Well, there are uses for ALTER TABLE in an application, but that isn't one of them. At most, they should go into an admin part that's only used every now and then...

    np: Underworld - I'm A Big Sister, And I'm A Girl, And I'm A Princess, And This Is My Horse (RiverRun Project)

  • (cs) in reply to Arancaytar
    Arancaytar:
    It executes an SQL query that would fetch all rows (no LIMIT). PHP probably fetches the resulting rows, and even if it doesn't, the poor database server has its work cut out.

    PHP doesn't fetch any rows automatically, at least not with any of the APIs that I've used.

    Still, the DBMS has to perform a full table scan for each comment.

    Beyond that, this code is just too stupid to comprehend.

  • Andrew (unregistered) in reply to dpm
    dpm:
    taylonr:
    The turned off post count (instead of just fixing the bug) and forums sped up by several orders of magnitude.
    That is quite impressive. Let's say it now takes one second to load a page. Before they disabled the count, it was taking one thousand seconds (three orders of magnitude), which is sixteen minutes and forty seconds. I admire your patience to wait that long for a single page!

    Maybe, they're binary orders of magnitude. 2N grows a bit slower than 10M. Eight seconds is tolerable.

  • AlexG (unregistered) in reply to blah
    blah:
    This code reminds me of a certain interview WTF.

    "The alter statements lead you to run the CREATE TABLE query, but there is no CREATE TABLE in SQL. What do you do?"

    The alter statements lead you to run the CREATE TABLE query, but there is no CREATE TABLE in SQL. Why is that, Leon?

  • DHager (unregistered)

    Anon, Andrew:

    I too thought: "Maybe he meant binary?"

    But on further reflection I can think of any time I've ever seen someone use intelligently use the phrase "orders of magnitude" in anything but base ten.

    So no. It can't be binary. If you're someone who wants to justify " orders of magnitude" as a binary scale, then you're just as depraved as those hard drive companies and their "GB=1000KB".

  • reading nazi (unregistered) in reply to Andrew

    But reading earlier posts is not?

  • (cs) in reply to Markp
    Markp:
    ParkinT:
    What could have possibly been the intention of the developer who wrote this?

    Well, it makes perfect sense if you look at how they purge the cache:

    function PurgeItemCache($bNewConnection = false)
    {
       $this->sql = new SqlHelper(dbhost, dbname, dbuser, dbpass, $bNewConnection);
       $this->connected = $this->sql->connected;
    
       $query = "DROP TABLE item_cache";
       $this->sql->query($query);
    }

    Given the sterling quality of the original submission, I have to ask: do the damnfools actually purge the cache this way?

  • Anrs (unregistered) in reply to dpm
    dpm:
    taylonr:
    The turned off post count (instead of just fixing the bug) and forums sped up by several orders of magnitude.
    That is quite impressive. Let's say it now takes one second to load a page. Before they disabled the count, it was taking one thousand seconds (three orders of magnitude), which is sixteen minutes and forty seconds. I admire your patience to wait that long for a single page!

    Maybe your assumption is wrong, and it now takes 0,07 seconds to load the page. And maybe "several" can be just two.

  • Monkey Brains (unregistered) in reply to Andrew
    Andrew:
    dpm:
    taylonr:
    The turned off post count (instead of just fixing the bug) and forums sped up by several orders of magnitude.
    That is quite impressive. Let's say it now takes one second to load a page. Before they disabled the count, it was taking one thousand seconds (three orders of magnitude), which is sixteen minutes and forty seconds. I admire your patience to wait that long for a single page!

    Maybe, they're binary orders of magnitude. 2N grows a bit slower than 10M. Eight seconds is tolerable.

    Perhaps he meant it in an emotional sense and not a mathematical one, being without a stopwatch and all.

    Some posters will jump at any chance to display their superior math skills.

  • Sigivald (unregistered) in reply to gabba
    So ... the real WTF is the forum software? That has never happened before.

    You seem to have an extraneous "the" in there. Let me help:

    the real WTF is forum software.

    You're welcome.

    (Actually, I think the WTF-for-reals is having to use BBCode.)

  • (cs) in reply to Leak
    Leak:
    PerdidoPunk:
    TRWTF is that noone has mentioned the blatantly incorrect use of ALTER TABLE within application code...
    Well, there are uses for ALTER TABLE in an application, but that isn't one of them. At most, they should go into an admin part that's only used every now and then...

    I can't think of any situations where altering the database from within application code is the best strategy. However, I'm always on the lookout for better ways to do things. Could you give an example of a use case where altering the DB schema from application code is best practice? (Or maybe you were just trying to be sarcastic in your comment...)

  • (cs) in reply to DHager
    DHager:
    Anon, Andrew:

    I too thought: "Maybe he meant binary?"

    But on further reflection I can think of any time I've ever seen someone use intelligently use the phrase "orders of magnitude" in anything but base ten.

    So no. It can't be binary. If you're someone who wants to justify " orders of magnitude" as a binary scale, then you're just as depraved as those hard drive companies and their "GB=1000KB".

    Ah, the black swan excuse. "I've never seen it, so it can't be true." Or, more precisely in your case, "I may have seen it, but I can't remember it, so from a personal cognitive point of view, it can't be true." Or alternatively, by redefining the sense of "intelligently," you are guilty of petitio principii.

    I've always been accustomed to think of the final order of magnitude in base ten as "any multiple higher than the square root of ten, and less than ten to the power of 3/2" which just feels like a better bracketing system, somehow.

    Anyhow ... you're completely ignoring, amongst other things, Pogson's system for measuring apparent magnitude, which measured orders of magnitude by the intuitively obvious multiple of the fifth root of one hundred.

    If you squinted hard at that web page, maybe it just looked enough like half of the North Star ...

  • (cs)

    Thank God it was a db table, not a wooden one.

    Imagine a system where every time you request a page, it is printed, put on a wooden table, having a picture taken of it, then that picture is developed, scanned in and shown. But first we need to check if the table is still there, of course. If it is not there, instead of TRUE (picture was taken) or FALSE (picture was not taken), it returns WOODEN_TABLE_NOT_FOUND, leading to the CD tray to open and the server to reset...

  • silent d (unregistered) in reply to SQB
    SQB:
    Thank God it was a db table, not a wooden one.

    If it was a wooden table, the app would need to contact a carpenter every time it needed to CREATE a new table or ALTER an existing one.

    But to DROP a table, anyone strong enough to pick up the table in the first place will do.

  • Bobbo (unregistered) in reply to Anrs
    Anrs:
    And maybe "several" can be just two.

    Oxford English dicco says maybe it can't.

    Just saying, like.

Leave a comment on “Yes, the Table is Still There”

Log In or post as a guest

Replying to comment #:

« Return to Article