-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*: use CLUSTERED and NONCLUSTERED to control primary key type #22409
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6d24df3
apply the new syntax and update tests
tangenta 34fb11a
add special comments to output from SHOW CRAETE TABLE
tangenta d7d836d
refine tidb_pk_type in information_schema.tables
tangenta 4367bdb
fix integration test
tangenta 6ae866c
Merge remote-tracking branch 'upstream/master' into clustered-index-s…
tangenta ee2a2c8
address comment
tangenta 547f620
Merge remote-tracking branch 'upstream/master' into clustered-index-s…
tangenta 958155f
Merge remote-tracking branch 'upstream/master' into clustered-index-s…
tangenta 3f5a248
revert ee2a2c8
tangenta 437e55c
Merge remote-tracking branch 'upstream/master' into clustered-index-s…
tangenta e532176
Merge remote-tracking branch 'upstream/master' into clustered-index-s…
tangenta 1939010
Merge branch 'master' into clustered-index-syntax
ti-srebot 3c06957
Merge branch 'master' into clustered-index-syntax
ti-srebot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -628,7 +628,8 @@ func columnDefToCol(ctx sessionctx.Context, offset int, colDef *ast.ColumnDef, o | |
case ast.ColumnOptionPrimaryKey: | ||
// Check PriKeyFlag first to avoid extra duplicate constraints. | ||
if col.Flag&mysql.PriKeyFlag == 0 { | ||
constraint := &ast.Constraint{Tp: ast.ConstraintPrimaryKey, Keys: keys} | ||
constraint := &ast.Constraint{Tp: ast.ConstraintPrimaryKey, Keys: keys, | ||
Option: &ast.IndexOption{PrimaryKeyTp: v.PrimaryKeyTp}} | ||
constraints = append(constraints, constraint) | ||
col.Flag |= mysql.PriKeyFlag | ||
// Add NotNullFlag early so that processColumnFlags() can see it. | ||
|
@@ -1424,23 +1425,35 @@ func buildTableInfo( | |
if err != nil { | ||
return nil, err | ||
} | ||
if !config.GetGlobalConfig().AlterPrimaryKey { | ||
singleIntPK := isSingleIntPK(constr, lastCol) | ||
clusteredIdx := ctx.GetSessionVars().EnableClusteredIndex | ||
if singleIntPK || clusteredIdx { | ||
// Primary key cannot be invisible. | ||
if constr.Option != nil && constr.Option.Visibility == ast.IndexVisibilityInvisible { | ||
return nil, ErrPKIndexCantBeInvisible | ||
} | ||
} | ||
if singleIntPK { | ||
pkTp := model.PrimaryKeyTypeDefault | ||
if constr.Option != nil { | ||
pkTp = constr.Option.PrimaryKeyTp | ||
} | ||
switch pkTp { | ||
case model.PrimaryKeyTypeNonClustered: | ||
break | ||
case model.PrimaryKeyTypeClustered: | ||
if isSingleIntPK(constr, lastCol) { | ||
tbInfo.PKIsHandle = true | ||
// Avoid creating index for PK handle column. | ||
continue | ||
} | ||
if clusteredIdx { | ||
} else { | ||
tbInfo.IsCommonHandle = true | ||
} | ||
case model.PrimaryKeyTypeDefault: | ||
alterPKConf := config.GetGlobalConfig().AlterPrimaryKey | ||
if isSingleIntPK(constr, lastCol) { | ||
tbInfo.PKIsHandle = !alterPKConf | ||
} else { | ||
tbInfo.IsCommonHandle = !alterPKConf && ctx.GetSessionVars().EnableClusteredIndex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we return a warning if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, the variable has lower priority. |
||
} | ||
} | ||
if tbInfo.PKIsHandle || tbInfo.IsCommonHandle { | ||
// Primary key cannot be invisible. | ||
if constr.Option != nil && constr.Option.Visibility == ast.IndexVisibilityInvisible { | ||
return nil, ErrPKIndexCantBeInvisible | ||
} | ||
} | ||
if tbInfo.PKIsHandle { | ||
continue | ||
} | ||
} | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
&& ctx.GetSessionVars().EnableClusteredIndex
either to make it consistent with common handle?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of tests will be broken. Let's do this in another PR when it is decided.