Skip to content

Commit

Permalink
Use ast-paths for subquery planning to improve performance (vitessio#…
Browse files Browse the repository at this point in the history
…17738)

Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Co-authored-by: Manan Gupta <manan@planetscale.com>
Co-authored-by: Vicent Marti <vmg@strn.cat>
Co-authored-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
4 people authored Feb 15, 2025
1 parent cf7fa68 commit f131dd6
Show file tree
Hide file tree
Showing 34 changed files with 7,571 additions and 203 deletions.
10 changes: 6 additions & 4 deletions go/tools/asthelpergen/asthelpergen.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"vitess.io/vitess/go/tools/codegen"
)

const licenseFileHeader = `Copyright 2023 The Vitess Authors.
const licenseFileHeader = `Copyright 2025 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -51,10 +51,10 @@ type (
addType(t types.Type)
scope() *types.Scope
findImplementations(iff *types.Interface, impl func(types.Type) error) error
iface() *types.Interface
iface() *types.Interface // the root interface that all nodes are expected to implement
}
generator interface {
genFile() (string, *jen.File)
genFile(generatorSPI) (string, *jen.File)
interfaceMethod(t types.Type, iface *types.Interface, spi generatorSPI) error
structMethod(t types.Type, strct *types.Struct, spi generatorSPI) error
ptrToStructMethod(t types.Type, strct *types.Struct, spi generatorSPI) error
Expand Down Expand Up @@ -206,9 +206,11 @@ func GenerateASTHelpers(options *Options) (map[string]*jen.File, error) {

nt := tt.Type().(*types.Named)
pName := nt.Obj().Pkg().Name()
ifaceName := types.TypeString(nt, noQualifier)
generator := newGenerator(loaded[0].Module, loaded[0].TypesSizes, nt,
newEqualsGen(pName, &options.Equals),
newCloneGen(pName, &options.Clone),
newPathGen(pName, ifaceName),
newVisitGen(pName),
newRewriterGen(pName, types.TypeString(nt, noQualifier)),
newCOWGen(pName, nt),
Expand Down Expand Up @@ -298,7 +300,7 @@ func (gen *astHelperGen) createFiles() map[string]*jen.File {

result := map[string]*jen.File{}
for _, g := range gen.gens {
fName, jenFile := g.genFile()
fName, jenFile := g.genFile(gen)
result[fName] = jenFile
}
return result
Expand Down
2 changes: 1 addition & 1 deletion go/tools/asthelpergen/clone_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *cloneGen) addFunc(name string, code *jen.Statement) {
c.file.Add(code)
}

func (c *cloneGen) genFile() (string, *jen.File) {
func (c *cloneGen) genFile(generatorSPI) (string, *jen.File) {
return "ast_clone.go", c.file
}

Expand Down
2 changes: 1 addition & 1 deletion go/tools/asthelpergen/copy_on_rewrite_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *cowGen) addFunc(code *jen.Statement) {
c.file.Add(code)
}

func (c *cowGen) genFile() (string, *jen.File) {
func (c *cowGen) genFile(generatorSPI) (string, *jen.File) {
return "ast_copy_on_rewrite.go", c.file
}

Expand Down
6 changes: 2 additions & 4 deletions go/tools/asthelpergen/equals_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (e *equalsGen) customComparatorField(t types.Type) string {
return printableTypeName(t) + "_"
}

func (e *equalsGen) genFile() (string, *jen.File) {
func (e *equalsGen) genFile(generatorSPI) (string, *jen.File) {
e.file.Type().Id(Comparator).StructFunc(func(g *jen.Group) {
for tname, t := range e.comparators {
if t == nil {
Expand Down Expand Up @@ -303,6 +303,4 @@ func (e *equalsGen) sliceMethod(t types.Type, slice *types.Slice, spi generatorS
return nil
}

func (e *equalsGen) basicMethod(types.Type, *types.Basic, generatorSPI) error {
return nil
}
func (*equalsGen) basicMethod(types.Type, *types.Basic, generatorSPI) error { return nil }
27 changes: 25 additions & 2 deletions go/tools/asthelpergen/integration/ast_clone.go

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

26 changes: 5 additions & 21 deletions go/tools/asthelpergen/integration/ast_copy_on_rewrite.go

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

36 changes: 32 additions & 4 deletions go/tools/asthelpergen/integration/ast_equals.go

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

136 changes: 136 additions & 0 deletions go/tools/asthelpergen/integration/ast_path.go

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

Loading

0 comments on commit f131dd6

Please sign in to comment.