Skip to content

Commit

Permalink
Optimise AST rewriting (#17623)
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Harshit Gangal <[email protected]>
Co-authored-by: Harshit Gangal <[email protected]>
  • Loading branch information
systay and harshit-gangal authored Jan 28, 2025
1 parent c2f4dcf commit 19890cf
Show file tree
Hide file tree
Showing 11 changed files with 1,279 additions and 1,327 deletions.
557 changes: 0 additions & 557 deletions go/vt/sqlparser/ast_rewriting.go

This file was deleted.

565 changes: 0 additions & 565 deletions go/vt/sqlparser/ast_rewriting_test.go

This file was deleted.

18 changes: 4 additions & 14 deletions go/vt/sqlparser/bind_var_needs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ type BindVarNeeds struct {
NeedSystemVariable,
// NeedUserDefinedVariables keeps track of all user defined variables a query is using
NeedUserDefinedVariables []string
otherRewrites bool
}

// MergeWith adds bind vars needs coming from sub scopes
func (bvn *BindVarNeeds) MergeWith(other *BindVarNeeds) {
bvn.NeedFunctionResult = append(bvn.NeedFunctionResult, other.NeedFunctionResult...)
bvn.NeedSystemVariable = append(bvn.NeedSystemVariable, other.NeedSystemVariable...)
bvn.NeedUserDefinedVariables = append(bvn.NeedUserDefinedVariables, other.NeedUserDefinedVariables...)
otherRewrites int
}

// AddFuncResult adds a function bindvar need
Expand Down Expand Up @@ -58,14 +51,11 @@ func (bvn *BindVarNeeds) NeedsSysVar(name string) bool {
}

func (bvn *BindVarNeeds) NoteRewrite() {
bvn.otherRewrites = true
bvn.otherRewrites++
}

func (bvn *BindVarNeeds) HasRewrites() bool {
return bvn.otherRewrites ||
len(bvn.NeedFunctionResult) > 0 ||
len(bvn.NeedUserDefinedVariables) > 0 ||
len(bvn.NeedSystemVariable) > 0
func (bvn *BindVarNeeds) NumberOfRewrites() int {
return len(bvn.NeedFunctionResult) + len(bvn.NeedUserDefinedVariables) + len(bvn.NeedSystemVariable) + bvn.otherRewrites
}

func contains(strings []string, name string) bool {
Expand Down
Loading

0 comments on commit 19890cf

Please sign in to comment.