Skip to Content.
Sympa Menu

freetds - Re: [freetds] absolute fetches

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT schemamania.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] absolute fetches
  • Date: Tue, 8 Apr 2003 04:02:49 -0400

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.

--jkl




Archive powered by MHonArc 2.6.24.

Top of Page