Skip to content

Commit

Permalink
优化MySQL generated virtual column 改表消耗 (#609)
Browse files Browse the repository at this point in the history
* add column(nornal、virtual、STORED)区分myslq版本确定是否绕过osc
---------

Co-authored-by: caiyihong <caiyihong@youmi.net>
  • Loading branch information
hjweddie and caiyihong authored Oct 29, 2023
1 parent 56a117f commit 078585e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions session/session_inception.go
Original file line number Diff line number Diff line change
Expand Up @@ -4860,14 +4860,18 @@ func (s *session) checkAddColumn(t *TableInfo, c *ast.AlterTableSpec) {
if !s.hasError() {
isPrimary := false
isUnique := false
var isStore *bool
for _, op := range nc.Options {
switch op.Tp {
case ast.ColumnOptionPrimaryKey:
isPrimary = true
case ast.ColumnOptionUniqKey:
isUnique = true
case ast.ColumnOptionGenerated:
isStore = &op.Stored
}
}

if isPrimary || isUnique {
if s.dbType == DBTypeOceanBase {
s.appendErrorNo(ER_CANT_ADD_PK_OR_UK_COLUMN, nc.Name.Name.String())
Expand Down Expand Up @@ -4914,6 +4918,16 @@ func (s *session) checkAddColumn(t *TableInfo, c *ast.AlterTableSpec) {
}
t.Indexes = append(t.Indexes, index)
}
} else {
// 此时已经排除主键/唯一键的情况
// 8.0版本下只有STORED column不支持Only Modifies Metadata
if s.dbVersion >= 80000 && (nil == isStore || !*isStore) {
s.myRecord.useOsc = false
}
// 如果mysql版本小于8.0,只有VIRTUAL column支持Only Modifies Metadata
if s.dbVersion < 80000 && nil != isStore && !*isStore {
s.myRecord.useOsc = false
}
}
}

Expand Down

0 comments on commit 078585e

Please sign in to comment.