[PATCH] btree_gist: add cross-type integer operator support for GiST

First seen: 2026-05-02 17:26:43+00:00 · Messages: 3 · Participants: 1

Latest Update

2026-06-04 · claude-opus-4-6

Monthly Summary: Cross-type integer operator support for btree_gist (May 2026)

Overview

This thread proposes adding cross-type operator family entries to btree_gist for integer types (int2, int4, int8), addressing a long-standing usability gap where GiST indexes silently fail to match index quals when the query datum type differs from the indexed column type.

The Problem

When a query like WHERE camera_id = 1189 is issued against an int8 column, the parser resolves 1189 as int4 and selects =(int8, int4) from pg_operator. For B-tree indexes, cross-type operators are registered in the opfamily, so op_in_opfamily() succeeds. For gist_int8_ops, only same-type =(int8, int8) is registered, causing the planner to silently drop the qual from index consideration.

This is particularly damaging for multi-column GiST indexes (e.g., GIST (scalar_col, range_col)) used for exclusion constraints and range overlap queries, where the scalar equality is typically the most selective predicate. ORMs and parameterized queries routinely send int4 literals, creating a silent performance cliff.

Proposed Design

typedef struct gbt_subtype_info {
    Oid         subtype;
    gbt_cmp_fn  lt, le, eq, ge, gt;
    gbt_dist_fn dist;
} gbt_subtype_info;

Open Design Questions

  1. Whether reusing btree's existing cross-type comparison functions (btint48cmp, etc.) via amproc lookup would be cleaner than a hand-rolled dispatch table.
  2. Whether gistvalidate() needs adjustment to avoid warnings about operators lacking matching support procs.
  3. KNN distance overflow safety for cross-type subtraction.
  4. Whether a framework-level fix (teaching GiST to look up cross-type comparisons generically) would be preferable to per-opclass tables.

Current Status

The thread remains an initial RFC with no patch posted and no community response. The author bumped the thread once during the month to draw attention, but received no feedback from committers or reviewers. The proposal is still awaiting its first substantive review.

History (1 prior analysis)
2026-06-04 · claude-opus-4-6

Incremental Update: Partial patch attached — first concrete implementation

The original author (alexandernst) has now posted an actual partial patch, moving the thread from pure RFC status to having reviewable code. This is the first substantive progress since the thread began.

What's new

The patch is described as containing "only the main code changes" — intentionally omitting regression tests and documentation. The author is seeking early feedback on the core approach before investing in the full submission.

Significance

This is the critical transition from "is there interest?" to "here is the implementation." Reviewers can now evaluate:

  1. Whether the dispatch-table approach described in the RFC is what was actually implemented
  2. How cross-type comparisons are handled within the INT{2,4,8}KEY structures
  3. Whether amvalidate() issues are addressed or deferred
  4. The actual catalog changes (ALTER OPERATOR FAMILY ... ADD OPERATOR entries)
  5. How the KNN distance operator handles overflow for cross-type subtraction

What's still missing

  • No regression tests
  • No documentation updates
  • No reviewer or committer feedback yet
  • The author explicitly gates further work on whether the approach is deemed "reasonable"

The thread remains waiting for community review. The ball is now in reviewers' court to assess the implementation strategy.