Re: Why search term results different query plan? - Mailing list pgsql-general

From Tom Lane
Subject Re: Why search term results different query plan?
Date
Msg-id 178.1001817104@sss.pgh.pa.us
Whole thread Raw
In response to Why search term results different query plan?  ("Erol Öz" <eroloz@esg.com.tr>)
List pgsql-general
"=?iso-8859-9?B?RXJvbCDWeg==?=" <eroloz@esg.com.tr> writes:
> Could anybody give me hint, or reccomend a source about this:
> Please note that two queries are different only in search terms (STAR and
> A). Plan and performane difference between them confused me.

Note the difference in the estimated number of rows matched in
product_t:

>          ->  Seq Scan on product_t p  (cost=0.00..613.41 rows=1 width=94)

>          ->  Seq Scan on product_t p  (cost=0.00..613.41 rows=8321 width=94)

The planner thinks --- not unreasonably, IMHO --- that LIKE '%A%' will
match many more rows than LIKE '%STAR%'.  Accordingly, it prepares
different plans for the two cases.

Since you're complaining, I suppose that LIKE '%STAR%' matches many more
rows than random chance would suggest, and so that plan turns out to be
poorly chosen.

            regards, tom lane

pgsql-general by date:

Previous
From: sean-pgsql-general@chittenden.org
Date:
Subject: Re: Encoding passwords
Next
From: Tom Lane
Date:
Subject: Re: Why search term results different query plan?