pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Richard Guo <guofenglinux@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Reducing duplicativeness of EquivalenceClass-derived clauses
Date: Wed, 26 Oct 2022 09:54:17 -0400
Message-ID: <217731.1666792457@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMbWs4-6-ywf8AoQJ9z48q+v1eL5Scsw-d_nsr9s+dm-Ge4VGA@mail.gmail.com>
References: <78062.1666735746@sss.pgh.pa.us>
	<CAMbWs4-6-ywf8AoQJ9z48q+v1eL5Scsw-d_nsr9s+dm-Ge4VGA@mail.gmail.com>

Richard Guo <guofenglinux@gmail.com> writes:
> On Wed, Oct 26, 2022 at 6:09 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> The only thing that I think might be controversial here is that
>> I dropped the check for matching operator OID.  To preserve that,
>> we'd have needed to use get_commutator() in the reverse-match cases,
>> which it seemed to me would be a completely unjustified expenditure
>> of cycles.  The operators we select for freshly-generated clauses
>> will certainly always match those of previously-generated clauses.
>> Maybe there's a chance that they'd not match those of ec_sources
>> clauses (that is, the user-written clauses we started from), but
>> if they don't and that actually makes any difference then surely
>> we are talking about a buggy opclass definition.

> The operator is chosen according to the two given EC members's data
> type.  Since we are dealing with the same pair of EC members, I think
> the operator is always the same one. So it also seems no problem to drop
> the check for operator. I wonder if we can even add an assertion if
> we've found a RestrictInfo from ec_derives that the operator matches.

Yeah, I considered that --- even if somehow an ec_sources entry isn't
an exact match, ec_derives ought to be.  However, it still didn't seem
worth a get_commutator() call.  We'd basically be expending cycles to
check that select_equality_operator yields the same result with the same
inputs as it did before, and that doesn't seem terribly interesting to
check.  I'm also not sure what's the point of allowing divergence
from the requested operator in some but not all paths.

I added a bit of instrumentation to count how many times we need to build
new join clauses in create_join_clause.  In the current core regression
tests, I see this change reducing the number of new join clauses built
here from 9673 to 5142 (out of 26652 calls).  So not quite 50% savings,
but pretty close to it.  That should mean that this change is about
a wash just in terms of the code it touches directly: each iteration
of the search loops is nearly twice as expensive as before, but we'll
only need to do about half as many.  So whatever we save downstream
is pure gravy.

			regards, tom lane





view thread (6+ messages)  latest in thread

Message-ID: <217731.1666792457@sss.pgh.pa.us>
Permalink:  ../217731.1666792457@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/217731.1666792457@sss.pgh.pa.us

 · 

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-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, guofenglinux@gmail.com
  Subject: Re: Reducing duplicativeness of EquivalenceClass-derived clauses
  In-Reply-To: <217731.1666792457@sss.pgh.pa.us>
  References: <78062.1666735746@sss.pgh.pa.us> <CAMbWs4-6-ywf8AoQJ9z48q+v1eL5Scsw-d_nsr9s+dm-Ge4VGA@mail.gmail.com> <217731.1666792457@sss.pgh.pa.us>

* 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