[BugFix] Preserve key column keyness on MODIFY COLUMN for DUPLICATE/UNIQUE tables#75329
Open
richerduong wants to merge 1 commit into
Open
[BugFix] Preserve key column keyness on MODIFY COLUMN for DUPLICATE/UNIQUE tables#75329richerduong wants to merge 1 commit into
richerduong wants to merge 1 commit into
Conversation
…NIQUE tables MODIFY COLUMN on a key column of a DUPLICATE or UNIQUE table, without restating the KEY keyword, failed with a misleading "Can not change aggregation type" error (e.g. changing only a key column's comment). Root cause: in SchemaChangeHandler.processModifyColumn, the rebuilt column defaults to non-key when KEY is omitted. The UNIQUE and DUPLICATE branches then assigned it an aggregation type (REPLACE/NONE), silently demoting the key column to a value column. That fabricated aggregation type later clashed with the original key column's null aggregation type in Column.checkSchemaChangeAllowed, surfacing the misleading error. A keyness flip is not a supported MODIFY COLUMN operation (the range-distribution path already rejects it explicitly). Mirror the existing PRIMARY KEY behavior: when the base column is a key and KEY is omitted, preserve its keyness instead of demoting it. PRIMARY KEY and AGGREGATE tables already behaved this way. Adds ModifyColumnKeynessTest covering DUPLICATE and UNIQUE key-column modify without the KEY keyword, plus a value-column guard against an over-broad fix. Signed-off-by: Richer Duong <duongricher@gmail.com>
richerduong
force-pushed
the
keyness-fix-74553
branch
from
June 25, 2026 05:14
cdfeb83 to
82c6da9
Compare
Author
|
Hi @gengjun-git and @meegoo, could you please review this? |
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.
Why I'm doing:
ALTER TABLE ... MODIFY COLUMNon a key column of a DUPLICATE or UNIQUE table, without restating theKEYkeyword, fails with a misleadingCan not change aggregation typeerror, even when only the column comment or type is changed. OmittingKEYis a very natural thing to do, and the error gives no hint about the real cause.The same problem reproduces on UNIQUE KEY tables. It does not happen on PRIMARY KEY or AGGREGATE tables (see root cause).
What I'm doing:
Root cause: in
SchemaChangeHandler.processModifyColumn, the column rebuilt from theMODIFY COLUMNclause is non-key whenKEYis omitted. The UNIQUE and DUPLICATE branches then assign it an aggregation type (REPLACEorNONE), silently demoting the existing key column to a value column. That implicitly assigned aggregation type later clashes with the original key column'snullaggregation type inColumn.checkSchemaChangeAllowed, which throwsCan not change aggregation type.A keyness flip is not a supported
MODIFY COLUMNoperation. The range-distribution guard in the same method already rejects it explicitly. This change mirrors the existing PRIMARY KEY backward-compatibility behavior: when the base column is a key andKEYis omitted, preserve its keyness instead of demoting it. PRIMARY KEY and AGGREGATE tables already behave this way.Adds
ModifyColumnKeynessTestcovering DUPLICATE and UNIQUE key-column modifications without theKEYkeyword, plus a value-column case to guard against an over-broad fix. The two key-column tests fail withCan not change aggregation typeon the unpatched code and pass with the fix; the value-column test passes in both cases.Fixes #74553
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: