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

2010-02-15 Thread Robert Haas
On Sat, Feb 13, 2010 at 2:58 AM, Bryce Nesbitt bry...@obviously.com wrote: So as the op, back to the original posting In the real world, what should I do?  Does it make sense to pull the AND articles.indexed clause into an outer query?  Will that query simply perform poorly on other

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

2010-02-12 Thread Kevin Grittner
Bryce Nesbitt bry...@obviously.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

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

2010-02-12 Thread Karl Denninger
Exists can be quite slow. So can not exists See if you can re-write it using a sub-select - just replace the exists with (select ...) is not null Surprisingly this often results in a MUCH better query plan under Postgresql. Why the planner evaluates it better eludes me (it shouldn't) but

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

2010-02-12 Thread Kevin Grittner
Karl Denninger k...@denninger.net wrote: Kevin Grittner wrote: I suspect that the above might do pretty well in 8.4. Exists can be quite slow. So can not exists See if you can re-write it using a sub-select - just replace the exists with (select ...) is not null Surprisingly

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

2010-02-12 Thread Karl Denninger
Yes: select forum, * from post where marked is not true and toppost = 1 and (select login from ignore_thread where login='xxx' and number=post.number) is null and (replied now() - '30 days'::interval) and (replied (select lastview from forumlog where login='xxx' and

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

2010-02-12 Thread Kevin Grittner
Karl Denninger k...@denninger.net wrote: Kevin Grittner wrote: Have you seen such a difference under 8.4? Can you provide a self-contained example? Yes: [query and EXPLAIN ANALYZE of fast query] The alternative: [query with no other information] goes nuts. Which means what?

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

2010-02-12 Thread Tom Lane
Karl Denninger k...@denninger.net writes: Explain Analyze on the alternative CLAIMS the same query planner time (within a few milliseconds) with explain analyze. But if I replace the executing code with one that has the alternative (not exists) syntax in it, the system load goes to crap

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

2010-02-12 Thread Bryce Nesbitt
Kevin Grittner wrote: Bryce Nesbitt bry...@obviously.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

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

2010-02-12 Thread Bryce Nesbitt
So as the op, back to the original posting In the real world, what should I do?  Does it make sense to pull the "AND articles.indexed" clause into an outer query?  Will that query simply perform poorly on other arbitrary combinations of words? I'm happy to test any given query against