Enhancement: add gp_matviews, a schema-qualified view over gp_matview_aux - #1970
Open
xinzweb wants to merge 2 commits into
Open
Enhancement: add gp_matviews, a schema-qualified view over gp_matview_aux#1970xinzweb wants to merge 2 commits into
xinzweb wants to merge 2 commits into
Conversation
gp_matview_aux.mvname is populated from a bare, non-schema-qualified relation name (InsertMatviewAuxEntry(), gp_matview_aux.c), so two materialized views sharing a name in different schemas produce identical, indistinguishable mvname values. Flagged same-day in review on the PR that introduced it (apache#720) but never actioned. Add gp_matviews, modeled on pg_matviews, which live-joins gp_matview_aux -> pg_class -> pg_namespace for an always-correct schema-qualified name (mvschema/mvname) instead of the stored, non-qualified copy. Because it's resolved live rather than synced, ALTER MATERIALIZED VIEW ... RENAME and SET SCHEMA can never leave it stale - there is no sync code to miss, unlike a second stored column would require (verified: no code anywhere handles gp_matview_aux on ALTER TABLE ... SET SCHEMA today, since mvname never tracked schema in the first place - a new synced column would need to add that from scratch and could reproduce the same staleness bug this fixes). gp_matview_aux.mvname itself is left completely unchanged - still populated, still synced on rename via the existing mvaux_rename() - and marked deprecated via COMMENT ON COLUMN, pointing at gp_matviews. This is additive only: no column removed, no existing behavior changed, nothing breaks for any existing direct consumer of mvname. Fixes apache#726 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PJKwGjLr1ee53Uh8aq1v2H
Captured against a real live 6-segment gpdemo cluster (1 coordinator + 1 standby + 2 primaries + 2 mirrors), built from this branch, via psql -X -a -q -d regression < matview_data.sql (pg_regress's own harness isn't wired up for this ad hoc Docker-built cluster). Pure addition at the exact insertion point in matview_data.sql - confirmed via diff against the pristine upstream expected file that nothing else changed (0 deletions, 66 insertions). Also confirmed live: misc_sanity.sql diffs byte-identical against its checked-in expected output (the new view/comments don't trip any existing sanity check), and aqumv.sql's diff against its checked-in expected output is 100% pre-existing drift unrelated to this patch (GUC-ordering in EXPLAIN VERBOSE, new DISTRIBUTED BY notices, topology-based Motion labels) - grepped for gp_matview/mvname/mvschema in that diff and found zero hits, so aqumv.out is intentionally left untouched here. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PJKwGjLr1ee53Uh8aq1v2H
xinzweb
pushed a commit
to xinzweb/apache-skills
that referenced
this pull request
Sep 7, 2026
apache/cloudberry#1970 opened against xinzweb:t726-remove-mvname-column. Flips hub status Coding -> Review and records the cross-repo pointer. Also notes the local validation cluster container was torn down now that it's no longer needed. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PJKwGjLr1ee53Uh8aq1v2H
There was a problem hiding this comment.
Hi, @xinzweb welcome!🎊 Thanks for taking the effort to make our project better! 🙌 Keep making such awesome contributions!
yjhjstz
reviewed
Sep 7, 2026
|
|
||
| COMMENT ON VIEW gp_matviews IS 'Schema-qualified view of gp_matview_aux, resolving mvname live from pg_class/pg_namespace instead of a stored copy. Prefer this over gp_matview_aux.mvname, which is not schema-qualified (see https://github.com/apache/cloudberry/issues/726).'; | ||
|
|
||
| COMMENT ON COLUMN gp_matview_aux.mvname IS 'Deprecated: bare, non-schema-qualified materialized view name, retained for backward compatibility only. Two materialized views with the same name in different schemas are indistinguishable via this column. Use gp_matviews.mvname (with gp_matviews.mvschema) instead. See https://github.com/apache/cloudberry/issues/726.'; |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #726
What does this PR do?
gp_matview_aux.mvnameis populated from a bare, non-schema-qualifiedrelation name (
InsertMatviewAuxEntry(),gp_matview_aux.c), so twomaterialized views sharing a name in different schemas produce identical,
indistinguishable
mvnamevalues.This PR adds
gp_matviews, modeled onpg_matviews, which live-joinsgp_matview_aux→pg_class→pg_namespacefor an always-correctschema-qualified name (
mvschema/mvname).gp_matview_aux.mvnameisleft completely unchanged — still populated, still synced on rename via
the existing
mvaux_rename()— and marked deprecated viaCOMMENT ON COLUMN, pointing callers at the new view. This is purely additive: nocolumn removed, no existing behavior changed.
I considered (and rejected) two alternatives:
mvnamecolumn (the maintainer'sliteral suggestion on the introducing PR, Fix REFRESH fast path. #720) —
mvnameisNameData(63 usable bytes); a schema prefix could silently truncateor re-collide for long identifiers.
mvschemacolumn instead of a view — Iverified (
grep) that no code anywhere syncs a matview's schema onALTER ... SET SCHEMAtoday, sincemvnamenever tracked schema. Anew synced column would need that sync code added from scratch, and if
ever missed, would reproduce the exact staleness bug this issue is
about. A live-resolved view can't go stale by construction.
Root cause:
namestrcpy(&mvname, get_rel_name(mvoid))atgp_matview_aux.c:253never schema-qualifies. Introduced in #720(merged 2024-12-02); flagged same-day in that PR's own review by
@yjhnupt, with @yjhjstz suggesting the schema-prefix approach above —
the follow-up sat unactioned for ~20 months.
Type of Change
Test Plan
test in
matview_data.sql(createmv0in two schemas, confirmgp_matview_aux.mvnamecan't distinguish them butgp_matviews.mvschemacan; confirmALTER ... RENAMEresolveslive)
make installcheckmake -C src/test installcheck-cbdb-parallelNeither
make installcheckcommand was run as literally stated — seeAdditional Context for what was actually run and why.
Impact
Performance: None — purely additive, no existing code path changed.
User-facing changes: New
gp_matviewsview available;gp_matview_aux.mvnamenow documented (viaCOMMENT ON COLUMN) asdeprecated, but unchanged in behavior.
Dependencies: None.
Checklist
Additional Context
AI disclosure: this change was drafted end-to-end by Claude Code
under my direction — design (including a design pivot from an initial
breaking-change approach after I asked about it), implementation, and
this PR description. I reviewed the diff and the live-cluster evidence
below before submitting; I'm accountable for what's in this PR.
What was actually run, honestly:
mvn apache-rat:check— passed clean (0 unapproved).gpdemocluster via a Docker-based local toolchain, not the officialCI matrix. Confirmed live: the mvname column in gp_matview_aux may be confused. #726 scenario (
gp_matview_aux.mvnamecan't distinguish two same-named matviews in different schemas;
gp_matviews.mvschemacan),ALTER ... RENAMEresolves live, the newCOMMENT ONdeprecation notices are queryable(
col_description()/obj_description()), catalog version bootstrapscleanly,
-Werrorcompiles clean.matview_data.sqlwas piped throughpsqldirectly against the livecluster (not
pg_regress/make installcheck— not wired up for thisad hoc cluster) and the new test's expected output spliced into
matview_data.outat its exact insertion point — confirmed via diffagainst the pristine upstream file that this is a pure addition (0
deletions).
misc_sanity.sqldiffed byte-identical against its checked-inexpected output.
aqumv.sql,pax_storage, orsinglenode_regressat all (only the now-superseded removal designneeded to) — nothing to test there.