Skip to content

Commit

Permalink
expression: refactor names from VectorHelper to VSInfo (#58192)
Browse files Browse the repository at this point in the history
ref #54245
  • Loading branch information
breezewish authored Dec 12, 2024
1 parent 96103da commit 4e6468d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
13 changes: 8 additions & 5 deletions pkg/expression/vs_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@ var (
}
)

// VectorHelper is a helper struct for vector indexes.
type VectorHelper struct {
// VSInfo is an easy to use struct for interpreting a VectorSearch expression.
// NOTE: not all VectorSearch functions are supported by the index. The caller
// needs to check the distance function name.
type VSInfo struct {
DistanceFnName model.CIStr
FnPbCode tipb.ScalarFuncSig
Vec types.VectorFloat32
Column *Column
}

// ExtractVectorHelper extracts a VectorSearchExpr from an expression.
// InterpretVectorSearchExpr try to interpret a VectorSearch expression.
// If interpret successfully, return a VSInfo struct, otherwise return nil.
// NOTE: not all VectorSearch functions are supported by the index. The caller
// needs to check the distance function name.
func ExtractVectorHelper(expr Expression) *VectorHelper {
func InterpretVectorSearchExpr(expr Expression) *VSInfo {
x, ok := expr.(*ScalarFunction)
if !ok {
return nil
Expand Down Expand Up @@ -82,7 +85,7 @@ func ExtractVectorHelper(expr Expression) *VectorHelper {

intest.Assert(vectorConstant.Value.Kind() == types.KindVectorFloat32, "internal: expect vectorFloat32 constant, but got %s", vectorConstant.Value.String())

return &VectorHelper{
return &VSInfo{
DistanceFnName: x.FuncName,
FnPbCode: x.Function.PbCode(),
Vec: vectorConstant.Value.GetVectorFloat32(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ func getPhysTopN(lt *logicalop.LogicalTopN, prop *property.PhysicalProperty) []b
if len(lt.ByItems) != 1 {
return ret
}
vs := expression.ExtractVectorHelper(lt.ByItems[0].Expr)
vs := expression.InterpretVectorSearchExpr(lt.ByItems[0].Expr)
if vs == nil {
return ret
}
Expand All @@ -2211,7 +2211,7 @@ func getPhysTopN(lt *logicalop.LogicalTopN, prop *property.PhysicalProperty) []b
ExpectedCnt: math.MaxFloat64,
CTEProducerStatus: prop.CTEProducerStatus,
}
resultProp.VectorProp.VectorHelper = vs
resultProp.VectorProp.VSInfo = vs
resultProp.VectorProp.TopK = uint32(lt.Count + lt.Offset)
topN := PhysicalTopN{
ByItems: lt.ByItems,
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ func compareCandidates(sctx base.PlanContext, prop *property.PhysicalProperty, l
}

func isMatchProp(ds *logicalop.DataSource, path *util.AccessPath, prop *property.PhysicalProperty) bool {
if prop.VectorProp.VectorHelper != nil && path.Index != nil && path.Index.VectorInfo != nil {
if prop.VectorProp.VSInfo != nil && path.Index != nil && path.Index.VectorInfo != nil {
if path.Index == nil || path.Index.VectorInfo == nil {
return false
}
Expand Down Expand Up @@ -2911,7 +2911,7 @@ func getOriginalPhysicalTableScan(ds *logicalop.DataSource, prop *property.Physi
if usedStats != nil && usedStats.GetUsedInfo(ts.physicalTableID) != nil {
ts.usedStatsInfo = usedStats.GetUsedInfo(ts.physicalTableID)
}
if isMatchProp && prop.VectorProp.VectorHelper == nil {
if isMatchProp && prop.VectorProp.VSInfo == nil {
ts.Desc = prop.SortItems[0].Desc
ts.KeepOrder = true
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/property/physical_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ type PhysicalProperty struct {
CTEProducerStatus cteProducerStatus

VectorProp struct {
*expression.VectorHelper
*expression.VSInfo
TopK uint32
}
}
Expand Down Expand Up @@ -381,7 +381,7 @@ func (p *PhysicalProperty) HashCode() []byte {
for _, col := range p.MPPPartitionCols {
p.hashcode = append(p.hashcode, col.hashCode()...)
}
if p.VectorProp.VectorHelper != nil {
if p.VectorProp.VSInfo != nil {
// We only accpect the vector information from the TopN which is directly above the DataSource.
// So it's safe to not hash the vector constant.
p.hashcode = append(p.hashcode, p.VectorProp.Column.HashCode()...)
Expand Down

0 comments on commit 4e6468d

Please sign in to comment.