Re: Hashed SAOP on composite type with non-hashable column errors at runtime

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrei Lepikhov <lepihov(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org, Peter Eisentraut <peter(at)eisentraut(dot)org>
Subject: Re: Hashed SAOP on composite type with non-hashable column errors at runtime
Date: 2026-06-05 18:12:02
Message-ID: 3735597.1780683122@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Andrei Lepikhov <lepihov(at)gmail(dot)com> writes:
> There is an issue when we use a record-based array operation in SQL:

> EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, BUFFERS OFF, SUMMARY OFF)
> SELECT count(*) FROM test
> WHERE (a,b) = ANY (ARRAY[
> (1, 'w1'::tsvector), (2, 'w2'::tsvector), (3, 'w3'::tsvector),
> (4, 'w4'::tsvector), (5, 'w5'::tsvector), (6, 'w6'::tsvector),
> (7, 'w7'::tsvector), (8, 'w8'::tsvector), (9, 'w9'::tsvector)
> ]);
> ERROR: could not identify a hash function for type tsvector

Yeah, this is a bug, but I don't think you've identified the
full scope of the problem. In the first place, there's another
get_op_hash_functions call in selfuncs.c that's also at risk.
In the second place, the same hazard exists for range and
multirange types, which can have non-hashable subtypes.
AFAICT noplace at all is defending against that.

So I'm unexcited about putting the fix for this into
convert_saop_to_hashed_saop_walker as you've done here.
I think it needs to be addressed at the level of the relevant
lsyscache.c lookup functions, so that there's some chance that
future code additions will get this right. Draft fix attached.

I can't get excited about the test case you suggest;
it's rather expensive and it will do nothing whatever
to guard against future mistakes of the same kind.

I'm also unexcited about your 0002 and 0003. I don't really
care about optimizing the anonymous-record case; by and large,
it's coincidental that complicated operations work at all on
anonymous record types.

regards, tom lane

Attachment Content-Type Size
v1-0001-Fix-missed-checks-for-hashability-of-container-ty.patch text/x-diff 13.1 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2026-06-05 18:17:21 Re: Hashed SAOP on composite type with non-hashable column errors at runtime
Previous Message Matheus Alcantara 2026-06-05 18:09:26 Re: BUG #19480: PL/Python SRF crashes (SIGSEGV) when function is replaced mid-iteration: use-after-free in PLy_funct