Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
Signed-off-by: arenatlx <314806019@qq.com>
  • Loading branch information
AilinKid committed Nov 14, 2024
1 parent aeed37b commit 980b58c
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ import (
func GenHash64Equals4LogicalOps() ([]byte, error) {
var structures = []any{logicalop.LogicalJoin{}, logicalop.LogicalAggregation{}, logicalop.LogicalApply{},
logicalop.LogicalExpand{}, logicalop.LogicalLimit{}, logicalop.LogicalMaxOneRow{}, logicalop.DataSource{},
logicalop.LogicalMemTable{}, logicalop.LogicalUnionAll{}, logicalop.LogicalPartitionUnionAll{}}
logicalop.LogicalMemTable{}, logicalop.LogicalUnionAll{}, logicalop.LogicalPartitionUnionAll{}, logicalop.LogicalProjection{},
logicalop.LogicalSelection{}, logicalop.LogicalShow{}, logicalop.LogicalShowDDLJobs{}, logicalop.LogicalSort{},
}
c := new(cc)
c.write(codeGenHash64EqualsPrefix)
for _, s := range structures {
Expand Down Expand Up @@ -132,7 +134,16 @@ func logicalOpName2PlanCodecString(name string) string {
return "plancodec.TypeUnion"
case "LogicalPartitionUnionAll":
return "plancodec.TypePartitionUnion"

case "LogicalProjection":
return "plancodec.TypeProj"
case "LogicalSelection":
return "plancodec.TypeSel"
case "LogicalShow":
return "plancodec.TypeShow"
case "LogicalShowDDLJobs":
return "plancodec.TypeShowDDLJobs"
case "LogicalSort":
return "plancodec.TypeSort"
default:
return ""
}
Expand Down
171 changes: 171 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.

46 changes: 4 additions & 42 deletions pkg/planner/core/operator/logicalop/logical_projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/pingcap/tidb/pkg/expression"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/planner/cardinality"
base2 "github.com/pingcap/tidb/pkg/planner/cascades/base"
"github.com/pingcap/tidb/pkg/planner/core/base"
ruleutil "github.com/pingcap/tidb/pkg/planner/core/rule/util"
fd "github.com/pingcap/tidb/pkg/planner/funcdep"
Expand All @@ -35,19 +34,19 @@ import (

// LogicalProjection represents a select fields plan.
type LogicalProjection struct {
LogicalSchemaProducer
LogicalSchemaProducer `hash64-equals:"true"`

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

// CalculateNoDelay indicates this Projection is the root Plan and should be
// calculated without delay and will not return any result to client.
// Currently it is "true" only when the current sql query is a "DO" statement.
// See "https://dev.mysql.com/doc/refman/5.7/en/do.html" for more detail.
CalculateNoDelay bool
CalculateNoDelay bool `hash64-equals:"true"`

// Proj4Expand is used for expand to project same column reference, while these
// col may be filled with null so we couldn't just eliminate this projection itself.
Proj4Expand bool
Proj4Expand bool `hash64-equals:"true"`
}

// Init initializes LogicalProjection.
Expand All @@ -56,43 +55,6 @@ func (p LogicalProjection) Init(ctx base.PlanContext, qbOffset int) *LogicalProj
return &p
}

// *************************** start implementation of HashEquals interface ****************************

// Hash64 implements the base.Hash64.<0th> interface.
func (p *LogicalProjection) Hash64(h base2.Hasher) {
h.HashInt(len(p.Exprs))
for _, one := range p.Exprs {
one.Hash64(h)
}
h.HashBool(p.CalculateNoDelay)
h.HashBool(p.Proj4Expand)
}

// Equals implements the base.HashEquals.<1st> interface.
func (p *LogicalProjection) Equals(other any) bool {
if other == nil {
return false
}
var p2 *LogicalProjection
switch x := other.(type) {
case *LogicalProjection:
p2 = x
case LogicalProjection:
p2 = &x
default:
return false
}
if len(p.Exprs) != len(p2.Exprs) {
return false
}
for i, one := range p.Exprs {
if !one.Equals(p2.Exprs[i]) {
return false
}
}
return p.CalculateNoDelay == p2.CalculateNoDelay && p.Proj4Expand == p2.Proj4Expand
}

// *************************** start implementation of Plan interface **********************************

// ExplainInfo implements Plan interface.
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/operator/logicalop/logical_selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type LogicalSelection struct {
// Originally the WHERE or ON condition is parsed into a single expression,
// but after we converted to CNF(Conjunctive normal form), it can be
// split into a list of AND conditions.
Conditions []expression.Expression
Conditions []expression.Expression `hash64-equals:"true"`
}

// Init initializes LogicalSelection.
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/operator/logicalop/logical_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

// LogicalShow represents a show plan.
type LogicalShow struct {
LogicalSchemaProducer
LogicalSchemaProducer `hash64-equals:"true"`
ShowContents

Extractor base.ShowPredicateExtractor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

// LogicalShowDDLJobs is for showing DDL job list.
type LogicalShowDDLJobs struct {
LogicalSchemaProducer
LogicalSchemaProducer `hash64-equals:"true"`

JobNumber int64
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/operator/logicalop/logical_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
type LogicalSort struct {
BaseLogicalPlan

ByItems []*util.ByItems
ByItems []*util.ByItems `hash64-equals:"true"`
}

// Init initializes LogicalSort.
Expand Down

0 comments on commit 980b58c

Please sign in to comment.