-
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
fix alter add index on virtual column bug #7575
fix alter add index on virtual column bug #7575
Conversation
ddl/index.go
Outdated
closed bool | ||
priority int | ||
|
||
// The following attributes are used to reduce memory allocation. | ||
defaultVals []types.Datum | ||
idxRecords []*indexRecord | ||
rowMap map[int64]types.Datum | ||
rowSlice []types.Datum |
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.
colSlice
instead of row
?
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.
colSlice
is just a buffer, main purpose is getting row
for expression eval
.
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.
I think rowBuffer
is a more clear name.
ddl/index.go
Outdated
w.rowSlice[col.Offset] = ri | ||
} | ||
} | ||
w.row = chunk.MutRowFromDatums(w.rowSlice).ToRow() |
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.
Since rowSlice
is only used here, and the check are both if len(colExprMap) != 0
. So let it be a local variable instead of one in struct.
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.
put it in the struct is used to reduce memory allocations. @winoros
@crazycs520 Please pick the proper items in Related changes, in the pr description. |
ddl/index.go
Outdated
@@ -843,14 +890,28 @@ func (w *addIndexWorker) run(d *ddlCtx) { | |||
log.Infof("[ddl-reorg] worker[%v] exit", w.id) | |||
} | |||
|
|||
func makeupIndexColFieldMap(t table.Table, indexInfo *model.IndexInfo) map[int64]*types.FieldType { | |||
func makeupIndexColFieldMapAndColExpr(sessCtx sessionctx.Context, t table.Table, indexInfo *model.IndexInfo) (map[int64]*types.FieldType, map[int64]expression.Expression, error) { |
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.
You can add a struct like
type SomeStruct struct {
tp *types.FieldType
genExpr expression.Expression
}
then return map like map[int64]*SomeStruct
to avoid using two map.
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.
But I respectively need 2 map, colFieldMap
use to decode row, and colExprMap
use to expression to eval.
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.
You can achieve decoding row and eval an expression by using just one map.
…ex-on-vir-col-bug
…ex-on-vir-col-bug
…ex-on-vir-col-bug
50d4890
to
121a7f0
Compare
121a7f0
to
bc00f25
Compare
…ex-on-vir-col-bug
@winkyao PTAL |
/run-all-tests |
/run-common-test |
/run-all-tests |
…ex-on-vir-col-bug
/run-all-tests |
@crazycs520 Please fix conflicts. |
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.
reset LGTM
…ex-on-vir-col-bug
4fa73c1
to
3ac1fb2
Compare
…ex-on-vir-col-bug
@@ -273,6 +273,12 @@ func (s *testSuite) TestAdmin(c *C) { | |||
tk.MustExec("ALTER TABLE t1 ADD INDEX idx3 (c4);") | |||
tk.MustExec("admin check table t1;") | |||
|
|||
// For add index on virtual column | |||
tk.MustExec("drop table if exists t1;") |
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.
Please add more test cases.
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.
@winkyao done.
/run-all-tests |
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.
LGTM
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.
LGTM
util/rowDecoder/decoder.go
Outdated
package decoder | ||
|
||
import ( | ||
"github.com/pingcap/tidb/mysql" |
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.
Put it to line 20.
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.
done. @zimulala PTAL
10f2197
to
2818aab
Compare
tk.MustExec("alter table t1 add index idx_g(g);") | ||
tk.MustExec("alter table t1 add index idx_h(h);") | ||
tk.MustExec("alter table t1 add index idx_j(j);") | ||
tk.MustExec("alter table t1 add index idx_i(i);") |
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.
Are we going to add some indexes for multiple columns?
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.
done. @zimulala PTAL
3a80405
to
012ea29
Compare
/run-all-tests |
…ex-on-vir-col-bug
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.
LGTM
/run-all-tests |
/run-all-tests |
What problem does this PR solve?
When alter add index on a virtual generated column, we shoud work out the val by colGenExpr.
The old TiDB will use test virtual generated column default value to fill back to index record when alter add index.
What is changed and how it works?
If index.column is a virtual generated column, get the
generatedExpr
, and also, we need to decode the column of virtual column dependent on.after decode from raw data, we have to use
generatedExpr
to eval the virtual column data.Check List
Tests
Unit test
Increased code complexity
Related changes
tidb-ansible
repository