Skip to content

Commit

Permalink
Fix panic caused by resolve index table in subscription (#20793)
Browse files Browse the repository at this point in the history
Fix panic caused by resolve index table in subscription

Approved by: @daviszhen, @ouyuanning, @reusee, @sukki37
  • Loading branch information
ck89119 committed Dec 17, 2024
1 parent 32aad92 commit 254d24a
Show file tree
Hide file tree
Showing 19 changed files with 150 additions and 34 deletions.
42 changes: 42 additions & 0 deletions pkg/frontend/compiler_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,48 @@ func (tcc *TxnCompilerContext) Resolve(dbName string, tableName string, snapshot
return obj, tableDef
}

func (tcc *TxnCompilerContext) ResolveIndexTableByRef(
ref *plan.ObjectRef,
tblName string,
snapshot *plan2.Snapshot,
) (*plan2.ObjectRef, *plan2.TableDef) {
start := time.Now()
defer func() {
end := time.Since(start).Seconds()
v2.TxnStatementResolveDurationHistogram.Observe(end)
v2.TotalResolveDurationHistogram.Observe(end)
}()

// no need to ensureDatabaseIsNotEmpty

var subMeta *plan.SubscriptionMeta
if ref.PubInfo != nil {
subMeta = &plan.SubscriptionMeta{
AccountId: ref.PubInfo.TenantId,
}
}

ctx, table, err := tcc.getRelation(ref.SchemaName, tblName, subMeta, snapshot)
if err != nil {
return nil, nil
}

obj := &plan2.ObjectRef{
SchemaName: ref.SchemaName,
ObjName: tblName,
Obj: int64(table.GetTableID(ctx)),
SubscriptionName: ref.SubscriptionName,
PubInfo: ref.PubInfo,
}

tableDef := table.CopyTableDef(ctx)
if tableDef.IsTemporary {
tableDef.Name = tblName
}

return obj, tableDef
}

func (tcc *TxnCompilerContext) ResolveUdf(name string, args []*plan.Expr) (udf *function.Udf, err error) {
var matchNum int
var argstr string
Expand Down
10 changes: 10 additions & 0 deletions pkg/frontend/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,16 @@ func TestSession_TxnCompilerContext(t *testing.T) {
convey.So(object, convey.ShouldNotBeNil)
convey.So(tableRef, convey.ShouldNotBeNil)

ref := &plan.ObjectRef{
SchemaName: "schema",
PubInfo: &plan.PubInfo{
TenantId: 0,
},
}
object, tableRef = tcc.ResolveIndexTableByRef(ref, "indexTable", &plan2.Snapshot{TS: ts})
convey.So(object, convey.ShouldNotBeNil)
convey.So(tableRef, convey.ShouldNotBeNil)

pkd := tcc.GetPrimaryKeyDef("abc", "t1", &plan2.Snapshot{TS: ts})
convey.So(len(pkd), convey.ShouldBeZeroValue)

Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/compile/sql_executor_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ func (c *compilerContext) ResolveById(tableId uint64, snapshot *plan.Snapshot) (
return c.Resolve(dbName, tableName, snapshot)
}

func (c *compilerContext) ResolveIndexTableByRef(ref *plan.ObjectRef, tblName string, snapshot *plan.Snapshot) (*plan.ObjectRef, *plan.TableDef) {
return c.Resolve(plan.DbNameOfObjRef(ref), tblName, snapshot)
}

func (c *compilerContext) Resolve(dbName string, tableName string, snapshot *plan.Snapshot) (*plan.ObjectRef, *plan.TableDef) {
// In order to be compatible with various GUI clients and BI tools, lower case db and table name if it's a mysql system table
if slices.Contains(mysql.CaseInsensitiveDbs, strings.ToLower(dbName)) {
Expand Down
7 changes: 3 additions & 4 deletions pkg/sql/plan/apply_indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ func (builder *QueryBuilder) tryIndexOnlyScan(idxDef *IndexDef, node *plan.Node,
}

idxTag := builder.genNewTag()
idxObjRef, idxTableDef := builder.compCtx.Resolve(node.ObjRef.SchemaName, idxDef.IndexTableName, scanSnapshot)
idxObjRef, idxTableDef := builder.compCtx.ResolveIndexTableByRef(node.ObjRef, idxDef.IndexTableName, scanSnapshot)
builder.addNameByColRef(idxTag, idxTableDef)
leadingColExpr := GetColExpr(idxTableDef.Cols[0].Typ, idxTag, 0)

Expand Down Expand Up @@ -772,7 +772,7 @@ func (builder *QueryBuilder) getIndexForNonEquiCond(indexes []*IndexDef, node *p

func (builder *QueryBuilder) applyIndexJoin(idxDef *IndexDef, node *plan.Node, filterType int, filterIdx []int32, scanSnapshot *Snapshot) (int32, int32) {
idxTag := builder.genNewTag()
idxObjRef, idxTableDef := builder.compCtx.Resolve(node.ObjRef.SchemaName, idxDef.IndexTableName, scanSnapshot)
idxObjRef, idxTableDef := builder.compCtx.ResolveIndexTableByRef(node.ObjRef, idxDef.IndexTableName, scanSnapshot)
builder.addNameByColRef(idxTag, idxTableDef)

numParts := len(idxDef.Parts)
Expand Down Expand Up @@ -985,8 +985,7 @@ func (builder *QueryBuilder) applyIndicesForJoins(nodeID int32, node *plan.Node,
}

idxTag := builder.genNewTag()
//idxObjRef, idxTableDef := builder.compCtx.Resolve(leftChild.ObjRef.SchemaName, idxDef.IndexTableName, *ts)
idxObjRef, idxTableDef := builder.compCtx.Resolve(leftChild.ObjRef.SchemaName, idxDef.IndexTableName, scanSnapshot)
idxObjRef, idxTableDef := builder.compCtx.ResolveIndexTableByRef(leftChild.ObjRef, idxDef.IndexTableName, scanSnapshot)
builder.addNameByColRef(idxTag, idxTableDef)

rfTag := builder.genNewMsgTag()
Expand Down
3 changes: 1 addition & 2 deletions pkg/sql/plan/apply_indices_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func (builder *QueryBuilder) applyIndicesForFiltersUsingMasterIndex(nodeID int32
//ts1 := scanNode.ScanTS
for i, filterExp := range scanNode.FilterList {
// TODO: node should hold snapshot info and account info
//idxObjRef, idxTableDef := builder.compCtx.Resolve(scanNode.ObjRef.SchemaName, indexDef.IndexTableName, timestamp.Timestamp{})
idxObjRef, idxTableDef := builder.compCtx.Resolve(scanNode.ObjRef.SchemaName, indexDef.IndexTableName, nil)
idxObjRef, idxTableDef := builder.compCtx.ResolveIndexTableByRef(scanNode.ObjRef, indexDef.IndexTableName, nil)

// 1. SELECT pk from idx WHERE prefix_eq(`__mo_index_idx_col`,serial_full("0","value"))
currIdxScanTag, currScanId := makeIndexTblScan(builder, builder.ctxByNode[nodeID], filterExp, idxTableDef, idxObjRef, scanNode.ScanSnapshot, colDefs)
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/plan/apply_indices_vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ func (builder *QueryBuilder) applyIndicesForSortUsingVectorIndex(nodeID int32, p
scanSnapshot = &Snapshot{}
}

idxObjRefs[0], idxTableDefs[0] = builder.compCtx.Resolve(scanNode.ObjRef.SchemaName, multiTableIndexWithSortDistFn.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Metadata].IndexTableName, scanSnapshot)
idxObjRefs[1], idxTableDefs[1] = builder.compCtx.Resolve(scanNode.ObjRef.SchemaName, multiTableIndexWithSortDistFn.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Centroids].IndexTableName, scanSnapshot)
idxObjRefs[2], idxTableDefs[2] = builder.compCtx.Resolve(scanNode.ObjRef.SchemaName, multiTableIndexWithSortDistFn.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Entries].IndexTableName, scanSnapshot)
idxObjRefs[0], idxTableDefs[0] = builder.compCtx.ResolveIndexTableByRef(scanNode.ObjRef, multiTableIndexWithSortDistFn.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Metadata].IndexTableName, scanSnapshot)
idxObjRefs[1], idxTableDefs[1] = builder.compCtx.ResolveIndexTableByRef(scanNode.ObjRef, multiTableIndexWithSortDistFn.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Centroids].IndexTableName, scanSnapshot)
idxObjRefs[2], idxTableDefs[2] = builder.compCtx.ResolveIndexTableByRef(scanNode.ObjRef, multiTableIndexWithSortDistFn.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Entries].IndexTableName, scanSnapshot)

builder.addNameByColRef(idxTags["meta.scan"], idxTableDefs[0])
builder.addNameByColRef(idxTags["centroids.scan"], idxTableDefs[1])
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/plan/bind_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (builder *QueryBuilder) bindDelete(stmt *tree.Delete, bindCtx *BindContext)
return 0, moerr.NewUnsupportedDML(builder.GetContext(), "have vector index table")
}

idxObjRef, idxTableDef := builder.compCtx.Resolve(dmlCtx.objRefs[0].SchemaName, idxDef.IndexTableName, bindCtx.snapshot)
idxObjRef, idxTableDef := builder.compCtx.ResolveIndexTableByRef(dmlCtx.objRefs[0], idxDef.IndexTableName, bindCtx.snapshot)
if len(idxTableDef.Name2ColIndex) == 0 {
idxTableDef.Name2ColIndex = make(map[string]int32)
for colIdx, col := range idxTableDef.Cols {
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/plan/bind_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindInsert(
if !idxDef.TableExist || skipUniqueIdx[j] || !idxDef.Unique {
continue
}
_, idxTableDef := builder.compCtx.Resolve(dmlCtx.objRefs[0].SchemaName, idxDef.IndexTableName, bindCtx.snapshot)
_, idxTableDef := builder.compCtx.ResolveIndexTableByRef(dmlCtx.objRefs[0], idxDef.IndexTableName, bindCtx.snapshot)
var pkIdxInBat int32

if len(idxDef.Parts) == 1 {
Expand Down Expand Up @@ -246,7 +246,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindInsert(
continue
}

idxObjRefs[i], idxTableDefs[i] = builder.compCtx.Resolve(objRef.SchemaName, idxDef.IndexTableName, bindCtx.snapshot)
idxObjRefs[i], idxTableDefs[i] = builder.compCtx.ResolveIndexTableByRef(objRef, idxDef.IndexTableName, bindCtx.snapshot)
}
} else {
if pkName != catalog.FakePrimaryKeyColName {
Expand Down Expand Up @@ -339,7 +339,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindInsert(
continue
}

idxObjRefs[i], idxTableDefs[i] = builder.compCtx.Resolve(objRef.SchemaName, idxDef.IndexTableName, bindCtx.snapshot)
idxObjRefs[i], idxTableDefs[i] = builder.compCtx.ResolveIndexTableByRef(objRef, idxDef.IndexTableName, bindCtx.snapshot)

if !idxDef.Unique {
continue
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/plan/bind_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (builder *QueryBuilder) bindUpdate(stmt *tree.Update, bindCtx *BindContext)
continue
}

idxObjRef, idxTableDef := builder.compCtx.Resolve(dmlCtx.objRefs[i].SchemaName, idxDef.IndexTableName, bindCtx.snapshot)
idxObjRef, idxTableDef := builder.compCtx.ResolveIndexTableByRef(dmlCtx.objRefs[i], idxDef.IndexTableName, bindCtx.snapshot)
idxTag := builder.genNewTag()
builder.addNameByColRef(idxTag, idxTableDef)

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/plan/build_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func buildDelete(stmt *tree.Delete, ctx CompilerContext, isPrepareStmt bool) (*P
partTableIds := make([]uint64, tableDef.Partition.PartitionNum)
partTableNames := make([]string, tableDef.Partition.PartitionNum)
for j, partition := range tableDef.Partition.Partitions {
_, partTableDef := ctx.Resolve(tblInfo.objRef[i].SchemaName, partition.PartitionTableName, nil)
_, partTableDef := ctx.Resolve(DbNameOfObjRef(tblInfo.objRef[i]), partition.PartitionTableName, nil)
partTableIds[j] = partTableDef.TblId
partTableNames[j] = partition.PartitionTableName
}
Expand Down
34 changes: 17 additions & 17 deletions pkg/sql/plan/build_dml_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ func makeDeleteNodeInfo(ctx CompilerContext, objRef *ObjectRef, tableDef *TableD
partTableIds := make([]uint64, tableDef.Partition.PartitionNum)
partTableNames := make([]string, tableDef.Partition.PartitionNum)
for i, partition := range tableDef.Partition.Partitions {
_, partTableDef := ctx.Resolve(objRef.SchemaName, partition.PartitionTableName, nil)
_, partTableDef := ctx.Resolve(DbNameOfObjRef(objRef), partition.PartitionTableName, nil)
partTableIds[i] = partTableDef.TblId
partTableNames[i] = partition.PartitionTableName
}
Expand Down Expand Up @@ -1303,7 +1303,7 @@ func getPartTableIdsAndNames(ctx CompilerContext, objRef *ObjectRef, tableDef *T
partTableIds = make([]uint64, tableDef.Partition.PartitionNum)
partTableNames = make([]string, tableDef.Partition.PartitionNum)
for i, partition := range tableDef.Partition.Partitions {
_, partTableDef := ctx.Resolve(objRef.SchemaName, partition.PartitionTableName, nil)
_, partTableDef := ctx.Resolve(DbNameOfObjRef(objRef), partition.PartitionTableName, nil)
partTableIds[i] = partTableDef.TblId
partTableNames[i] = partition.PartitionTableName
}
Expand Down Expand Up @@ -3594,9 +3594,9 @@ func buildPreInsertMultiTableIndexes(ctx CompilerContext, builder *QueryBuilder,
//idxRefs[1], idxTableDefs[1] = ctx.Resolve(objRef.SchemaName, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Centroids].IndexTableName, timestamp.Timestamp{})
//idxRefs[2], idxTableDefs[2] = ctx.Resolve(objRef.SchemaName, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Entries].IndexTableName, timestamp.Timestamp{})

idxRefs[0], idxTableDefs[0] = ctx.Resolve(objRef.SchemaName, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Metadata].IndexTableName, nil)
idxRefs[1], idxTableDefs[1] = ctx.Resolve(objRef.SchemaName, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Centroids].IndexTableName, nil)
idxRefs[2], idxTableDefs[2] = ctx.Resolve(objRef.SchemaName, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Entries].IndexTableName, nil)
idxRefs[0], idxTableDefs[0] = ctx.ResolveIndexTableByRef(objRef, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Metadata].IndexTableName, nil)
idxRefs[1], idxTableDefs[1] = ctx.ResolveIndexTableByRef(objRef, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Centroids].IndexTableName, nil)
idxRefs[2], idxTableDefs[2] = ctx.ResolveIndexTableByRef(objRef, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Entries].IndexTableName, nil)

// remove row_id
for i := range idxTableDefs {
Expand Down Expand Up @@ -3658,9 +3658,9 @@ func buildDeleteMultiTableIndexes(ctx CompilerContext, builder *QueryBuilder, bi
//idxRefs[1], idxTableDefs[1] = ctx.Resolve(delCtx.objRef.SchemaName, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Centroids].IndexTableName, timestamp.Timestamp{})
//idxRefs[2], idxTableDefs[2] = ctx.Resolve(delCtx.objRef.SchemaName, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Entries].IndexTableName, timestamp.Timestamp{})

idxRefs[0], idxTableDefs[0] = ctx.Resolve(delCtx.objRef.SchemaName, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Metadata].IndexTableName, nil)
idxRefs[1], idxTableDefs[1] = ctx.Resolve(delCtx.objRef.SchemaName, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Centroids].IndexTableName, nil)
idxRefs[2], idxTableDefs[2] = ctx.Resolve(delCtx.objRef.SchemaName, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Entries].IndexTableName, nil)
idxRefs[0], idxTableDefs[0] = ctx.ResolveIndexTableByRef(delCtx.objRef, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Metadata].IndexTableName, nil)
idxRefs[1], idxTableDefs[1] = ctx.ResolveIndexTableByRef(delCtx.objRef, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Centroids].IndexTableName, nil)
idxRefs[2], idxTableDefs[2] = ctx.ResolveIndexTableByRef(delCtx.objRef, multiTableIndex.IndexDefs[catalog.SystemSI_IVFFLAT_TblType_Entries].IndexTableName, nil)

entriesObjRef, entriesTableDef := idxRefs[2], idxTableDefs[2]
if entriesTableDef == nil {
Expand Down Expand Up @@ -3791,7 +3791,7 @@ func buildDeleteMultiTableIndexes(ctx CompilerContext, builder *QueryBuilder, bi
func buildPreInsertRegularIndex(stmt *tree.Insert, ctx CompilerContext, builder *QueryBuilder, bindCtx *BindContext, objRef *ObjectRef, tableDef *TableDef,
sourceStep int32, ifInsertFromUniqueColMap map[string]bool, indexdef *plan.IndexDef, idx int) error {

idxRef, idxTableDef := ctx.Resolve(objRef.SchemaName, indexdef.IndexTableName, nil)
idxRef, idxTableDef := ctx.ResolveIndexTableByRef(objRef, indexdef.IndexTableName, nil)
// remove row_id
idxTableDef.Cols = RemoveIf[*ColDef](idxTableDef.Cols, func(col *ColDef) bool {
return col.Name == catalog.Row_ID
Expand All @@ -3813,7 +3813,7 @@ func buildPreInsertRegularIndex(stmt *tree.Insert, ctx CompilerContext, builder
// with the primary key of the hidden table as the unique key.
// package contains some information needed by the fuzzy filter to run background SQL.
if indexdef.GetUnique() {
_, idxTableDef := ctx.Resolve(objRef.SchemaName, indexdef.IndexTableName, nil)
_, idxTableDef := ctx.ResolveIndexTableByRef(objRef, indexdef.IndexTableName, nil)
// remove row_id
idxTableDef.Cols = RemoveIf[*ColDef](idxTableDef.Cols, func(colVal *ColDef) bool {
return colVal.Name == catalog.Row_ID
Expand Down Expand Up @@ -3897,7 +3897,7 @@ func buildPreInsertRegularIndex(stmt *tree.Insert, ctx CompilerContext, builder

func buildPreInsertMasterIndex(stmt *tree.Insert, ctx CompilerContext, builder *QueryBuilder, bindCtx *BindContext, objRef *ObjectRef, tableDef *TableDef,
sourceStep int32, ifInsertFromUniqueColMap map[string]bool, indexdef *plan.IndexDef, idx int) error {
idxRef, idxTableDef := ctx.Resolve(objRef.SchemaName, indexdef.IndexTableName, nil)
idxRef, idxTableDef := ctx.ResolveIndexTableByRef(objRef, indexdef.IndexTableName, nil)
// remove row_id
idxTableDef.Cols = RemoveIf[*ColDef](idxTableDef.Cols, func(colVal *ColDef) bool {
return colVal.Name == catalog.Row_ID
Expand Down Expand Up @@ -3947,7 +3947,7 @@ func buildDeleteRegularIndex(ctx CompilerContext, builder *QueryBuilder, bindCtx
var isUk = indexdef.Unique
var isSK = !isUk && catalog.IsRegularIndexAlgo(indexdef.IndexAlgo)

uniqueObjRef, uniqueTableDef := builder.compCtx.Resolve(delCtx.objRef.SchemaName, indexdef.IndexTableName, nil)
uniqueObjRef, uniqueTableDef := builder.compCtx.ResolveIndexTableByRef(delCtx.objRef, indexdef.IndexTableName, nil)
if uniqueTableDef == nil {
return moerr.NewNoSuchTable(builder.GetContext(), delCtx.objRef.SchemaName, indexdef.IndexTableName)
}
Expand Down Expand Up @@ -4058,7 +4058,7 @@ func buildDeleteMasterIndex(ctx CompilerContext, builder *QueryBuilder, bindCtx
indexdef *plan.IndexDef, idx int, typMap map[string]plan.Type, posMap map[string]int) error {
isUpdate := delCtx.updateColLength > 0
// Used by pre-insert vector index.
masterObjRef, masterTableDef := ctx.Resolve(delCtx.objRef.SchemaName, indexdef.IndexTableName, nil)
masterObjRef, masterTableDef := ctx.ResolveIndexTableByRef(delCtx.objRef, indexdef.IndexTableName, nil)
if masterTableDef == nil {
return moerr.NewNoSuchTable(builder.GetContext(), delCtx.objRef.SchemaName, indexdef.IndexName)
}
Expand Down Expand Up @@ -4471,7 +4471,7 @@ func buildPreInsertFullTextIndex(stmt *tree.Insert, ctx CompilerContext, builder

lastNodeId = builder.appendNode(projectNode, bindCtx)

indexObjRef, indexTableDef := ctx.Resolve(objRef.SchemaName, indexdef.IndexTableName, nil)
indexObjRef, indexTableDef := ctx.ResolveIndexTableByRef(objRef, indexdef.IndexTableName, nil)
if indexTableDef == nil {
return moerr.NewNoSuchTable(builder.GetContext(), objRef.SchemaName, indexdef.IndexName)
}
Expand Down Expand Up @@ -4717,7 +4717,7 @@ func buildPreDeleteFullTextIndex(ctx CompilerContext, builder *QueryBuilder, bin
indexdef *plan.IndexDef, idx int, typMap map[string]plan.Type, posMap map[string]int) error {

//isUpdate := delCtx.updateColLength > 0
indexObjRef, indexTableDef := ctx.Resolve(delCtx.objRef.SchemaName, indexdef.IndexTableName, nil)
indexObjRef, indexTableDef := ctx.ResolveIndexTableByRef(delCtx.objRef, indexdef.IndexTableName, nil)
if indexTableDef == nil {
return moerr.NewNoSuchTable(builder.GetContext(), delCtx.objRef.SchemaName, indexdef.IndexName)
}
Expand Down Expand Up @@ -4784,7 +4784,7 @@ func buildPostDeleteFullTextIndex(ctx CompilerContext, builder *QueryBuilder, bi
isDelete := true
isInsert := delCtx.updateColLength > 0

indexObjRef, indexTableDef := ctx.Resolve(delCtx.objRef.SchemaName, indexdef.IndexTableName, nil)
indexObjRef, indexTableDef := ctx.ResolveIndexTableByRef(delCtx.objRef, indexdef.IndexTableName, nil)
if indexTableDef == nil {
return moerr.NewNoSuchTable(builder.GetContext(), delCtx.objRef.SchemaName, indexdef.IndexName)
}
Expand All @@ -4802,7 +4802,7 @@ func buildPostInsertFullTextIndex(stmt *tree.Insert, ctx CompilerContext, builde
isInsert := true
isDeleteWithoutFilters := false

indexObjRef, indexTableDef := ctx.Resolve(objRef.SchemaName, indexdef.IndexTableName, nil)
indexObjRef, indexTableDef := ctx.ResolveIndexTableByRef(objRef, indexdef.IndexTableName, nil)
if indexTableDef == nil {
return moerr.NewNoSuchTable(builder.GetContext(), objRef.SchemaName, indexdef.IndexName)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/plan/build_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func getPartitionInfos(ctx CompilerContext, objRef *ObjectRef, tableDef *TableDe
partTableIds := make([]uint64, tableDef.Partition.PartitionNum)
partTableNames := make([]string, tableDef.Partition.PartitionNum)
for i, partition := range tableDef.Partition.Partitions {
_, partTableDef := ctx.Resolve(objRef.SchemaName, partition.PartitionTableName, nil)
_, partTableDef := ctx.Resolve(DbNameOfObjRef(objRef), partition.PartitionTableName, nil)
partTableIds[i] = partTableDef.TblId
partTableNames[i] = partition.PartitionTableName
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/plan/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func (m *MockCompilerContext) CheckSubscriptionValid(subName, accName string, pu
panic("implement me")
}

func (m *MockCompilerContext) ResolveIndexTableByRef(ref *ObjectRef, tblName string, snapshot *Snapshot) (*ObjectRef, *TableDef) {
return m.Resolve(DbNameOfObjRef(ref), tblName, snapshot)
}

func (m *MockCompilerContext) ResolveSubscriptionTableById(tableId uint64, pubmeta *SubscriptionMeta) (*ObjectRef, *TableDef) {
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/plan/opt_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ func (builder *QueryBuilder) lockTableIfLockNoRowsAtTheEndForDelAndUpdate() (err
tableIDs[tableDef.TblId] = true
for _, idx := range tableDef.Indexes {
if idx.TableExist {
_, idxTableDef := builder.compCtx.Resolve(objRef.SchemaName, idx.IndexTableName, nil)
_, idxTableDef := builder.compCtx.ResolveIndexTableByRef(objRef, idx.IndexTableName, nil)
if idxTableDef == nil {
return
}
Expand Down
Loading

0 comments on commit 254d24a

Please sign in to comment.