Re: Postgres undeterministically uses a bad plan, how to convince it otherwise?

From: cen <cen(dot)is(dot)imba(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Postgres undeterministically uses a bad plan, how to convince it otherwise?
Date: 2023-03-03 09:35:21
Message-ID: 01101f47-e596-cc72-cd7c-d9d027c9b9ef@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Likely to be safe, you'd just include both. The problem is that the
> query planner makes use of equivalence classes to deduce equivalence
> in quals.
>
> If you have a query such as:
>
> select * from t1 inner join t2 on t1.x = t2.y where t1.x = 3;
>
> then the planner can deduce that t2.y must also be 3 and that qual can
> be pushed down to the scan level. If t2.y = 3 is quite selective and
> there's an index on that column, then this deduction is likely going
> to be a very good win, as the alternative of not using it requires
> looking at all rows in t2.

Does equivalency only work for constants as in the sample you provided
or will it also be found in b1."number" and t0."block_number" in my
sample query?

Meaning the columns could be used interchangeably in all the WHERE
clauses and the ORDER clause, then it is a matter of figuring out what
costs less.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Rowley 2023-03-03 10:29:15 Re: Postgres undeterministically uses a bad plan, how to convince it otherwise?
Previous Message Alban Hertroys 2023-03-03 08:31:03 Re: DISTINCT *and* ORDER BY in aggregate functions on expressions(!)y