Skip to content

Commit

Permalink
*: make IsVirtualGeneratedColumn more readable (#47203)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored Sep 22, 2023
1 parent 4e82952 commit e8247b5
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 43 deletions.
10 changes: 1 addition & 9 deletions ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ func (w *updateColumnWorker) calcChecksums() []uint32 {
w.checksumBuffer.Cols = w.checksumBuffer.Cols[:0]
}
for _, col := range w.table.DeletableCols() {
if col.ID == id || (col.IsGenerated() && !col.GeneratedStored) {
if col.ID == id || (col.IsVirtualGenerated()) {
continue
}
d := w.rowMap[col.ID]
Expand Down Expand Up @@ -1958,14 +1958,6 @@ func generateOriginDefaultValue(col *model.ColumnInfo, ctx sessionctx.Context) (
return odValue, nil
}

// isVirtualGeneratedColumn checks the column if it is virtual.
func isVirtualGeneratedColumn(col *model.ColumnInfo) bool {
if col.IsGenerated() && !col.GeneratedStored {
return true
}
return false
}

func indexInfoContains(idxID int64, idxInfos []*model.IndexInfo) bool {
for _, idxInfo := range idxInfos {
if idxID == idxInfo.ID {
Expand Down
2 changes: 1 addition & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4903,7 +4903,7 @@ func checkTableDefCompatible(source *model.TableInfo, target *model.TableInfo) e
// Col compatible check
for i, sourceCol := range source.Cols() {
targetCol := target.Cols()[i]
if isVirtualGeneratedColumn(sourceCol) != isVirtualGeneratedColumn(targetCol) {
if sourceCol.IsVirtualGenerated() != targetCol.IsVirtualGenerated() {
return dbterror.ErrUnsupportedOnGeneratedColumn.GenWithStackByArgs("Exchanging partitions for non-generated columns")
}
// It should strictyle compare expressions for generated columns
Expand Down
2 changes: 1 addition & 1 deletion expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ func ColumnInfos2ColumnsAndNames(ctx sessionctx.Context, dbName, tblName model.C
}()
ctx.GetSessionVars().StmtCtx.IgnoreTruncate.Store(true)
for i, col := range colInfos {
if col.IsGenerated() && !col.GeneratedStored {
if col.IsVirtualGenerated() {
expr, err := generatedexpr.ParseExpression(col.GeneratedExprString)
if err != nil {
return nil, nil, errors.Trace(err)
Expand Down
5 changes: 5 additions & 0 deletions parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ type ColumnInfo struct {
Version uint64 `json:"version"`
}

// IsVirtualGenerated checks the column if it is virtual.
func (c *ColumnInfo) IsVirtualGenerated() bool {
return c.IsGenerated() && !c.GeneratedStored
}

// Clone clones ColumnInfo.
func (c *ColumnInfo) Clone() *ColumnInfo {
if c == nil {
Expand Down
2 changes: 1 addition & 1 deletion planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,7 @@ func (ds *DataSource) convertToTableScan(prop *property.PhysicalProperty, candid
}
if ts.StoreType == kv.TiFlash {
for _, col := range ts.Columns {
if col.IsGenerated() && !col.GeneratedStored {
if col.IsVirtualGenerated() {
col.AddFlag(mysql.GeneratedColumnFlag)
}
}
Expand Down
2 changes: 1 addition & 1 deletion planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ func getColsInfo(tn *ast.TableName) (indicesInfo []*model.IndexInfo, colsInfo []
tbl := tn.TableInfo
for _, col := range tbl.Columns {
// The virtual column will not store any data in TiKV, so it should be ignored when collect statistics
if col.IsGenerated() && !col.GeneratedStored {
if col.IsVirtualGenerated() {
continue
}
if mysql.HasPriKeyFlag(col.GetFlag()) && tbl.HasClusteredIndex() {
Expand Down
11 changes: 0 additions & 11 deletions server/err/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "error",
srcs = ["error.go"],
importpath = "github.com/pingcap/tidb/server/error",
visibility = ["//visibility:public"],
deps = [
"//errno",
"//util/dbterror",
],
)

go_library(
name = "err",
srcs = ["error.go"],
Expand Down
2 changes: 1 addition & 1 deletion statistics/handle/globalstats/global_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func MergePartitionStats2GlobalStats(
if len(histIDs) == 0 {
for _, col := range globalTableInfo.Columns {
// The virtual generated column stats can not be merged to the global stats.
if col.IsGenerated() && !col.GeneratedStored {
if col.IsVirtualGenerated() {
continue
}
histIDs = append(histIDs, col.ID)
Expand Down
9 changes: 3 additions & 6 deletions table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ func DecodeRawRowData(ctx sessionctx.Context, meta *model.TableInfo, h kv.Handle
v[i] = ri
continue
}
if col.IsGenerated() && !col.GeneratedStored {
if col.IsVirtualGenerated() {
continue
}
if col.ChangeStateInfo != nil {
Expand Down Expand Up @@ -1948,18 +1948,15 @@ func CanSkip(info *model.TableInfo, col *table.Column, value *types.Datum) bool
if col.GetDefaultValue() == nil && value.IsNull() && col.GetOriginDefaultValue() == nil {
return true
}
if col.IsGenerated() && !col.GeneratedStored {
if col.IsVirtualGenerated() {
return true
}
return false
}

// canSkipUpdateBinlog checks whether the column can be skipped or not.
func (t *TableCommon) canSkipUpdateBinlog(col *table.Column, value types.Datum) bool {
if col.IsGenerated() && !col.GeneratedStored {
return true
}
return false
return col.IsVirtualGenerated()
}

// FindIndexByColName returns a public table index containing only one column named `name`.
Expand Down
12 changes: 0 additions & 12 deletions testkit/testsetup/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "testbridge",
srcs = ["bridge.go"],
importpath = "github.com/pingcap/tidb/util/testbridge",
visibility = ["//visibility:public"],
deps = [
"@com_github_pingcap_log//:log",
"@org_uber_go_zap//:zap",
"@org_uber_go_zap//zapcore",
],
)

go_library(
name = "testsetup",
srcs = ["bridge.go"],
Expand Down

0 comments on commit e8247b5

Please sign in to comment.