pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
full text search index scan query plan changed in 8.4.2?
3+ messages / 3 participants
[nested] [flat]

* full text search index scan query plan changed in 8.4.2?
@ 2010-02-28 20:42  xu fei <autofei@yahoo.com>
  0 siblings, 1 reply; 3+ messages in thread

From: xu fei @ 2010-02-28 20:42 UTC (permalink / raw)
  To: pgsql-hackers@postgresql.org

Hi, hackers:

I am testing the index used by full text search recently.

I have install 8.3.9 and 8.4.2 separately. 

In 8.3.9, the query plan is like:

postgres=# explain SELECT s.name as source , t.name as target FROM element as s, element as t WHERE to_tsvector('testcfg',s.name)  @@ to_tsquery('testcfg',replace(t.name,':','|'));                                                                         QUERY PLAN                     ------------------------------------------------------------------------------------------------------------------------------------------------------------ 
Nested Loop  (cost=0.01..259.92 rows=491 width=18)   
 ->  Seq Scan on element t  (cost=0.00..13.01 rows=701 width=9)   
 ->  Index Scan using element_ftsidx_test on element s  (cost=0.01..0.33 rows=1 width=9)         
     Index Cond: (to_tsvector('testcfg'::regconfig, (s.name)::text) @@ to_tsquery('testcfg'::regconfig, replace((t.name)::text, ':'::text, '|'::text)))
(4 rows)

I have index: "element_ftsidx_test" gin (to_tsvector('testcfg'::regconfig, name::text))

The same index and query in 8.4.2: 

postgres=# explain SELECT s.name as source , t.name as target FROM element as s, element as t WHERE to_tsvector('testcfg',s.name)  @@ to_tsquery('testcfg',replace(t.name,':','|')) ;                                                                            QUERY PLAN               ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
Nested Loop  (cost=0.32..3123.51 rows=2457 width=18)   
 ->  Seq Scan on element t  (cost=0.00..13.01 rows=701 width=9)   
 ->  Bitmap Heap Scan on element s  (cost=0.32..4.36 rows=4 width=9)              Recheck Cond: (to_tsvector('testcfg'::regconfig, (s.name)::text) @@ to_tsquery('testcfg'::regconfig, replace((t.name)::text, ':'::text, '|'::text)))         
        ->  Bitmap Index Scan on element_ftsidx_test  (cost=0.00..0.32 rows=4 width=0)
             Index Cond: (to_tsvector('testcfg'::regconfig, (s.name)::text) @@ to_tsquery('testcfg'::regconfig, replace((t.name)::text, ':'::text, '|'::text)))
(6 rows)

Why the query plans are different and why? Thanks!

Xu Fei


      




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [HACKERS] full text search index scan query plan changed in 8.4.2?
@ 2010-02-28 22:41  Josh Berkus <josh@agliodbs.com>
  parent: xu fei <autofei@yahoo.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Josh Berkus @ 2010-02-28 22:41 UTC (permalink / raw)
  To: xu fei <autofei@yahoo.com>; +Cc: pgsql-performance

Xufei,

List changed to psql-performance, which is where this discussion belongs.

> I am testing the index used by full text search recently.
> 
> I have install 8.3.9 and 8.4.2 separately. 
> 
> In 8.3.9, the query plan is like:
> 
> postgres=# explain SELECT s.name as source , t.name as target FROM element as s, element as t WHERE to_tsvector('testcfg',s.name)  @@ to_tsquery('testcfg',replace(t.name,':','|'));                                                                         QUERY PLAN                     ------------------------------------------------------------------------------------------------------------------------------------------------------------ 
> Nested Loop  (cost=0.01..259.92 rows=491 width=18)   
>  ->  Seq Scan on element t  (cost=0.00..13.01 rows=701 width=9)   
>  ->  Index Scan using element_ftsidx_test on element s  (cost=0.01..0.33 rows=1 width=9)         
>      Index Cond: (to_tsvector('testcfg'::regconfig, (s.name)::text) @@ to_tsquery('testcfg'::regconfig, replace((t.name)::text, ':'::text, '|'::text)))
> (4 rows)
> 
> I have index: "element_ftsidx_test" gin (to_tsvector('testcfg'::regconfig, name::text))
> 
> The same index and query in 8.4.2: 
> 
> postgres=# explain SELECT s.name as source , t.name as target FROM element as s, element as t WHERE to_tsvector('testcfg',s.name)  @@ to_tsquery('testcfg',replace(t.name,':','|')) ;                                                                            QUERY PLAN               ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
> Nested Loop  (cost=0.32..3123.51 rows=2457 width=18)   
>  ->  Seq Scan on element t  (cost=0.00..13.01 rows=701 width=9)   
>  ->  Bitmap Heap Scan on element s  (cost=0.32..4.36 rows=4 width=9)              Recheck Cond: (to_tsvector('testcfg'::regconfig, (s.name)::text) @@ to_tsquery('testcfg'::regconfig, replace((t.name)::text, ':'::text, '|'::text)))         
>         ->  Bitmap Index Scan on element_ftsidx_test  (cost=0.00..0.32 rows=4 width=0)
>              Index Cond: (to_tsvector('testcfg'::regconfig, (s.name)::text) @@ to_tsquery('testcfg'::regconfig, replace((t.name)::text, ':'::text, '|'::text)))
> (6 rows)
> 
> Why the query plans are different and why? Thanks!

Because the row estimates changed, since 8.4 improved row estimation for
TSearch.  The 2nd query is probably actually faster, no?  If not, you
may need to increase your stats collection.  Or at least show us a
VACUUM ANALYZE.

--Josh Berkus




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [HACKERS] full text search index scan query plan changed in 8.4.2?
@ 2010-03-01 02:38  Chris <dmagick@gmail.com>
  parent: Josh Berkus <josh@agliodbs.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Chris @ 2010-03-01 02:38 UTC (permalink / raw)
  To: Josh Berkus <josh@agliodbs.com>; +Cc: xu fei <autofei@yahoo.com>; pgsql-performance

Josh Berkus wrote:
> Xufei,
> 
> List changed to psql-performance, which is where this discussion belongs.
> 
>> I am testing the index used by full text search recently.
>>
>> I have install 8.3.9 and 8.4.2 separately. 
>>
>> In 8.3.9, the query plan is like:
>>
>> postgres=# explain SELECT s.name as source , t.name as target FROM element as s, element as t WHERE to_tsvector('testcfg',s.name)  @@ to_tsquery('testcfg',replace(t.name,':','|'));                                                                         QUERY PLAN                     ------------------------------------------------------------------------------------------------------------------------------------------------------------ 
>> Nested Loop  (cost=0.01..259.92 rows=491 width=18)   
>>  ->  Seq Scan on element t  (cost=0.00..13.01 rows=701 width=9)   
>>  ->  Index Scan using element_ftsidx_test on element s  (cost=0.01..0.33 rows=1 width=9)         
>>      Index Cond: (to_tsvector('testcfg'::regconfig, (s.name)::text) @@ to_tsquery('testcfg'::regconfig, replace((t.name)::text, ':'::text, '|'::text)))
>> (4 rows)
>>
>> I have index: "element_ftsidx_test" gin (to_tsvector('testcfg'::regconfig, name::text))
>>
>> The same index and query in 8.4.2: 
>>
>> postgres=# explain SELECT s.name as source , t.name as target FROM element as s, element as t WHERE to_tsvector('testcfg',s.name)  @@ to_tsquery('testcfg',replace(t.name,':','|')) ;                                                                            QUERY PLAN               ------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
>> Nested Loop  (cost=0.32..3123.51 rows=2457 width=18)   
>>  ->  Seq Scan on element t  (cost=0.00..13.01 rows=701 width=9)   
>>  ->  Bitmap Heap Scan on element s  (cost=0.32..4.36 rows=4 width=9)              Recheck Cond: (to_tsvector('testcfg'::regconfig, (s.name)::text) @@ to_tsquery('testcfg'::regconfig, replace((t.name)::text, ':'::text, '|'::text)))         
>>         ->  Bitmap Index Scan on element_ftsidx_test  (cost=0.00..0.32 rows=4 width=0)
>>              Index Cond: (to_tsvector('testcfg'::regconfig, (s.name)::text) @@ to_tsquery('testcfg'::regconfig, replace((t.name)::text, ':'::text, '|'::text)))
>> (6 rows)
>>
>> Why the query plans are different and why? Thanks!
> 
> Because the row estimates changed, since 8.4 improved row estimation for
> TSearch.  The 2nd query is probably actually faster, no?  If not, you
> may need to increase your stats collection.  Or at least show us a
> VACUUM ANALYZE.

I'm sure you mean explain analyze :)

-- 
Postgresql & php tutorials
http://www.designmagick.com/




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2010-03-01 02:38 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-02-28 20:42 full text search index scan query plan changed in 8.4.2? xu fei <autofei@yahoo.com>
2010-02-28 22:41 ` Josh Berkus <josh@agliodbs.com>
2010-03-01 02:38   ` Chris <dmagick@gmail.com>

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