Skip to content

Commit

Permalink
fix opt bug: not ResolveAlias for sk (#20903)
Browse files Browse the repository at this point in the history
fix opt bug: not ResolveAlias for sk

Approved by: @badboynt1, @heni02
  • Loading branch information
ouyuanning authored Dec 24, 2024
1 parent e4dae1c commit 2926919
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
10 changes: 5 additions & 5 deletions pkg/sql/plan/apply_indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func (builder *QueryBuilder) applyExtraFiltersOnIndex(idxDef *IndexDef, node *pl
continue
}
for k := range idxDef.Parts {
colIdx := node.TableDef.Name2ColIndex[idxDef.Parts[k]]
colIdx := node.TableDef.Name2ColIndex[catalog.ResolveAlias(idxDef.Parts[k])]
if colIdx != col.ColPos {
continue
}
Expand Down Expand Up @@ -497,7 +497,7 @@ func tryMatchMoreLeadingFilters(idxDef *IndexDef, node *plan.Node, pos int32) []
if i == 0 {
continue //already hit
}
currentPos, ok := node.TableDef.Name2ColIndex[idxDef.Parts[i]]
currentPos, ok := node.TableDef.Name2ColIndex[catalog.ResolveAlias(idxDef.Parts[i])]
if !ok {
break
}
Expand Down Expand Up @@ -714,7 +714,7 @@ func (builder *QueryBuilder) tryIndexOnlyScan(idxDef *IndexDef, node *plan.Node,
idxColMap[[2]int32{node.BindingTags[0], colIdx}] = leadingColExpr
} else {
for i := 0; i < numKeyParts; i++ {
colIdx := node.TableDef.Name2ColIndex[idxDef.Parts[i]]
colIdx := node.TableDef.Name2ColIndex[catalog.ResolveAlias(idxDef.Parts[i])]
origType := node.TableDef.Cols[colIdx].Typ
mappedExpr, _ := MakeSerialExtractExpr(builder.GetContext(), DeepCopyExpr(leadingColExpr), origType, int64(i))
idxColMap[[2]int32{node.BindingTags[0], colIdx}] = mappedExpr
Expand Down Expand Up @@ -877,7 +877,7 @@ func (builder *QueryBuilder) getMostSelectiveIndexForPointSelect(indexes []*Inde

filterIdx = filterIdx[:0]
for j := 0; j < numKeyParts; j++ {
colIdx := node.TableDef.Name2ColIndex[idxDef.Parts[j]]
colIdx := node.TableDef.Name2ColIndex[catalog.ResolveAlias(idxDef.Parts[j])]
idx, ok := col2filter[colIdx]
if !ok {
break
Expand Down Expand Up @@ -994,7 +994,7 @@ func (builder *QueryBuilder) applyIndicesForJoins(nodeID int32, node *plan.Node,

condIdx = condIdx[:0]
for i := 0; i < numKeyParts; i++ {
colIdx := leftChild.TableDef.Name2ColIndex[idxDef.Parts[i]]
colIdx := leftChild.TableDef.Name2ColIndex[catalog.ResolveAlias(idxDef.Parts[i])]
idx, ok := col2Cond[colIdx]
if !ok {
break
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/plan/apply_indices_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package plan

import (
"github.com/matrixorigin/matrixone/pkg/catalog"
"github.com/matrixorigin/matrixone/pkg/common/mpool"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
Expand Down Expand Up @@ -234,7 +235,7 @@ func makeIndexTblScan(builder *QueryBuilder, bindCtx *BindContext, filterExp *pl

func isKeyPresentInList(key string, list []string) bool {
for _, item := range list {
if key == item {
if key == catalog.ResolveAlias(item) {
return true
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/plan/build_dml_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ func isPrimaryKey(tableDef *TableDef, colNames []string) bool {
if uniqueKeyCount == 1 {
for _, col := range tableDef.Cols {
for _, colName := range colNames {
if col.Name == colName {
if col.Name == catalog.ResolveAlias(colName) {
if col.Default.NullAbility {
return false
}
Expand Down
5 changes: 5 additions & 0 deletions test/distributed/cases/optimizer/index.result
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,9 @@ insert into t1 select *,1111,* from generate_series(100001,150000) g;
update t1 set c1=c1+1000000, c2=1,c3=c3-1000000 where c2=1;
delete from t1;
drop table t1;
create table t1 (a timestamp, b varchar(10), key(b));
insert into t1 select "2024-01-01 10:10:10", "a"||result from generate_series(1,200000)g;
select * from t1 where a >= "2020-01-01 10:10:10" and a <= "2034-01-01 10:10:10" and b in ("a1");
a b
2024-01-01 10:10:10 a1
drop database d1;
3 changes: 3 additions & 0 deletions test/distributed/cases/optimizer/index.test
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,7 @@ insert into t1 select *,1111,* from generate_series(100001,150000) g;
update t1 set c1=c1+1000000, c2=1,c3=c3-1000000 where c2=1;
delete from t1;
drop table t1;
create table t1 (a timestamp, b varchar(10), key(b));
insert into t1 select "2024-01-01 10:10:10", "a"||result from generate_series(1,200000)g;
select * from t1 where a >= "2020-01-01 10:10:10" and a <= "2034-01-01 10:10:10" and b in ("a1");
drop database d1;

0 comments on commit 2926919

Please sign in to comment.