From: Frank Joerdens <frank@joerdens.de>
To: pgsql-performance@postgresql.org
Cc: Nic <nferrier@tapsellferrier.co.uk>
Cc: Seb Potter <seb@woome.com>
Subject: Re: Query w empty result set with LIMIT orders of magnitude slower than without (SOLVED, pls disregard)
Date: Tue, 26 Aug 2008 17:59:49 +0100
Message-ID: <7d10d2df0808260959g4284009bt90d028e23e68a015@mail.gmail.com> (raw)
Eh, there was a spurious join in that query which was created by an
ORM which messed things up apparently. Sorry for the noise. This
abstracted version of the original query that does the same is fast:
woome=> EXPLAIN ANALYZE
SELECT *
FROM webapp_invite i
INNER JOIN webapp_person p ON (i.id = p.id)
WHERE p.is_suspended = false
AND p.is_banned = false
AND i.woouser = 'suggus'
ORDER BY i.id DESC LIMIT 5;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=4549.51..4549.52 rows=5 width=238) (actual
time=0.071..0.071 rows=0 loops=1)
-> Sort (cost=4549.51..4549.58 rows=31 width=238) (actual
time=0.070..0.070 rows=0 loops=1)
Sort Key: i.id
Sort Method: quicksort Memory: 25kB
-> Nested Loop (cost=12.20..4548.99 rows=31 width=238)
(actual time=0.036..0.036 rows=0 loops=1)
-> Bitmap Heap Scan on webapp_invite i
(cost=12.20..1444.45 rows=382 width=44) (actual time=0.034..0.034
rows=0 loops=1)
Recheck Cond: ((woouser)::text = 'suggus'::text)
-> Bitmap Index Scan on
webapp_invite_woouser_idx (cost=0.00..12.10 rows=382 width=0) (actual
time=0.032..0.032 rows=0 loops=1)
Index Cond: ((woouser)::text = 'suggus'::text)
-> Index Scan using webapp_person_pkey on
webapp_person p (cost=0.00..8.11 rows=1 width=194) (never executed)
Index Cond: (p.id = i.id)
Filter: ((NOT p.is_suspended) AND (NOT p.is_banned))
Total runtime: 0.183 ms
(13 rows)
Time: 1.114 ms
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: frank@joerdens.de, nferrier@tapsellferrier.co.uk, seb@woome.com
Subject: Re: Query w empty result set with LIMIT orders of magnitude slower than without (SOLVED, pls disregard)
In-Reply-To: <7d10d2df0808260959g4284009bt90d028e23e68a015@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