From: Tom Lane <tgl@sss.pgh.pa.us>
To: arnaulist@andromeiberica.com
Cc: pgsql-performance@postgresql.org
Subject: Re: Is it possible to speed this query up?
Date: Wed, 26 Jul 2006 16:24:47 -0400
Message-ID: <17741.1153945487@sss.pgh.pa.us> (raw)
In-Reply-To: <44C79FED.5080702@andromeiberica.com>
References: <44C79FED.5080702@andromeiberica.com>
Arnau <arnaulist@andromeiberica.com> writes:
> the explain analyze shouts the following:
The expensive part appears to be this indexscan:
> -> Index Scan using pk_agndusrgrp_usergroup on
> agenda_users_groups ug (cost=0.00..123740.26 rows=2936058 width=30)
> (actual time=0.101..61921.260 rows=2836638 loops=1)
Since there's no index condition, the planner is evidently using this
scan just to obtain sort order. I think ordinarily it would use a
seqscan and then sort the final result, which'd be a lot faster if the
whole result were being selected. But you have a LIMIT and it's
mistakenly guessing that only a small part of the table will need to be
scanned before the LIMIT is satisfied.
Bottom line: try dropping the LIMIT. If you really need the limit to be
enforced on the SQL side, you could try declaring the query as a cursor
and only fetching 150 rows from it.
regards, tom lane
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, arnaulist@andromeiberica.com
Subject: Re: Is it possible to speed this query up?
In-Reply-To: <17741.1153945487@sss.pgh.pa.us>
* 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