Skip to content

fix: quoted identifiers with uppercase letters cause index lookup failures#286

Merged
tjgreen42 merged 2 commits intomainfrom
fix/case-sensitive-index-names
Mar 13, 2026
Merged

fix: quoted identifiers with uppercase letters cause index lookup failures#286
tjgreen42 merged 2 commits intomainfrom
fix/case-sensitive-index-names

Conversation

@tjgreen42
Copy link
Copy Markdown
Collaborator

Summary

  • Fix index name resolution failure when using quoted identifiers with uppercase letters (e.g., CREATE INDEX "IX_foo" ...)
  • Use quote_qualified_identifier() instead of psprintf("%s.%s", ...) when constructing schema-qualified index names internally
  • Add regression test covering uppercase index names, uppercase schema names, and combinations

Root cause

When constructing schema-qualified index names during INSERT and scan operations, the code used psprintf("%s.%s", schema, relname) which produced unquoted strings like public.IX_foo. These were then parsed by stringToQualifiedNameList() which follows SQL identifier rules and lowercases unquoted identifiers to ix_foo, causing get_relname_relid() to fail the catalog lookup.

The fix uses Postgres's quote_qualified_identifier() which properly quotes identifiers that need quoting (e.g., producing public."IX_foo").

Affected paths:

  • INSERT (via tp_insert in build.c)
  • Index scan with non-search-path schemas (via tp_get_qualified_index_name in scan.c)
  • User-supplied schema-qualified names to to_bm25query(), bm25_dump_index(), etc. (these require the user to quote properly, matching standard SQL behavior)

Fixes #285

Testing

New quoted_identifiers regression test covers:

  1. Uppercase index name — INSERT, SELECT, UPDATE, DELETE, VACUUM
  2. Uppercase schema name with lowercase index
  3. Both uppercase schema and index
  4. Schema-qualified queries via to_bm25query()
  5. Debug functions (bm25_dump_index, bm25_summarize_index) with quoted names

…lures

Use quote_qualified_identifier() instead of psprintf("%s.%s", ...) when
constructing schema-qualified index names internally. The old approach
produced unquoted names like "public.IX_foo" which stringToQualifiedNameList()
lowercased to "ix_foo", failing the catalog lookup.

Fixes #285
@tjgreen42 tjgreen42 marked this pull request as ready for review March 13, 2026 17:13
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — straightforward fix swapping psprintf for quote_qualified_identifier, with good regression test coverage.

Extended reasoning...

Overview

This PR fixes a bug where uppercase letters in quoted identifiers (e.g., CREATE INDEX "IX_foo" ...) caused index lookup failures. The fix is a minimal 2-line change in build.c and scan.c, replacing psprintf("%s.%s", schema, relname) with PostgreSQL's built-in quote_qualified_identifier(). A new quoted_identifiers regression test with 9 test cases is added, and the Makefile is updated to include it.

Security risks

None. The change swaps one PostgreSQL catalog utility function for another. quote_qualified_identifier() is a well-tested, widely-used PostgreSQL core function. No user input handling, authentication, or permissions logic is affected.

Level of scrutiny

Low scrutiny warranted. This is a mechanical fix using an established PostgreSQL API to replace a clearly incorrect string formatting pattern. The root cause and fix are well-understood, and the regression test thoroughly covers the affected code paths (INSERT, scan, UPDATE, DELETE, VACUUM, and utility functions).

Other factors

The two bug reports are both minor: (1) a pre-existing schema_name memory leak that exists in the old code and is reclaimed by per-tuple context reset anyway, and (2) a test coverage nit where Test 4 doesn't exercise the BM25 scan path for the both-uppercase case (though quote_qualified_identifier handles each identifier independently, so this is low risk). Neither warrants blocking the fix.

@tjgreen42 tjgreen42 merged commit 082d951 into main Mar 13, 2026
15 checks passed
@tjgreen42 tjgreen42 deleted the fix/case-sensitive-index-names branch March 13, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Index name case sensitivity issue when inserting record

1 participant