in reply to DBI with ORDER BY

You may already know this, nevertheless, perhaps your colleague was referring to the database not storing the data in a specific order, and it is possible that you misheard. ;-)

The database first selects the data per your instructions, and only then applies the SORT on the selected set in a db buffer. Inherently there is no order in the database.

DBI itself is an abstraction layer as others have mentioned. And while I haven't experienced it, it is possible that fetchall_hashref buggers up the specified ORDER. Other than that, no, DBI doesn't mess with your instructions to fetch the data.

Perhaps a friendly discussion with your co-worker will shed more light. Be sure to come back and update this thread so we may all learn for the better.

--

when small people start casting long shadows, it is time to go to bed

Replies are listed 'Best First'.
Re^2: DBI with ORDER BY
by YoungPups (Beadle) on Mar 10, 2005 at 21:25 UTC

    I just got my code review, and it sounds like it was more of a philosophical objection on his part. He's of the opinion that you should handle sorting in your program rather than make the DB do it. I disagree (pretty strongly), but that is at least a reasonable objection.

    Most places I've worked, the machines that hosted our DBs were much beefier than the machines we did processing on, so I always made the database do as much of the work as I could. Plus, it seems to me to be a bit like reinventing the wheel to sort the results of a query in your script when the DB can do it for you, and is specifically set up to optimize such a sort.

    Anyway, it sounds like I had just misheard why he was asking other coders to avoid ORDER BY statements.

      I agree with you. In fact, I would say, get the db to do as much of set-based text processing as you can. It not the beefiness of the db servers that I think of -- it is the decades of heavy-duty, focused research on working with sets. Databases are just super at performing those tasks. Just check the query plan for any query -- it is pretty amazing.

      Otoh, dbs are a royal pain in the derierre working with arrays and hashes kinda datasets. Once you get your data, nicely stuffed in an array, Perl can whip through it at close to machine speed (well, pretty much) searching for arbit. patterns and repurposing it as desired.

      Maybe it is time for your code-reviewer to get a code review. ;-)

      --
      when small people start casting long shadows, it is time to go to bed