Re: Slight change in query leads to unexpected change in query plan - Mailing list pgsql-general

From Tom Lane
Subject Re: Slight change in query leads to unexpected change in query plan
Date
Msg-id 13786.1245766316@sss.pgh.pa.us
Whole thread Raw
In response to Re: Slight change in query leads to unexpected change in query plan  (Jack Orenstein <jack.orenstein@hds.com>)
Responses Re: Slight change in query leads to unexpected change in query plan
List pgsql-general
Jack Orenstein <jack.orenstein@hds.com> writes:
>    Limit  (cost=0.00..324.99 rows=100 width=451)
>      ->  Index Scan using t_pkey on t  (cost=0.00..296027.98 rows=91088 width=451)
>            Index Cond: (pk > 1000000000)

> Adding the value restriction at the top of this query plan wouldn't increase the
> cost very much.

You're missing the point: with the value restriction in place, it's
estimating that it will probably have to scan all 91000 rows (because
there are fewer than 100 satisfying the value restriction).  And that
is going to cost somewhere north of 296027 cost units --- the cost
shown, plus 91000 invocations of the value-restriction check.
Which is considerably more than the cost of the other plan.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Explaining functions.
Next
From: David Fetter
Date:
Subject: Re: [BUGS] Integrity check