| From: | Zhijie Hou <houzhijie22(at)gmail(dot)com> |
|---|---|
| To: | "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Fix unrecognized scankey subtype error with SP-GiST exclusion constraints |
| Date: | 2026-11-28 14:05:14 |
| Message-ID: | 300d646e-d21f-4b81-aa44-991998a85cd4@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
While testing exclusion constraints with SP-GiST indexes, I noticed that
enforcing an exclusion constraint using SP-GiST box_ops or poly_ops
fails with "unrecognized scankey subtype: 0":
CREATE TABLE t_spg (
b box,
p polygon,
EXCLUDE USING spgist (b WITH &&),
EXCLUDE USING spgist (p WITH &&)
);
INSERT INTO t_spg VALUES ('((0,0),(1,1))', '((0,0),(0,2),(2,0))');
ERROR: unrecognized scankey subtype: 0
In check_exclusion_or_unique_constraint(), ScanKeyEntryInitialize() is
called with InvalidOid for sk_subtype. That works for B-tree, Hash, and
range GiST opclasses because they treat !OidIsValid(sk_subtype) as the
opclass input type (rd_opcintype), and for other GiST/SP-GiST opclasses
that do not inspect sk_subtype.
However, SP-GiST box_ops and poly_ops share
spg_box_quad_inner_consistent() and spg_box_quad_leaf_consistent(),
where spg_box_quad_get_scankey_bbox() switches on sk->sk_subtype (BOXOID
vs. POLYGONOID) to extract the query bounding box and decide whether
recheck is needed. Since spgInnerConsistentIn and spgLeafConsistentIn do
not carry opcintype, spg_box_quad_get_scankey_bbox() cannot infer the
argument type when sk_subtype is InvalidOid.
Attached is a patch that passes index->rd_opcintype[i] as sk_subtype in
check_exclusion_or_unique_constraint(). Since
spg_box_quad_get_scankey_bbox() was introduced in commit ff963b393ca (PG
11), this affects all supported branches.
--
Best Regards,
Zhijie Hou
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Fix-unrecognized-scankey-subtype-error-with-SP-Gi.patch | text/plain | 4.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andrei Lepikhov | 2026-11-28 14:07:59 | Re: Use local buffer for packed numerics |
| Previous Message | Kirill Reshke | 2026-11-28 13:22:25 | Re: Set 1s WaitLatch timeout if standby limit has expired in ResolveRecoveryConflictWithBufferPin |