Hi all,
Given a query that returns 10,000 rows
if I just want the first 100
Am I better calling fetchrow_hashref 100 times
or
Should I just call fetchall_arrayref get all 10,000 and take the first 100 rows in the array.
my thinking is the query has returned all the data so I am better just to fetch it all rather than repeatedly fetching some of the rows in a loop.
I think fetchall is better as I can use the array size to get the total rowcount instead of doing a second query with a count(*). Assuming I cant rely on $dbh->rows() for selects.
so 1 query with fetchall , using array size for the total rows
or 2 query multiple limited fetchrow calls and using count for total rows
I guess I am asking is it in theory worth just trying to fetch only what you need if it means you have to do a second query to find the total rows.
cheers
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.