Skip to content

Commit

Permalink
update: add alter table partition clause count check(#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchuanchuan committed Dec 17, 2023
1 parent 58a697e commit 02acf74
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion session/session_inception.go
Original file line number Diff line number Diff line change
Expand Up @@ -3518,7 +3518,9 @@ func (s *session) checkAlterTable(node *ast.AlterTableStmt, sql string) {
ast.AlterTableOptimizePartition,
ast.AlterTableRepairPartition,
ast.AlterTableImportPartitionTablespace,
ast.AlterTableDiscardPartitionTablespace:
ast.AlterTableDiscardPartitionTablespace,
ast.AlterTablePartitionAttributes,
ast.AlterTablePartitionOptions:
s.appendErrorNo(ER_PARTITION_NOT_ALLOWED)
_ = s.fetchPartitionFromDB(table)

Expand Down Expand Up @@ -3548,6 +3550,8 @@ func (s *session) checkAlterTable(node *ast.AlterTableStmt, sql string) {
}
}

s.checkMultiPartitionParts(node.Specs)

if !s.hasError() && s.inc.ColumnsMustHaveIndex != "" {
tableCopy := s.getTableFromCache(node.Table.Schema.O, node.Table.Name.O, true)
s.checkColumnsMustHaveindex(tableCopy)
Expand Down Expand Up @@ -3604,6 +3608,39 @@ func (s *session) checkAlterTable(node *ast.AlterTableStmt, sql string) {
}
}

func (s *session) checkMultiPartitionParts(specs []*ast.AlterTableSpec) {
if len(specs) <= 1 {
return
}
count := 0
for _, alter := range specs {
switch alter.Tp {
/* 分区表 */
case ast.AlterTableAddPartitions,
ast.AlterTableDropPartition,
ast.AlterTableRemovePartitioning,
ast.AlterTablePartition,
ast.AlterTableAlterPartition,
ast.AlterTableCoalescePartitions,
ast.AlterTableTruncatePartition,
ast.AlterTableRebuildPartition,
ast.AlterTableReorganizePartition,
ast.AlterTableCheckPartitions,
ast.AlterTableExchangePartition,
ast.AlterTableOptimizePartition,
ast.AlterTableRepairPartition,
ast.AlterTableImportPartitionTablespace,
ast.AlterTableDiscardPartitionTablespace,
ast.AlterTablePartitionAttributes,
ast.AlterTablePartitionOptions:
count++
}
}
if count > 1 {
s.appendErrorMsg("Syntax error, PARTITION does not support multiple clauses.")
}
}

func (s *session) checkAlterTableAlterColumn(t *TableInfo, c *ast.AlterTableSpec) {
// log.Info("checkAlterTableAlterColumn")

Expand Down

0 comments on commit 02acf74

Please sign in to comment.