pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: cen <cen.is.imba@gmail.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Postgres undeterministically uses a bad plan, how to convince it otherwise?
Date: Fri, 3 Mar 2023 10:35:21 +0100
Message-ID: <01101f47-e596-cc72-cd7c-d9d027c9b9ef@gmail.com> (raw)
In-Reply-To: <CAApHDvruKcvjLrgu6QwKpQJfeR+w9u6PrbkhGWggdLMAnbZ82Q@mail.gmail.com>
References: <9c98978d-fc72-8655-bb29-5aaa941bee36@gmail.com>
	<9641fdf1-a4d1-2fad-2400-794dcf7dc5cc@gmail.com>
	<0701777f-d9ab-e406-9b90-539eac169410@gmail.com>
	<CAApHDvruKcvjLrgu6QwKpQJfeR+w9u6PrbkhGWggdLMAnbZ82Q@mail.gmail.com>

> 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.








view thread (10+ messages)  latest in thread

Message-ID: <01101f47-e596-cc72-cd7c-d9d027c9b9ef@gmail.com>
Permalink:  ../01101f47-e596-cc72-cd7c-d9d027c9b9ef@gmail.com/
Also on:    postgresql.org/message-id/01101f47-e596-cc72-cd7c-d9d027c9b9ef@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: cen.is.imba@gmail.com, dgrowleyml@gmail.com
  Subject: Re: Postgres undeterministically uses a bad plan, how to convince it otherwise?
  In-Reply-To: <01101f47-e596-cc72-cd7c-d9d027c9b9ef@gmail.com>
  References: <9c98978d-fc72-8655-bb29-5aaa941bee36@gmail.com> <9641fdf1-a4d1-2fad-2400-794dcf7dc5cc@gmail.com> <0701777f-d9ab-e406-9b90-539eac169410@gmail.com> <CAApHDvruKcvjLrgu6QwKpQJfeR+w9u6PrbkhGWggdLMAnbZ82Q@mail.gmail.com> <01101f47-e596-cc72-cd7c-d9d027c9b9ef@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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