in reply to More on selecting rows with DBI...

Glancing through the cheetah book, there's three ways to get data from DBI: row methods (each time you call the method, it returns the next row), atomic methods (for returning only one row, doesn't help you), and batch methods (fetchall_arrayref(), selectall_arrayref(), like chromatic mentioned). The batch methods can indeed knock a system on its behind if the result set is big; it's certainly better to prepare and execute your SELECT, roughly make sure you can handle the results, then use fetchall_arrayref rather than selectall_arrayref. If you don't use all the data, though, this can be wasteful. If you're grabbing sequential sections of the result set (which it looked like from your question), I don't see a problem with just doing atomic fetches 20 times a pop when you need the next set.

If you're using MySQL (I haven't used any other rdbms), LIMIT is a good option, like others have said. From the manual: "mysql> select * from table LIMIT 5,10; # Retrieve rows 6-15" looks like what you need. But unless the offset parameter of LIMIT can be a bound value (anyone know?), I think you'd take a performance hit for having the DB redo the query plan each time.

A side note that bit me: if you want to use LIMIT with UPDATE, you'll need MySQL 3.23.

Replies are listed 'Best First'.
RE: Re: More on selecting rows with DBI...
by btrott (Parson) on May 02, 2000 at 20:00 UTC
    Actually, I don't think the binding of the value is that much of an issue with MySQL. According to the Appendix in the DBI book, MySQL doesn't actually support bound variables--the use of placeholders is merely emulated by DBI. Can anyone who actually has the DBI book confirm this? :)
      The MySQL book (Paul DuBois) explicitly states that queries aren't cached, in the section on placeholders.

      He also says that you might as well use them, because if you port to another database, you might get the benefit there. I'd add that they make your queries easier to read and they do quoting for you automatically. Save yourself some trouble.

        Oh, yes, I definitely would recommend using bind variables. :) It's just that in this particular case of MySQL-specific syntax (LIMIT [offset], rows), it's worthwhile to note that MySQL doesn't actually support bound variables; so it's not an issue in this *particular* case.

        In general, though, it's *highly* recommended.