[freetds] absolute fetches

James K. Lowden jklowden at schemamania.org
Tue Apr 8 04:02:49 EDT 2003

On Mon, 07 Apr 2003 17:09:52 -0400, Jon Pounder <JonP at inline.net> wrote:
> Ok, is there any other way then to quickly run through the first n
> records and throw away the results ?
> eg: I want rows 100 to 110, from looking at the code now, I gather than
> to implement this, rows 1 to 99 are actually all transferred from the db
> server to the driver and then thrown away, is there any facility for
> doing a fetch_next without actually transferring the data ?

No, Jon, there's not.  The TDS protocol is a pipe.  You send it a query;
it sends you results.  The results don't live *anywhere* except in the
pipe.  Unlike other database systems (of which I know only a little),
there's no server-side memory cache for the client library to talk to. 
The server simply selects the rows you specify, and shoots them out the
pipe.  Or dribbles, as the case may be.  

That's why you can't know the rowcount until the query's been processed
and the rows fetched.  The server doesn't itself know how many rows there
were until it shipped them all.  

As Frediano said, there are several SQL techniques to compensate:
temporary tables with identity columns, T-SQL cursors, even (ugh!) the
"top" modifier, lately.  However, except in unusual circumstances, none of
these will be faster than simply reading and discarding the rows you're
trying to skip.  


More information about the FreeTDS mailing list