Skip to content

Commit e14a2a9

Browse files
committed
output vector distance directly by Reader
1 parent 3d62766 commit e14a2a9

36 files changed

+164
-156
lines changed

pkg/sql/plan/agg_pushdown_pullup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ func applyAggPushdown(agg, join, leftChild *plan.Node, builder *QueryBuilder) {
118118
//newGroupBy := DeepCopyExprList(agg.GroupBy)
119119
newGroupBy := []*plan.Expr{DeepCopyExpr(filterTag(join.OnList[0], leftChildTag))}
120120

121-
newGroupTag := builder.genNewTag()
122-
newAggTag := builder.genNewTag()
121+
newGroupTag := builder.genNewBindTag()
122+
newAggTag := builder.genNewBindTag()
123123
newNodeID := builder.appendNode(
124124
&plan.Node{
125125
NodeType: plan.Node_AGG,

pkg/sql/plan/apply_indices.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ func (builder *QueryBuilder) tryIndexOnlyScan(idxDef *IndexDef, node *plan.Node,
672672
return -1
673673
}
674674

675-
idxTag := builder.genNewTag()
675+
idxTag := builder.genNewBindTag()
676676
idxObjRef, idxTableDef, e := builder.compCtx.ResolveIndexTableByRef(node.ObjRef, idxDef.IndexTableName, scanSnapshot)
677677
if e != nil {
678678
panic(e)
@@ -759,7 +759,7 @@ func (builder *QueryBuilder) getIndexForNonEquiCond(indexes []*IndexDef, node *p
759759
}
760760

761761
func (builder *QueryBuilder) applyIndexJoin(idxDef *IndexDef, node *plan.Node, filterType int, filterIdx []int32, scanSnapshot *Snapshot) (int32, int32) {
762-
idxTag := builder.genNewTag()
762+
idxTag := builder.genNewBindTag()
763763
idxObjRef, idxTableDef, err := builder.compCtx.ResolveIndexTableByRef(node.ObjRef, idxDef.IndexTableName, scanSnapshot)
764764
if err != nil {
765765
panic(err)
@@ -989,7 +989,7 @@ func (builder *QueryBuilder) applyIndicesForJoins(nodeID int32, node *plan.Node,
989989
continue
990990
}
991991

992-
idxTag := builder.genNewTag()
992+
idxTag := builder.genNewBindTag()
993993
idxObjRef, idxTableDef, err := builder.compCtx.ResolveIndexTableByRef(leftChild.ObjRef, idxDef.IndexTableName, scanSnapshot)
994994
if err != nil {
995995
panic(err)

pkg/sql/plan/apply_indices_hnsw.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (builder *QueryBuilder) applyIndicesForSortUsingHnsw(nodeID int32, projNode
103103
origFuncName)
104104

105105
// JOIN between source table and hnsw_search table function
106-
tableFuncTag := builder.genNewTag()
106+
tableFuncTag := builder.genNewBindTag()
107107
tableFuncNode := &plan.Node{
108108
NodeType: plan.Node_FUNCTION_SCAN,
109109
Stats: &plan.Stats{},

pkg/sql/plan/apply_indices_ivfflat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (builder *QueryBuilder) applyIndicesForSortUsingIvfflat(nodeID int32, projN
124124
origFuncName)
125125

126126
// JOIN between source table and hnsw_search table function
127-
tableFuncTag := builder.genNewTag()
127+
tableFuncTag := builder.genNewBindTag()
128128
tableFuncNode := &plan.Node{
129129
NodeType: plan.Node_FUNCTION_SCAN,
130130
Stats: &plan.Stats{},

pkg/sql/plan/apply_indices_master.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func makeIndexTblScan(builder *QueryBuilder, bindCtx *BindContext, filterExp *pl
126126
idxTableDef *TableDef, idxObjRef *ObjectRef, scanSnapshot *Snapshot, colDefs []*plan.ColDef) (int32, int32) {
127127

128128
// a. Scan * WHERE prefix_eq(`__mo_index_idx_col`,serial_full("0","value"))
129-
idxScanTag := builder.genNewTag()
129+
idxScanTag := builder.genNewBindTag()
130130
args := filterExp.GetF().Args
131131

132132
var filterList *plan.Expr

pkg/sql/plan/bind_delete.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (builder *QueryBuilder) bindDelete(ctx CompilerContext, stmt *tree.Delete,
166166
idxTableDef.Name2ColIndex[col.Name] = int32(colIdx)
167167
}
168168
}
169-
idxTag := builder.genNewTag()
169+
idxTag := builder.genNewBindTag()
170170
builder.addNameByColRef(idxTag, idxTableDef)
171171

172172
idxScanNodes[i][j] = &plan.Node{
@@ -252,7 +252,7 @@ func (builder *QueryBuilder) bindDelete(ctx CompilerContext, stmt *tree.Delete,
252252

253253
dmlNode := &plan.Node{
254254
NodeType: plan.Node_MULTI_UPDATE,
255-
BindingTags: []int32{builder.genNewTag()},
255+
BindingTags: []int32{builder.genNewBindTag()},
256256
}
257257
selectNodeTag := selectNode.BindingTags[0]
258258
var lockTargets []*plan.LockTarget
@@ -355,7 +355,7 @@ func (builder *QueryBuilder) bindDelete(ctx CompilerContext, stmt *tree.Delete,
355355
NodeType: plan.Node_LOCK_OP,
356356
Children: []int32{lastNodeID},
357357
TableDef: dmlCtx.tableDefs[0],
358-
BindingTags: []int32{builder.genNewTag()},
358+
BindingTags: []int32{builder.genNewBindTag()},
359359
LockTargets: lockTargets,
360360
}, bindCtx)
361361

pkg/sql/plan/bind_insert.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindInsert(
133133

134134
selectNode := builder.qry.Nodes[lastNodeID]
135135
selectTag := selectNode.BindingTags[0]
136-
scanTag := builder.genNewTag()
136+
scanTag := builder.genNewBindTag()
137137
updateExprs := make(map[string]*plan.Expr)
138138

139139
if len(astUpdateExprs) == 0 {
@@ -259,7 +259,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindInsert(
259259
NodeType: plan.Node_LOCK_OP,
260260
Children: []int32{lastNodeID},
261261
TableDef: tableDef,
262-
BindingTags: []int32{builder.genNewTag()},
262+
BindingTags: []int32{builder.genNewBindTag()},
263263
LockTargets: lockTargets,
264264
}, bindCtx)
265265
reCheckifNeedLockWholeTable(builder)
@@ -563,7 +563,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindInsert(
563563
}
564564

565565
// step 2: append unique dedup join on the `__mo_index_idx_col` if expression
566-
idxTag := builder.genNewTag()
566+
idxTag := builder.genNewBindTag()
567567
builder.addNameByColRef(idxTag, idxTableDefs[i])
568568

569569
idxScanNode := &plan.Node{
@@ -649,7 +649,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindInsert(
649649

650650
if newProjLen > len(selectNode.ProjectList) {
651651
newProjList := make([]*plan.Expr, 0, newProjLen)
652-
finalProjTag := builder.genNewTag()
652+
finalProjTag := builder.genNewBindTag()
653653
pkPos := colName2Idx[tableDef.Name+"."+tableDef.Pkey.PkeyColName]
654654

655655
// input batch columns
@@ -836,7 +836,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindInsert(
836836
now, we need to join the index table to fetch the right rowid.
837837
*/
838838

839-
idxTag := builder.genNewTag()
839+
idxTag := builder.genNewBindTag()
840840
builder.addNameByColRef(idxTag, idxTableDefs[i])
841841

842842
idxScanNode := &plan.Node{
@@ -891,7 +891,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindInsert(
891891

892892
dmlNode := &plan.Node{
893893
NodeType: plan.Node_MULTI_UPDATE,
894-
BindingTags: []int32{builder.genNewTag()},
894+
BindingTags: []int32{builder.genNewBindTag()},
895895
}
896896

897897
insertCols := make([]plan.ColRef, len(tableDef.Cols)-1)
@@ -1133,8 +1133,8 @@ func (builder *QueryBuilder) appendNodesForInsertStmt(
11331133

11341134
projList1 := make([]*plan.Expr, 0, len(tableDef.Cols)-1)
11351135
projList2 := make([]*plan.Expr, 0, len(tableDef.Cols)-1)
1136-
projTag1 := builder.genNewTag()
1137-
preInsertTag := builder.genNewTag()
1136+
projTag1 := builder.genNewBindTag()
1137+
preInsertTag := builder.genNewBindTag()
11381138

11391139
var (
11401140
compPkeyExpr *plan.Expr
@@ -1272,7 +1272,7 @@ func (builder *QueryBuilder) appendNodesForInsertStmt(
12721272
NodeType: plan.Node_PROJECT,
12731273
ProjectList: projList2,
12741274
Children: []int32{lastNodeID},
1275-
BindingTags: []int32{builder.genNewTag()},
1275+
BindingTags: []int32{builder.genNewBindTag()},
12761276
}, tmpCtx)
12771277

12781278
return lastNodeID, colName2Idx, skipUniqueIdx, nil
@@ -1288,7 +1288,7 @@ func (builder *QueryBuilder) buildValueScan(
12881288
var err error
12891289

12901290
proc := builder.compCtx.GetProcess()
1291-
lastTag := builder.genNewTag()
1291+
lastTag := builder.genNewBindTag()
12921292
colCount := len(colNames)
12931293
rowsetData := &plan.RowsetData{
12941294
Cols: make([]*plan.ColData, colCount),
@@ -1403,7 +1403,7 @@ func (builder *QueryBuilder) buildValueScan(
14031403
return 0, err
14041404
}
14051405

1406-
lastTag = builder.genNewTag()
1406+
lastTag = builder.genNewBindTag()
14071407
nodeID = builder.appendNode(&plan.Node{
14081408
NodeType: plan.Node_PROJECT,
14091409
ProjectList: projectList,

pkg/sql/plan/bind_load.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (builder *QueryBuilder) bindExternalScan(
4242
stmt *tree.Load,
4343
bindCtx *BindContext,
4444
dmlCtx *DMLContext) (int32, map[string]*plan.Expr, error) {
45-
externalScanTag := builder.genNewTag()
45+
externalScanTag := builder.genNewBindTag()
4646
err := dmlCtx.ResolveTables(builder.compCtx, tree.TableExprs{stmt.Table}, nil, nil, true)
4747
if err != nil {
4848
return -1, nil, err

pkg/sql/plan/bind_replace.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindReplace(
5959
selectNode := builder.qry.Nodes[lastNodeID]
6060
selectTag := selectNode.BindingTags[0]
6161

62-
fullProjTag := builder.genNewTag()
62+
fullProjTag := builder.genNewBindTag()
6363
fullProjList := make([]*plan.Expr, 0, len(selectNode.ProjectList)+len(tableDef.Cols))
6464
for i, expr := range selectNode.ProjectList {
6565
fullProjList = append(fullProjList, &plan.Expr{
@@ -80,7 +80,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindReplace(
8080

8181
// get old columns from existing main table
8282
{
83-
oldScanTag := builder.genNewTag()
83+
oldScanTag := builder.genNewBindTag()
8484

8585
builder.addNameByColRef(oldScanTag, tableDef)
8686

@@ -186,7 +186,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindReplace(
186186

187187
// detect primary key confliction
188188
{
189-
scanTag := builder.genNewTag()
189+
scanTag := builder.genNewBindTag()
190190

191191
// handle primary/unique key confliction
192192
builder.addNameByColRef(scanTag, tableDef)
@@ -268,7 +268,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindReplace(
268268
continue
269269
}
270270

271-
idxTag := builder.genNewTag()
271+
idxTag := builder.genNewBindTag()
272272
builder.addNameByColRef(idxTag, idxTableDefs[i])
273273

274274
idxScanNode := &plan.Node{
@@ -352,7 +352,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindReplace(
352352

353353
// get old RowID for index tables
354354
for i := range tableDef.Indexes {
355-
idxTag := builder.genNewTag()
355+
idxTag := builder.genNewBindTag()
356356
builder.addNameByColRef(idxTag, idxTableDefs[i])
357357

358358
idxScanNode := &plan.Node{
@@ -408,7 +408,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindReplace(
408408
lockTargets := make([]*plan.LockTarget, 0)
409409
updateCtxList := make([]*plan.UpdateCtx, 0)
410410

411-
finalProjTag := builder.genNewTag()
411+
finalProjTag := builder.genNewBindTag()
412412
finalProjList := make([]*plan.Expr, 0, len(tableDef.Cols)+len(tableDef.Indexes)*2)
413413
var newPkIdx int32
414414

@@ -580,7 +580,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindReplace(
580580
NodeType: plan.Node_LOCK_OP,
581581
Children: []int32{lastNodeID},
582582
TableDef: tableDef,
583-
BindingTags: []int32{builder.genNewTag()},
583+
BindingTags: []int32{builder.genNewBindTag()},
584584
LockTargets: lockTargets,
585585
}, bindCtx)
586586
reCheckifNeedLockWholeTable(builder)
@@ -589,7 +589,7 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindReplace(
589589
lastNodeID = builder.appendNode(&plan.Node{
590590
NodeType: plan.Node_MULTI_UPDATE,
591591
Children: []int32{lastNodeID},
592-
BindingTags: []int32{builder.genNewTag()},
592+
BindingTags: []int32{builder.genNewBindTag()},
593593
UpdateCtxList: updateCtxList,
594594
}, bindCtx)
595595

@@ -614,8 +614,8 @@ func (builder *QueryBuilder) appendNodesForReplaceStmt(
614614

615615
projList1 := make([]*plan.Expr, 0, len(tableDef.Cols)-1)
616616
projList2 := make([]*plan.Expr, 0, len(tableDef.Cols)-1)
617-
projTag1 := builder.genNewTag()
618-
preInsertTag := builder.genNewTag()
617+
projTag1 := builder.genNewBindTag()
618+
preInsertTag := builder.genNewBindTag()
619619

620620
var (
621621
compPkeyExpr *plan.Expr
@@ -778,7 +778,7 @@ func (builder *QueryBuilder) appendNodesForReplaceStmt(
778778
NodeType: plan.Node_PROJECT,
779779
ProjectList: projList2,
780780
Children: []int32{lastNodeID},
781-
BindingTags: []int32{builder.genNewTag()},
781+
BindingTags: []int32{builder.genNewBindTag()},
782782
}, tmpCtx)
783783

784784
return lastNodeID, colName2Idx, skipUniqueIdx, nil

pkg/sql/plan/bind_update.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func (builder *QueryBuilder) bindUpdate(stmt *tree.Update, bindCtx *BindContext)
270270
}
271271

272272
if updatePkOrUk {
273-
newProjTag := builder.genNewTag()
273+
newProjTag := builder.genNewBindTag()
274274
newProjList := make([]*plan.Expr, len(selectNode.ProjectList))
275275
for i := range selectNode.ProjectList {
276276
newProjList[i] = &plan.Expr{
@@ -325,7 +325,7 @@ func (builder *QueryBuilder) bindUpdate(stmt *tree.Update, bindCtx *BindContext)
325325
newProjNode.ProjectList = append(newProjNode.ProjectList, newPkExpr)
326326
}
327327

328-
scanTag := builder.genNewTag()
328+
scanTag := builder.genNewBindTag()
329329
scanNodeID := builder.appendNode(&plan.Node{
330330
NodeType: plan.Node_TABLE_SCAN,
331331
TableDef: tableDef,
@@ -406,7 +406,7 @@ func (builder *QueryBuilder) bindUpdate(stmt *tree.Update, bindCtx *BindContext)
406406
if err != nil {
407407
return 0, err
408408
}
409-
idxTag := builder.genNewTag()
409+
idxTag := builder.genNewBindTag()
410410
builder.addNameByColRef(idxTag, idxTableDef)
411411

412412
idxScanNode := &plan.Node{
@@ -549,7 +549,7 @@ func (builder *QueryBuilder) bindUpdate(stmt *tree.Update, bindCtx *BindContext)
549549
if err != nil {
550550
return 0, err
551551
}
552-
idxTag := builder.genNewTag()
552+
idxTag := builder.genNewBindTag()
553553
builder.addNameByColRef(idxTag, idxTableDef)
554554

555555
idxScanNodes[i][j] = &plan.Node{
@@ -624,7 +624,7 @@ func (builder *QueryBuilder) bindUpdate(stmt *tree.Update, bindCtx *BindContext)
624624
lockTargets := make([]*plan.LockTarget, 0)
625625
updateCtxList := make([]*plan.UpdateCtx, 0)
626626

627-
finalProjTag := builder.genNewTag()
627+
finalProjTag := builder.genNewBindTag()
628628
finalColName2Idx := make(map[string]int32)
629629
var finalProjList []*plan.Expr
630630

@@ -846,15 +846,15 @@ func (builder *QueryBuilder) bindUpdate(stmt *tree.Update, bindCtx *BindContext)
846846

847847
dmlNode := &plan.Node{
848848
NodeType: plan.Node_MULTI_UPDATE,
849-
BindingTags: []int32{builder.genNewTag()},
849+
BindingTags: []int32{builder.genNewBindTag()},
850850
UpdateCtxList: updateCtxList,
851851
}
852852

853853
lastNodeID = builder.appendNode(&plan.Node{
854854
NodeType: plan.Node_LOCK_OP,
855855
Children: []int32{lastNodeID},
856856
TableDef: dmlCtx.tableDefs[0],
857-
BindingTags: []int32{builder.genNewTag()},
857+
BindingTags: []int32{builder.genNewBindTag()},
858858
LockTargets: lockTargets,
859859
}, bindCtx)
860860
reCheckifNeedLockWholeTable(builder)

0 commit comments

Comments
 (0)