Skip to content

Commit

Permalink
planner: add hash64 equals for tableDual/topN/unionScan/Window. (ping…
Browse files Browse the repository at this point in the history
  • Loading branch information
AilinKid authored Nov 15, 2024
1 parent 4272a56 commit 89804dd
Show file tree
Hide file tree
Showing 10 changed files with 671 additions and 15 deletions.
22 changes: 22 additions & 0 deletions pkg/meta/model/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/parser/types"
"github.com/pingcap/tidb/pkg/planner/cascades/base"
)

// DistanceMetric is the distance metric used by the vector index.
Expand Down Expand Up @@ -78,6 +79,27 @@ type IndexInfo struct {
VectorInfo *VectorIndexInfo `json:"vector_index"` // VectorInfo is the vector index information.
}

// Hash64 implement HashEquals interface.
func (index *IndexInfo) Hash64(h base.Hasher) {
h.HashInt64(index.ID)
}

// Equals implements HashEquals interface.
func (index *IndexInfo) Equals(other any) bool {
// any(nil) can still be converted as (*IndexInfo)(nil)
index2, ok := other.(*IndexInfo)
if !ok {
return false
}
if index == nil {
return index2 == nil
}
if index2 == nil {
return false
}
return index.ID == index2.ID
}

// Clone clones IndexInfo.
func (index *IndexInfo) Clone() *IndexInfo {
if index == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func GenHash64Equals4LogicalOps() ([]byte, error) {
logicalop.LogicalExpand{}, logicalop.LogicalLimit{}, logicalop.LogicalMaxOneRow{}, logicalop.DataSource{},
logicalop.LogicalMemTable{}, logicalop.LogicalUnionAll{}, logicalop.LogicalPartitionUnionAll{}, logicalop.LogicalProjection{},
logicalop.LogicalSelection{}, logicalop.LogicalShow{}, logicalop.LogicalShowDDLJobs{}, logicalop.LogicalSort{},
logicalop.LogicalTableDual{}, logicalop.LogicalTopN{}, logicalop.LogicalUnionScan{}, logicalop.LogicalWindow{},
}
c := new(cc)
c.write(codeGenHash64EqualsPrefix)
Expand Down Expand Up @@ -144,6 +145,14 @@ func logicalOpName2PlanCodecString(name string) string {
return "plancodec.TypeShowDDLJobs"
case "LogicalSort":
return "plancodec.TypeSort"
case "LogicalTableDual":
return "plancodec.TypeDual"
case "LogicalTopN":
return "plancodec.TypeTopN"
case "LogicalUnionScan":
return "plancodec.TypeUnionScan"
case "LogicalWindow":
return "plancodec.TypeWindow"
default:
return ""
}
Expand Down
219 changes: 219 additions & 0 deletions pkg/planner/core/operator/logicalop/hash64_equals_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/planner/core/operator/logicalop/logical_table_dual.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import (
// outputting 0/1 row with zero column. This semantic may be different from your expectation sometimes but should not
// cause any actual problems now.
type LogicalTableDual struct {
LogicalSchemaProducer
LogicalSchemaProducer `hash64-equals:"true"`

// RowCount could only be 0 or 1.
RowCount int
RowCount int `hash64-equals:"true"`
}

// Init initializes LogicalTableDual.
Expand Down
10 changes: 5 additions & 5 deletions pkg/planner/core/operator/logicalop/logical_top_n.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ import (
type LogicalTopN struct {
BaseLogicalPlan

ByItems []*util.ByItems
ByItems []*util.ByItems `hash64-equals:"true"`
// PartitionBy is used for extended TopN to consider K heaps. Used by rule_derive_topn_from_window
PartitionBy []property.SortItem // This is used for enhanced topN optimization
Offset uint64
Count uint64
PreferLimitToCop bool
PartitionBy []property.SortItem `hash64-equals:"true"` // This is used for enhanced topN optimization
Offset uint64 `hash64-equals:"true"`
Count uint64 `hash64-equals:"true"`
PreferLimitToCop bool `hash64-equals:"true"`
}

// Init initializes LogicalTopN.
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/core/operator/logicalop/logical_union_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
type LogicalUnionScan struct {
BaseLogicalPlan

Conditions []expression.Expression
Conditions []expression.Expression `hash64-equals:"true"`

HandleCols util.HandleCols
HandleCols util.HandleCols `hash64-equals:"true"`
}

// Init initializes LogicalUnionScan.
Expand Down
Loading

0 comments on commit 89804dd

Please sign in to comment.