Skip site navigation (1) Skip section navigation (2)

Re: Performance of count(*)

From: "Craig A(dot) James" <cjames(at)modgraph-usa(dot)com>
To: Brian Hurt <bhurt(at)janestcapital(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Performance of count(*)
Date: 2007-03-22 17:02:00
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
Brian Hurt wrote:
>> One of our biggest single problems is this very thing.  It's not a 
>> Postgres problem specifically, but more embedded in the idea of a 
>> relational database: There are no "job status" or "rough estimate of 
>> results" or "give me part of the answer" features that are critical to 
>> many real applications.
> For the "give me part of the answer", I'm wondering if cursors wouldn't 
> work (and if not, why not)?

There is no mechanism in Postgres (or any RDB that I know of) to say, "Give me rows 1000 through 1010", that doesn't also execute the query on rows 1-1000.  In other words, the RDBMS does the work for 1010 rows, when only 10 are needed -- 100 times more work than is necessary.

Limit/Offset will return the correct 10 rows, but at the cost of doing the previous 1000 rows and discarding them.

Web applications are stateless.  To use a cursor, you'd have to keep it around for hours or days, and create complex "server affinity" code to direct a user back to the same server of your server farm (where that cursor is being held), on the chance that the user will come back and ask for rows 1000 through 1010, then a cursor isn't up to the task.


In response to

pgsql-performance by date

Next:From: Bill MoranDate: 2007-03-22 17:03:35
Subject: Re: Potential memory usage issue
Previous:From: Carlos MorenoDate: 2007-03-22 16:58:45
Subject: Re: Performance of count(*)

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group