Skip to content

Commit

Permalink
bug fix: unique key/secondary key get incorrect value (#18711) (#18717)
Browse files Browse the repository at this point in the history
  • Loading branch information
ouyuanning authored Sep 12, 2024
1 parent 2fed24b commit 9eebbf7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
15 changes: 7 additions & 8 deletions pkg/sql/plan/build_dml_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2758,15 +2758,14 @@ func recomputeMoCPKeyViaProjection(builder *QueryBuilder, bindCtx *BindContext,
}

if tableDef.Pkey.PkeyColName == catalog.CPrimaryKeyColName {
pkNamesMap := make(map[string]int)
for _, name := range tableDef.Pkey.Names {
pkNamesMap[name] = 1
}

// pkNamesMap := make(map[string]int)
prikeyPos := make([]int, 0)
for i, coldef := range tableDef.Cols {
if _, ok := pkNamesMap[coldef.Name]; ok {
prikeyPos = append(prikeyPos, i)
for _, name := range tableDef.Pkey.Names {
for i, coldef := range tableDef.Cols {
if coldef.Name == name {
prikeyPos = append(prikeyPos, i)
break
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion test/distributed/cases/dml/select/select.result
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,11 @@ select * from t1 where a in (3,3,3,2,1);
a b
1 1
2 2
3 3
3 3
drop table if exists t1;
create table t1 (a int, b varchar, c int, primary key (c,a), key idx_b(b));
insert into t1 select result, result || "_a",result+100000000 from generate_series(1,10000) g;
select * from t1 where b in ("11_a","21_a");
a b c
11 11_a 100000011
21 21_a 100000021
5 changes: 5 additions & 0 deletions test/distributed/cases/dml/select/select.test
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,8 @@ insert into t1 values (1,1),(2,2),(3,3);
-- @separator:table
select mo_ctl('dn', 'flush', 'select.t1');
select * from t1 where a in (3,3,3,2,1);

drop table if exists t1;
create table t1 (a int, b varchar, c int, primary key (c,a), key idx_b(b));
insert into t1 select result, result || "_a",result+100000000 from generate_series(1,10000) g;
select * from t1 where b in ("11_a","21_a");

0 comments on commit 9eebbf7

Please sign in to comment.