Re: Cross-type index comparison support in contrib/btree_gin

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Arseniy Mukhin <arseniy(dot)mukhin(dot)dev(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Cross-type index comparison support in contrib/btree_gin
Date: 2025-07-02 17:59:17
Message-ID: 3533666.1751479157@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Arseniy Mukhin <arseniy(dot)mukhin(dot)dev(at)gmail(dot)com> writes:
> Sorry, I think I wasn't clear enough. I agree with this logic, but I
> think it implies an impossible scenario for the "equals" case. The
> scenario where during a scan we first have keys that are less than
> orig_datum, and then a key that is equal to orig_datum. Why I think
> such a scenario is impossible: GIN uses partial_key as a lower bound
> when positioning the start of a partial match scan. So if there is any
> key in the index that is equal to "partial key", it must be the very
> first key in the scan. Then if the very first key in the scan is less
> than orig_datum, that means partial_key was also less than orig_datum
> (because partial_key is a lower bound). And the only reason
> partial_key might not be equal to orig_datum is that there is no value
> equal to orig_datum in the index type. So we can say that if the very
> first key in the scan is less than orig_datum, then there is no key in
> the index that could be equal to orig_datum, and we can stop right
> there.

OK, I got your point finally. It seems perhaps a little fragile
to write the code like this, but I agree that it should work.

v5 attached incorporates your test additions and responds to your
other review suggestions. Also, I changed the representation of
the opclass strategy numbers to use 4 bits for the btree strategy,
because I realized that we could write the strategy numbers in the
.sql file as hex literals and thereby improve readability --- the
RHS type and the btree strategy are now independent hex digits
in the DDL.

regards, tom lane

Attachment Content-Type Size
v5-0001-Break-out-xxx2yyy_opt_overflow-APIs-for-more-date.patch text/x-diff 9.4 KB
v5-0002-Preliminary-refactoring.patch text/x-diff 7.6 KB
v5-0003-Add-cross-type-comparisons-for-integer-types.patch text/x-diff 36.5 KB
v5-0004-Add-cross-type-comparisons-for-float-types.patch text/x-diff 14.0 KB
v5-0005-Add-cross-type-comparisons-for-string-types.patch text/x-diff 8.4 KB
v5-0006-Add-cross-type-comparisons-for-datetime-types.patch text/x-diff 37.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Burd 2025-07-02 18:10:19 Re: Expanding HOT updates for expression and partial indexes
Previous Message Nathan Bossart 2025-07-02 17:37:37 Re: add function for creating/attaching hash table in DSM registry