fix: quoted identifiers with uppercase letters cause index lookup failures#286
fix: quoted identifiers with uppercase letters cause index lookup failures#286
Conversation
…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
There was a problem hiding this comment.
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.
Summary
CREATE INDEX "IX_foo" ...)quote_qualified_identifier()instead ofpsprintf("%s.%s", ...)when constructing schema-qualified index names internallyRoot cause
When constructing schema-qualified index names during INSERT and scan operations, the code used
psprintf("%s.%s", schema, relname)which produced unquoted strings likepublic.IX_foo. These were then parsed bystringToQualifiedNameList()which follows SQL identifier rules and lowercases unquoted identifiers toix_foo, causingget_relname_relid()to fail the catalog lookup.The fix uses Postgres's
quote_qualified_identifier()which properly quotes identifiers that need quoting (e.g., producingpublic."IX_foo").Affected paths:
tp_insertinbuild.c)tp_get_qualified_index_nameinscan.c)to_bm25query(),bm25_dump_index(), etc. (these require the user to quote properly, matching standard SQL behavior)Fixes #285
Testing
New
quoted_identifiersregression test covers:to_bm25query()bm25_dump_index,bm25_summarize_index) with quoted names