Re: Why search term results different query plan?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Erol Öz <eroloz(at)esg(dot)com(dot)tr>
Cc: "PostgreSQL General List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why search term results different query plan?
Date: 2001-09-30 02:31:44
Message-ID: 178.1001817104@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"=?iso-8859-9?B?RXJvbCDWeg==?=" <eroloz(at)esg(dot)com(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-09-30 02:37:24 Re: Why search term results different query plan?
Previous Message sean-pgsql-general 2001-09-30 02:08:26 Re: Encoding passwords