The following bug has been logged online:
Bug reference: 4940
Logged by: Robert Treat
Email address: xzilla@users.sourceforge.net
PostgreSQL version: 8.3.7
Operating system: Linux 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008
x86_64 x86_64 x86_64 GNU/Linux
Description: Performance regression between 8.2 and 8.3.7
Details:
Upgrading from 8.2 to 8.3.7, I get a worse plan... verified settings /
hardware / analyze all good. if i push the ORDER BY to an outer select, I
get 8.2's plan.
new bad plan:
# explain analyze SELECT forum_thread_id FROM forums_threads WHERE NOT
is_locked AND active AND (to_tsvector('english', title) @@
to_tsquery('english', 'mario')) ORDER BY last_updated_tsz DESC OFFSET 0
LIMIT 20;
QUERY PLAN
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------
Limit (cost=0.00..3222.14 rows=20 width=12) (actual
time=1634.956..15483.223 rows=20 loops=1)
-> Index Scan Backward using forums_threads_last_updated_tsz_idx on
forums_threads (cost=0.00..202511.62 rows=1257 width=12) (actual
time=1634.951..15483.145 rows=20 loops=1)
Filter: ((NOT is_locked) AND active AND
(to_tsvector('english'::regconfig, title) @@ '''mario'''::tsquery))
Total runtime: 15483.367 ms
(4 rows)
better plan that matches 8.2:
# explain analyze select * from (SELECT forum_thread_id, last_updated_tsz
FROM forums_threads WHERE NOT is_locked AND active AND
(to_tsvector('english', title) @@ to_tsquery('english', 'mario')) OFFSET 0
LIMIT 20) x order by last_updated_tsz DESC;
QUERY PLAN
----------------------------------------------------------------------------
----------------------------------------------------------------------------
---------
Sort (cost=61.47..61.52 rows=20 width=12) (actual time=0.284..0.300
rows=20 loops=1)
Sort Key: forums_threads.last_updated_tsz
Sort Method: quicksort Memory: 25kB
-> Limit (cost=0.00..60.84 rows=20 width=12) (actual time=0.083..0.230
rows=20 loops=1)
-> Index Scan using forums_threads_title_gin_idx on forums_threads
(cost=0.00..3823.73 rows=1257 width=12) (actual time=0.080..0.192 rows=20
loops=1)
Index Cond: (to_tsvector('english'::regconfig, title) @@
'''mario'''::tsquery)
Filter: ((NOT is_locked) AND active)
Total runtime: 0.391 ms
(8 rows)
Not sure there is anything I can do settings wise to fix this, seems like
performance regression; any thoughts?