pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alex Turner <armtuk@gmail.com>
To: pepone. onrez <pepone.onrez@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: query performance
Date: Sun, 13 Jan 2008 23:43:35 -0500
Message-ID: <33c6269f0801132043x343ea3b5uddbe969595d11630@mail.gmail.com> (raw)
In-Reply-To: <198501d60801132027h1201ba2dk6f596576ae9e48df@mail.gmail.com>
References: <198501d60801131858n529b46dcmeb286cda32d56e93@mail.gmail.com>
	<dcc563d10801131939t6df7fe66n150fde7562362a61@mail.gmail.com>
	<18894.1200282745@sss.pgh.pa.us>
	<198501d60801132027h1201ba2dk6f596576ae9e48df@mail.gmail.com>

If you have to access the data this way (with no where clause at all - which
sometimes you do) then I have already provided a solution that will work
reasonably well.  If you create what is essentially a materialized view of
just the id field, the sequence scan will return much fewer pages than when
you do it on the main table.  Then you join it to the indexed main table,
and page in just the rows you need.  Voila - much faster result.  Of course
we haven't really talked about how that will affect insert speed and delete
speed if you trigger then up, but you haven't really talked about any
requirements there.

Alex

On Jan 13, 2008 11:27 PM, pepone. onrez <pepone.onrez@gmail.com> wrote:

> Sorry Alex i forget mention that i have setscan of in my last test.
>
> now I have set seqscan on  and indexscan on and added order by _id
>
> The table has an index in the _id field
>
> CREATE INDEX i_documentcontent_document
>   ON t_documentcontent
>   USING btree
>   (_document);
>
> The database was rencently vacum analyze , but not vacun full
>
> here is the explain of 2 diferent queries , when i put a large OFFSET
>
>  EXPLAIN ANALYZE SELECT
>     t_documentcontent._id AS _id
>     FROM t_documentcontent ORDER BY _id LIMIT 50 OFFSET 50000
>
> "Limit  (cost=137068.24..137068.36 rows=50 width=58) (actual time=
> 41119.702..41119.792 rows=50 loops=1)"
> "  ->  Sort  (cost=136943.24..137320.26 rows=150807 width=58) (actual
> time=41064.802..41100.424 rows=50050 loops=1)"
> "        Sort Key: _id"
> "        ->  Seq Scan on t_documentcontent  (cost= 0.00..110772.07rows=150807 width=58) (actual time=
> 106.679..33267.194 rows=150807 loops=1)"
> "Total runtime: 41120.015 ms"
>
>  EXPLAIN ANALYZE SELECT
>     t_documentcontent._id AS _id
>     FROM t_documentcontent ORDER BY _id LIMIT 50 OFFSET 10000
>
> "Limit  (cost=39839.37..40038.56 rows=50 width=58) (actual time=
> 1172.969..1194.228 rows=50 loops=1)"
> "  ->  Index Scan using i_documentcontent_id on t_documentcontent  (cost=
> 0.00..600805.54 rows=150807 width=58) (actual time= 0.077..1189.688rows=10050 loops=1)"
> "Total runtime: 1194.316 ms"
>
> Tom
>  i using uuid for the _id field that is the primary key  add a WHERE id >
> ?  don 't apply
> the cursor aproach is also not suitable for same of my queries
>
> I use this query for paginate contents of a filesysstem with lots of
> documents avoid offset is not posible always

view thread (47+ messages)  latest in thread

Message-ID: <33c6269f0801132043x343ea3b5uddbe969595d11630@mail.gmail.com>
Permalink:  ../33c6269f0801132043x343ea3b5uddbe969595d11630@mail.gmail.com/
Also on:    postgresql.org/message-id/33c6269f0801132043x343ea3b5uddbe969595d11630@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: armtuk@gmail.com, pepone.onrez@gmail.com
  Subject: Re: query performance
  In-Reply-To: <33c6269f0801132043x343ea3b5uddbe969595d11630@mail.gmail.com>
  References: <198501d60801131858n529b46dcmeb286cda32d56e93@mail.gmail.com> <dcc563d10801131939t6df7fe66n150fde7562362a61@mail.gmail.com> <18894.1200282745@sss.pgh.pa.us> <198501d60801132027h1201ba2dk6f596576ae9e48df@mail.gmail.com> <33c6269f0801132043x343ea3b5uddbe969595d11630@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox