Re: 512,600ms query becomes 7500ms... but why? Postgres 8.3 query planner quirk?

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Bryce Nesbitt" <bryce2(at)obviously(dot)com>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: 512,600ms query becomes 7500ms... but why? Postgres 8.3 query planner quirk?
Date: 2010-02-12 15:09:41
Message-ID: 4B751AD5020000250002F248@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Bryce Nesbitt <bryce2(at)obviously(dot)com> wrote:

> I've got a very slow query, which I can make faster by doing
> something seemingly trivial.

Out of curiosity, what kind of performance do you get with?:

EXPLAIN ANALYZE
SELECT contexts.context_key
FROM contexts
JOIN articles ON (articles.context_key = contexts.context_key)
JOIN matview_82034 ON (matview_82034.context_key =
contexts.context_key)
WHERE EXISTS
(
SELECT *
FROM article_words
JOIN words using (word_key)
WHERE context_key = contexts.context_key
AND word = 'insider'
)
AND EXISTS
(
SELECT *
FROM article_words
JOIN words using (word_key)
WHERE context_key = contexts.context_key
AND word = 'trading'
)
AND EXISTS
(
SELECT *
FROM virtual_ancestors a
JOIN bp_categories ON (bp_categories.context_key =
a.ancestor_key)
WHERE a.context_key = contexts.context_key
AND lower(bp_categories.category) = 'law'
)
AND articles.indexed
;

(You may have to add some table aliases in the subqueries.)

If you are able to make a copy on 8.4 and test the various forms,
that would also be interesting. I suspect that the above might do
pretty well in 8.4.

-Kevin

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Robert Haas 2010-02-12 15:49:16 Re: Re: Faster CREATE DATABASE by delaying fsync (was 8.4.1 ubuntu karmic slow createdb)
Previous Message Kevin Grittner 2010-02-12 15:05:09 Re: Almost infinite query -> Different Query Plan when changing where clause value