| From: | Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | 王跃林 <violin0613(at)tju(dot)edu(dot)cn>, pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>, 3764353996 <3764353996(at)qq(dot)com> |
| Subject: | Re: Fw:Re: Fw: gbt_var_consistent in contrib/btree_gist/btree_utils_var.c has internal-node type confusion on the <> strategy, bypassing exclusion constraints |
| Date: | 2026-07-02 17:46:04 |
| Message-ID: | CAJTYsWVus+7hn846A0gMJYk+9uUGZxizk5Herbxb4CmhF3vndQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi,
On Thu, 2 Jul 2026 at 22:24, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com> writes:
> > On Thu, 2 Jul 2026 at 20:08, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >> None of this passes the smell test for me. If it's unsafe to
> >> call the type's f_eq function on a truncated key, how is it
> >> any safer to call the f_cmp function?
>
> > I think the difference is that for bit/varbit f_eq and f_cmp aren't the
> > same kind of function. f_eq is biteq (reads bit_len, does VARSIZE-8),
> > while f_cmp is byteacmp (plain byte-wise, only needs the varlena
> > header).
>
> Oh! You are right, the internal keys are *not* valid bit/varbit
> values, just bytea. The level of non-documentation in this code
> is staggering.
>
> So the actual API contract here is that f_eq etc. are to be used only
> on leaf keys, while f_cmp is to be used only on internal keys. It's
> not too surprising that whoever added NotEqual support didn't know
> that, it being documented nowhere.
>
> It kind of looks actually like there's an expectation that all
> internal keys are effectively bytea's; note the naming of
> gbt_bytea_pf_match, despite the fact that it's applied to all
> types under the purview of btree_utils_var.c.
>
> Anyway, I think part of our work here has got to be to raise the
> level of documentation of this code. I've had it with having
> to reverse-engineer details as fundamental as these.
>
I've added some documentation in code, patch attached.
Please help reviewing if it looks good or should we be adding
something more.
Regards,
Ayush
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-Fix-btree_gist-strategy-on-internal-index-pages.patch | application/octet-stream | 5.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Geoghegan | 2026-07-02 18:32:31 | Re: BTree index corruption (heap-tid-past-end, unexpected zero page, misplaced TID in posting list) recurring on high-churn tables, PG 18.3, data_checksums=on, no preceding crash |
| Previous Message | Thom Brown | 2026-07-02 16:58:07 | EXPLAIN (VERBOSE) fails with for JSON_ARRAYAGG/JSON_OBJECTAGG + window function |