Repository navigation
Check actual hash support when altering a distribution key type - #2308
Merged
reshke merged 3 commits intoNov 14, 2026
Merged
Conversation
x4m
approved these changes
Nov 12, 2026
Contributor
|
Some cases not covered: case 1 case 2 |
Contributor
Author
Yes, thx, this report looks related, will fix inside this PR |
reshke
added a commit
to reshke/cloudberrydb
that referenced
this pull request
Nov 12, 2026
Check concrete hash support when ALTER COLUMN TYPE or CTAS chooses a
new distribution key. A generic array or record operator class alone does
not guarantee that its element or field types can be hashed. Retain the
existing ALTER COLUMN behavior: reject an incompatible change on populated
tables, or use random distribution for empty tables. CTAS skips unusable
default classes so the fallback can select a legacy class, another key,
or random distribution.
The affected paths previously produced:
ALTER COLUMN k TYPE money[] followed by INSERT:
ERROR: could not identify a hash function for type money
CTAS from a legacy-distributed money key with the PostgreSQL planner:
ERROR: cache lookup failed for opclass 0 (lsyscache.c:1366)
Also reject adding or dropping row-type attributes while the type is used
in a distribution key, directly or through a container. Even adding a
hashable NULL field changes hash_record: in a two-segment check, 13 of 20
existing values then required a different segment. Protect table row types
and cascading attribute drops too. Hold locks on traversed types and
referencing relations to serialize new dependencies and policy changes;
ignore expression-only dependencies such as domain defaults.
Shape changes remain available for non-key columns and random or replicated
tables. Dependent empty hash-distributed tables are deliberately guarded as
well; change their distribution policy before changing the key's row type.
Add coverage for ALTER COLUMN, legacy CTAS, nested row types, cascades and
allowed shape changes. Adapt existing row-value deformation fixtures to use
another key or random distribution so they exercise their original purpose.
Includes the follow-ups reported in apache#2308,
issuecomment-6819847655.
reshke
force-pushed
the
fix-mpp-alter-distribution-hashability-20261112
branch
from
November 12, 2026 12:44
c8983b9 to
e3f6cd6
Compare
reshke
added a commit
to reshke/cloudberrydb
that referenced
this pull request
Nov 13, 2026
Check concrete hash support when ALTER COLUMN TYPE or CTAS chooses a
new distribution key. A generic array or record operator class alone does
not guarantee that its element or field types can be hashed. Retain the
existing ALTER COLUMN behavior: reject an incompatible change on populated
tables, or use random distribution for empty tables. CTAS skips unusable
default classes so the fallback can select a legacy class, another key,
or random distribution.
The affected paths previously produced:
ALTER COLUMN k TYPE money[] followed by INSERT:
ERROR: could not identify a hash function for type money
CTAS from a legacy-distributed money key with the PostgreSQL planner:
ERROR: cache lookup failed for opclass 0 (lsyscache.c:1366)
Also reject adding or dropping row-type attributes while the type is used
in a distribution key, directly or through a container. Even adding a
hashable NULL field changes hash_record: in a two-segment check, 13 of 20
existing values then required a different segment. Protect table row types
and cascading attribute drops too. Hold locks on traversed types and
referencing relations to serialize new dependencies and policy changes;
ignore expression-only dependencies such as domain defaults.
Shape changes remain available for non-key columns and random or replicated
tables. Dependent empty hash-distributed tables are deliberately guarded as
well; change their distribution policy before changing the key's row type.
Add coverage for ALTER COLUMN, legacy CTAS, nested row types, cascades and
allowed shape changes. Adapt existing row-value deformation fixtures to use
another key or random distribution so they exercise their original purpose.
Includes the follow-ups reported in apache#2308,
issuecomment-6819847655.
reshke
force-pushed
the
fix-mpp-alter-distribution-hashability-20261112
branch
from
November 13, 2026 17:37
e2189ca to
af78cb8
Compare
reshke
added a commit
to reshke/cloudberrydb
that referenced
this pull request
Nov 14, 2026
Check concrete hash support when ALTER COLUMN TYPE or CTAS chooses a
new distribution key. A generic array or record operator class alone does
not guarantee that its element or field types can be hashed. Retain the
existing ALTER COLUMN behavior: reject an incompatible change on populated
tables, or use random distribution for empty tables. CTAS skips unusable
default classes so the fallback can select a legacy class, another key,
or random distribution.
The affected paths previously produced:
ALTER COLUMN k TYPE money[] followed by INSERT:
ERROR: could not identify a hash function for type money
CTAS from a legacy-distributed money key with the PostgreSQL planner:
ERROR: cache lookup failed for opclass 0 (lsyscache.c:1366)
Also reject adding or dropping row-type attributes while the type is used
in a distribution key, directly or through a container. Even adding a
hashable NULL field changes hash_record: in a two-segment check, 13 of 20
existing values then required a different segment. Protect table row types
and cascading attribute drops too. Hold locks on traversed types and
referencing relations to serialize new dependencies and policy changes;
ignore expression-only dependencies such as domain defaults.
Shape changes remain available for non-key columns and random or replicated
tables. Dependent empty hash-distributed tables are deliberately guarded as
well; change their distribution policy before changing the key's row type.
Add coverage for ALTER COLUMN, legacy CTAS, nested row types, cascades and
allowed shape changes. Adapt existing row-value deformation fixtures to use
another key or random distribution so they exercise their original purpose.
Includes the follow-ups reported in apache#2308,
issuecomment-6819847655.
reshke
force-pushed
the
fix-mpp-alter-distribution-hashability-20261112
branch
from
November 14, 2026 02:31
af78cb8 to
5e8d554
Compare
reshke
added a commit
to reshke/cloudberrydb
that referenced
this pull request
Nov 14, 2026
Check concrete hash support when ALTER COLUMN TYPE or CTAS chooses a
new distribution key. A generic array or record operator class alone does
not guarantee that its element or field types can be hashed. Retain the
existing ALTER COLUMN behavior: reject an incompatible change on populated
tables, or use random distribution for empty tables. CTAS skips unusable
default classes so the fallback can select a legacy class, another key,
or random distribution.
The affected paths previously produced:
ALTER COLUMN k TYPE money[] followed by INSERT:
ERROR: could not identify a hash function for type money
CTAS from a legacy-distributed money key with the PostgreSQL planner:
ERROR: cache lookup failed for opclass 0 (lsyscache.c:1366)
Also reject adding or dropping row-type attributes while the type is used
in a distribution key, directly or through a container. Even adding a
hashable NULL field changes hash_record: in a two-segment check, 13 of 20
existing values then required a different segment. Protect table row types
and cascading attribute drops too. Hold locks on traversed types and
referencing relations to serialize new dependencies and policy changes;
ignore expression-only dependencies such as domain defaults.
Shape changes remain available for non-key columns and random or replicated
tables. Dependent empty hash-distributed tables are deliberately guarded as
well; change their distribution policy before changing the key's row type.
Add coverage for ALTER COLUMN, legacy CTAS, nested row types, cascades and
allowed shape changes. Adapt existing row-value deformation fixtures to use
another key or random distribution so they exercise their original purpose.
Includes the follow-ups reported in apache#2308,
issuecomment-6819847655.
reshke
force-pushed
the
fix-mpp-alter-distribution-hashability-20261112
branch
from
November 14, 2026 06:19
5e8d554 to
96bf8f2
Compare
reshke
enabled auto-merge (rebase)
November 14, 2026 14:51
Check concrete hash support when ALTER COLUMN TYPE or CTAS chooses a
new distribution key. A generic array or record operator class alone does
not guarantee that its element or field types can be hashed. Retain the
existing ALTER COLUMN behavior: reject an incompatible change on populated
tables, or use random distribution for empty tables. CTAS skips unusable
default classes so the fallback can select a legacy class, another key,
or random distribution.
The affected paths previously produced:
ALTER COLUMN k TYPE money[] followed by INSERT:
ERROR: could not identify a hash function for type money
CTAS from a legacy-distributed money key with the PostgreSQL planner:
ERROR: cache lookup failed for opclass 0 (lsyscache.c:1366)
Also reject adding or dropping row-type attributes while the type is used
in a distribution key, directly or through a container. Even adding a
hashable NULL field changes hash_record: in a two-segment check, 13 of 20
existing values then required a different segment. Protect table row types
and cascading attribute drops too. Hold locks on traversed types and
referencing relations to serialize new dependencies and policy changes;
ignore expression-only dependencies such as domain defaults.
Shape changes remain available for non-key columns and random or replicated
tables. Dependent empty hash-distributed tables are deliberately guarded as
well; change their distribution policy before changing the key's row type.
Add coverage for ALTER COLUMN, legacy CTAS, nested row types, cascades and
allowed shape changes. Adapt existing row-value deformation fixtures to use
another key or random distribution so they exercise their original purpose.
Includes the follow-ups reported in apache#2308,
issuecomment-6819847655.
Regression output has no blank line before the added test cases: reset optimizer_trace_fallback; -- A source distribution key need not have a usable default hash opclass. Remove the extra lines from both gpctas expected variants and alter_distribution_policy.
Keep the mutable fullname rowtype out of the distribution key in the PAX copy of rowtypes. In singlenode mode distribution clauses have no effect and emit a warning, so retain the original CTAS fixture there.
reshke
force-pushed
the
fix-mpp-alter-distribution-hashability-20261112
branch
from
November 14, 2026 14:51
96bf8f2 to
8fd2049
Compare
reshke
disabled auto-merge
November 14, 2026 14:51
reshke
enabled auto-merge (squash)
November 14, 2026 14:51
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.
ALTER COLUMN TYPE looked up a default hash operator class without checking whether its support functions can hash the concrete element or field types. For example, this left an empty table distributed by money[]:
Both array types select array_ops, so ATPrepAlterColumnType considered their distribution compatible even though money has no default hash support. Use cdb_default_distribution_opclass_for_type, as CREATE TABLE does, so the existing incompatible-type handling also covers containers: reject the change on a populated table, or switch an empty table to random distribution.
Add coverage for both cases and for a compatible int[] to bigint[] change.
Fixes #ISSUE_Number
What does this PR do?
Type of Change
Breaking Changes
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelImpact
Performance:
User-facing changes:
Dependencies:
Checklist
Additional Context
CI Skip Instructions