Skip to content

fix: inject btree_gist for any scalar element under gist (#81) - #104

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/81-btree-gist-injection
Oct 20, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/81-btree-gist-injection

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #81

Problem

btree_gist was injected only for a GiST exclusion constraint with an = element, and the method was compared case-sensitively:

b.HasExclusionConstraint(ex => ex.WithColumn(x => x.DeskId, "<>").WithOverlaps(x => x.Period));
b.HasExclusionConstraint(ex => ex.WithEquality(x => x.DeskId).WithOverlaps(x => x.Period).UseMethod("GiST"));

Both scaffolded without CREATE EXTENSION, and on a database without the extension both failed at apply with 42704: data type integer has no default operator class for access method "gist".

Change

  • NpgsqlComplexIndexMigrationsModelDiffer: NeedsBtreeGist replaces the = check. It applies when the method is gist (ordinal-ignore-case) and an element is either a column whose store type has no default GiST operator class of its own, or an expression compared with a B-tree operator (=, <>, !=, <, <=, >, >=). Types with their own: ranges and multiranges (by suffix), box, circle, point, polygon, tsvector, tsquery, and the extension types geometry, geography, box2d, box3d, ltree, cube, hstore, seg. Anything else, an unknown store type and arrays included, injects. Over-injecting costs an IF NOT EXISTS no-op; under-injecting fails the migration.
  • ResolvedExclusionPart carries the column's store type, kept out of equality so a column type change does not rebuild the constraint (PostgreSQL rebuilds its index with the column).
  • One change in behaviour beyond the fix: a constraint over range elements only (period WITH =, period WITH &&) no longer injects btree_gist. The PostgreSQL 16 test shows it applies without the extension.
  • Tests: Postgres16IntegrationTests is new, with its own postgres:16 container and one fresh database per test. PostgresIntegrationTests' "inconclusive locally, fail on CI" rule moved into RequireDatabase so both classes share it. The CI job keeps its name, Integration (PostgreSQL 18), and runs both through TestCategory=Integration.
  • Docs: docs/postgresql-constraints.md, the packed PostgreSQL README, the XML doc on NpgsqlExclusionConstraintExtensions, CLAUDE.md and CONTRIBUTING.md now say "scalar elements, whatever the operator". One ### Fixed line goes into the root and PostgreSQL changelogs.

Tests

  • NpgsqlExclusionConstraintDifferTests: <> on an integer injects first, UseMethod("GiST") injects, and range elements alone do not.
  • Postgres16IntegrationTests: on a fresh database, the <> constraint applies and rejects an overlapping row on another desk (23P01), UseMethod("GiST") applies and installs btree_gist, and range-only applies without it.
  • With the old rule restored, all six fail. Both <> and GiST fail on PostgreSQL 16 with 42704, and range-only fails because the old rule injects. With only the case-insensitive comparison reverted, both GiST tests fail.
  • Full suite, integration included: 404 passed.

🤖 Generated with Claude Code

btree_gist was injected only for a gist exclusion constraint with an '='
element, compared case-sensitively. A scalar element compared with '<>'
(or any other operator) got no CREATE EXTENSION, and UseMethod("GiST")
skipped it; on a database without the extension both failed at apply with
42704 "data type integer has no default operator class for access method
gist".

The differ now injects it when the method is gist in any spelling and an
element is a column whose store type has no default GiST operator class of
its own, or an expression under a B-tree operator. Range elements alone no
longer inject it, since ranges carry their own.

Postgres16IntegrationTests applies each case to a fresh database on
PostgreSQL 16; the shared PostgreSQL 18 database usually has btree_gist
installed by an earlier test, which hid the failure. Proven by restoring
the old rule: three differ tests and three PostgreSQL 16 tests fail, two
with 42704; restoring only the case-sensitive comparison fails both
UseMethod("GiST") tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 5.5.0 milestone Oct 20, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working severity/low Cosmetic, message or documentation-level difference package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints labels Oct 20, 2026
# Conflicts:
#	CHANGELOG.md
#	src/EFCore.ComplexIndexes.PostgreSQL/CHANGELOG.md
@CaffeinatedCoder
CaffeinatedCoder merged commit 75fe23e into main Oct 20, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/81-btree-gist-injection branch October 20, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints bug Something isn't working package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

btree_gist is injected only for gist with '=', and UseMethod("GiST") skips it

1 participant