Re: Discussion on missing optimizations
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Cc: Andres Freund <andres@anarazel.de>,
Adam Brusselback <adambrusselback@gmail.com>,
Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2017-10-07T16:15:30Z
Lists: pgsql-hackers
Attachments
- convert-x-equals-x.patch (text/x-diff) patch
Petr Jelinek <petr.jelinek@2ndquadrant.com> writes: > On 07/10/17 04:19, Tom Lane wrote: >> (edit: a few minutes later, I seem to remember that equivclass.c has >> to do something special with the X=X case, so maybe it could do >> something else special instead, with little new overhead.) > So I wrote prototype of achieving this optimization and it seems to be > really quite simple code-wise (see attached). I did only a limited > manual testing of this but I don't see any negative impact on planning time. No, I'm afraid you didn't read that comment closely enough. This will flat out fail for cases like "select ... where x=x order by x", because there will already be a single-element EC for x and so the clause will just disappear entirely. If that doesn't happen, then instead you're creating an EC with duplicate entries, which is an idea I seriously dislike; the semantics of that don't seem clear at all to me. What I was imagining was that having detected X=X, instead of "throwing back" the clause as-is we could throw back an X IS NOT NULL clause, along the lines of the attached. This passes the smell test for me in the sense of not adding any significant number of planner cycles except when the weird case occurs. It leaves something on the table in that there are some situations where X=X could be converted, but we won't do it because we don't see the clause as being a potential EC (because it's not at top level), as in the second new regression test case below. I think that's probably all right; I don't see any way to be more thorough without adding a lot of new cycles all the time, and I don't believe this is worth that. regards, tom lane
Commits
-
Reduce "X = X" to "X IS NOT NULL", if it's easy to do so.
- 8ec5429e2f42 11.0 landed