pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Tom Lane <tgl@sss.pgh.pa.us>
To: Paul Ramsey <pramsey@cleverelephant.ca>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Allowing extensions to supply operator-/function-specific info
Date: Tue, 05 Mar 2019 18:56:11 -0500
Message-ID: <25179.1551830171@sss.pgh.pa.us> (raw )
In-Reply-To: <A9E1964E-AD79-48B7-8F63-1D7B0A3F2A89@cleverelephant.ca >
References: <15193.1548028093@sss.pgh.pa.us >
<6953.1548297558@sss.pgh.pa.us >
<6044.1548524131@sss.pgh.pa.us >
<CA+TgmoYkLjVcbZZ8PYyaCTMYZJCQ8eiod8MSRMDaczjBw=a0bQ@mail.gmail.com >
<19993.1548697885@sss.pgh.pa.us >
<CACowWR3jZ4Xo1atU5xTDpEoeeKSw1==sKPhCy3a29HtcE9oQVQ@mail.gmail.com >
<7671.1551135674@sss.pgh.pa.us >
<CACowWR3_RyPSYO6a8TVLZ7KnL_rDNh2ywkSTeqFmrAPpP4y6-g@mail.gmail.com >
<11051.1551139751@sss.pgh.pa.us >
<CACowWR1ycbLx0t7WwT8uuJnK7E3U+tfzKXBRPaQrgHiCG+hvbA@mail.gmail.com >
<14747.1551219541@sss.pgh.pa.us >
<91BAE1F4-7C16-4F87-849F-B01175A8D7D8@cleverelephant.ca >
<17244.1551226168@sss.pgh.pa.us >
<74C11775-67A7-48D2-B1E3-24C52A686F86@cleverelephant.ca >
<15086.1551310830@sss.pgh.pa.us >
<BBB5F584-5036-4A11-B5FF-D30632EC9E1A@cleverelephant.ca >
<24277.1551320775@sss.pgh.pa.us >
<CACowWR3fZRV6fGrH7vsVLqLz0TQJpmzb=wcipqAQBVZSn0sT4g@mail.gmail.com >
<26156.1551734021@sss.pgh.pa.us >
<B256FF5D-EF73-4FDE-A50D-9C9E9FB3B159@cleverelephant.ca >
<31607.1551739943@sss.pgh.pa.us >
<48F6F422-4! ! ! F50-4DA6-A6A1-13C4AA1B9D27@cleverelephant.ca >
<914.1551745379@sss.pgh.pa.us >
<B021B357-A20A-4FDD-8657-062A8899C9A1@cleverelephant.ca >
<24446.1551828396@sss.pgh.pa.us >
<A9E1964E-AD79-48B7-8F63-1D7B0A3F2A89@cleverelephant.ca >
Paul Ramsey <pramsey@cleverelephant.ca> writes:
> On Mar 5, 2019, at 3:26 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Hm, I think your addition of this bit is wrong:
>>
>> + /*
>> + * Arguments were swapped to put the index value on the
>> + * left, so we need the commutated operator for
>> + * the OpExpr
>> + */
>> + if (swapped)
>> + {
>> + oproid = get_commutator(oproid);
>> + if (!OidIsValid(oproid))
>> PG_RETURN_POINTER((Node *)NULL);
>> + }
>>
>> We already did the operator lookup with the argument types in the desired
>> order, so this is introducing an extra swap. The only reason it appears
>> to work, I suspect, is that all your index operators are self-commutators.
> I was getting regression failures until I re-swapped the operator…
> SELEcT * FROM foobar WHERE ST_Within(ConstA, VarB)
Ah ... so the real problem here is that *not* all of your functions
treat their first two inputs alike, and the hypothetical future
improvement I commented about is needed right now. I should've
looked more closely at the strategies in your table; then I would've
realized the patch as I proposed it didn't work.
But this code isn't right either. I'm surprised you're not getting
crashes --- perhaps there aren't cases where the first and second args
are of incompatible types? Also, it's certainly wrong to be doing this
sort of swap in only one of the two code paths.
There's more than one way you could handle this, but the way that
I was vaguely imagining was to have two strategy entries in each
IndexableFunction entry, one to apply if the first function argument
is the indexable one, and the other to apply if the second function
argument is the indexable one. If you leave the operator lookup as
I had it (using the already-swapped data types) then you'd have to
make sure that the latter set of strategy entries are written as
if the arguments get swapped before selecting the strategy, which
would be confusing perhaps :-( --- for instance, st_within would
use RTContainedByStrategyNumber in the first case but
RTContainsStrategyNumber in the second. But otherwise you need the
separate get_commutator step, which seems like one more catalog lookup
than you really need.
> I feel OK about it, if for no other reason than it passes all the tests :)
Then you're at least missing adequate tests for the 3-arg functions...
3 args with the index column second will not work as this stands.
regards, tom lane
view thread (38+ messages) latest in thread
Message-ID: <25179.1551830171@sss.pgh.pa.us>
Permalink: ../25179.1551830171@sss.pgh.pa.us/
Also on: postgresql.org/message-id/25179.1551830171@sss.pgh.pa.us
copy link · copy postgr.es
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 using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, pramsey@cleverelephant.ca, pgsql-hackers@lists.postgresql.org
Subject: Re: Allowing extensions to supply operator-/function-specific info
In-Reply-To: <25179.1551830171@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