You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: strip same-schema OPERATOR() qualifiers after external plan inspection (#697) - #703
With --plan-host and target schema public, a view or materialized view that uses an operator owned by an extension installed in public (for example hstore's -> or ?) was reported as modified on every plan. The plan database is inspected with only the temporary schema on search_path, so ruleutils deparses the operator as OPERATOR(public.->), while the target side prints the bare ->. The two definitions never matched, so the view (and everything depending on it) was dropped and recreated on every apply.
The same operators were also rendered inconsistently across contexts on the current side: column defaults, generated expressions and index expressions are deparsed under search_path = pg_catalog, so they came out as OPERATOR(public.->) (defaults) or, after prefix stripping, as OPERATOR(->) (generated columns, indexes), a form PostgreSQL never emits. A dump of a table with an hstore default therefore failed to plan with embedded Postgres at all.
Changes:
ir.normalizeOperatorSyntax reduces OPERATOR(<own schema>.op) to the bare operator in every deparsed expression context (views, generated expressions, index expressions and predicates, column defaults including nextval-backed ones), on both the current and desired side. Raw function bodies are untouched: OPERATOR() carries its own precedence there and is compared as written.
Operators that duplicate a pg_catalog operator's name and operand types are only reachable schema-qualified, and ruleutils always qualifies them. The inspector records the names whose every overload is shadowed (Metadata.ShadowedOperators) and both normalization paths keep their qualifier. The decision is per name because the normalizer only sees deparsed text; a name with both shadowed and unshadowed overloads (a custom public.->(jsonb, text) next to hstore's ->) is not exempted, so the extension operator, the common case, always compares cleanly.
Routine parameter defaults are normalized on the plan side like column defaults, so an operator in a DEFAULT of a function or procedure parameter no longer replans the routine.
newSameSchemaQualifierStripper (plan side, after the temp-schema rename) strips OPERATOR(public.op) like it already stripped public.func( and ::public.type, honours the shadowed set, and now also skips double-quoted identifiers.
TestNormalizeOperatorSyntax (ir): same-schema operators become bare, shadowed and other-schema operators keep their qualifier, quoted text is untouched, nextval defaults are covered, and StripSchemaPrefixFromBody leaves OPERATOR(public.*) as written.
TestNormalizeSchemaNames_StripsSameSchemaOperatorQualifiers (cmd/plan): plan-side stripping with a shadowed name, a string literal and quoted identifiers.
TestExternalDatabase_ExtensionOperatorInPublicPlansClean (cmd/plan): hstore operators in a default, generated column, CHECK, index expression and predicate, function parameter default, view (with a quoted "OPERATOR(public.->)" alias) and matview plan as a no-op through an external plan database, with a fully shadowed public.+ and a mixed-overload public.-> present on both databases; asserts the target IR exempts only +. Fails before the fix with the recreate shown in External plan database with target schema public renders extension operators as OPERATOR(public.->), recreating views on every plan #697.
Verified manually: the same schema plans clean with both providers, round-trips through apply, and with a custom public.+(integer, integer) the restored copy keeps OPERATOR(public.+) in the default and generated column.
go test ./ir
go test ./cmd/plan -run 'TestNormalizeSchemaNames|TestExternalDatabase_'
go test ./internal/diff
…ection (#697)
With an external plan database and target schema public, a view using an
operator owned by an extension installed in public (hstore's ->) was deparsed
as OPERATOR(public.->) on the plan side and as -> on the target side, so the
view was recreated on every plan. The same-schema qualifier stripper now also
removes OPERATOR(schema.op), as it already does for schema.func( and ::schema.type.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This PR addresses #697 by normalizing same-schema operator qualifiers during external planning, preventing unchanged views and materialized views from being reported as modified.
Changes:
Strip OPERATOR(schema.op) qualifiers during desired-state normalization.
Add unit coverage for operator normalization and preservation of string literals.
Add an external-database regression test using hstore views and materialized views.
File
Description
cmd/plan/plan.go
Adds same-schema operator qualifier stripping.
cmd/plan/plan_test.go
Tests qualified operators, literals, and already-bare operators.
cmd/plan/external_db_integration_test.go
Checks that unchanged hstore views produce a no-op external plan.
…iers (#697)
Review follow-up: the plan-side stripper also mangled double-quoted
identifiers, and stripping only the desired side left column defaults,
generated expressions and index expressions (deparsed under
search_path = pg_catalog) disagreeing with the current side.
The IR normalizer now reduces OPERATOR(<own schema>.op) and the OPERATOR(op)
artifact of prefix stripping to the bare operator in every expression
context, on both sides, so a dump with an hstore default also plans with
embedded Postgres. The plan-side stripper skips double-quoted identifiers
the same way it skips string literals.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Operator-wrapper normalization can change precedence and operator resolution, hiding required function and default updates and emitting SQL that uses the wrong operator.
… bodies alone (#697)
Review follow-up. The operator rewrite moves out of StripSchemaPrefixFromBody,
which also compares raw function bodies where OPERATOR() carries its own
precedence, into normalizeDeparsedExpression for deparsed contexts only, and
prefix stripping no longer turns OPERATOR(schema.op) into OPERATOR(op).
An operator in the managed schema that duplicates a pg_catalog operator's
name and operand types is only reachable schema-qualified; the inspector now
records such names (Metadata.ShadowedOperators) and both normalization paths
keep their qualifier. nextval-backed defaults are normalized too.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Inconsistent schema-qualifier normalization for routine parameter defaults and overloaded operators causes unchanged routines, views, and materialized views to be reported as changed.
This also normalizes function and procedure parameter defaults, but normalizeSchemaNames never normalizes their DefaultValue after renaming the temporary schema. With intarray in app, a qualified default such as ARRAY[1] OPERATOR(app.+) ARRAY[2] becomes bare + in the current IR but stays qualified in the temporary-schema IR, so verbatim parameter comparison repeatedly reports a routine change. Apply stripQualifiers(replaceString(*param.DefaultValue)) to non-nil defaults in both parameter loops in cmd/plan/plan.go, without rewriting routine bodies.
…parameter defaults (#697)
Review follow-up. The shadowed-operator exemption is decided per name
because the normalizer only sees deparsed text, so a name with both a
shadowed and an unshadowed overload (a custom public.->(jsonb, text) next
to hstore's ->) is no longer exempted: the extension operator is the common
case and the one this fix is for. Routine parameter defaults are normalized
after the temp-schema rename like column defaults.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…697)
Review follow-up: handle a quote_ident-form schema (OPERATOR("My Schema".op)),
share the operator character set as ir.OperatorNameChars, make the
OPERATOR( look-behind in prefix stripping constant-time, and stop re-running
the pattern inside the plan-side replacement.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ate OPERATOR keyword case (#697)
Review follow-up: newSameSchemaQualifierStripper recognizes the target
schema in bare and quote_ident form for function, cast and operator
qualifiers; the OPERATOR( look-behind in prefix stripping accepts any
keyword case and whitespace; doc wording fixed.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…yword case in the scanner (#697)
Review follow-up: the plan-side stripper handles a quote_ident-form
function or type name after the schema qualifier, and
normalizeOperatorSyntax detects the OPERATOR keyword like
followsOperatorKeyword does (any case, optional whitespace).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…n defaults (#697)
The plan-side stripper now handles quoted object names, so the current-side
default normalizer must too, or a default such as public."MyFunc"() compares
differently on the two sides (broke dependency/issue_571 in CI). The
replacement is also quote-aware now, so string literals are left alone.
Regenerates the issue 571 fixture: its default reads "MyFunc"() like every
other expression context already did.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With
--plan-hostand target schemapublic, a view or materialized view that uses an operator owned by an extension installed inpublic(for example hstore's->or?) was reported as modified on every plan. The plan database is inspected with only the temporary schema onsearch_path, so ruleutils deparses the operator asOPERATOR(public.->), while the target side prints the bare->. The two definitions never matched, so the view (and everything depending on it) was dropped and recreated on every apply.The same operators were also rendered inconsistently across contexts on the current side: column defaults, generated expressions and index expressions are deparsed under
search_path = pg_catalog, so they came out asOPERATOR(public.->)(defaults) or, after prefix stripping, asOPERATOR(->)(generated columns, indexes), a form PostgreSQL never emits. A dump of a table with an hstore default therefore failed to plan with embedded Postgres at all.Changes:
ir.normalizeOperatorSyntaxreducesOPERATOR(<own schema>.op)to the bare operator in every deparsed expression context (views, generated expressions, index expressions and predicates, column defaults includingnextval-backed ones), on both the current and desired side. Raw function bodies are untouched:OPERATOR()carries its own precedence there and is compared as written.pg_catalogoperator's name and operand types are only reachable schema-qualified, and ruleutils always qualifies them. The inspector records the names whose every overload is shadowed (Metadata.ShadowedOperators) and both normalization paths keep their qualifier. The decision is per name because the normalizer only sees deparsed text; a name with both shadowed and unshadowed overloads (a custompublic.->(jsonb, text)next to hstore's->) is not exempted, so the extension operator, the common case, always compares cleanly.DEFAULTof a function or procedure parameter no longer replans the routine.newSameSchemaQualifierStripper(plan side, after the temp-schema rename) stripsOPERATOR(public.op)like it already strippedpublic.func(and::public.type, honours the shadowed set, and now also skips double-quoted identifiers.Fixes #697
Test plan
TestNormalizeOperatorSyntax(ir): same-schema operators become bare, shadowed and other-schema operators keep their qualifier, quoted text is untouched,nextvaldefaults are covered, andStripSchemaPrefixFromBodyleavesOPERATOR(public.*)as written.TestNormalizeSchemaNames_StripsSameSchemaOperatorQualifiers(cmd/plan): plan-side stripping with a shadowed name, a string literal and quoted identifiers.TestExternalDatabase_ExtensionOperatorInPublicPlansClean(cmd/plan): hstore operators in a default, generated column, CHECK, index expression and predicate, function parameter default, view (with a quoted"OPERATOR(public.->)"alias) and matview plan as a no-op through an external plan database, with a fully shadowedpublic.+and a mixed-overloadpublic.->present on both databases; asserts the target IR exempts only+. Fails before the fix with the recreate shown in External plan database with target schema public renders extension operators as OPERATOR(public.->), recreating views on every plan #697.apply, and with a custompublic.+(integer, integer)the restored copy keepsOPERATOR(public.+)in the default and generated column.🤖 Generated with Claude Code