From e201915b766f639129a37451c040c423e4af870b Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 24 Jan 2023 07:37:27 +0100 Subject: [PATCH 1/5] add code for generating copy-on-rewrite logic Signed-off-by: Andres Taylor --- go/tools/asthelpergen/asthelpergen.go | 3 +- go/tools/asthelpergen/clone_gen.go | 20 +- go/tools/asthelpergen/copy_on_rewrite_gen.go | 385 ++ go/vt/sqlparser/ast.go | 22 +- go/vt/sqlparser/ast_clone.go | 29 +- go/vt/sqlparser/ast_copy_on_rewrite.go | 6168 ++++++++++++++++++ go/vt/sqlparser/ast_copy_on_rewrite_test.go | 93 + go/vt/sqlparser/ast_equals.go | 30 +- go/vt/sqlparser/ast_format.go | 2 +- go/vt/sqlparser/ast_format_fast.go | 2 +- go/vt/sqlparser/ast_funcs.go | 6 +- go/vt/sqlparser/ast_rewrite.go | 47 +- go/vt/sqlparser/ast_visit.go | 26 +- go/vt/sqlparser/cow.go | 95 + go/vt/vtgate/planbuilder/operators/union.go | 16 +- 15 files changed, 6817 insertions(+), 127 deletions(-) create mode 100644 go/tools/asthelpergen/copy_on_rewrite_gen.go create mode 100644 go/vt/sqlparser/ast_copy_on_rewrite.go create mode 100644 go/vt/sqlparser/ast_copy_on_rewrite_test.go create mode 100644 go/vt/sqlparser/cow.go diff --git a/go/tools/asthelpergen/asthelpergen.go b/go/tools/asthelpergen/asthelpergen.go index 08b191a75d6..9e1275182d0 100644 --- a/go/tools/asthelpergen/asthelpergen.go +++ b/go/tools/asthelpergen/asthelpergen.go @@ -31,7 +31,7 @@ import ( "golang.org/x/tools/go/packages" ) -const licenseFileHeader = `Copyright 2021 The Vitess Authors. +const licenseFileHeader = `Copyright 2023 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. @@ -244,6 +244,7 @@ func GenerateASTHelpers(options *Options) (map[string]*jen.File, error) { newCloneGen(pName, &options.Clone), newVisitGen(pName), newRewriterGen(pName, types.TypeString(nt, noQualifier)), + newCOWGen(pName, nt), ) it, err := generator.GenerateCode() diff --git a/go/tools/asthelpergen/clone_gen.go b/go/tools/asthelpergen/clone_gen.go index 594e4455a12..79251140845 100644 --- a/go/tools/asthelpergen/clone_gen.go +++ b/go/tools/asthelpergen/clone_gen.go @@ -93,7 +93,7 @@ func (c *cloneGen) sliceMethod(t types.Type, slice *types.Slice, spi generatorSP funcName := cloneName + name c.addFunc(funcName, - //func (n Bytes) Clone() Bytes { + // func (n Bytes) Clone() Bytes { jen.Func().Id(funcName).Call(jen.Id("n").Id(typeString)).Id(typeString).Block( // if n == nil { return nil } ifNilReturnNil("n"), @@ -116,9 +116,9 @@ func (c *cloneGen) copySliceElement(t types.Type, elType types.Type, spi generat return jen.Id("copy").Call(jen.Id("res"), jen.Id("n")) } - //for i := range n { + // for i := range n { // res[i] = CloneAST(x) - //} + // } spi.addType(elType) return jen.For(jen.List(jen.Id("i"), jen.Id("x"))).Op(":=").Range().Id("n").Block( @@ -128,17 +128,17 @@ func (c *cloneGen) copySliceElement(t types.Type, elType types.Type, spi generat func (c *cloneGen) interfaceMethod(t types.Type, iface *types.Interface, spi generatorSPI) error { - //func CloneAST(in AST) AST { + // func CloneAST(in AST) AST { // if in == nil { // return nil - //} + // } // switch in := in.(type) { - //case *RefContainer: + // case *RefContainer: // return in.CloneRefOfRefContainer() - //} + // } // // this should never happen // return nil - //} + // } typeString := types.TypeString(t, noQualifier) typeName := printableTypeName(t) @@ -196,7 +196,7 @@ func (c *cloneGen) ptrToBasicMethod(t types.Type, _ *types.Basic, spi generatorS func (c *cloneGen) ptrToOtherMethod(t types.Type, ptr *types.Pointer, spi generatorSPI) error { receiveType := types.TypeString(t, noQualifier) - funcName := "Clone" + printableTypeName(t) + funcName := cloneName + printableTypeName(t) c.addFunc(funcName, jen.Func().Id(funcName).Call(jen.Id("n").Id(receiveType)).Id(receiveType).Block( ifNilReturnNil("n"), @@ -224,7 +224,7 @@ func (c *cloneGen) ptrToStructMethod(t types.Type, strct *types.Struct, spi gene receiveType := types.TypeString(t, noQualifier) funcName := cloneName + printableTypeName(t) - //func CloneRefOfType(n *Type) *Type + // func CloneRefOfType(n *Type) *Type funcDeclaration := jen.Func().Id(funcName).Call(jen.Id("n").Id(receiveType)).Id(receiveType) if slices.Contains(c.exclude, receiveType) { diff --git a/go/tools/asthelpergen/copy_on_rewrite_gen.go b/go/tools/asthelpergen/copy_on_rewrite_gen.go new file mode 100644 index 00000000000..365061e308b --- /dev/null +++ b/go/tools/asthelpergen/copy_on_rewrite_gen.go @@ -0,0 +1,385 @@ +/* +Copyright 2023 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package asthelpergen + +import ( + "go/types" + + "github.com/dave/jennifer/jen" +) + +type cowGen struct { + file *jen.File + baseType string +} + +var _ generator = (*cowGen)(nil) + +func newCOWGen(pkgname string, nt *types.Named) *cowGen { + file := jen.NewFile(pkgname) + file.HeaderComment(licenseFileHeader) + file.HeaderComment("Code generated by ASTHelperGen. DO NOT EDIT.") + + return &cowGen{ + file: file, + baseType: nt.Obj().Id(), + } +} + +func (c *cowGen) addFunc(code *jen.Statement) { + c.file.Add(code) +} + +func (c *cowGen) genFile() (string, *jen.File) { + return "ast_copy_on_rewrite.go", c.file +} + +const cowName = "copyOnRewrite" + +// readValueOfType produces code to read the expression of type `t`, and adds the type to the todo-list +func (c *cowGen) readValueOfType(t types.Type, expr jen.Code, spi generatorSPI) jen.Code { + switch t.Underlying().(type) { + case *types.Interface: + if types.TypeString(t, noQualifier) == "any" { + // these fields have to be taken care of manually + return expr + } + } + spi.addType(t) + return jen.Id("c").Dot(cowName + printableTypeName(t)).Call(expr) +} + +func (c *cowGen) sliceMethod(t types.Type, slice *types.Slice, spi generatorSPI) error { + if !types.Implements(t, spi.iface()) { + return nil + } + + typeString := types.TypeString(t, noQualifier) + + changedVarName := "changed" + fieldVar := "res" + elemTyp := types.TypeString(slice.Elem(), noQualifier) + + name := printableTypeName(t) + funcName := cowName + name + var visitElements *jen.Statement + + if types.Implements(slice.Elem(), spi.iface()) { + visitElements = ifPreNotNilOrReturnsTrue().Block( + jen.Id(fieldVar).Op(":=").Id("make").Params(jen.Id(typeString), jen.Id("len").Params(jen.Id("n"))), // _Foo := make([]Typ, len(n)) + jen.For(jen.List(jen.Id("x"), jen.Id("el")).Op(":=").Id("range n")).Block( + c.visitFieldOrElement("this", "change", slice.Elem(), jen.Id("el"), spi), + // jen.Id(fieldVar).Index(jen.Id("x")).Op("=").Id("this").Op(".").Params(jen.Id(types.TypeString(elemTyp, noQualifier))), + jen.Id(fieldVar).Index(jen.Id("x")).Op("=").Id("this").Op(".").Params(jen.Id(elemTyp)), + jen.If(jen.Id("change")).Block( + jen.Id(changedVarName).Op("=").True(), + ), + ), + jen.If(jen.Id("changed")).Block( + jen.Id("out").Op("=").Id("res"), + ), + ) + } else { + visitElements = jen.If(jen.Id("c.pre != nil")).Block( + jen.Id("c.pre(n, parent)"), + ) + } + + block := c.funcDecl(funcName, typeString).Block( + ifNilReturnNilAndFalse("n"), + jen.Id("out").Op("=").Id("n"), + visitElements, + ifPostNotNilVisit("out"), + jen.Return(), + ) + c.addFunc(block) + return nil +} + +func (c *cowGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSPI) error { + if !types.Implements(t, spi.iface()) { + return nil + } + + typeString := types.TypeString(t, noQualifier) + typeName := printableTypeName(t) + + var stmts []jen.Code + stmts = append(stmts, + jen.If(jen.Id("c").Dot("cursor").Dot("stop")).Block(jen.Return(jen.Id("n"), jen.False())), + ifNotNil("c.pre", jen.Id("c.pre").Params(jen.Id("n"), jen.Id("parent"))), + ifNotNil("c.post", jen.List(jen.Id("out"), jen.Id("changed")).Op("=").Id("c.postVisit").Params(jen.Id("n"), jen.Id("parent"))). + Else().Block(jen.Id("out = n")), + jen.Return(), + ) + funcName := cowName + typeName + funcDecl := c.funcDecl(funcName, typeString).Block(stmts...) + c.addFunc(funcDecl) + return nil +} + +func (c *cowGen) copySliceElement(t types.Type, elType types.Type, spi generatorSPI) jen.Code { + if !isNamed(t) && isBasic(elType) { + // copy(res, n) + return jen.Id("copy").Call(jen.Id("res"), jen.Id("n")) + } + + // for i := range n { + // res[i] = CloneAST(x) + // } + spi.addType(elType) + + return jen.For(jen.List(jen.Id("i"), jen.Id("x"))).Op(":=").Range().Id("n").Block( + jen.Id("res").Index(jen.Id("i")).Op("=").Add(c.readValueOfType(elType, jen.Id("x"), spi)), + ) +} + +func ifNotNil(id string, stmts ...jen.Code) *jen.Statement { + return jen.If(jen.Id(id).Op("!=").Nil()).Block(stmts...) +} + +func ifNilReturnNilAndFalse(id string) *jen.Statement { + return jen.If(jen.Id(id).Op("==").Nil().Op("||").Id("c").Dot("cursor").Dot("stop")).Block(jen.Return(jen.Id("n"), jen.False())) +} + +func ifPreNotNilOrReturnsTrue() *jen.Statement { + // if c.pre == nil || c.pre(n, parent) { + return jen.If( + jen.Id("c").Dot("pre").Op("==").Nil().Op("||").Id("c").Dot("pre").Params( + jen.Id("n"), + jen.Id("parent"), + )) + +} + +func (c *cowGen) interfaceMethod(t types.Type, iface *types.Interface, spi generatorSPI) error { + if !types.Implements(t, spi.iface()) { + return nil + } + + // func (c cow) cowAST(in AST) (AST, bool) { + // if in == nil { + // return nil, false + // } + // + // if c.old == in { + // return c.new, true + // } + // switch in := in.(type) { + // case *RefContainer: + // return c.CowRefOfRefContainer(in) + // } + // // this should never happen + // return nil + // } + + typeString := types.TypeString(t, noQualifier) + typeName := printableTypeName(t) + + stmts := []jen.Code{ifNilReturnNilAndFalse("n")} + + var cases []jen.Code + _ = findImplementations(spi.scope(), iface, func(t types.Type) error { + if _, ok := t.Underlying().(*types.Interface); ok { + return nil + } + spi.addType(t) + typeString := types.TypeString(t, noQualifier) + + // case Type: return CloneType(in) + block := jen.Case(jen.Id(typeString)).Block(jen.Return(c.readValueOfType(t, jen.List(jen.Id("n"), jen.Id("parent")), spi))) + cases = append(cases, block) + + return nil + }) + + cases = append(cases, + jen.Default().Block( + jen.Comment("this should never happen"), + jen.Return(jen.Nil(), jen.False()), + )) + + // switch n := node.(type) { + stmts = append(stmts, jen.Switch(jen.Id("n").Op(":=").Id("n").Assert(jen.Id("type")).Block( + cases..., + ))) + + funcName := cowName + typeName + funcDecl := c.funcDecl(funcName, typeString).Block(stmts...) + c.addFunc(funcDecl) + return nil +} + +func (c *cowGen) ptrToBasicMethod(t types.Type, _ *types.Basic, spi generatorSPI) error { + if !types.Implements(t, spi.iface()) { + return nil + } + + ptr := t.Underlying().(*types.Pointer) + return c.ptrToOtherMethod(t, ptr, spi) +} + +func (c *cowGen) ptrToOtherMethod(t types.Type, ptr *types.Pointer, spi generatorSPI) error { + if !types.Implements(t, spi.iface()) { + return nil + } + + receiveType := types.TypeString(t, noQualifier) + + funcName := cowName + printableTypeName(t) + c.addFunc(c.funcDecl(funcName, receiveType).Block( + jen.Comment("apan was here"), + jen.Return(jen.Id("n"), jen.False()), + )) + return nil +} + +// func (c cow) COWRefOfType(n *Type) (*Type, bool) +func (c *cowGen) funcDecl(funcName, typeName string) *jen.Statement { + return jen.Func().Params(jen.Id("c").Id("*cow")).Id(funcName).Call(jen.List(jen.Id("n").Id(typeName), jen.Id("parent").Id(c.baseType))).Params(jen.Id("out").Id(c.baseType), jen.Id("changed").Id("bool")) +} + +func (c *cowGen) visitFieldOrElement(varName, changedVarName string, typ types.Type, el *jen.Statement, spi generatorSPI) *jen.Statement { + // _Field, changedField := c.COWType(n., n) + return jen.List(jen.Id(varName), jen.Id(changedVarName)).Op(":=").Add(c.readValueOfType(typ, jen.List(el, jen.Id("n")), spi)) +} + +func (c *cowGen) structMethod(t types.Type, strct *types.Struct, spi generatorSPI) error { + if !types.Implements(t, spi.iface()) { + return nil + } + + c.visitStruct(t, strct, spi, nil, false) + return nil +} + +func (c *cowGen) ptrToStructMethod(t types.Type, strct *types.Struct, spi generatorSPI) error { + if !types.Implements(t, spi.iface()) { + return nil + } + start := ifNilReturnNilAndFalse("n") + + c.visitStruct(t, strct, spi, start, true) + return nil +} + +func (c *cowGen) visitStruct(t types.Type, strct *types.Struct, spi generatorSPI, start *jen.Statement, ref bool) { + receiveType := types.TypeString(t, noQualifier) + funcName := cowName + printableTypeName(t) + + funcDeclaration := c.funcDecl(funcName, receiveType) + + var fields []jen.Code + out := "out" + changed := "changed" + var fieldSetters []jen.Code + kopy := jen.Id(changed).Op(":=") + if ref { + fieldSetters = append(fieldSetters, kopy.Op("*").Id("n")) // changed := *n + } else { + fieldSetters = append(fieldSetters, kopy.Id("n")) // changed := n + } + var changedVariables []string + for i := 0; i < strct.NumFields(); i++ { + field := strct.Field(i).Name() + typ := strct.Field(i).Type() + changedVarName := "changed" + field + + fieldType := types.TypeString(typ, noQualifier) + fieldVar := "_" + field + if types.Implements(typ, spi.iface()) { + fields = append(fields, c.visitFieldOrElement(fieldVar, changedVarName, typ, jen.Id("n").Dot(field), spi)) + changedVariables = append(changedVariables, changedVarName) + fieldSetters = append(fieldSetters, jen.List(jen.Id(changed).Dot(field), jen.Op("_")).Op("=").Id(fieldVar).Op(".").Params(jen.Id(fieldType))) + } else { + // _Foo := make([]*Type, len(n.Foo)) + // var changedFoo bool + // for x, el := range n.Foo { + // c, changed := c.COWSliceOfRefOfType(el, n) + // if changed { + // changedFoo = true + // } + // _Foo[i] = c.(*Type) + // } + + slice, isSlice := typ.(*types.Slice) + if isSlice && types.Implements(slice.Elem(), spi.iface()) { + elemTyp := slice.Elem() + spi.addType(elemTyp) + x := jen.Id("x") + el := jen.Id("el") + // changed := jen.Id("changed") + fields = append(fields, + jen.Var().Id(changedVarName).Bool(), // var changedFoo bool + jen.Id(fieldVar).Op(":=").Id("make").Params(jen.Id(fieldType), jen.Id("len").Params(jen.Id("n").Dot(field))), // _Foo := make([]Typ, len(n.Foo)) + jen.For(jen.List(x, el).Op(":=").Id("range n").Dot(field)).Block( + c.visitFieldOrElement("this", "changed", elemTyp, jen.Id("el"), spi), + jen.Id(fieldVar).Index(jen.Id("x")).Op("=").Id("this").Op(".").Params(jen.Id(types.TypeString(elemTyp, noQualifier))), + jen.If(jen.Id("changed")).Block( + jen.Id(changedVarName).Op("=").True(), + ), + ), + ) + changedVariables = append(changedVariables, changedVarName) + fieldSetters = append(fieldSetters, jen.Id(changed).Dot(field).Op("=").Id(fieldVar)) + } + } + } + + var cond *jen.Statement + for _, variable := range changedVariables { + if cond == nil { + cond = jen.Id(variable) + } else { + cond = cond.Op("||").Add(jen.Id(variable)) + } + + } + + fieldSetters = append(fieldSetters, jen.Id(out).Op("=").Op("&").Id(changed)) + ifChanged := jen.If(cond).Block(fieldSetters...) + + var stmts []jen.Code + if start != nil { + stmts = append(stmts, start) + } + + // handle all fields with CloneAble types + var visitChildren []jen.Code + visitChildren = append(visitChildren, fields...) + if len(fieldSetters) > 2 /*we add two statements always*/ { + visitChildren = append(visitChildren, ifChanged) + } + + children := ifPreNotNilOrReturnsTrue().Block(visitChildren...) + stmts = append(stmts, + jen.Id(out).Op("=").Id("n"), + children, + ) + + stmts = append( + stmts, + ifPostNotNilVisit(out), + jen.Return(), + ) + + c.addFunc(funcDeclaration.Block(stmts...)) +} + +func ifPostNotNilVisit(out string) *jen.Statement { + return ifNotNil("c.post", jen.List(jen.Id(out), jen.Id("changed")).Op("=").Id("c").Dot("postVisit").Params(jen.Id(out), jen.Id("parent"))) +} diff --git a/go/vt/sqlparser/ast.go b/go/vt/sqlparser/ast.go index cab6d4a3864..d0e8e85c19c 100644 --- a/go/vt/sqlparser/ast.go +++ b/go/vt/sqlparser/ast.go @@ -2532,7 +2532,7 @@ type ( } // JSONTableExpr describes the components of JSON_TABLE() - // For more information, visit https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html#function_json-table + // For more information, postVisit https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html#function_json-table JSONTableExpr struct { Expr Expr Alias IdentifierCS @@ -2693,14 +2693,14 @@ type ( JSONValueMergeType int8 // JSONRemoveExpr represents the JSON_REMOVE() - // For more information, visit https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-remove + // For more information, postVisit https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-remove JSONRemoveExpr struct { JSONDoc Expr PathList Exprs } // JSONRemoveExpr represents the JSON_UNQUOTE() - // For more information, visit https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-unquote + // For more information, postVisit https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-unquote JSONUnquoteExpr struct { JSONValue Expr } @@ -2791,7 +2791,7 @@ type ( } // RegexpInstrExpr represents REGEXP_INSTR() - // For more information, visit https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-instr + // For more information, postVisit https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-instr RegexpInstrExpr struct { Expr Expr Pattern Expr @@ -2802,7 +2802,7 @@ type ( } // RegexpLikeExpr represents REGEXP_LIKE() - // For more information, visit https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-like + // For more information, postVisit https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-like RegexpLikeExpr struct { Expr Expr Pattern Expr @@ -2810,7 +2810,7 @@ type ( } // RegexpReplaceExpr represents REGEXP_REPLACE() - // For more information, visit https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-replace + // For more information, postVisit https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-replace RegexpReplaceExpr struct { Expr Expr Pattern Expr @@ -2821,7 +2821,7 @@ type ( } // RegexpSubstrExpr represents REGEXP_SUBSTR() - // For more information, visit https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-substr + // For more information, postVisit https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-substr RegexpSubstrExpr struct { Expr Expr Pattern Expr @@ -2881,7 +2881,7 @@ type ( // ExtractValueExpr stands for EXTRACTVALUE() XML function // Extract a value from an XML string using XPath notation - // For more details, visit https://dev.mysql.com/doc/refman/8.0/en/xml-functions.html#function_extractvalue + // For more details, postVisit https://dev.mysql.com/doc/refman/8.0/en/xml-functions.html#function_extractvalue ExtractValueExpr struct { Fragment Expr XPathExpr Expr @@ -2889,7 +2889,7 @@ type ( // UpdateXMLExpr stands for UpdateXML() XML function // Return replaced XML fragment - // For more details, visit https://dev.mysql.com/doc/refman/8.0/en/xml-functions.html#function_updatexml + // For more details, postVisit https://dev.mysql.com/doc/refman/8.0/en/xml-functions.html#function_updatexml UpdateXMLExpr struct { Target Expr XPathExpr Expr @@ -2914,7 +2914,7 @@ type ( // For FORMAT_BYTES, it means count // For FORMAT_PICO_TIME, it means time_val // For PS_THREAD_ID it means connection_id - // For more details, visit https://dev.mysql.com/doc/refman/8.0/en/performance-schema-functions.html + // For more details, postVisit https://dev.mysql.com/doc/refman/8.0/en/performance-schema-functions.html PerformanceSchemaFuncExpr struct { Type PerformanceSchemaType Argument Expr @@ -2925,7 +2925,7 @@ type ( // GTIDFuncExpr stands for GTID Functions // Set1 Acts as gtid_set for WAIT_FOR_EXECUTED_GTID_SET() and WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS() - // For more details, visit https://dev.mysql.com/doc/refman/8.0/en/gtid-functions.html + // For more details, postVisit https://dev.mysql.com/doc/refman/8.0/en/gtid-functions.html GTIDFuncExpr struct { Type GTIDType Set1 Expr diff --git a/go/vt/sqlparser/ast_clone.go b/go/vt/sqlparser/ast_clone.go index a2aa1e35c9f..8aa602a50e9 100644 --- a/go/vt/sqlparser/ast_clone.go +++ b/go/vt/sqlparser/ast_clone.go @@ -1,5 +1,5 @@ /* -Copyright 2021 The Vitess Authors. +Copyright 2023 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. @@ -223,8 +223,8 @@ func CloneSQLNode(in SQLNode) SQLNode { return CloneRefOfJSONKeysExpr(in) case *JSONObjectExpr: return CloneRefOfJSONObjectExpr(in) - case JSONObjectParam: - return CloneJSONObjectParam(in) + case *JSONObjectParam: + return CloneRefOfJSONObjectParam(in) case *JSONOverlapsExpr: return CloneRefOfJSONOverlapsExpr(in) case *JSONPrettyExpr: @@ -1577,9 +1577,15 @@ func CloneRefOfJSONObjectExpr(n *JSONObjectExpr) *JSONObjectExpr { return &out } -// CloneJSONObjectParam creates a deep clone of the input. -func CloneJSONObjectParam(n JSONObjectParam) JSONObjectParam { - return *CloneRefOfJSONObjectParam(&n) +// CloneRefOfJSONObjectParam creates a deep clone of the input. +func CloneRefOfJSONObjectParam(n *JSONObjectParam) *JSONObjectParam { + if n == nil { + return nil + } + out := *n + out.Key = CloneExpr(n.Key) + out.Value = CloneExpr(n.Value) + return &out } // CloneRefOfJSONOverlapsExpr creates a deep clone of the input. @@ -4049,17 +4055,6 @@ func CloneSliceOfRefOfJSONObjectParam(n []*JSONObjectParam) []*JSONObjectParam { return res } -// CloneRefOfJSONObjectParam creates a deep clone of the input. -func CloneRefOfJSONObjectParam(n *JSONObjectParam) *JSONObjectParam { - if n == nil { - return nil - } - out := *n - out.Key = CloneExpr(n.Key) - out.Value = CloneExpr(n.Value) - return &out -} - // CloneSliceOfRefOfJtColumnDefinition creates a deep clone of the input. func CloneSliceOfRefOfJtColumnDefinition(n []*JtColumnDefinition) []*JtColumnDefinition { if n == nil { diff --git a/go/vt/sqlparser/ast_copy_on_rewrite.go b/go/vt/sqlparser/ast_copy_on_rewrite.go new file mode 100644 index 00000000000..0dc7ebf0e6b --- /dev/null +++ b/go/vt/sqlparser/ast_copy_on_rewrite.go @@ -0,0 +1,6168 @@ +/* +Copyright 2023 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// Code generated by ASTHelperGen. DO NOT EDIT. + +package sqlparser + +func (c *cow) copyOnRewriteSQLNode(n SQLNode, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *AddColumns: + return c.copyOnRewriteRefOfAddColumns(n, parent) + case *AddConstraintDefinition: + return c.copyOnRewriteRefOfAddConstraintDefinition(n, parent) + case *AddIndexDefinition: + return c.copyOnRewriteRefOfAddIndexDefinition(n, parent) + case AlgorithmValue: + return c.copyOnRewriteAlgorithmValue(n, parent) + case *AliasedExpr: + return c.copyOnRewriteRefOfAliasedExpr(n, parent) + case *AliasedTableExpr: + return c.copyOnRewriteRefOfAliasedTableExpr(n, parent) + case *AlterCharset: + return c.copyOnRewriteRefOfAlterCharset(n, parent) + case *AlterCheck: + return c.copyOnRewriteRefOfAlterCheck(n, parent) + case *AlterColumn: + return c.copyOnRewriteRefOfAlterColumn(n, parent) + case *AlterDatabase: + return c.copyOnRewriteRefOfAlterDatabase(n, parent) + case *AlterIndex: + return c.copyOnRewriteRefOfAlterIndex(n, parent) + case *AlterMigration: + return c.copyOnRewriteRefOfAlterMigration(n, parent) + case *AlterTable: + return c.copyOnRewriteRefOfAlterTable(n, parent) + case *AlterView: + return c.copyOnRewriteRefOfAlterView(n, parent) + case *AlterVschema: + return c.copyOnRewriteRefOfAlterVschema(n, parent) + case *AndExpr: + return c.copyOnRewriteRefOfAndExpr(n, parent) + case Argument: + return c.copyOnRewriteArgument(n, parent) + case *ArgumentLessWindowExpr: + return c.copyOnRewriteRefOfArgumentLessWindowExpr(n, parent) + case *AutoIncSpec: + return c.copyOnRewriteRefOfAutoIncSpec(n, parent) + case *Avg: + return c.copyOnRewriteRefOfAvg(n, parent) + case *Begin: + return c.copyOnRewriteRefOfBegin(n, parent) + case *BetweenExpr: + return c.copyOnRewriteRefOfBetweenExpr(n, parent) + case *BinaryExpr: + return c.copyOnRewriteRefOfBinaryExpr(n, parent) + case *BitAnd: + return c.copyOnRewriteRefOfBitAnd(n, parent) + case *BitOr: + return c.copyOnRewriteRefOfBitOr(n, parent) + case *BitXor: + return c.copyOnRewriteRefOfBitXor(n, parent) + case BoolVal: + return c.copyOnRewriteBoolVal(n, parent) + case *CallProc: + return c.copyOnRewriteRefOfCallProc(n, parent) + case *CaseExpr: + return c.copyOnRewriteRefOfCaseExpr(n, parent) + case *CastExpr: + return c.copyOnRewriteRefOfCastExpr(n, parent) + case *ChangeColumn: + return c.copyOnRewriteRefOfChangeColumn(n, parent) + case *CharExpr: + return c.copyOnRewriteRefOfCharExpr(n, parent) + case *CheckConstraintDefinition: + return c.copyOnRewriteRefOfCheckConstraintDefinition(n, parent) + case *ColName: + return c.copyOnRewriteRefOfColName(n, parent) + case *CollateExpr: + return c.copyOnRewriteRefOfCollateExpr(n, parent) + case *ColumnDefinition: + return c.copyOnRewriteRefOfColumnDefinition(n, parent) + case *ColumnType: + return c.copyOnRewriteRefOfColumnType(n, parent) + case Columns: + return c.copyOnRewriteColumns(n, parent) + case *CommentOnly: + return c.copyOnRewriteRefOfCommentOnly(n, parent) + case *Commit: + return c.copyOnRewriteRefOfCommit(n, parent) + case *CommonTableExpr: + return c.copyOnRewriteRefOfCommonTableExpr(n, parent) + case *ComparisonExpr: + return c.copyOnRewriteRefOfComparisonExpr(n, parent) + case *ConstraintDefinition: + return c.copyOnRewriteRefOfConstraintDefinition(n, parent) + case *ConvertExpr: + return c.copyOnRewriteRefOfConvertExpr(n, parent) + case *ConvertType: + return c.copyOnRewriteRefOfConvertType(n, parent) + case *ConvertUsingExpr: + return c.copyOnRewriteRefOfConvertUsingExpr(n, parent) + case *Count: + return c.copyOnRewriteRefOfCount(n, parent) + case *CountStar: + return c.copyOnRewriteRefOfCountStar(n, parent) + case *CreateDatabase: + return c.copyOnRewriteRefOfCreateDatabase(n, parent) + case *CreateTable: + return c.copyOnRewriteRefOfCreateTable(n, parent) + case *CreateView: + return c.copyOnRewriteRefOfCreateView(n, parent) + case *CurTimeFuncExpr: + return c.copyOnRewriteRefOfCurTimeFuncExpr(n, parent) + case *DeallocateStmt: + return c.copyOnRewriteRefOfDeallocateStmt(n, parent) + case *Default: + return c.copyOnRewriteRefOfDefault(n, parent) + case *Definer: + return c.copyOnRewriteRefOfDefiner(n, parent) + case *Delete: + return c.copyOnRewriteRefOfDelete(n, parent) + case *DerivedTable: + return c.copyOnRewriteRefOfDerivedTable(n, parent) + case *DropColumn: + return c.copyOnRewriteRefOfDropColumn(n, parent) + case *DropDatabase: + return c.copyOnRewriteRefOfDropDatabase(n, parent) + case *DropKey: + return c.copyOnRewriteRefOfDropKey(n, parent) + case *DropTable: + return c.copyOnRewriteRefOfDropTable(n, parent) + case *DropView: + return c.copyOnRewriteRefOfDropView(n, parent) + case *ExecuteStmt: + return c.copyOnRewriteRefOfExecuteStmt(n, parent) + case *ExistsExpr: + return c.copyOnRewriteRefOfExistsExpr(n, parent) + case *ExplainStmt: + return c.copyOnRewriteRefOfExplainStmt(n, parent) + case *ExplainTab: + return c.copyOnRewriteRefOfExplainTab(n, parent) + case Exprs: + return c.copyOnRewriteExprs(n, parent) + case *ExtractFuncExpr: + return c.copyOnRewriteRefOfExtractFuncExpr(n, parent) + case *ExtractValueExpr: + return c.copyOnRewriteRefOfExtractValueExpr(n, parent) + case *ExtractedSubquery: + return c.copyOnRewriteRefOfExtractedSubquery(n, parent) + case *FirstOrLastValueExpr: + return c.copyOnRewriteRefOfFirstOrLastValueExpr(n, parent) + case *Flush: + return c.copyOnRewriteRefOfFlush(n, parent) + case *Force: + return c.copyOnRewriteRefOfForce(n, parent) + case *ForeignKeyDefinition: + return c.copyOnRewriteRefOfForeignKeyDefinition(n, parent) + case *FrameClause: + return c.copyOnRewriteRefOfFrameClause(n, parent) + case *FramePoint: + return c.copyOnRewriteRefOfFramePoint(n, parent) + case *FromFirstLastClause: + return c.copyOnRewriteRefOfFromFirstLastClause(n, parent) + case *FuncExpr: + return c.copyOnRewriteRefOfFuncExpr(n, parent) + case *GTIDFuncExpr: + return c.copyOnRewriteRefOfGTIDFuncExpr(n, parent) + case GroupBy: + return c.copyOnRewriteGroupBy(n, parent) + case *GroupConcatExpr: + return c.copyOnRewriteRefOfGroupConcatExpr(n, parent) + case IdentifierCI: + return c.copyOnRewriteIdentifierCI(n, parent) + case IdentifierCS: + return c.copyOnRewriteIdentifierCS(n, parent) + case *IndexDefinition: + return c.copyOnRewriteRefOfIndexDefinition(n, parent) + case *IndexHint: + return c.copyOnRewriteRefOfIndexHint(n, parent) + case IndexHints: + return c.copyOnRewriteIndexHints(n, parent) + case *IndexInfo: + return c.copyOnRewriteRefOfIndexInfo(n, parent) + case *Insert: + return c.copyOnRewriteRefOfInsert(n, parent) + case *InsertExpr: + return c.copyOnRewriteRefOfInsertExpr(n, parent) + case *IntervalExpr: + return c.copyOnRewriteRefOfIntervalExpr(n, parent) + case *IntervalFuncExpr: + return c.copyOnRewriteRefOfIntervalFuncExpr(n, parent) + case *IntroducerExpr: + return c.copyOnRewriteRefOfIntroducerExpr(n, parent) + case *IsExpr: + return c.copyOnRewriteRefOfIsExpr(n, parent) + case *JSONArrayExpr: + return c.copyOnRewriteRefOfJSONArrayExpr(n, parent) + case *JSONAttributesExpr: + return c.copyOnRewriteRefOfJSONAttributesExpr(n, parent) + case *JSONContainsExpr: + return c.copyOnRewriteRefOfJSONContainsExpr(n, parent) + case *JSONContainsPathExpr: + return c.copyOnRewriteRefOfJSONContainsPathExpr(n, parent) + case *JSONExtractExpr: + return c.copyOnRewriteRefOfJSONExtractExpr(n, parent) + case *JSONKeysExpr: + return c.copyOnRewriteRefOfJSONKeysExpr(n, parent) + case *JSONObjectExpr: + return c.copyOnRewriteRefOfJSONObjectExpr(n, parent) + case *JSONObjectParam: + return c.copyOnRewriteRefOfJSONObjectParam(n, parent) + case *JSONOverlapsExpr: + return c.copyOnRewriteRefOfJSONOverlapsExpr(n, parent) + case *JSONPrettyExpr: + return c.copyOnRewriteRefOfJSONPrettyExpr(n, parent) + case *JSONQuoteExpr: + return c.copyOnRewriteRefOfJSONQuoteExpr(n, parent) + case *JSONRemoveExpr: + return c.copyOnRewriteRefOfJSONRemoveExpr(n, parent) + case *JSONSchemaValidFuncExpr: + return c.copyOnRewriteRefOfJSONSchemaValidFuncExpr(n, parent) + case *JSONSchemaValidationReportFuncExpr: + return c.copyOnRewriteRefOfJSONSchemaValidationReportFuncExpr(n, parent) + case *JSONSearchExpr: + return c.copyOnRewriteRefOfJSONSearchExpr(n, parent) + case *JSONStorageFreeExpr: + return c.copyOnRewriteRefOfJSONStorageFreeExpr(n, parent) + case *JSONStorageSizeExpr: + return c.copyOnRewriteRefOfJSONStorageSizeExpr(n, parent) + case *JSONTableExpr: + return c.copyOnRewriteRefOfJSONTableExpr(n, parent) + case *JSONUnquoteExpr: + return c.copyOnRewriteRefOfJSONUnquoteExpr(n, parent) + case *JSONValueExpr: + return c.copyOnRewriteRefOfJSONValueExpr(n, parent) + case *JSONValueMergeExpr: + return c.copyOnRewriteRefOfJSONValueMergeExpr(n, parent) + case *JSONValueModifierExpr: + return c.copyOnRewriteRefOfJSONValueModifierExpr(n, parent) + case *JoinCondition: + return c.copyOnRewriteRefOfJoinCondition(n, parent) + case *JoinTableExpr: + return c.copyOnRewriteRefOfJoinTableExpr(n, parent) + case *JtColumnDefinition: + return c.copyOnRewriteRefOfJtColumnDefinition(n, parent) + case *JtOnResponse: + return c.copyOnRewriteRefOfJtOnResponse(n, parent) + case *KeyState: + return c.copyOnRewriteRefOfKeyState(n, parent) + case *LagLeadExpr: + return c.copyOnRewriteRefOfLagLeadExpr(n, parent) + case *Limit: + return c.copyOnRewriteRefOfLimit(n, parent) + case ListArg: + return c.copyOnRewriteListArg(n, parent) + case *Literal: + return c.copyOnRewriteRefOfLiteral(n, parent) + case *Load: + return c.copyOnRewriteRefOfLoad(n, parent) + case *LocateExpr: + return c.copyOnRewriteRefOfLocateExpr(n, parent) + case *LockOption: + return c.copyOnRewriteRefOfLockOption(n, parent) + case *LockTables: + return c.copyOnRewriteRefOfLockTables(n, parent) + case *LockingFunc: + return c.copyOnRewriteRefOfLockingFunc(n, parent) + case MatchAction: + return c.copyOnRewriteMatchAction(n, parent) + case *MatchExpr: + return c.copyOnRewriteRefOfMatchExpr(n, parent) + case *Max: + return c.copyOnRewriteRefOfMax(n, parent) + case *MemberOfExpr: + return c.copyOnRewriteRefOfMemberOfExpr(n, parent) + case *Min: + return c.copyOnRewriteRefOfMin(n, parent) + case *ModifyColumn: + return c.copyOnRewriteRefOfModifyColumn(n, parent) + case *NTHValueExpr: + return c.copyOnRewriteRefOfNTHValueExpr(n, parent) + case *NamedWindow: + return c.copyOnRewriteRefOfNamedWindow(n, parent) + case NamedWindows: + return c.copyOnRewriteNamedWindows(n, parent) + case *Nextval: + return c.copyOnRewriteRefOfNextval(n, parent) + case *NotExpr: + return c.copyOnRewriteRefOfNotExpr(n, parent) + case *NtileExpr: + return c.copyOnRewriteRefOfNtileExpr(n, parent) + case *NullTreatmentClause: + return c.copyOnRewriteRefOfNullTreatmentClause(n, parent) + case *NullVal: + return c.copyOnRewriteRefOfNullVal(n, parent) + case *Offset: + return c.copyOnRewriteRefOfOffset(n, parent) + case OnDup: + return c.copyOnRewriteOnDup(n, parent) + case *OptLike: + return c.copyOnRewriteRefOfOptLike(n, parent) + case *OrExpr: + return c.copyOnRewriteRefOfOrExpr(n, parent) + case *Order: + return c.copyOnRewriteRefOfOrder(n, parent) + case OrderBy: + return c.copyOnRewriteOrderBy(n, parent) + case *OrderByOption: + return c.copyOnRewriteRefOfOrderByOption(n, parent) + case *OtherAdmin: + return c.copyOnRewriteRefOfOtherAdmin(n, parent) + case *OtherRead: + return c.copyOnRewriteRefOfOtherRead(n, parent) + case *OverClause: + return c.copyOnRewriteRefOfOverClause(n, parent) + case *ParenTableExpr: + return c.copyOnRewriteRefOfParenTableExpr(n, parent) + case *ParsedComments: + return c.copyOnRewriteRefOfParsedComments(n, parent) + case *PartitionDefinition: + return c.copyOnRewriteRefOfPartitionDefinition(n, parent) + case *PartitionDefinitionOptions: + return c.copyOnRewriteRefOfPartitionDefinitionOptions(n, parent) + case *PartitionEngine: + return c.copyOnRewriteRefOfPartitionEngine(n, parent) + case *PartitionOption: + return c.copyOnRewriteRefOfPartitionOption(n, parent) + case *PartitionSpec: + return c.copyOnRewriteRefOfPartitionSpec(n, parent) + case *PartitionValueRange: + return c.copyOnRewriteRefOfPartitionValueRange(n, parent) + case Partitions: + return c.copyOnRewritePartitions(n, parent) + case *PerformanceSchemaFuncExpr: + return c.copyOnRewriteRefOfPerformanceSchemaFuncExpr(n, parent) + case *PrepareStmt: + return c.copyOnRewriteRefOfPrepareStmt(n, parent) + case ReferenceAction: + return c.copyOnRewriteReferenceAction(n, parent) + case *ReferenceDefinition: + return c.copyOnRewriteRefOfReferenceDefinition(n, parent) + case *RegexpInstrExpr: + return c.copyOnRewriteRefOfRegexpInstrExpr(n, parent) + case *RegexpLikeExpr: + return c.copyOnRewriteRefOfRegexpLikeExpr(n, parent) + case *RegexpReplaceExpr: + return c.copyOnRewriteRefOfRegexpReplaceExpr(n, parent) + case *RegexpSubstrExpr: + return c.copyOnRewriteRefOfRegexpSubstrExpr(n, parent) + case *Release: + return c.copyOnRewriteRefOfRelease(n, parent) + case *RenameColumn: + return c.copyOnRewriteRefOfRenameColumn(n, parent) + case *RenameIndex: + return c.copyOnRewriteRefOfRenameIndex(n, parent) + case *RenameTable: + return c.copyOnRewriteRefOfRenameTable(n, parent) + case *RenameTableName: + return c.copyOnRewriteRefOfRenameTableName(n, parent) + case *RevertMigration: + return c.copyOnRewriteRefOfRevertMigration(n, parent) + case *Rollback: + return c.copyOnRewriteRefOfRollback(n, parent) + case RootNode: + return c.copyOnRewriteRootNode(n, parent) + case *SRollback: + return c.copyOnRewriteRefOfSRollback(n, parent) + case *Savepoint: + return c.copyOnRewriteRefOfSavepoint(n, parent) + case *Select: + return c.copyOnRewriteRefOfSelect(n, parent) + case SelectExprs: + return c.copyOnRewriteSelectExprs(n, parent) + case *SelectInto: + return c.copyOnRewriteRefOfSelectInto(n, parent) + case *Set: + return c.copyOnRewriteRefOfSet(n, parent) + case *SetExpr: + return c.copyOnRewriteRefOfSetExpr(n, parent) + case SetExprs: + return c.copyOnRewriteSetExprs(n, parent) + case *Show: + return c.copyOnRewriteRefOfShow(n, parent) + case *ShowBasic: + return c.copyOnRewriteRefOfShowBasic(n, parent) + case *ShowCreate: + return c.copyOnRewriteRefOfShowCreate(n, parent) + case *ShowFilter: + return c.copyOnRewriteRefOfShowFilter(n, parent) + case *ShowMigrationLogs: + return c.copyOnRewriteRefOfShowMigrationLogs(n, parent) + case *ShowOther: + return c.copyOnRewriteRefOfShowOther(n, parent) + case *ShowThrottledApps: + return c.copyOnRewriteRefOfShowThrottledApps(n, parent) + case *ShowThrottlerStatus: + return c.copyOnRewriteRefOfShowThrottlerStatus(n, parent) + case *StarExpr: + return c.copyOnRewriteRefOfStarExpr(n, parent) + case *Std: + return c.copyOnRewriteRefOfStd(n, parent) + case *StdDev: + return c.copyOnRewriteRefOfStdDev(n, parent) + case *StdPop: + return c.copyOnRewriteRefOfStdPop(n, parent) + case *StdSamp: + return c.copyOnRewriteRefOfStdSamp(n, parent) + case *Stream: + return c.copyOnRewriteRefOfStream(n, parent) + case *SubPartition: + return c.copyOnRewriteRefOfSubPartition(n, parent) + case *SubPartitionDefinition: + return c.copyOnRewriteRefOfSubPartitionDefinition(n, parent) + case *SubPartitionDefinitionOptions: + return c.copyOnRewriteRefOfSubPartitionDefinitionOptions(n, parent) + case SubPartitionDefinitions: + return c.copyOnRewriteSubPartitionDefinitions(n, parent) + case *Subquery: + return c.copyOnRewriteRefOfSubquery(n, parent) + case *SubstrExpr: + return c.copyOnRewriteRefOfSubstrExpr(n, parent) + case *Sum: + return c.copyOnRewriteRefOfSum(n, parent) + case TableExprs: + return c.copyOnRewriteTableExprs(n, parent) + case TableName: + return c.copyOnRewriteTableName(n, parent) + case TableNames: + return c.copyOnRewriteTableNames(n, parent) + case TableOptions: + return c.copyOnRewriteTableOptions(n, parent) + case *TableSpec: + return c.copyOnRewriteRefOfTableSpec(n, parent) + case *TablespaceOperation: + return c.copyOnRewriteRefOfTablespaceOperation(n, parent) + case *TimestampFuncExpr: + return c.copyOnRewriteRefOfTimestampFuncExpr(n, parent) + case *TrimFuncExpr: + return c.copyOnRewriteRefOfTrimFuncExpr(n, parent) + case *TruncateTable: + return c.copyOnRewriteRefOfTruncateTable(n, parent) + case *UnaryExpr: + return c.copyOnRewriteRefOfUnaryExpr(n, parent) + case *Union: + return c.copyOnRewriteRefOfUnion(n, parent) + case *UnlockTables: + return c.copyOnRewriteRefOfUnlockTables(n, parent) + case *Update: + return c.copyOnRewriteRefOfUpdate(n, parent) + case *UpdateExpr: + return c.copyOnRewriteRefOfUpdateExpr(n, parent) + case UpdateExprs: + return c.copyOnRewriteUpdateExprs(n, parent) + case *UpdateXMLExpr: + return c.copyOnRewriteRefOfUpdateXMLExpr(n, parent) + case *Use: + return c.copyOnRewriteRefOfUse(n, parent) + case *VExplainStmt: + return c.copyOnRewriteRefOfVExplainStmt(n, parent) + case *VStream: + return c.copyOnRewriteRefOfVStream(n, parent) + case ValTuple: + return c.copyOnRewriteValTuple(n, parent) + case *Validation: + return c.copyOnRewriteRefOfValidation(n, parent) + case Values: + return c.copyOnRewriteValues(n, parent) + case *ValuesFuncExpr: + return c.copyOnRewriteRefOfValuesFuncExpr(n, parent) + case *VarPop: + return c.copyOnRewriteRefOfVarPop(n, parent) + case *VarSamp: + return c.copyOnRewriteRefOfVarSamp(n, parent) + case *Variable: + return c.copyOnRewriteRefOfVariable(n, parent) + case *Variance: + return c.copyOnRewriteRefOfVariance(n, parent) + case VindexParam: + return c.copyOnRewriteVindexParam(n, parent) + case *VindexSpec: + return c.copyOnRewriteRefOfVindexSpec(n, parent) + case *WeightStringFuncExpr: + return c.copyOnRewriteRefOfWeightStringFuncExpr(n, parent) + case *When: + return c.copyOnRewriteRefOfWhen(n, parent) + case *Where: + return c.copyOnRewriteRefOfWhere(n, parent) + case *WindowDefinition: + return c.copyOnRewriteRefOfWindowDefinition(n, parent) + case WindowDefinitions: + return c.copyOnRewriteWindowDefinitions(n, parent) + case *WindowSpecification: + return c.copyOnRewriteRefOfWindowSpecification(n, parent) + case *With: + return c.copyOnRewriteRefOfWith(n, parent) + case *XorExpr: + return c.copyOnRewriteRefOfXorExpr(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteRefOfAddColumns(n *AddColumns, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + var changedColumns bool + _Columns := make([]*ColumnDefinition, len(n.Columns)) + for x, el := range n.Columns { + this, changed := c.copyOnRewriteRefOfColumnDefinition(el, n) + _Columns[x] = this.(*ColumnDefinition) + if changed { + changedColumns = true + } + } + _After, changedAfter := c.copyOnRewriteRefOfColName(n.After, n) + if changedColumns || changedAfter { + changed := *n + changed.Columns = _Columns + changed.After, _ = _After.(*ColName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAddConstraintDefinition(n *AddConstraintDefinition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _ConstraintDefinition, changedConstraintDefinition := c.copyOnRewriteRefOfConstraintDefinition(n.ConstraintDefinition, n) + if changedConstraintDefinition { + changed := *n + changed.ConstraintDefinition, _ = _ConstraintDefinition.(*ConstraintDefinition) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAddIndexDefinition(n *AddIndexDefinition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _IndexDefinition, changedIndexDefinition := c.copyOnRewriteRefOfIndexDefinition(n.IndexDefinition, n) + if changedIndexDefinition { + changed := *n + changed.IndexDefinition, _ = _IndexDefinition.(*IndexDefinition) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAliasedExpr(n *AliasedExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _As, changedAs := c.copyOnRewriteIdentifierCI(n.As, n) + if changedExpr || changedAs { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.As, _ = _As.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAliasedTableExpr(n *AliasedTableExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteSimpleTableExpr(n.Expr, n) + _Partitions, changedPartitions := c.copyOnRewritePartitions(n.Partitions, n) + _As, changedAs := c.copyOnRewriteIdentifierCS(n.As, n) + _Hints, changedHints := c.copyOnRewriteIndexHints(n.Hints, n) + _Columns, changedColumns := c.copyOnRewriteColumns(n.Columns, n) + if changedExpr || changedPartitions || changedAs || changedHints || changedColumns { + changed := *n + changed.Expr, _ = _Expr.(SimpleTableExpr) + changed.Partitions, _ = _Partitions.(Partitions) + changed.As, _ = _As.(IdentifierCS) + changed.Hints, _ = _Hints.(IndexHints) + changed.Columns, _ = _Columns.(Columns) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAlterCharset(n *AlterCharset, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAlterCheck(n *AlterCheck, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + if changedName { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAlterColumn(n *AlterColumn, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Column, changedColumn := c.copyOnRewriteRefOfColName(n.Column, n) + _DefaultVal, changedDefaultVal := c.copyOnRewriteExpr(n.DefaultVal, n) + if changedColumn || changedDefaultVal { + changed := *n + changed.Column, _ = _Column.(*ColName) + changed.DefaultVal, _ = _DefaultVal.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAlterDatabase(n *AlterDatabase, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _DBName, changedDBName := c.copyOnRewriteIdentifierCS(n.DBName, n) + if changedDBName { + changed := *n + changed.DBName, _ = _DBName.(IdentifierCS) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAlterIndex(n *AlterIndex, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + if changedName { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAlterMigration(n *AlterMigration, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Ratio, changedRatio := c.copyOnRewriteRefOfLiteral(n.Ratio, n) + if changedRatio { + changed := *n + changed.Ratio, _ = _Ratio.(*Literal) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAlterTable(n *AlterTable, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) + var changedAlterOptions bool + _AlterOptions := make([]AlterOption, len(n.AlterOptions)) + for x, el := range n.AlterOptions { + this, changed := c.copyOnRewriteAlterOption(el, n) + _AlterOptions[x] = this.(AlterOption) + if changed { + changedAlterOptions = true + } + } + _PartitionSpec, changedPartitionSpec := c.copyOnRewriteRefOfPartitionSpec(n.PartitionSpec, n) + _PartitionOption, changedPartitionOption := c.copyOnRewriteRefOfPartitionOption(n.PartitionOption, n) + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + if changedTable || changedAlterOptions || changedPartitionSpec || changedPartitionOption || changedComments { + changed := *n + changed.Table, _ = _Table.(TableName) + changed.AlterOptions = _AlterOptions + changed.PartitionSpec, _ = _PartitionSpec.(*PartitionSpec) + changed.PartitionOption, _ = _PartitionOption.(*PartitionOption) + changed.Comments, _ = _Comments.(*ParsedComments) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAlterView(n *AlterView, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _ViewName, changedViewName := c.copyOnRewriteTableName(n.ViewName, n) + _Definer, changedDefiner := c.copyOnRewriteRefOfDefiner(n.Definer, n) + _Columns, changedColumns := c.copyOnRewriteColumns(n.Columns, n) + _Select, changedSelect := c.copyOnRewriteSelectStatement(n.Select, n) + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + if changedViewName || changedDefiner || changedColumns || changedSelect || changedComments { + changed := *n + changed.ViewName, _ = _ViewName.(TableName) + changed.Definer, _ = _Definer.(*Definer) + changed.Columns, _ = _Columns.(Columns) + changed.Select, _ = _Select.(SelectStatement) + changed.Comments, _ = _Comments.(*ParsedComments) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAlterVschema(n *AlterVschema, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) + _VindexSpec, changedVindexSpec := c.copyOnRewriteRefOfVindexSpec(n.VindexSpec, n) + var changedVindexCols bool + _VindexCols := make([]IdentifierCI, len(n.VindexCols)) + for x, el := range n.VindexCols { + this, changed := c.copyOnRewriteIdentifierCI(el, n) + _VindexCols[x] = this.(IdentifierCI) + if changed { + changedVindexCols = true + } + } + _AutoIncSpec, changedAutoIncSpec := c.copyOnRewriteRefOfAutoIncSpec(n.AutoIncSpec, n) + if changedTable || changedVindexSpec || changedVindexCols || changedAutoIncSpec { + changed := *n + changed.Table, _ = _Table.(TableName) + changed.VindexSpec, _ = _VindexSpec.(*VindexSpec) + changed.VindexCols = _VindexCols + changed.AutoIncSpec, _ = _AutoIncSpec.(*AutoIncSpec) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAndExpr(n *AndExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Left, changedLeft := c.copyOnRewriteExpr(n.Left, n) + _Right, changedRight := c.copyOnRewriteExpr(n.Right, n) + if changedLeft || changedRight { + changed := *n + changed.Left, _ = _Left.(Expr) + changed.Right, _ = _Right.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfArgumentLessWindowExpr(n *ArgumentLessWindowExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _OverClause, changedOverClause := c.copyOnRewriteRefOfOverClause(n.OverClause, n) + if changedOverClause { + changed := *n + changed.OverClause, _ = _OverClause.(*OverClause) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAutoIncSpec(n *AutoIncSpec, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Column, changedColumn := c.copyOnRewriteIdentifierCI(n.Column, n) + _Sequence, changedSequence := c.copyOnRewriteTableName(n.Sequence, n) + if changedColumn || changedSequence { + changed := *n + changed.Column, _ = _Column.(IdentifierCI) + changed.Sequence, _ = _Sequence.(TableName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfAvg(n *Avg, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfBegin(n *Begin, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfBetweenExpr(n *BetweenExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Left, changedLeft := c.copyOnRewriteExpr(n.Left, n) + _From, changedFrom := c.copyOnRewriteExpr(n.From, n) + _To, changedTo := c.copyOnRewriteExpr(n.To, n) + if changedLeft || changedFrom || changedTo { + changed := *n + changed.Left, _ = _Left.(Expr) + changed.From, _ = _From.(Expr) + changed.To, _ = _To.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfBinaryExpr(n *BinaryExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Left, changedLeft := c.copyOnRewriteExpr(n.Left, n) + _Right, changedRight := c.copyOnRewriteExpr(n.Right, n) + if changedLeft || changedRight { + changed := *n + changed.Left, _ = _Left.(Expr) + changed.Right, _ = _Right.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfBitAnd(n *BitAnd, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfBitOr(n *BitOr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfBitXor(n *BitXor, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCallProc(n *CallProc, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteTableName(n.Name, n) + _Params, changedParams := c.copyOnRewriteExprs(n.Params, n) + if changedName || changedParams { + changed := *n + changed.Name, _ = _Name.(TableName) + changed.Params, _ = _Params.(Exprs) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCaseExpr(n *CaseExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + var changedWhens bool + _Whens := make([]*When, len(n.Whens)) + for x, el := range n.Whens { + this, changed := c.copyOnRewriteRefOfWhen(el, n) + _Whens[x] = this.(*When) + if changed { + changedWhens = true + } + } + _Else, changedElse := c.copyOnRewriteExpr(n.Else, n) + if changedExpr || changedWhens || changedElse { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.Whens = _Whens + changed.Else, _ = _Else.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCastExpr(n *CastExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _Type, changedType := c.copyOnRewriteRefOfConvertType(n.Type, n) + if changedExpr || changedType { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.Type, _ = _Type.(*ConvertType) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfChangeColumn(n *ChangeColumn, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _OldColumn, changedOldColumn := c.copyOnRewriteRefOfColName(n.OldColumn, n) + _NewColDefinition, changedNewColDefinition := c.copyOnRewriteRefOfColumnDefinition(n.NewColDefinition, n) + _After, changedAfter := c.copyOnRewriteRefOfColName(n.After, n) + if changedOldColumn || changedNewColDefinition || changedAfter { + changed := *n + changed.OldColumn, _ = _OldColumn.(*ColName) + changed.NewColDefinition, _ = _NewColDefinition.(*ColumnDefinition) + changed.After, _ = _After.(*ColName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCharExpr(n *CharExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Exprs, changedExprs := c.copyOnRewriteExprs(n.Exprs, n) + if changedExprs { + changed := *n + changed.Exprs, _ = _Exprs.(Exprs) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCheckConstraintDefinition(n *CheckConstraintDefinition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfColName(n *ColName, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + _Qualifier, changedQualifier := c.copyOnRewriteTableName(n.Qualifier, n) + if changedName || changedQualifier { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + changed.Qualifier, _ = _Qualifier.(TableName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCollateExpr(n *CollateExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfColumnDefinition(n *ColumnDefinition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + if changedName { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfColumnType(n *ColumnType, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Length, changedLength := c.copyOnRewriteRefOfLiteral(n.Length, n) + _Scale, changedScale := c.copyOnRewriteRefOfLiteral(n.Scale, n) + if changedLength || changedScale { + changed := *n + changed.Length, _ = _Length.(*Literal) + changed.Scale, _ = _Scale.(*Literal) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteColumns(n Columns, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(Columns, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteIdentifierCI(el, n) + res[x] = this.(IdentifierCI) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCommentOnly(n *CommentOnly, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCommit(n *Commit, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCommonTableExpr(n *CommonTableExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _ID, changedID := c.copyOnRewriteIdentifierCS(n.ID, n) + _Columns, changedColumns := c.copyOnRewriteColumns(n.Columns, n) + _Subquery, changedSubquery := c.copyOnRewriteRefOfSubquery(n.Subquery, n) + if changedID || changedColumns || changedSubquery { + changed := *n + changed.ID, _ = _ID.(IdentifierCS) + changed.Columns, _ = _Columns.(Columns) + changed.Subquery, _ = _Subquery.(*Subquery) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfComparisonExpr(n *ComparisonExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Left, changedLeft := c.copyOnRewriteExpr(n.Left, n) + _Right, changedRight := c.copyOnRewriteExpr(n.Right, n) + _Escape, changedEscape := c.copyOnRewriteExpr(n.Escape, n) + if changedLeft || changedRight || changedEscape { + changed := *n + changed.Left, _ = _Left.(Expr) + changed.Right, _ = _Right.(Expr) + changed.Escape, _ = _Escape.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfConstraintDefinition(n *ConstraintDefinition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + _Details, changedDetails := c.copyOnRewriteConstraintInfo(n.Details, n) + if changedName || changedDetails { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + changed.Details, _ = _Details.(ConstraintInfo) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfConvertExpr(n *ConvertExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _Type, changedType := c.copyOnRewriteRefOfConvertType(n.Type, n) + if changedExpr || changedType { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.Type, _ = _Type.(*ConvertType) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfConvertType(n *ConvertType, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Length, changedLength := c.copyOnRewriteRefOfLiteral(n.Length, n) + _Scale, changedScale := c.copyOnRewriteRefOfLiteral(n.Scale, n) + if changedLength || changedScale { + changed := *n + changed.Length, _ = _Length.(*Literal) + changed.Scale, _ = _Scale.(*Literal) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfConvertUsingExpr(n *ConvertUsingExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCount(n *Count, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Args, changedArgs := c.copyOnRewriteExprs(n.Args, n) + if changedArgs { + changed := *n + changed.Args, _ = _Args.(Exprs) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCountStar(n *CountStar, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCreateDatabase(n *CreateDatabase, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + _DBName, changedDBName := c.copyOnRewriteIdentifierCS(n.DBName, n) + if changedComments || changedDBName { + changed := *n + changed.Comments, _ = _Comments.(*ParsedComments) + changed.DBName, _ = _DBName.(IdentifierCS) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCreateTable(n *CreateTable, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) + _TableSpec, changedTableSpec := c.copyOnRewriteRefOfTableSpec(n.TableSpec, n) + _OptLike, changedOptLike := c.copyOnRewriteRefOfOptLike(n.OptLike, n) + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + if changedTable || changedTableSpec || changedOptLike || changedComments { + changed := *n + changed.Table, _ = _Table.(TableName) + changed.TableSpec, _ = _TableSpec.(*TableSpec) + changed.OptLike, _ = _OptLike.(*OptLike) + changed.Comments, _ = _Comments.(*ParsedComments) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCreateView(n *CreateView, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _ViewName, changedViewName := c.copyOnRewriteTableName(n.ViewName, n) + _Definer, changedDefiner := c.copyOnRewriteRefOfDefiner(n.Definer, n) + _Columns, changedColumns := c.copyOnRewriteColumns(n.Columns, n) + _Select, changedSelect := c.copyOnRewriteSelectStatement(n.Select, n) + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + if changedViewName || changedDefiner || changedColumns || changedSelect || changedComments { + changed := *n + changed.ViewName, _ = _ViewName.(TableName) + changed.Definer, _ = _Definer.(*Definer) + changed.Columns, _ = _Columns.(Columns) + changed.Select, _ = _Select.(SelectStatement) + changed.Comments, _ = _Comments.(*ParsedComments) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfCurTimeFuncExpr(n *CurTimeFuncExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + _Fsp, changedFsp := c.copyOnRewriteExpr(n.Fsp, n) + if changedName || changedFsp { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + changed.Fsp, _ = _Fsp.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfDeallocateStmt(n *DeallocateStmt, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + if changedComments || changedName { + changed := *n + changed.Comments, _ = _Comments.(*ParsedComments) + changed.Name, _ = _Name.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfDefault(n *Default, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfDefiner(n *Definer, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfDelete(n *Delete, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _With, changedWith := c.copyOnRewriteRefOfWith(n.With, n) + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + _Targets, changedTargets := c.copyOnRewriteTableNames(n.Targets, n) + _TableExprs, changedTableExprs := c.copyOnRewriteTableExprs(n.TableExprs, n) + _Partitions, changedPartitions := c.copyOnRewritePartitions(n.Partitions, n) + _Where, changedWhere := c.copyOnRewriteRefOfWhere(n.Where, n) + _OrderBy, changedOrderBy := c.copyOnRewriteOrderBy(n.OrderBy, n) + _Limit, changedLimit := c.copyOnRewriteRefOfLimit(n.Limit, n) + if changedWith || changedComments || changedTargets || changedTableExprs || changedPartitions || changedWhere || changedOrderBy || changedLimit { + changed := *n + changed.With, _ = _With.(*With) + changed.Comments, _ = _Comments.(*ParsedComments) + changed.Targets, _ = _Targets.(TableNames) + changed.TableExprs, _ = _TableExprs.(TableExprs) + changed.Partitions, _ = _Partitions.(Partitions) + changed.Where, _ = _Where.(*Where) + changed.OrderBy, _ = _OrderBy.(OrderBy) + changed.Limit, _ = _Limit.(*Limit) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfDerivedTable(n *DerivedTable, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Select, changedSelect := c.copyOnRewriteSelectStatement(n.Select, n) + if changedSelect { + changed := *n + changed.Select, _ = _Select.(SelectStatement) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfDropColumn(n *DropColumn, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteRefOfColName(n.Name, n) + if changedName { + changed := *n + changed.Name, _ = _Name.(*ColName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfDropDatabase(n *DropDatabase, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + _DBName, changedDBName := c.copyOnRewriteIdentifierCS(n.DBName, n) + if changedComments || changedDBName { + changed := *n + changed.Comments, _ = _Comments.(*ParsedComments) + changed.DBName, _ = _DBName.(IdentifierCS) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfDropKey(n *DropKey, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + if changedName { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfDropTable(n *DropTable, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _FromTables, changedFromTables := c.copyOnRewriteTableNames(n.FromTables, n) + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + if changedFromTables || changedComments { + changed := *n + changed.FromTables, _ = _FromTables.(TableNames) + changed.Comments, _ = _Comments.(*ParsedComments) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfDropView(n *DropView, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _FromTables, changedFromTables := c.copyOnRewriteTableNames(n.FromTables, n) + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + if changedFromTables || changedComments { + changed := *n + changed.FromTables, _ = _FromTables.(TableNames) + changed.Comments, _ = _Comments.(*ParsedComments) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfExecuteStmt(n *ExecuteStmt, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + var changedArguments bool + _Arguments := make([]*Variable, len(n.Arguments)) + for x, el := range n.Arguments { + this, changed := c.copyOnRewriteRefOfVariable(el, n) + _Arguments[x] = this.(*Variable) + if changed { + changedArguments = true + } + } + if changedName || changedComments || changedArguments { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + changed.Comments, _ = _Comments.(*ParsedComments) + changed.Arguments = _Arguments + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfExistsExpr(n *ExistsExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Subquery, changedSubquery := c.copyOnRewriteRefOfSubquery(n.Subquery, n) + if changedSubquery { + changed := *n + changed.Subquery, _ = _Subquery.(*Subquery) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfExplainStmt(n *ExplainStmt, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Statement, changedStatement := c.copyOnRewriteStatement(n.Statement, n) + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + if changedStatement || changedComments { + changed := *n + changed.Statement, _ = _Statement.(Statement) + changed.Comments, _ = _Comments.(*ParsedComments) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfExplainTab(n *ExplainTab, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) + if changedTable { + changed := *n + changed.Table, _ = _Table.(TableName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteExprs(n Exprs, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(Exprs, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteExpr(el, n) + res[x] = this.(Expr) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfExtractFuncExpr(n *ExtractFuncExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfExtractValueExpr(n *ExtractValueExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Fragment, changedFragment := c.copyOnRewriteExpr(n.Fragment, n) + _XPathExpr, changedXPathExpr := c.copyOnRewriteExpr(n.XPathExpr, n) + if changedFragment || changedXPathExpr { + changed := *n + changed.Fragment, _ = _Fragment.(Expr) + changed.XPathExpr, _ = _XPathExpr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfExtractedSubquery(n *ExtractedSubquery, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Original, changedOriginal := c.copyOnRewriteExpr(n.Original, n) + _Subquery, changedSubquery := c.copyOnRewriteRefOfSubquery(n.Subquery, n) + _OtherSide, changedOtherSide := c.copyOnRewriteExpr(n.OtherSide, n) + _alternative, changedalternative := c.copyOnRewriteExpr(n.alternative, n) + if changedOriginal || changedSubquery || changedOtherSide || changedalternative { + changed := *n + changed.Original, _ = _Original.(Expr) + changed.Subquery, _ = _Subquery.(*Subquery) + changed.OtherSide, _ = _OtherSide.(Expr) + changed.alternative, _ = _alternative.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfFirstOrLastValueExpr(n *FirstOrLastValueExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _NullTreatmentClause, changedNullTreatmentClause := c.copyOnRewriteRefOfNullTreatmentClause(n.NullTreatmentClause, n) + _OverClause, changedOverClause := c.copyOnRewriteRefOfOverClause(n.OverClause, n) + if changedExpr || changedNullTreatmentClause || changedOverClause { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.NullTreatmentClause, _ = _NullTreatmentClause.(*NullTreatmentClause) + changed.OverClause, _ = _OverClause.(*OverClause) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfFlush(n *Flush, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _TableNames, changedTableNames := c.copyOnRewriteTableNames(n.TableNames, n) + if changedTableNames { + changed := *n + changed.TableNames, _ = _TableNames.(TableNames) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfForce(n *Force, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfForeignKeyDefinition(n *ForeignKeyDefinition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Source, changedSource := c.copyOnRewriteColumns(n.Source, n) + _IndexName, changedIndexName := c.copyOnRewriteIdentifierCI(n.IndexName, n) + _ReferenceDefinition, changedReferenceDefinition := c.copyOnRewriteRefOfReferenceDefinition(n.ReferenceDefinition, n) + if changedSource || changedIndexName || changedReferenceDefinition { + changed := *n + changed.Source, _ = _Source.(Columns) + changed.IndexName, _ = _IndexName.(IdentifierCI) + changed.ReferenceDefinition, _ = _ReferenceDefinition.(*ReferenceDefinition) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfFrameClause(n *FrameClause, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Start, changedStart := c.copyOnRewriteRefOfFramePoint(n.Start, n) + _End, changedEnd := c.copyOnRewriteRefOfFramePoint(n.End, n) + if changedStart || changedEnd { + changed := *n + changed.Start, _ = _Start.(*FramePoint) + changed.End, _ = _End.(*FramePoint) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfFramePoint(n *FramePoint, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfFromFirstLastClause(n *FromFirstLastClause, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfFuncExpr(n *FuncExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Qualifier, changedQualifier := c.copyOnRewriteIdentifierCS(n.Qualifier, n) + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + _Exprs, changedExprs := c.copyOnRewriteSelectExprs(n.Exprs, n) + if changedQualifier || changedName || changedExprs { + changed := *n + changed.Qualifier, _ = _Qualifier.(IdentifierCS) + changed.Name, _ = _Name.(IdentifierCI) + changed.Exprs, _ = _Exprs.(SelectExprs) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfGTIDFuncExpr(n *GTIDFuncExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Set1, changedSet1 := c.copyOnRewriteExpr(n.Set1, n) + _Set2, changedSet2 := c.copyOnRewriteExpr(n.Set2, n) + _Timeout, changedTimeout := c.copyOnRewriteExpr(n.Timeout, n) + _Channel, changedChannel := c.copyOnRewriteExpr(n.Channel, n) + if changedSet1 || changedSet2 || changedTimeout || changedChannel { + changed := *n + changed.Set1, _ = _Set1.(Expr) + changed.Set2, _ = _Set2.(Expr) + changed.Timeout, _ = _Timeout.(Expr) + changed.Channel, _ = _Channel.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteGroupBy(n GroupBy, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(GroupBy, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteExpr(el, n) + res[x] = this.(Expr) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfGroupConcatExpr(n *GroupConcatExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Exprs, changedExprs := c.copyOnRewriteExprs(n.Exprs, n) + _OrderBy, changedOrderBy := c.copyOnRewriteOrderBy(n.OrderBy, n) + _Limit, changedLimit := c.copyOnRewriteRefOfLimit(n.Limit, n) + if changedExprs || changedOrderBy || changedLimit { + changed := *n + changed.Exprs, _ = _Exprs.(Exprs) + changed.OrderBy, _ = _OrderBy.(OrderBy) + changed.Limit, _ = _Limit.(*Limit) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteIdentifierCI(n IdentifierCI, parent SQLNode) (out SQLNode, changed bool) { + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteIdentifierCS(n IdentifierCS, parent SQLNode) (out SQLNode, changed bool) { + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfIndexDefinition(n *IndexDefinition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Info, changedInfo := c.copyOnRewriteRefOfIndexInfo(n.Info, n) + if changedInfo { + changed := *n + changed.Info, _ = _Info.(*IndexInfo) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfIndexHint(n *IndexHint, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + var changedIndexes bool + _Indexes := make([]IdentifierCI, len(n.Indexes)) + for x, el := range n.Indexes { + this, changed := c.copyOnRewriteIdentifierCI(el, n) + _Indexes[x] = this.(IdentifierCI) + if changed { + changedIndexes = true + } + } + if changedIndexes { + changed := *n + changed.Indexes = _Indexes + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteIndexHints(n IndexHints, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(IndexHints, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteRefOfIndexHint(el, n) + res[x] = this.(*IndexHint) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfIndexInfo(n *IndexInfo, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + _ConstraintName, changedConstraintName := c.copyOnRewriteIdentifierCI(n.ConstraintName, n) + if changedName || changedConstraintName { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + changed.ConstraintName, _ = _ConstraintName.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfInsert(n *Insert, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) + _Partitions, changedPartitions := c.copyOnRewritePartitions(n.Partitions, n) + _Columns, changedColumns := c.copyOnRewriteColumns(n.Columns, n) + _Rows, changedRows := c.copyOnRewriteInsertRows(n.Rows, n) + _OnDup, changedOnDup := c.copyOnRewriteOnDup(n.OnDup, n) + if changedComments || changedTable || changedPartitions || changedColumns || changedRows || changedOnDup { + changed := *n + changed.Comments, _ = _Comments.(*ParsedComments) + changed.Table, _ = _Table.(TableName) + changed.Partitions, _ = _Partitions.(Partitions) + changed.Columns, _ = _Columns.(Columns) + changed.Rows, _ = _Rows.(InsertRows) + changed.OnDup, _ = _OnDup.(OnDup) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfInsertExpr(n *InsertExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Str, changedStr := c.copyOnRewriteExpr(n.Str, n) + _Pos, changedPos := c.copyOnRewriteExpr(n.Pos, n) + _Len, changedLen := c.copyOnRewriteExpr(n.Len, n) + _NewStr, changedNewStr := c.copyOnRewriteExpr(n.NewStr, n) + if changedStr || changedPos || changedLen || changedNewStr { + changed := *n + changed.Str, _ = _Str.(Expr) + changed.Pos, _ = _Pos.(Expr) + changed.Len, _ = _Len.(Expr) + changed.NewStr, _ = _NewStr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfIntervalExpr(n *IntervalExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfIntervalFuncExpr(n *IntervalFuncExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _Exprs, changedExprs := c.copyOnRewriteExprs(n.Exprs, n) + if changedExpr || changedExprs { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.Exprs, _ = _Exprs.(Exprs) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfIntroducerExpr(n *IntroducerExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfIsExpr(n *IsExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Left, changedLeft := c.copyOnRewriteExpr(n.Left, n) + if changedLeft { + changed := *n + changed.Left, _ = _Left.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONArrayExpr(n *JSONArrayExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Params, changedParams := c.copyOnRewriteExprs(n.Params, n) + if changedParams { + changed := *n + changed.Params, _ = _Params.(Exprs) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONAttributesExpr(n *JSONAttributesExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) + _Path, changedPath := c.copyOnRewriteExpr(n.Path, n) + if changedJSONDoc || changedPath { + changed := *n + changed.JSONDoc, _ = _JSONDoc.(Expr) + changed.Path, _ = _Path.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONContainsExpr(n *JSONContainsExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Target, changedTarget := c.copyOnRewriteExpr(n.Target, n) + _Candidate, changedCandidate := c.copyOnRewriteExpr(n.Candidate, n) + var changedPathList bool + _PathList := make([]Expr, len(n.PathList)) + for x, el := range n.PathList { + this, changed := c.copyOnRewriteExpr(el, n) + _PathList[x] = this.(Expr) + if changed { + changedPathList = true + } + } + if changedTarget || changedCandidate || changedPathList { + changed := *n + changed.Target, _ = _Target.(Expr) + changed.Candidate, _ = _Candidate.(Expr) + changed.PathList = _PathList + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONContainsPathExpr(n *JSONContainsPathExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) + _OneOrAll, changedOneOrAll := c.copyOnRewriteExpr(n.OneOrAll, n) + var changedPathList bool + _PathList := make([]Expr, len(n.PathList)) + for x, el := range n.PathList { + this, changed := c.copyOnRewriteExpr(el, n) + _PathList[x] = this.(Expr) + if changed { + changedPathList = true + } + } + if changedJSONDoc || changedOneOrAll || changedPathList { + changed := *n + changed.JSONDoc, _ = _JSONDoc.(Expr) + changed.OneOrAll, _ = _OneOrAll.(Expr) + changed.PathList = _PathList + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONExtractExpr(n *JSONExtractExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) + var changedPathList bool + _PathList := make([]Expr, len(n.PathList)) + for x, el := range n.PathList { + this, changed := c.copyOnRewriteExpr(el, n) + _PathList[x] = this.(Expr) + if changed { + changedPathList = true + } + } + if changedJSONDoc || changedPathList { + changed := *n + changed.JSONDoc, _ = _JSONDoc.(Expr) + changed.PathList = _PathList + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONKeysExpr(n *JSONKeysExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) + _Path, changedPath := c.copyOnRewriteExpr(n.Path, n) + if changedJSONDoc || changedPath { + changed := *n + changed.JSONDoc, _ = _JSONDoc.(Expr) + changed.Path, _ = _Path.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONObjectExpr(n *JSONObjectExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + var changedParams bool + _Params := make([]*JSONObjectParam, len(n.Params)) + for x, el := range n.Params { + this, changed := c.copyOnRewriteRefOfJSONObjectParam(el, n) + _Params[x] = this.(*JSONObjectParam) + if changed { + changedParams = true + } + } + if changedParams { + changed := *n + changed.Params = _Params + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONObjectParam(n *JSONObjectParam, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Key, changedKey := c.copyOnRewriteExpr(n.Key, n) + _Value, changedValue := c.copyOnRewriteExpr(n.Value, n) + if changedKey || changedValue { + changed := *n + changed.Key, _ = _Key.(Expr) + changed.Value, _ = _Value.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONOverlapsExpr(n *JSONOverlapsExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONDoc1, changedJSONDoc1 := c.copyOnRewriteExpr(n.JSONDoc1, n) + _JSONDoc2, changedJSONDoc2 := c.copyOnRewriteExpr(n.JSONDoc2, n) + if changedJSONDoc1 || changedJSONDoc2 { + changed := *n + changed.JSONDoc1, _ = _JSONDoc1.(Expr) + changed.JSONDoc2, _ = _JSONDoc2.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONPrettyExpr(n *JSONPrettyExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONVal, changedJSONVal := c.copyOnRewriteExpr(n.JSONVal, n) + if changedJSONVal { + changed := *n + changed.JSONVal, _ = _JSONVal.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONQuoteExpr(n *JSONQuoteExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _StringArg, changedStringArg := c.copyOnRewriteExpr(n.StringArg, n) + if changedStringArg { + changed := *n + changed.StringArg, _ = _StringArg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONRemoveExpr(n *JSONRemoveExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) + _PathList, changedPathList := c.copyOnRewriteExprs(n.PathList, n) + if changedJSONDoc || changedPathList { + changed := *n + changed.JSONDoc, _ = _JSONDoc.(Expr) + changed.PathList, _ = _PathList.(Exprs) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONSchemaValidFuncExpr(n *JSONSchemaValidFuncExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Schema, changedSchema := c.copyOnRewriteExpr(n.Schema, n) + _Document, changedDocument := c.copyOnRewriteExpr(n.Document, n) + if changedSchema || changedDocument { + changed := *n + changed.Schema, _ = _Schema.(Expr) + changed.Document, _ = _Document.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONSchemaValidationReportFuncExpr(n *JSONSchemaValidationReportFuncExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Schema, changedSchema := c.copyOnRewriteExpr(n.Schema, n) + _Document, changedDocument := c.copyOnRewriteExpr(n.Document, n) + if changedSchema || changedDocument { + changed := *n + changed.Schema, _ = _Schema.(Expr) + changed.Document, _ = _Document.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONSearchExpr(n *JSONSearchExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) + _OneOrAll, changedOneOrAll := c.copyOnRewriteExpr(n.OneOrAll, n) + _SearchStr, changedSearchStr := c.copyOnRewriteExpr(n.SearchStr, n) + _EscapeChar, changedEscapeChar := c.copyOnRewriteExpr(n.EscapeChar, n) + var changedPathList bool + _PathList := make([]Expr, len(n.PathList)) + for x, el := range n.PathList { + this, changed := c.copyOnRewriteExpr(el, n) + _PathList[x] = this.(Expr) + if changed { + changedPathList = true + } + } + if changedJSONDoc || changedOneOrAll || changedSearchStr || changedEscapeChar || changedPathList { + changed := *n + changed.JSONDoc, _ = _JSONDoc.(Expr) + changed.OneOrAll, _ = _OneOrAll.(Expr) + changed.SearchStr, _ = _SearchStr.(Expr) + changed.EscapeChar, _ = _EscapeChar.(Expr) + changed.PathList = _PathList + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONStorageFreeExpr(n *JSONStorageFreeExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONVal, changedJSONVal := c.copyOnRewriteExpr(n.JSONVal, n) + if changedJSONVal { + changed := *n + changed.JSONVal, _ = _JSONVal.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONStorageSizeExpr(n *JSONStorageSizeExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONVal, changedJSONVal := c.copyOnRewriteExpr(n.JSONVal, n) + if changedJSONVal { + changed := *n + changed.JSONVal, _ = _JSONVal.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONTableExpr(n *JSONTableExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _Alias, changedAlias := c.copyOnRewriteIdentifierCS(n.Alias, n) + _Filter, changedFilter := c.copyOnRewriteExpr(n.Filter, n) + var changedColumns bool + _Columns := make([]*JtColumnDefinition, len(n.Columns)) + for x, el := range n.Columns { + this, changed := c.copyOnRewriteRefOfJtColumnDefinition(el, n) + _Columns[x] = this.(*JtColumnDefinition) + if changed { + changedColumns = true + } + } + if changedExpr || changedAlias || changedFilter || changedColumns { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.Alias, _ = _Alias.(IdentifierCS) + changed.Filter, _ = _Filter.(Expr) + changed.Columns = _Columns + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONUnquoteExpr(n *JSONUnquoteExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONValue, changedJSONValue := c.copyOnRewriteExpr(n.JSONValue, n) + if changedJSONValue { + changed := *n + changed.JSONValue, _ = _JSONValue.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONValueExpr(n *JSONValueExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) + _Path, changedPath := c.copyOnRewriteExpr(n.Path, n) + _ReturningType, changedReturningType := c.copyOnRewriteRefOfConvertType(n.ReturningType, n) + _EmptyOnResponse, changedEmptyOnResponse := c.copyOnRewriteRefOfJtOnResponse(n.EmptyOnResponse, n) + _ErrorOnResponse, changedErrorOnResponse := c.copyOnRewriteRefOfJtOnResponse(n.ErrorOnResponse, n) + if changedJSONDoc || changedPath || changedReturningType || changedEmptyOnResponse || changedErrorOnResponse { + changed := *n + changed.JSONDoc, _ = _JSONDoc.(Expr) + changed.Path, _ = _Path.(Expr) + changed.ReturningType, _ = _ReturningType.(*ConvertType) + changed.EmptyOnResponse, _ = _EmptyOnResponse.(*JtOnResponse) + changed.ErrorOnResponse, _ = _ErrorOnResponse.(*JtOnResponse) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONValueMergeExpr(n *JSONValueMergeExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) + _JSONDocList, changedJSONDocList := c.copyOnRewriteExprs(n.JSONDocList, n) + if changedJSONDoc || changedJSONDocList { + changed := *n + changed.JSONDoc, _ = _JSONDoc.(Expr) + changed.JSONDocList, _ = _JSONDocList.(Exprs) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJSONValueModifierExpr(n *JSONValueModifierExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) + var changedParams bool + _Params := make([]*JSONObjectParam, len(n.Params)) + for x, el := range n.Params { + this, changed := c.copyOnRewriteRefOfJSONObjectParam(el, n) + _Params[x] = this.(*JSONObjectParam) + if changed { + changedParams = true + } + } + if changedJSONDoc || changedParams { + changed := *n + changed.JSONDoc, _ = _JSONDoc.(Expr) + changed.Params = _Params + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJoinCondition(n *JoinCondition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _On, changedOn := c.copyOnRewriteExpr(n.On, n) + _Using, changedUsing := c.copyOnRewriteColumns(n.Using, n) + if changedOn || changedUsing { + changed := *n + changed.On, _ = _On.(Expr) + changed.Using, _ = _Using.(Columns) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJoinTableExpr(n *JoinTableExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _LeftExpr, changedLeftExpr := c.copyOnRewriteTableExpr(n.LeftExpr, n) + _RightExpr, changedRightExpr := c.copyOnRewriteTableExpr(n.RightExpr, n) + _Condition, changedCondition := c.copyOnRewriteRefOfJoinCondition(n.Condition, n) + if changedLeftExpr || changedRightExpr || changedCondition { + changed := *n + changed.LeftExpr, _ = _LeftExpr.(TableExpr) + changed.RightExpr, _ = _RightExpr.(TableExpr) + changed.Condition, _ = _Condition.(*JoinCondition) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJtColumnDefinition(n *JtColumnDefinition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfJtOnResponse(n *JtOnResponse, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfKeyState(n *KeyState, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfLagLeadExpr(n *LagLeadExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _N, changedN := c.copyOnRewriteExpr(n.N, n) + _Default, changedDefault := c.copyOnRewriteExpr(n.Default, n) + _OverClause, changedOverClause := c.copyOnRewriteRefOfOverClause(n.OverClause, n) + _NullTreatmentClause, changedNullTreatmentClause := c.copyOnRewriteRefOfNullTreatmentClause(n.NullTreatmentClause, n) + if changedExpr || changedN || changedDefault || changedOverClause || changedNullTreatmentClause { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.N, _ = _N.(Expr) + changed.Default, _ = _Default.(Expr) + changed.OverClause, _ = _OverClause.(*OverClause) + changed.NullTreatmentClause, _ = _NullTreatmentClause.(*NullTreatmentClause) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfLimit(n *Limit, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Offset, changedOffset := c.copyOnRewriteExpr(n.Offset, n) + _Rowcount, changedRowcount := c.copyOnRewriteExpr(n.Rowcount, n) + if changedOffset || changedRowcount { + changed := *n + changed.Offset, _ = _Offset.(Expr) + changed.Rowcount, _ = _Rowcount.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfLiteral(n *Literal, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfLoad(n *Load, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfLocateExpr(n *LocateExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _SubStr, changedSubStr := c.copyOnRewriteExpr(n.SubStr, n) + _Str, changedStr := c.copyOnRewriteExpr(n.Str, n) + _Pos, changedPos := c.copyOnRewriteExpr(n.Pos, n) + if changedSubStr || changedStr || changedPos { + changed := *n + changed.SubStr, _ = _SubStr.(Expr) + changed.Str, _ = _Str.(Expr) + changed.Pos, _ = _Pos.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfLockOption(n *LockOption, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfLockTables(n *LockTables, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfLockingFunc(n *LockingFunc, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteExpr(n.Name, n) + _Timeout, changedTimeout := c.copyOnRewriteExpr(n.Timeout, n) + if changedName || changedTimeout { + changed := *n + changed.Name, _ = _Name.(Expr) + changed.Timeout, _ = _Timeout.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfMatchExpr(n *MatchExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + var changedColumns bool + _Columns := make([]*ColName, len(n.Columns)) + for x, el := range n.Columns { + this, changed := c.copyOnRewriteRefOfColName(el, n) + _Columns[x] = this.(*ColName) + if changed { + changedColumns = true + } + } + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedColumns || changedExpr { + changed := *n + changed.Columns = _Columns + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfMax(n *Max, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfMemberOfExpr(n *MemberOfExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Value, changedValue := c.copyOnRewriteExpr(n.Value, n) + _JSONArr, changedJSONArr := c.copyOnRewriteExpr(n.JSONArr, n) + if changedValue || changedJSONArr { + changed := *n + changed.Value, _ = _Value.(Expr) + changed.JSONArr, _ = _JSONArr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfMin(n *Min, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfModifyColumn(n *ModifyColumn, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _NewColDefinition, changedNewColDefinition := c.copyOnRewriteRefOfColumnDefinition(n.NewColDefinition, n) + _After, changedAfter := c.copyOnRewriteRefOfColName(n.After, n) + if changedNewColDefinition || changedAfter { + changed := *n + changed.NewColDefinition, _ = _NewColDefinition.(*ColumnDefinition) + changed.After, _ = _After.(*ColName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfNTHValueExpr(n *NTHValueExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _N, changedN := c.copyOnRewriteExpr(n.N, n) + _OverClause, changedOverClause := c.copyOnRewriteRefOfOverClause(n.OverClause, n) + _FromFirstLastClause, changedFromFirstLastClause := c.copyOnRewriteRefOfFromFirstLastClause(n.FromFirstLastClause, n) + _NullTreatmentClause, changedNullTreatmentClause := c.copyOnRewriteRefOfNullTreatmentClause(n.NullTreatmentClause, n) + if changedExpr || changedN || changedOverClause || changedFromFirstLastClause || changedNullTreatmentClause { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.N, _ = _N.(Expr) + changed.OverClause, _ = _OverClause.(*OverClause) + changed.FromFirstLastClause, _ = _FromFirstLastClause.(*FromFirstLastClause) + changed.NullTreatmentClause, _ = _NullTreatmentClause.(*NullTreatmentClause) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfNamedWindow(n *NamedWindow, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Windows, changedWindows := c.copyOnRewriteWindowDefinitions(n.Windows, n) + if changedWindows { + changed := *n + changed.Windows, _ = _Windows.(WindowDefinitions) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteNamedWindows(n NamedWindows, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(NamedWindows, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteRefOfNamedWindow(el, n) + res[x] = this.(*NamedWindow) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfNextval(n *Nextval, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfNotExpr(n *NotExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfNtileExpr(n *NtileExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _N, changedN := c.copyOnRewriteExpr(n.N, n) + _OverClause, changedOverClause := c.copyOnRewriteRefOfOverClause(n.OverClause, n) + if changedN || changedOverClause { + changed := *n + changed.N, _ = _N.(Expr) + changed.OverClause, _ = _OverClause.(*OverClause) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfNullTreatmentClause(n *NullTreatmentClause, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfNullVal(n *NullVal, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfOffset(n *Offset, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteOnDup(n OnDup, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(OnDup, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteRefOfUpdateExpr(el, n) + res[x] = this.(*UpdateExpr) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfOptLike(n *OptLike, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _LikeTable, changedLikeTable := c.copyOnRewriteTableName(n.LikeTable, n) + if changedLikeTable { + changed := *n + changed.LikeTable, _ = _LikeTable.(TableName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfOrExpr(n *OrExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Left, changedLeft := c.copyOnRewriteExpr(n.Left, n) + _Right, changedRight := c.copyOnRewriteExpr(n.Right, n) + if changedLeft || changedRight { + changed := *n + changed.Left, _ = _Left.(Expr) + changed.Right, _ = _Right.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfOrder(n *Order, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteOrderBy(n OrderBy, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(OrderBy, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteRefOfOrder(el, n) + res[x] = this.(*Order) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfOrderByOption(n *OrderByOption, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Cols, changedCols := c.copyOnRewriteColumns(n.Cols, n) + if changedCols { + changed := *n + changed.Cols, _ = _Cols.(Columns) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfOtherAdmin(n *OtherAdmin, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfOtherRead(n *OtherRead, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfOverClause(n *OverClause, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _WindowName, changedWindowName := c.copyOnRewriteIdentifierCI(n.WindowName, n) + _WindowSpec, changedWindowSpec := c.copyOnRewriteRefOfWindowSpecification(n.WindowSpec, n) + if changedWindowName || changedWindowSpec { + changed := *n + changed.WindowName, _ = _WindowName.(IdentifierCI) + changed.WindowSpec, _ = _WindowSpec.(*WindowSpecification) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfParenTableExpr(n *ParenTableExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Exprs, changedExprs := c.copyOnRewriteTableExprs(n.Exprs, n) + if changedExprs { + changed := *n + changed.Exprs, _ = _Exprs.(TableExprs) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfParsedComments(n *ParsedComments, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfPartitionDefinition(n *PartitionDefinition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + _Options, changedOptions := c.copyOnRewriteRefOfPartitionDefinitionOptions(n.Options, n) + if changedName || changedOptions { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + changed.Options, _ = _Options.(*PartitionDefinitionOptions) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfPartitionDefinitionOptions(n *PartitionDefinitionOptions, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _ValueRange, changedValueRange := c.copyOnRewriteRefOfPartitionValueRange(n.ValueRange, n) + _Comment, changedComment := c.copyOnRewriteRefOfLiteral(n.Comment, n) + _Engine, changedEngine := c.copyOnRewriteRefOfPartitionEngine(n.Engine, n) + _DataDirectory, changedDataDirectory := c.copyOnRewriteRefOfLiteral(n.DataDirectory, n) + _IndexDirectory, changedIndexDirectory := c.copyOnRewriteRefOfLiteral(n.IndexDirectory, n) + _SubPartitionDefinitions, changedSubPartitionDefinitions := c.copyOnRewriteSubPartitionDefinitions(n.SubPartitionDefinitions, n) + if changedValueRange || changedComment || changedEngine || changedDataDirectory || changedIndexDirectory || changedSubPartitionDefinitions { + changed := *n + changed.ValueRange, _ = _ValueRange.(*PartitionValueRange) + changed.Comment, _ = _Comment.(*Literal) + changed.Engine, _ = _Engine.(*PartitionEngine) + changed.DataDirectory, _ = _DataDirectory.(*Literal) + changed.IndexDirectory, _ = _IndexDirectory.(*Literal) + changed.SubPartitionDefinitions, _ = _SubPartitionDefinitions.(SubPartitionDefinitions) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfPartitionEngine(n *PartitionEngine, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfPartitionOption(n *PartitionOption, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _ColList, changedColList := c.copyOnRewriteColumns(n.ColList, n) + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _SubPartition, changedSubPartition := c.copyOnRewriteRefOfSubPartition(n.SubPartition, n) + var changedDefinitions bool + _Definitions := make([]*PartitionDefinition, len(n.Definitions)) + for x, el := range n.Definitions { + this, changed := c.copyOnRewriteRefOfPartitionDefinition(el, n) + _Definitions[x] = this.(*PartitionDefinition) + if changed { + changedDefinitions = true + } + } + if changedColList || changedExpr || changedSubPartition || changedDefinitions { + changed := *n + changed.ColList, _ = _ColList.(Columns) + changed.Expr, _ = _Expr.(Expr) + changed.SubPartition, _ = _SubPartition.(*SubPartition) + changed.Definitions = _Definitions + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfPartitionSpec(n *PartitionSpec, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Names, changedNames := c.copyOnRewritePartitions(n.Names, n) + _Number, changedNumber := c.copyOnRewriteRefOfLiteral(n.Number, n) + _TableName, changedTableName := c.copyOnRewriteTableName(n.TableName, n) + var changedDefinitions bool + _Definitions := make([]*PartitionDefinition, len(n.Definitions)) + for x, el := range n.Definitions { + this, changed := c.copyOnRewriteRefOfPartitionDefinition(el, n) + _Definitions[x] = this.(*PartitionDefinition) + if changed { + changedDefinitions = true + } + } + if changedNames || changedNumber || changedTableName || changedDefinitions { + changed := *n + changed.Names, _ = _Names.(Partitions) + changed.Number, _ = _Number.(*Literal) + changed.TableName, _ = _TableName.(TableName) + changed.Definitions = _Definitions + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfPartitionValueRange(n *PartitionValueRange, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Range, changedRange := c.copyOnRewriteValTuple(n.Range, n) + if changedRange { + changed := *n + changed.Range, _ = _Range.(ValTuple) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewritePartitions(n Partitions, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(Partitions, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteIdentifierCI(el, n) + res[x] = this.(IdentifierCI) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfPerformanceSchemaFuncExpr(n *PerformanceSchemaFuncExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Argument, changedArgument := c.copyOnRewriteExpr(n.Argument, n) + if changedArgument { + changed := *n + changed.Argument, _ = _Argument.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfPrepareStmt(n *PrepareStmt, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + _Statement, changedStatement := c.copyOnRewriteExpr(n.Statement, n) + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + if changedName || changedStatement || changedComments { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + changed.Statement, _ = _Statement.(Expr) + changed.Comments, _ = _Comments.(*ParsedComments) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfReferenceDefinition(n *ReferenceDefinition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _ReferencedTable, changedReferencedTable := c.copyOnRewriteTableName(n.ReferencedTable, n) + _ReferencedColumns, changedReferencedColumns := c.copyOnRewriteColumns(n.ReferencedColumns, n) + _Match, changedMatch := c.copyOnRewriteMatchAction(n.Match, n) + _OnDelete, changedOnDelete := c.copyOnRewriteReferenceAction(n.OnDelete, n) + _OnUpdate, changedOnUpdate := c.copyOnRewriteReferenceAction(n.OnUpdate, n) + if changedReferencedTable || changedReferencedColumns || changedMatch || changedOnDelete || changedOnUpdate { + changed := *n + changed.ReferencedTable, _ = _ReferencedTable.(TableName) + changed.ReferencedColumns, _ = _ReferencedColumns.(Columns) + changed.Match, _ = _Match.(MatchAction) + changed.OnDelete, _ = _OnDelete.(ReferenceAction) + changed.OnUpdate, _ = _OnUpdate.(ReferenceAction) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfRegexpInstrExpr(n *RegexpInstrExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _Pattern, changedPattern := c.copyOnRewriteExpr(n.Pattern, n) + _Position, changedPosition := c.copyOnRewriteExpr(n.Position, n) + _Occurrence, changedOccurrence := c.copyOnRewriteExpr(n.Occurrence, n) + _ReturnOption, changedReturnOption := c.copyOnRewriteExpr(n.ReturnOption, n) + _MatchType, changedMatchType := c.copyOnRewriteExpr(n.MatchType, n) + if changedExpr || changedPattern || changedPosition || changedOccurrence || changedReturnOption || changedMatchType { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.Pattern, _ = _Pattern.(Expr) + changed.Position, _ = _Position.(Expr) + changed.Occurrence, _ = _Occurrence.(Expr) + changed.ReturnOption, _ = _ReturnOption.(Expr) + changed.MatchType, _ = _MatchType.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfRegexpLikeExpr(n *RegexpLikeExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _Pattern, changedPattern := c.copyOnRewriteExpr(n.Pattern, n) + _MatchType, changedMatchType := c.copyOnRewriteExpr(n.MatchType, n) + if changedExpr || changedPattern || changedMatchType { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.Pattern, _ = _Pattern.(Expr) + changed.MatchType, _ = _MatchType.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfRegexpReplaceExpr(n *RegexpReplaceExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _Pattern, changedPattern := c.copyOnRewriteExpr(n.Pattern, n) + _Repl, changedRepl := c.copyOnRewriteExpr(n.Repl, n) + _Occurrence, changedOccurrence := c.copyOnRewriteExpr(n.Occurrence, n) + _Position, changedPosition := c.copyOnRewriteExpr(n.Position, n) + _MatchType, changedMatchType := c.copyOnRewriteExpr(n.MatchType, n) + if changedExpr || changedPattern || changedRepl || changedOccurrence || changedPosition || changedMatchType { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.Pattern, _ = _Pattern.(Expr) + changed.Repl, _ = _Repl.(Expr) + changed.Occurrence, _ = _Occurrence.(Expr) + changed.Position, _ = _Position.(Expr) + changed.MatchType, _ = _MatchType.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfRegexpSubstrExpr(n *RegexpSubstrExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _Pattern, changedPattern := c.copyOnRewriteExpr(n.Pattern, n) + _Occurrence, changedOccurrence := c.copyOnRewriteExpr(n.Occurrence, n) + _Position, changedPosition := c.copyOnRewriteExpr(n.Position, n) + _MatchType, changedMatchType := c.copyOnRewriteExpr(n.MatchType, n) + if changedExpr || changedPattern || changedOccurrence || changedPosition || changedMatchType { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.Pattern, _ = _Pattern.(Expr) + changed.Occurrence, _ = _Occurrence.(Expr) + changed.Position, _ = _Position.(Expr) + changed.MatchType, _ = _MatchType.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfRelease(n *Release, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + if changedName { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfRenameColumn(n *RenameColumn, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _OldName, changedOldName := c.copyOnRewriteRefOfColName(n.OldName, n) + _NewName, changedNewName := c.copyOnRewriteRefOfColName(n.NewName, n) + if changedOldName || changedNewName { + changed := *n + changed.OldName, _ = _OldName.(*ColName) + changed.NewName, _ = _NewName.(*ColName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfRenameIndex(n *RenameIndex, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _OldName, changedOldName := c.copyOnRewriteIdentifierCI(n.OldName, n) + _NewName, changedNewName := c.copyOnRewriteIdentifierCI(n.NewName, n) + if changedOldName || changedNewName { + changed := *n + changed.OldName, _ = _OldName.(IdentifierCI) + changed.NewName, _ = _NewName.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfRenameTable(n *RenameTable, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfRenameTableName(n *RenameTableName, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) + if changedTable { + changed := *n + changed.Table, _ = _Table.(TableName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfRevertMigration(n *RevertMigration, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + if changedComments { + changed := *n + changed.Comments, _ = _Comments.(*ParsedComments) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfRollback(n *Rollback, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRootNode(n RootNode, parent SQLNode) (out SQLNode, changed bool) { + out = n + if c.pre == nil || c.pre(n, parent) { + _SQLNode, changedSQLNode := c.copyOnRewriteSQLNode(n.SQLNode, n) + if changedSQLNode { + changed := n + changed.SQLNode, _ = _SQLNode.(SQLNode) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfSRollback(n *SRollback, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + if changedName { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfSavepoint(n *Savepoint, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + if changedName { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfSelect(n *Select, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + var changedFrom bool + _From := make([]TableExpr, len(n.From)) + for x, el := range n.From { + this, changed := c.copyOnRewriteTableExpr(el, n) + _From[x] = this.(TableExpr) + if changed { + changedFrom = true + } + } + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + _SelectExprs, changedSelectExprs := c.copyOnRewriteSelectExprs(n.SelectExprs, n) + _Where, changedWhere := c.copyOnRewriteRefOfWhere(n.Where, n) + _With, changedWith := c.copyOnRewriteRefOfWith(n.With, n) + _GroupBy, changedGroupBy := c.copyOnRewriteGroupBy(n.GroupBy, n) + _Having, changedHaving := c.copyOnRewriteRefOfWhere(n.Having, n) + _Windows, changedWindows := c.copyOnRewriteNamedWindows(n.Windows, n) + _OrderBy, changedOrderBy := c.copyOnRewriteOrderBy(n.OrderBy, n) + _Limit, changedLimit := c.copyOnRewriteRefOfLimit(n.Limit, n) + _Into, changedInto := c.copyOnRewriteRefOfSelectInto(n.Into, n) + if changedFrom || changedComments || changedSelectExprs || changedWhere || changedWith || changedGroupBy || changedHaving || changedWindows || changedOrderBy || changedLimit || changedInto { + changed := *n + changed.From = _From + changed.Comments, _ = _Comments.(*ParsedComments) + changed.SelectExprs, _ = _SelectExprs.(SelectExprs) + changed.Where, _ = _Where.(*Where) + changed.With, _ = _With.(*With) + changed.GroupBy, _ = _GroupBy.(GroupBy) + changed.Having, _ = _Having.(*Where) + changed.Windows, _ = _Windows.(NamedWindows) + changed.OrderBy, _ = _OrderBy.(OrderBy) + changed.Limit, _ = _Limit.(*Limit) + changed.Into, _ = _Into.(*SelectInto) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteSelectExprs(n SelectExprs, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(SelectExprs, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteSelectExpr(el, n) + res[x] = this.(SelectExpr) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfSelectInto(n *SelectInto, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfSet(n *Set, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + _Exprs, changedExprs := c.copyOnRewriteSetExprs(n.Exprs, n) + if changedComments || changedExprs { + changed := *n + changed.Comments, _ = _Comments.(*ParsedComments) + changed.Exprs, _ = _Exprs.(SetExprs) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfSetExpr(n *SetExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Var, changedVar := c.copyOnRewriteRefOfVariable(n.Var, n) + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedVar || changedExpr { + changed := *n + changed.Var, _ = _Var.(*Variable) + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteSetExprs(n SetExprs, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(SetExprs, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteRefOfSetExpr(el, n) + res[x] = this.(*SetExpr) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfShow(n *Show, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Internal, changedInternal := c.copyOnRewriteShowInternal(n.Internal, n) + if changedInternal { + changed := *n + changed.Internal, _ = _Internal.(ShowInternal) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfShowBasic(n *ShowBasic, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Tbl, changedTbl := c.copyOnRewriteTableName(n.Tbl, n) + _DbName, changedDbName := c.copyOnRewriteIdentifierCS(n.DbName, n) + _Filter, changedFilter := c.copyOnRewriteRefOfShowFilter(n.Filter, n) + if changedTbl || changedDbName || changedFilter { + changed := *n + changed.Tbl, _ = _Tbl.(TableName) + changed.DbName, _ = _DbName.(IdentifierCS) + changed.Filter, _ = _Filter.(*ShowFilter) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfShowCreate(n *ShowCreate, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Op, changedOp := c.copyOnRewriteTableName(n.Op, n) + if changedOp { + changed := *n + changed.Op, _ = _Op.(TableName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfShowFilter(n *ShowFilter, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Filter, changedFilter := c.copyOnRewriteExpr(n.Filter, n) + if changedFilter { + changed := *n + changed.Filter, _ = _Filter.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfShowMigrationLogs(n *ShowMigrationLogs, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + if changedComments { + changed := *n + changed.Comments, _ = _Comments.(*ParsedComments) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfShowOther(n *ShowOther, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfShowThrottledApps(n *ShowThrottledApps, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfShowThrottlerStatus(n *ShowThrottlerStatus, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfStarExpr(n *StarExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _TableName, changedTableName := c.copyOnRewriteTableName(n.TableName, n) + if changedTableName { + changed := *n + changed.TableName, _ = _TableName.(TableName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfStd(n *Std, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfStdDev(n *StdDev, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfStdPop(n *StdPop, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfStdSamp(n *StdSamp, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfStream(n *Stream, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + _SelectExpr, changedSelectExpr := c.copyOnRewriteSelectExpr(n.SelectExpr, n) + _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) + if changedComments || changedSelectExpr || changedTable { + changed := *n + changed.Comments, _ = _Comments.(*ParsedComments) + changed.SelectExpr, _ = _SelectExpr.(SelectExpr) + changed.Table, _ = _Table.(TableName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfSubPartition(n *SubPartition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _ColList, changedColList := c.copyOnRewriteColumns(n.ColList, n) + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedColList || changedExpr { + changed := *n + changed.ColList, _ = _ColList.(Columns) + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfSubPartitionDefinition(n *SubPartitionDefinition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + _Options, changedOptions := c.copyOnRewriteRefOfSubPartitionDefinitionOptions(n.Options, n) + if changedName || changedOptions { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + changed.Options, _ = _Options.(*SubPartitionDefinitionOptions) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfSubPartitionDefinitionOptions(n *SubPartitionDefinitionOptions, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Comment, changedComment := c.copyOnRewriteRefOfLiteral(n.Comment, n) + _Engine, changedEngine := c.copyOnRewriteRefOfPartitionEngine(n.Engine, n) + _DataDirectory, changedDataDirectory := c.copyOnRewriteRefOfLiteral(n.DataDirectory, n) + _IndexDirectory, changedIndexDirectory := c.copyOnRewriteRefOfLiteral(n.IndexDirectory, n) + if changedComment || changedEngine || changedDataDirectory || changedIndexDirectory { + changed := *n + changed.Comment, _ = _Comment.(*Literal) + changed.Engine, _ = _Engine.(*PartitionEngine) + changed.DataDirectory, _ = _DataDirectory.(*Literal) + changed.IndexDirectory, _ = _IndexDirectory.(*Literal) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteSubPartitionDefinitions(n SubPartitionDefinitions, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(SubPartitionDefinitions, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteRefOfSubPartitionDefinition(el, n) + res[x] = this.(*SubPartitionDefinition) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfSubquery(n *Subquery, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Select, changedSelect := c.copyOnRewriteSelectStatement(n.Select, n) + if changedSelect { + changed := *n + changed.Select, _ = _Select.(SelectStatement) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfSubstrExpr(n *SubstrExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteExpr(n.Name, n) + _From, changedFrom := c.copyOnRewriteExpr(n.From, n) + _To, changedTo := c.copyOnRewriteExpr(n.To, n) + if changedName || changedFrom || changedTo { + changed := *n + changed.Name, _ = _Name.(Expr) + changed.From, _ = _From.(Expr) + changed.To, _ = _To.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfSum(n *Sum, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteTableExprs(n TableExprs, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(TableExprs, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteTableExpr(el, n) + res[x] = this.(TableExpr) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteTableName(n TableName, parent SQLNode) (out SQLNode, changed bool) { + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCS(n.Name, n) + _Qualifier, changedQualifier := c.copyOnRewriteIdentifierCS(n.Qualifier, n) + if changedName || changedQualifier { + changed := n + changed.Name, _ = _Name.(IdentifierCS) + changed.Qualifier, _ = _Qualifier.(IdentifierCS) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteTableNames(n TableNames, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(TableNames, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteTableName(el, n) + res[x] = this.(TableName) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteTableOptions(n TableOptions, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre != nil { + c.pre(n, parent) + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfTableSpec(n *TableSpec, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + var changedColumns bool + _Columns := make([]*ColumnDefinition, len(n.Columns)) + for x, el := range n.Columns { + this, changed := c.copyOnRewriteRefOfColumnDefinition(el, n) + _Columns[x] = this.(*ColumnDefinition) + if changed { + changedColumns = true + } + } + var changedIndexes bool + _Indexes := make([]*IndexDefinition, len(n.Indexes)) + for x, el := range n.Indexes { + this, changed := c.copyOnRewriteRefOfIndexDefinition(el, n) + _Indexes[x] = this.(*IndexDefinition) + if changed { + changedIndexes = true + } + } + var changedConstraints bool + _Constraints := make([]*ConstraintDefinition, len(n.Constraints)) + for x, el := range n.Constraints { + this, changed := c.copyOnRewriteRefOfConstraintDefinition(el, n) + _Constraints[x] = this.(*ConstraintDefinition) + if changed { + changedConstraints = true + } + } + _Options, changedOptions := c.copyOnRewriteTableOptions(n.Options, n) + _PartitionOption, changedPartitionOption := c.copyOnRewriteRefOfPartitionOption(n.PartitionOption, n) + if changedColumns || changedIndexes || changedConstraints || changedOptions || changedPartitionOption { + changed := *n + changed.Columns = _Columns + changed.Indexes = _Indexes + changed.Constraints = _Constraints + changed.Options, _ = _Options.(TableOptions) + changed.PartitionOption, _ = _PartitionOption.(*PartitionOption) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfTablespaceOperation(n *TablespaceOperation, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfTimestampFuncExpr(n *TimestampFuncExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr1, changedExpr1 := c.copyOnRewriteExpr(n.Expr1, n) + _Expr2, changedExpr2 := c.copyOnRewriteExpr(n.Expr2, n) + if changedExpr1 || changedExpr2 { + changed := *n + changed.Expr1, _ = _Expr1.(Expr) + changed.Expr2, _ = _Expr2.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfTrimFuncExpr(n *TrimFuncExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _TrimArg, changedTrimArg := c.copyOnRewriteExpr(n.TrimArg, n) + _StringArg, changedStringArg := c.copyOnRewriteExpr(n.StringArg, n) + if changedTrimArg || changedStringArg { + changed := *n + changed.TrimArg, _ = _TrimArg.(Expr) + changed.StringArg, _ = _StringArg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfTruncateTable(n *TruncateTable, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) + if changedTable { + changed := *n + changed.Table, _ = _Table.(TableName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfUnaryExpr(n *UnaryExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfUnion(n *Union, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Left, changedLeft := c.copyOnRewriteSelectStatement(n.Left, n) + _Right, changedRight := c.copyOnRewriteSelectStatement(n.Right, n) + _OrderBy, changedOrderBy := c.copyOnRewriteOrderBy(n.OrderBy, n) + _With, changedWith := c.copyOnRewriteRefOfWith(n.With, n) + _Limit, changedLimit := c.copyOnRewriteRefOfLimit(n.Limit, n) + _Into, changedInto := c.copyOnRewriteRefOfSelectInto(n.Into, n) + if changedLeft || changedRight || changedOrderBy || changedWith || changedLimit || changedInto { + changed := *n + changed.Left, _ = _Left.(SelectStatement) + changed.Right, _ = _Right.(SelectStatement) + changed.OrderBy, _ = _OrderBy.(OrderBy) + changed.With, _ = _With.(*With) + changed.Limit, _ = _Limit.(*Limit) + changed.Into, _ = _Into.(*SelectInto) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfUnlockTables(n *UnlockTables, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfUpdate(n *Update, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _With, changedWith := c.copyOnRewriteRefOfWith(n.With, n) + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + _TableExprs, changedTableExprs := c.copyOnRewriteTableExprs(n.TableExprs, n) + _Exprs, changedExprs := c.copyOnRewriteUpdateExprs(n.Exprs, n) + _Where, changedWhere := c.copyOnRewriteRefOfWhere(n.Where, n) + _OrderBy, changedOrderBy := c.copyOnRewriteOrderBy(n.OrderBy, n) + _Limit, changedLimit := c.copyOnRewriteRefOfLimit(n.Limit, n) + if changedWith || changedComments || changedTableExprs || changedExprs || changedWhere || changedOrderBy || changedLimit { + changed := *n + changed.With, _ = _With.(*With) + changed.Comments, _ = _Comments.(*ParsedComments) + changed.TableExprs, _ = _TableExprs.(TableExprs) + changed.Exprs, _ = _Exprs.(UpdateExprs) + changed.Where, _ = _Where.(*Where) + changed.OrderBy, _ = _OrderBy.(OrderBy) + changed.Limit, _ = _Limit.(*Limit) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfUpdateExpr(n *UpdateExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteRefOfColName(n.Name, n) + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedName || changedExpr { + changed := *n + changed.Name, _ = _Name.(*ColName) + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteUpdateExprs(n UpdateExprs, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(UpdateExprs, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteRefOfUpdateExpr(el, n) + res[x] = this.(*UpdateExpr) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfUpdateXMLExpr(n *UpdateXMLExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Target, changedTarget := c.copyOnRewriteExpr(n.Target, n) + _XPathExpr, changedXPathExpr := c.copyOnRewriteExpr(n.XPathExpr, n) + _NewXML, changedNewXML := c.copyOnRewriteExpr(n.NewXML, n) + if changedTarget || changedXPathExpr || changedNewXML { + changed := *n + changed.Target, _ = _Target.(Expr) + changed.XPathExpr, _ = _XPathExpr.(Expr) + changed.NewXML, _ = _NewXML.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfUse(n *Use, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _DBName, changedDBName := c.copyOnRewriteIdentifierCS(n.DBName, n) + if changedDBName { + changed := *n + changed.DBName, _ = _DBName.(IdentifierCS) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfVExplainStmt(n *VExplainStmt, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Statement, changedStatement := c.copyOnRewriteStatement(n.Statement, n) + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + if changedStatement || changedComments { + changed := *n + changed.Statement, _ = _Statement.(Statement) + changed.Comments, _ = _Comments.(*ParsedComments) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfVStream(n *VStream, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) + _SelectExpr, changedSelectExpr := c.copyOnRewriteSelectExpr(n.SelectExpr, n) + _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) + _Where, changedWhere := c.copyOnRewriteRefOfWhere(n.Where, n) + _Limit, changedLimit := c.copyOnRewriteRefOfLimit(n.Limit, n) + if changedComments || changedSelectExpr || changedTable || changedWhere || changedLimit { + changed := *n + changed.Comments, _ = _Comments.(*ParsedComments) + changed.SelectExpr, _ = _SelectExpr.(SelectExpr) + changed.Table, _ = _Table.(TableName) + changed.Where, _ = _Where.(*Where) + changed.Limit, _ = _Limit.(*Limit) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteValTuple(n ValTuple, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(ValTuple, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteExpr(el, n) + res[x] = this.(Expr) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfValidation(n *Validation, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteValues(n Values, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(Values, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteValTuple(el, n) + res[x] = this.(ValTuple) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfValuesFuncExpr(n *ValuesFuncExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteRefOfColName(n.Name, n) + if changedName { + changed := *n + changed.Name, _ = _Name.(*ColName) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfVarPop(n *VarPop, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfVarSamp(n *VarSamp, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfVariable(n *Variable, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + if changedName { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfVariance(n *Variance, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) + if changedArg { + changed := *n + changed.Arg, _ = _Arg.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteVindexParam(n VindexParam, parent SQLNode) (out SQLNode, changed bool) { + out = n + if c.pre == nil || c.pre(n, parent) { + _Key, changedKey := c.copyOnRewriteIdentifierCI(n.Key, n) + if changedKey { + changed := n + changed.Key, _ = _Key.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfVindexSpec(n *VindexSpec, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + _Type, changedType := c.copyOnRewriteIdentifierCI(n.Type, n) + var changedParams bool + _Params := make([]VindexParam, len(n.Params)) + for x, el := range n.Params { + this, changed := c.copyOnRewriteVindexParam(el, n) + _Params[x] = this.(VindexParam) + if changed { + changedParams = true + } + } + if changedName || changedType || changedParams { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + changed.Type, _ = _Type.(IdentifierCI) + changed.Params = _Params + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfWeightStringFuncExpr(n *WeightStringFuncExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + _As, changedAs := c.copyOnRewriteRefOfConvertType(n.As, n) + if changedExpr || changedAs { + changed := *n + changed.Expr, _ = _Expr.(Expr) + changed.As, _ = _As.(*ConvertType) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfWhen(n *When, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Cond, changedCond := c.copyOnRewriteExpr(n.Cond, n) + _Val, changedVal := c.copyOnRewriteExpr(n.Val, n) + if changedCond || changedVal { + changed := *n + changed.Cond, _ = _Cond.(Expr) + changed.Val, _ = _Val.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfWhere(n *Where, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) + if changedExpr { + changed := *n + changed.Expr, _ = _Expr.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfWindowDefinition(n *WindowDefinition, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + _WindowSpec, changedWindowSpec := c.copyOnRewriteRefOfWindowSpecification(n.WindowSpec, n) + if changedName || changedWindowSpec { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + changed.WindowSpec, _ = _WindowSpec.(*WindowSpecification) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteWindowDefinitions(n WindowDefinitions, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(WindowDefinitions, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteRefOfWindowDefinition(el, n) + res[x] = this.(*WindowDefinition) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfWindowSpecification(n *WindowSpecification, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) + _PartitionClause, changedPartitionClause := c.copyOnRewriteExprs(n.PartitionClause, n) + _OrderClause, changedOrderClause := c.copyOnRewriteOrderBy(n.OrderClause, n) + _FrameClause, changedFrameClause := c.copyOnRewriteRefOfFrameClause(n.FrameClause, n) + if changedName || changedPartitionClause || changedOrderClause || changedFrameClause { + changed := *n + changed.Name, _ = _Name.(IdentifierCI) + changed.PartitionClause, _ = _PartitionClause.(Exprs) + changed.OrderClause, _ = _OrderClause.(OrderBy) + changed.FrameClause, _ = _FrameClause.(*FrameClause) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfWith(n *With, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + var changedctes bool + _ctes := make([]*CommonTableExpr, len(n.ctes)) + for x, el := range n.ctes { + this, changed := c.copyOnRewriteRefOfCommonTableExpr(el, n) + _ctes[x] = this.(*CommonTableExpr) + if changed { + changedctes = true + } + } + if changedctes { + changed := *n + changed.ctes = _ctes + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfXorExpr(n *XorExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Left, changedLeft := c.copyOnRewriteExpr(n.Left, n) + _Right, changedRight := c.copyOnRewriteExpr(n.Right, n) + if changedLeft || changedRight { + changed := *n + changed.Left, _ = _Left.(Expr) + changed.Right, _ = _Right.(Expr) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteAggrFunc(n AggrFunc, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *Avg: + return c.copyOnRewriteRefOfAvg(n, parent) + case *BitAnd: + return c.copyOnRewriteRefOfBitAnd(n, parent) + case *BitOr: + return c.copyOnRewriteRefOfBitOr(n, parent) + case *BitXor: + return c.copyOnRewriteRefOfBitXor(n, parent) + case *Count: + return c.copyOnRewriteRefOfCount(n, parent) + case *CountStar: + return c.copyOnRewriteRefOfCountStar(n, parent) + case *GroupConcatExpr: + return c.copyOnRewriteRefOfGroupConcatExpr(n, parent) + case *Max: + return c.copyOnRewriteRefOfMax(n, parent) + case *Min: + return c.copyOnRewriteRefOfMin(n, parent) + case *Std: + return c.copyOnRewriteRefOfStd(n, parent) + case *StdDev: + return c.copyOnRewriteRefOfStdDev(n, parent) + case *StdPop: + return c.copyOnRewriteRefOfStdPop(n, parent) + case *StdSamp: + return c.copyOnRewriteRefOfStdSamp(n, parent) + case *Sum: + return c.copyOnRewriteRefOfSum(n, parent) + case *VarPop: + return c.copyOnRewriteRefOfVarPop(n, parent) + case *VarSamp: + return c.copyOnRewriteRefOfVarSamp(n, parent) + case *Variance: + return c.copyOnRewriteRefOfVariance(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteAlterOption(n AlterOption, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *AddColumns: + return c.copyOnRewriteRefOfAddColumns(n, parent) + case *AddConstraintDefinition: + return c.copyOnRewriteRefOfAddConstraintDefinition(n, parent) + case *AddIndexDefinition: + return c.copyOnRewriteRefOfAddIndexDefinition(n, parent) + case AlgorithmValue: + return c.copyOnRewriteAlgorithmValue(n, parent) + case *AlterCharset: + return c.copyOnRewriteRefOfAlterCharset(n, parent) + case *AlterCheck: + return c.copyOnRewriteRefOfAlterCheck(n, parent) + case *AlterColumn: + return c.copyOnRewriteRefOfAlterColumn(n, parent) + case *AlterIndex: + return c.copyOnRewriteRefOfAlterIndex(n, parent) + case *ChangeColumn: + return c.copyOnRewriteRefOfChangeColumn(n, parent) + case *DropColumn: + return c.copyOnRewriteRefOfDropColumn(n, parent) + case *DropKey: + return c.copyOnRewriteRefOfDropKey(n, parent) + case *Force: + return c.copyOnRewriteRefOfForce(n, parent) + case *KeyState: + return c.copyOnRewriteRefOfKeyState(n, parent) + case *LockOption: + return c.copyOnRewriteRefOfLockOption(n, parent) + case *ModifyColumn: + return c.copyOnRewriteRefOfModifyColumn(n, parent) + case *OrderByOption: + return c.copyOnRewriteRefOfOrderByOption(n, parent) + case *RenameColumn: + return c.copyOnRewriteRefOfRenameColumn(n, parent) + case *RenameIndex: + return c.copyOnRewriteRefOfRenameIndex(n, parent) + case *RenameTableName: + return c.copyOnRewriteRefOfRenameTableName(n, parent) + case TableOptions: + return c.copyOnRewriteTableOptions(n, parent) + case *TablespaceOperation: + return c.copyOnRewriteRefOfTablespaceOperation(n, parent) + case *Validation: + return c.copyOnRewriteRefOfValidation(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteCallable(n Callable, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *ArgumentLessWindowExpr: + return c.copyOnRewriteRefOfArgumentLessWindowExpr(n, parent) + case *Avg: + return c.copyOnRewriteRefOfAvg(n, parent) + case *CharExpr: + return c.copyOnRewriteRefOfCharExpr(n, parent) + case *ConvertExpr: + return c.copyOnRewriteRefOfConvertExpr(n, parent) + case *ConvertUsingExpr: + return c.copyOnRewriteRefOfConvertUsingExpr(n, parent) + case *Count: + return c.copyOnRewriteRefOfCount(n, parent) + case *CountStar: + return c.copyOnRewriteRefOfCountStar(n, parent) + case *CurTimeFuncExpr: + return c.copyOnRewriteRefOfCurTimeFuncExpr(n, parent) + case *ExtractFuncExpr: + return c.copyOnRewriteRefOfExtractFuncExpr(n, parent) + case *ExtractValueExpr: + return c.copyOnRewriteRefOfExtractValueExpr(n, parent) + case *FirstOrLastValueExpr: + return c.copyOnRewriteRefOfFirstOrLastValueExpr(n, parent) + case *FuncExpr: + return c.copyOnRewriteRefOfFuncExpr(n, parent) + case *GTIDFuncExpr: + return c.copyOnRewriteRefOfGTIDFuncExpr(n, parent) + case *GroupConcatExpr: + return c.copyOnRewriteRefOfGroupConcatExpr(n, parent) + case *InsertExpr: + return c.copyOnRewriteRefOfInsertExpr(n, parent) + case *IntervalFuncExpr: + return c.copyOnRewriteRefOfIntervalFuncExpr(n, parent) + case *JSONArrayExpr: + return c.copyOnRewriteRefOfJSONArrayExpr(n, parent) + case *JSONAttributesExpr: + return c.copyOnRewriteRefOfJSONAttributesExpr(n, parent) + case *JSONContainsExpr: + return c.copyOnRewriteRefOfJSONContainsExpr(n, parent) + case *JSONContainsPathExpr: + return c.copyOnRewriteRefOfJSONContainsPathExpr(n, parent) + case *JSONExtractExpr: + return c.copyOnRewriteRefOfJSONExtractExpr(n, parent) + case *JSONKeysExpr: + return c.copyOnRewriteRefOfJSONKeysExpr(n, parent) + case *JSONObjectExpr: + return c.copyOnRewriteRefOfJSONObjectExpr(n, parent) + case *JSONOverlapsExpr: + return c.copyOnRewriteRefOfJSONOverlapsExpr(n, parent) + case *JSONPrettyExpr: + return c.copyOnRewriteRefOfJSONPrettyExpr(n, parent) + case *JSONQuoteExpr: + return c.copyOnRewriteRefOfJSONQuoteExpr(n, parent) + case *JSONRemoveExpr: + return c.copyOnRewriteRefOfJSONRemoveExpr(n, parent) + case *JSONSchemaValidFuncExpr: + return c.copyOnRewriteRefOfJSONSchemaValidFuncExpr(n, parent) + case *JSONSchemaValidationReportFuncExpr: + return c.copyOnRewriteRefOfJSONSchemaValidationReportFuncExpr(n, parent) + case *JSONSearchExpr: + return c.copyOnRewriteRefOfJSONSearchExpr(n, parent) + case *JSONStorageFreeExpr: + return c.copyOnRewriteRefOfJSONStorageFreeExpr(n, parent) + case *JSONStorageSizeExpr: + return c.copyOnRewriteRefOfJSONStorageSizeExpr(n, parent) + case *JSONUnquoteExpr: + return c.copyOnRewriteRefOfJSONUnquoteExpr(n, parent) + case *JSONValueExpr: + return c.copyOnRewriteRefOfJSONValueExpr(n, parent) + case *JSONValueMergeExpr: + return c.copyOnRewriteRefOfJSONValueMergeExpr(n, parent) + case *JSONValueModifierExpr: + return c.copyOnRewriteRefOfJSONValueModifierExpr(n, parent) + case *LagLeadExpr: + return c.copyOnRewriteRefOfLagLeadExpr(n, parent) + case *LocateExpr: + return c.copyOnRewriteRefOfLocateExpr(n, parent) + case *MatchExpr: + return c.copyOnRewriteRefOfMatchExpr(n, parent) + case *Max: + return c.copyOnRewriteRefOfMax(n, parent) + case *MemberOfExpr: + return c.copyOnRewriteRefOfMemberOfExpr(n, parent) + case *Min: + return c.copyOnRewriteRefOfMin(n, parent) + case *NTHValueExpr: + return c.copyOnRewriteRefOfNTHValueExpr(n, parent) + case *NamedWindow: + return c.copyOnRewriteRefOfNamedWindow(n, parent) + case *NtileExpr: + return c.copyOnRewriteRefOfNtileExpr(n, parent) + case *PerformanceSchemaFuncExpr: + return c.copyOnRewriteRefOfPerformanceSchemaFuncExpr(n, parent) + case *RegexpInstrExpr: + return c.copyOnRewriteRefOfRegexpInstrExpr(n, parent) + case *RegexpLikeExpr: + return c.copyOnRewriteRefOfRegexpLikeExpr(n, parent) + case *RegexpReplaceExpr: + return c.copyOnRewriteRefOfRegexpReplaceExpr(n, parent) + case *RegexpSubstrExpr: + return c.copyOnRewriteRefOfRegexpSubstrExpr(n, parent) + case *SubstrExpr: + return c.copyOnRewriteRefOfSubstrExpr(n, parent) + case *Sum: + return c.copyOnRewriteRefOfSum(n, parent) + case *TimestampFuncExpr: + return c.copyOnRewriteRefOfTimestampFuncExpr(n, parent) + case *TrimFuncExpr: + return c.copyOnRewriteRefOfTrimFuncExpr(n, parent) + case *UpdateXMLExpr: + return c.copyOnRewriteRefOfUpdateXMLExpr(n, parent) + case *ValuesFuncExpr: + return c.copyOnRewriteRefOfValuesFuncExpr(n, parent) + case *WeightStringFuncExpr: + return c.copyOnRewriteRefOfWeightStringFuncExpr(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteColTuple(n ColTuple, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case ListArg: + return c.copyOnRewriteListArg(n, parent) + case *Subquery: + return c.copyOnRewriteRefOfSubquery(n, parent) + case ValTuple: + return c.copyOnRewriteValTuple(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteConstraintInfo(n ConstraintInfo, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *CheckConstraintDefinition: + return c.copyOnRewriteRefOfCheckConstraintDefinition(n, parent) + case *ForeignKeyDefinition: + return c.copyOnRewriteRefOfForeignKeyDefinition(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteDBDDLStatement(n DBDDLStatement, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *AlterDatabase: + return c.copyOnRewriteRefOfAlterDatabase(n, parent) + case *CreateDatabase: + return c.copyOnRewriteRefOfCreateDatabase(n, parent) + case *DropDatabase: + return c.copyOnRewriteRefOfDropDatabase(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteDDLStatement(n DDLStatement, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *AlterTable: + return c.copyOnRewriteRefOfAlterTable(n, parent) + case *AlterView: + return c.copyOnRewriteRefOfAlterView(n, parent) + case *CreateTable: + return c.copyOnRewriteRefOfCreateTable(n, parent) + case *CreateView: + return c.copyOnRewriteRefOfCreateView(n, parent) + case *DropTable: + return c.copyOnRewriteRefOfDropTable(n, parent) + case *DropView: + return c.copyOnRewriteRefOfDropView(n, parent) + case *RenameTable: + return c.copyOnRewriteRefOfRenameTable(n, parent) + case *TruncateTable: + return c.copyOnRewriteRefOfTruncateTable(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteExplain(n Explain, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *ExplainStmt: + return c.copyOnRewriteRefOfExplainStmt(n, parent) + case *ExplainTab: + return c.copyOnRewriteRefOfExplainTab(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteExpr(n Expr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *AndExpr: + return c.copyOnRewriteRefOfAndExpr(n, parent) + case Argument: + return c.copyOnRewriteArgument(n, parent) + case *ArgumentLessWindowExpr: + return c.copyOnRewriteRefOfArgumentLessWindowExpr(n, parent) + case *Avg: + return c.copyOnRewriteRefOfAvg(n, parent) + case *BetweenExpr: + return c.copyOnRewriteRefOfBetweenExpr(n, parent) + case *BinaryExpr: + return c.copyOnRewriteRefOfBinaryExpr(n, parent) + case *BitAnd: + return c.copyOnRewriteRefOfBitAnd(n, parent) + case *BitOr: + return c.copyOnRewriteRefOfBitOr(n, parent) + case *BitXor: + return c.copyOnRewriteRefOfBitXor(n, parent) + case BoolVal: + return c.copyOnRewriteBoolVal(n, parent) + case *CaseExpr: + return c.copyOnRewriteRefOfCaseExpr(n, parent) + case *CastExpr: + return c.copyOnRewriteRefOfCastExpr(n, parent) + case *CharExpr: + return c.copyOnRewriteRefOfCharExpr(n, parent) + case *ColName: + return c.copyOnRewriteRefOfColName(n, parent) + case *CollateExpr: + return c.copyOnRewriteRefOfCollateExpr(n, parent) + case *ComparisonExpr: + return c.copyOnRewriteRefOfComparisonExpr(n, parent) + case *ConvertExpr: + return c.copyOnRewriteRefOfConvertExpr(n, parent) + case *ConvertUsingExpr: + return c.copyOnRewriteRefOfConvertUsingExpr(n, parent) + case *Count: + return c.copyOnRewriteRefOfCount(n, parent) + case *CountStar: + return c.copyOnRewriteRefOfCountStar(n, parent) + case *CurTimeFuncExpr: + return c.copyOnRewriteRefOfCurTimeFuncExpr(n, parent) + case *Default: + return c.copyOnRewriteRefOfDefault(n, parent) + case *ExistsExpr: + return c.copyOnRewriteRefOfExistsExpr(n, parent) + case *ExtractFuncExpr: + return c.copyOnRewriteRefOfExtractFuncExpr(n, parent) + case *ExtractValueExpr: + return c.copyOnRewriteRefOfExtractValueExpr(n, parent) + case *ExtractedSubquery: + return c.copyOnRewriteRefOfExtractedSubquery(n, parent) + case *FirstOrLastValueExpr: + return c.copyOnRewriteRefOfFirstOrLastValueExpr(n, parent) + case *FuncExpr: + return c.copyOnRewriteRefOfFuncExpr(n, parent) + case *GTIDFuncExpr: + return c.copyOnRewriteRefOfGTIDFuncExpr(n, parent) + case *GroupConcatExpr: + return c.copyOnRewriteRefOfGroupConcatExpr(n, parent) + case *InsertExpr: + return c.copyOnRewriteRefOfInsertExpr(n, parent) + case *IntervalExpr: + return c.copyOnRewriteRefOfIntervalExpr(n, parent) + case *IntervalFuncExpr: + return c.copyOnRewriteRefOfIntervalFuncExpr(n, parent) + case *IntroducerExpr: + return c.copyOnRewriteRefOfIntroducerExpr(n, parent) + case *IsExpr: + return c.copyOnRewriteRefOfIsExpr(n, parent) + case *JSONArrayExpr: + return c.copyOnRewriteRefOfJSONArrayExpr(n, parent) + case *JSONAttributesExpr: + return c.copyOnRewriteRefOfJSONAttributesExpr(n, parent) + case *JSONContainsExpr: + return c.copyOnRewriteRefOfJSONContainsExpr(n, parent) + case *JSONContainsPathExpr: + return c.copyOnRewriteRefOfJSONContainsPathExpr(n, parent) + case *JSONExtractExpr: + return c.copyOnRewriteRefOfJSONExtractExpr(n, parent) + case *JSONKeysExpr: + return c.copyOnRewriteRefOfJSONKeysExpr(n, parent) + case *JSONObjectExpr: + return c.copyOnRewriteRefOfJSONObjectExpr(n, parent) + case *JSONOverlapsExpr: + return c.copyOnRewriteRefOfJSONOverlapsExpr(n, parent) + case *JSONPrettyExpr: + return c.copyOnRewriteRefOfJSONPrettyExpr(n, parent) + case *JSONQuoteExpr: + return c.copyOnRewriteRefOfJSONQuoteExpr(n, parent) + case *JSONRemoveExpr: + return c.copyOnRewriteRefOfJSONRemoveExpr(n, parent) + case *JSONSchemaValidFuncExpr: + return c.copyOnRewriteRefOfJSONSchemaValidFuncExpr(n, parent) + case *JSONSchemaValidationReportFuncExpr: + return c.copyOnRewriteRefOfJSONSchemaValidationReportFuncExpr(n, parent) + case *JSONSearchExpr: + return c.copyOnRewriteRefOfJSONSearchExpr(n, parent) + case *JSONStorageFreeExpr: + return c.copyOnRewriteRefOfJSONStorageFreeExpr(n, parent) + case *JSONStorageSizeExpr: + return c.copyOnRewriteRefOfJSONStorageSizeExpr(n, parent) + case *JSONUnquoteExpr: + return c.copyOnRewriteRefOfJSONUnquoteExpr(n, parent) + case *JSONValueExpr: + return c.copyOnRewriteRefOfJSONValueExpr(n, parent) + case *JSONValueMergeExpr: + return c.copyOnRewriteRefOfJSONValueMergeExpr(n, parent) + case *JSONValueModifierExpr: + return c.copyOnRewriteRefOfJSONValueModifierExpr(n, parent) + case *LagLeadExpr: + return c.copyOnRewriteRefOfLagLeadExpr(n, parent) + case ListArg: + return c.copyOnRewriteListArg(n, parent) + case *Literal: + return c.copyOnRewriteRefOfLiteral(n, parent) + case *LocateExpr: + return c.copyOnRewriteRefOfLocateExpr(n, parent) + case *LockingFunc: + return c.copyOnRewriteRefOfLockingFunc(n, parent) + case *MatchExpr: + return c.copyOnRewriteRefOfMatchExpr(n, parent) + case *Max: + return c.copyOnRewriteRefOfMax(n, parent) + case *MemberOfExpr: + return c.copyOnRewriteRefOfMemberOfExpr(n, parent) + case *Min: + return c.copyOnRewriteRefOfMin(n, parent) + case *NTHValueExpr: + return c.copyOnRewriteRefOfNTHValueExpr(n, parent) + case *NamedWindow: + return c.copyOnRewriteRefOfNamedWindow(n, parent) + case *NotExpr: + return c.copyOnRewriteRefOfNotExpr(n, parent) + case *NtileExpr: + return c.copyOnRewriteRefOfNtileExpr(n, parent) + case *NullVal: + return c.copyOnRewriteRefOfNullVal(n, parent) + case *Offset: + return c.copyOnRewriteRefOfOffset(n, parent) + case *OrExpr: + return c.copyOnRewriteRefOfOrExpr(n, parent) + case *PerformanceSchemaFuncExpr: + return c.copyOnRewriteRefOfPerformanceSchemaFuncExpr(n, parent) + case *RegexpInstrExpr: + return c.copyOnRewriteRefOfRegexpInstrExpr(n, parent) + case *RegexpLikeExpr: + return c.copyOnRewriteRefOfRegexpLikeExpr(n, parent) + case *RegexpReplaceExpr: + return c.copyOnRewriteRefOfRegexpReplaceExpr(n, parent) + case *RegexpSubstrExpr: + return c.copyOnRewriteRefOfRegexpSubstrExpr(n, parent) + case *Std: + return c.copyOnRewriteRefOfStd(n, parent) + case *StdDev: + return c.copyOnRewriteRefOfStdDev(n, parent) + case *StdPop: + return c.copyOnRewriteRefOfStdPop(n, parent) + case *StdSamp: + return c.copyOnRewriteRefOfStdSamp(n, parent) + case *Subquery: + return c.copyOnRewriteRefOfSubquery(n, parent) + case *SubstrExpr: + return c.copyOnRewriteRefOfSubstrExpr(n, parent) + case *Sum: + return c.copyOnRewriteRefOfSum(n, parent) + case *TimestampFuncExpr: + return c.copyOnRewriteRefOfTimestampFuncExpr(n, parent) + case *TrimFuncExpr: + return c.copyOnRewriteRefOfTrimFuncExpr(n, parent) + case *UnaryExpr: + return c.copyOnRewriteRefOfUnaryExpr(n, parent) + case *UpdateXMLExpr: + return c.copyOnRewriteRefOfUpdateXMLExpr(n, parent) + case ValTuple: + return c.copyOnRewriteValTuple(n, parent) + case *ValuesFuncExpr: + return c.copyOnRewriteRefOfValuesFuncExpr(n, parent) + case *VarPop: + return c.copyOnRewriteRefOfVarPop(n, parent) + case *VarSamp: + return c.copyOnRewriteRefOfVarSamp(n, parent) + case *Variable: + return c.copyOnRewriteRefOfVariable(n, parent) + case *Variance: + return c.copyOnRewriteRefOfVariance(n, parent) + case *WeightStringFuncExpr: + return c.copyOnRewriteRefOfWeightStringFuncExpr(n, parent) + case *XorExpr: + return c.copyOnRewriteRefOfXorExpr(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteInsertRows(n InsertRows, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *Select: + return c.copyOnRewriteRefOfSelect(n, parent) + case *Union: + return c.copyOnRewriteRefOfUnion(n, parent) + case Values: + return c.copyOnRewriteValues(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteSelectExpr(n SelectExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *AliasedExpr: + return c.copyOnRewriteRefOfAliasedExpr(n, parent) + case *Nextval: + return c.copyOnRewriteRefOfNextval(n, parent) + case *StarExpr: + return c.copyOnRewriteRefOfStarExpr(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteSelectStatement(n SelectStatement, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *Select: + return c.copyOnRewriteRefOfSelect(n, parent) + case *Union: + return c.copyOnRewriteRefOfUnion(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteShowInternal(n ShowInternal, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *ShowBasic: + return c.copyOnRewriteRefOfShowBasic(n, parent) + case *ShowCreate: + return c.copyOnRewriteRefOfShowCreate(n, parent) + case *ShowOther: + return c.copyOnRewriteRefOfShowOther(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteSimpleTableExpr(n SimpleTableExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *DerivedTable: + return c.copyOnRewriteRefOfDerivedTable(n, parent) + case TableName: + return c.copyOnRewriteTableName(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteStatement(n Statement, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *AlterDatabase: + return c.copyOnRewriteRefOfAlterDatabase(n, parent) + case *AlterMigration: + return c.copyOnRewriteRefOfAlterMigration(n, parent) + case *AlterTable: + return c.copyOnRewriteRefOfAlterTable(n, parent) + case *AlterView: + return c.copyOnRewriteRefOfAlterView(n, parent) + case *AlterVschema: + return c.copyOnRewriteRefOfAlterVschema(n, parent) + case *Begin: + return c.copyOnRewriteRefOfBegin(n, parent) + case *CallProc: + return c.copyOnRewriteRefOfCallProc(n, parent) + case *CommentOnly: + return c.copyOnRewriteRefOfCommentOnly(n, parent) + case *Commit: + return c.copyOnRewriteRefOfCommit(n, parent) + case *CreateDatabase: + return c.copyOnRewriteRefOfCreateDatabase(n, parent) + case *CreateTable: + return c.copyOnRewriteRefOfCreateTable(n, parent) + case *CreateView: + return c.copyOnRewriteRefOfCreateView(n, parent) + case *DeallocateStmt: + return c.copyOnRewriteRefOfDeallocateStmt(n, parent) + case *Delete: + return c.copyOnRewriteRefOfDelete(n, parent) + case *DropDatabase: + return c.copyOnRewriteRefOfDropDatabase(n, parent) + case *DropTable: + return c.copyOnRewriteRefOfDropTable(n, parent) + case *DropView: + return c.copyOnRewriteRefOfDropView(n, parent) + case *ExecuteStmt: + return c.copyOnRewriteRefOfExecuteStmt(n, parent) + case *ExplainStmt: + return c.copyOnRewriteRefOfExplainStmt(n, parent) + case *ExplainTab: + return c.copyOnRewriteRefOfExplainTab(n, parent) + case *Flush: + return c.copyOnRewriteRefOfFlush(n, parent) + case *Insert: + return c.copyOnRewriteRefOfInsert(n, parent) + case *Load: + return c.copyOnRewriteRefOfLoad(n, parent) + case *LockTables: + return c.copyOnRewriteRefOfLockTables(n, parent) + case *OtherAdmin: + return c.copyOnRewriteRefOfOtherAdmin(n, parent) + case *OtherRead: + return c.copyOnRewriteRefOfOtherRead(n, parent) + case *PrepareStmt: + return c.copyOnRewriteRefOfPrepareStmt(n, parent) + case *Release: + return c.copyOnRewriteRefOfRelease(n, parent) + case *RenameTable: + return c.copyOnRewriteRefOfRenameTable(n, parent) + case *RevertMigration: + return c.copyOnRewriteRefOfRevertMigration(n, parent) + case *Rollback: + return c.copyOnRewriteRefOfRollback(n, parent) + case *SRollback: + return c.copyOnRewriteRefOfSRollback(n, parent) + case *Savepoint: + return c.copyOnRewriteRefOfSavepoint(n, parent) + case *Select: + return c.copyOnRewriteRefOfSelect(n, parent) + case *Set: + return c.copyOnRewriteRefOfSet(n, parent) + case *Show: + return c.copyOnRewriteRefOfShow(n, parent) + case *ShowMigrationLogs: + return c.copyOnRewriteRefOfShowMigrationLogs(n, parent) + case *ShowThrottledApps: + return c.copyOnRewriteRefOfShowThrottledApps(n, parent) + case *ShowThrottlerStatus: + return c.copyOnRewriteRefOfShowThrottlerStatus(n, parent) + case *Stream: + return c.copyOnRewriteRefOfStream(n, parent) + case *TruncateTable: + return c.copyOnRewriteRefOfTruncateTable(n, parent) + case *Union: + return c.copyOnRewriteRefOfUnion(n, parent) + case *UnlockTables: + return c.copyOnRewriteRefOfUnlockTables(n, parent) + case *Update: + return c.copyOnRewriteRefOfUpdate(n, parent) + case *Use: + return c.copyOnRewriteRefOfUse(n, parent) + case *VExplainStmt: + return c.copyOnRewriteRefOfVExplainStmt(n, parent) + case *VStream: + return c.copyOnRewriteRefOfVStream(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteTableExpr(n TableExpr, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *AliasedTableExpr: + return c.copyOnRewriteRefOfAliasedTableExpr(n, parent) + case *JSONTableExpr: + return c.copyOnRewriteRefOfJSONTableExpr(n, parent) + case *JoinTableExpr: + return c.copyOnRewriteRefOfJoinTableExpr(n, parent) + case *ParenTableExpr: + return c.copyOnRewriteRefOfParenTableExpr(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteAlgorithmValue(n AlgorithmValue, parent SQLNode) (out SQLNode, changed bool) { + if c.cursor.stop { + return n, false + } + if c.pre != nil { + c.pre(n, parent) + } + if c.post != nil { + out, changed = c.postVisit(n, parent) + } else { + out = n + } + return +} +func (c *cow) copyOnRewriteArgument(n Argument, parent SQLNode) (out SQLNode, changed bool) { + if c.cursor.stop { + return n, false + } + if c.pre != nil { + c.pre(n, parent) + } + if c.post != nil { + out, changed = c.postVisit(n, parent) + } else { + out = n + } + return +} +func (c *cow) copyOnRewriteBoolVal(n BoolVal, parent SQLNode) (out SQLNode, changed bool) { + if c.cursor.stop { + return n, false + } + if c.pre != nil { + c.pre(n, parent) + } + if c.post != nil { + out, changed = c.postVisit(n, parent) + } else { + out = n + } + return +} +func (c *cow) copyOnRewriteListArg(n ListArg, parent SQLNode) (out SQLNode, changed bool) { + if c.cursor.stop { + return n, false + } + if c.pre != nil { + c.pre(n, parent) + } + if c.post != nil { + out, changed = c.postVisit(n, parent) + } else { + out = n + } + return +} +func (c *cow) copyOnRewriteMatchAction(n MatchAction, parent SQLNode) (out SQLNode, changed bool) { + if c.cursor.stop { + return n, false + } + if c.pre != nil { + c.pre(n, parent) + } + if c.post != nil { + out, changed = c.postVisit(n, parent) + } else { + out = n + } + return +} +func (c *cow) copyOnRewriteReferenceAction(n ReferenceAction, parent SQLNode) (out SQLNode, changed bool) { + if c.cursor.stop { + return n, false + } + if c.pre != nil { + c.pre(n, parent) + } + if c.post != nil { + out, changed = c.postVisit(n, parent) + } else { + out = n + } + return +} +func (c *cow) copyOnRewriteRefOfIdentifierCI(n *IdentifierCI, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfIdentifierCS(n *IdentifierCS, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfRootNode(n *RootNode, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _SQLNode, changedSQLNode := c.copyOnRewriteSQLNode(n.SQLNode, n) + if changedSQLNode { + changed := *n + changed.SQLNode, _ = _SQLNode.(SQLNode) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfTableName(n *TableName, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Name, changedName := c.copyOnRewriteIdentifierCS(n.Name, n) + _Qualifier, changedQualifier := c.copyOnRewriteIdentifierCS(n.Qualifier, n) + if changedName || changedQualifier { + changed := *n + changed.Name, _ = _Name.(IdentifierCS) + changed.Qualifier, _ = _Qualifier.(IdentifierCS) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} +func (c *cow) copyOnRewriteRefOfVindexParam(n *VindexParam, parent SQLNode) (out SQLNode, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _Key, changedKey := c.copyOnRewriteIdentifierCI(n.Key, n) + if changedKey { + changed := *n + changed.Key, _ = _Key.(IdentifierCI) + out = &changed + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent) + } + return +} diff --git a/go/vt/sqlparser/ast_copy_on_rewrite_test.go b/go/vt/sqlparser/ast_copy_on_rewrite_test.go new file mode 100644 index 00000000000..3bce67b929f --- /dev/null +++ b/go/vt/sqlparser/ast_copy_on_rewrite_test.go @@ -0,0 +1,93 @@ +/* +Copyright 2023 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package sqlparser + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestCopyOnRewrite(t *testing.T) { + // rewrite an expression without changing the original + expr, err := ParseExpr("a = b") + require.NoError(t, err) + out := CopyOnRewrite(expr, nil, func(cursor *CopyOnWriteCursor) { + col, ok := cursor.Node().(*ColName) + if !ok { + return + } + if col.Name.EqualString("a") { + cursor.Replace(NewIntLiteral("1")) + } + }) + + assert.Equal(t, "a = b", String(expr)) + assert.Equal(t, "1 = b", String(out)) +} + +func TestDontCopyWithoutRewrite(t *testing.T) { + // when no rewriting happens, we want the original back + expr, err := ParseExpr("a = b") + require.NoError(t, err) + out := CopyOnRewrite(expr, nil, func(cursor *CopyOnWriteCursor) {}) + + assert.Same(t, expr, out) +} + +func TestStopTreeWalk(t *testing.T) { + // stop walking down part of the AST + original := "a = b + c" + expr, err := ParseExpr(original) + require.NoError(t, err) + out := CopyOnRewrite(expr, func(node, parent SQLNode) bool { + _, ok := node.(*BinaryExpr) + return !ok + }, func(cursor *CopyOnWriteCursor) { + col, ok := cursor.Node().(*ColName) + if !ok { + return + } + + cursor.Replace(NewStrLiteral(col.Name.String())) + }) + + assert.Equal(t, original, String(expr)) + assert.Equal(t, "'a' = b + c", String(out)) // b + c are unchanged since they are under the + (*BinaryExpr) +} + +func TestStopTreeWalkButStillVisit(t *testing.T) { + // here we are asserting that even when we stop at the binary expression, we still visit it in the post visitor + original := "1337 = b + c" + expr, err := ParseExpr(original) + require.NoError(t, err) + out := CopyOnRewrite(expr, func(node, parent SQLNode) bool { + _, ok := node.(*BinaryExpr) + return !ok + }, func(cursor *CopyOnWriteCursor) { + switch cursor.Node().(type) { + case *BinaryExpr: + cursor.Replace(NewStrLiteral("johnny was here")) + case *ColName: + t.Errorf("should not visit ColName in the post") + } + }) + + assert.Equal(t, original, String(expr)) + assert.Equal(t, "1337 = 'johnny was here'", String(out)) // b + c are replaced +} diff --git a/go/vt/sqlparser/ast_equals.go b/go/vt/sqlparser/ast_equals.go index aa955f514f1..d6acae0e923 100644 --- a/go/vt/sqlparser/ast_equals.go +++ b/go/vt/sqlparser/ast_equals.go @@ -1,5 +1,5 @@ /* -Copyright 2021 The Vitess Authors. +Copyright 2023 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. @@ -626,12 +626,12 @@ func (cmp *Comparator) SQLNode(inA, inB SQLNode) bool { return false } return cmp.RefOfJSONObjectExpr(a, b) - case JSONObjectParam: - b, ok := inB.(JSONObjectParam) + case *JSONObjectParam: + b, ok := inB.(*JSONObjectParam) if !ok { return false } - return cmp.JSONObjectParam(a, b) + return cmp.RefOfJSONObjectParam(a, b) case *JSONOverlapsExpr: b, ok := inB.(*JSONOverlapsExpr) if !ok { @@ -2747,8 +2747,14 @@ func (cmp *Comparator) RefOfJSONObjectExpr(a, b *JSONObjectExpr) bool { return cmp.SliceOfRefOfJSONObjectParam(a.Params, b.Params) } -// JSONObjectParam does deep equals between the two objects. -func (cmp *Comparator) JSONObjectParam(a, b JSONObjectParam) bool { +// RefOfJSONObjectParam does deep equals between the two objects. +func (cmp *Comparator) RefOfJSONObjectParam(a, b *JSONObjectParam) bool { + if a == b { + return true + } + if a == nil || b == nil { + return false + } return cmp.Expr(a.Key, b.Key) && cmp.Expr(a.Value, b.Value) } @@ -6613,18 +6619,6 @@ func (cmp *Comparator) SliceOfRefOfJSONObjectParam(a, b []*JSONObjectParam) bool return true } -// RefOfJSONObjectParam does deep equals between the two objects. -func (cmp *Comparator) RefOfJSONObjectParam(a, b *JSONObjectParam) bool { - if a == b { - return true - } - if a == nil || b == nil { - return false - } - return cmp.Expr(a.Key, b.Key) && - cmp.Expr(a.Value, b.Value) -} - // SliceOfRefOfJtColumnDefinition does deep equals between the two objects. func (cmp *Comparator) SliceOfRefOfJtColumnDefinition(a, b []*JtColumnDefinition) bool { if len(a) != len(b) { diff --git a/go/vt/sqlparser/ast_format.go b/go/vt/sqlparser/ast_format.go index cb13ed2c007..fe7e4f94e9a 100644 --- a/go/vt/sqlparser/ast_format.go +++ b/go/vt/sqlparser/ast_format.go @@ -2477,7 +2477,7 @@ func (node *JSONObjectExpr) Format(buf *TrackedBuffer) { } // Format formats the node. -func (node JSONObjectParam) Format(buf *TrackedBuffer) { +func (node *JSONObjectParam) Format(buf *TrackedBuffer) { buf.astPrintf(node, "%v, %v", node.Key, node.Value) } diff --git a/go/vt/sqlparser/ast_format_fast.go b/go/vt/sqlparser/ast_format_fast.go index 629d76b4a77..b2d3e372476 100644 --- a/go/vt/sqlparser/ast_format_fast.go +++ b/go/vt/sqlparser/ast_format_fast.go @@ -3247,7 +3247,7 @@ func (node *JSONObjectExpr) formatFast(buf *TrackedBuffer) { } // formatFast formats the node. -func (node JSONObjectParam) formatFast(buf *TrackedBuffer) { +func (node *JSONObjectParam) formatFast(buf *TrackedBuffer) { node.Key.formatFast(buf) buf.WriteString(", ") node.Value.formatFast(buf) diff --git a/go/vt/sqlparser/ast_funcs.go b/go/vt/sqlparser/ast_funcs.go index fcced205ddb..aa680b84729 100644 --- a/go/vt/sqlparser/ast_funcs.go +++ b/go/vt/sqlparser/ast_funcs.go @@ -39,8 +39,8 @@ import ( //go:generate go run ../../tools/asthelpergen/main --in . --iface vitess.io/vitess/go/vt/sqlparser.SQLNode --clone_exclude "*ColName" --equals_custom "*ColName" //go:generate go run ../../tools/astfmtgen vitess.io/vitess/go/vt/sqlparser/... -// Walk calls visit on every node. -// If visit returns true, the underlying nodes +// Walk calls postVisit on every node. +// If postVisit returns true, the underlying nodes // are also visited. If it returns an error, walking // is interrupted, and the error is returned. func Walk(visit Visit, nodes ...SQLNode) error { @@ -54,7 +54,7 @@ func Walk(visit Visit, nodes ...SQLNode) error { } // Visit defines the signature of a function that -// can be used to visit all nodes of a parse tree. +// can be used to postVisit all nodes of a parse tree. // returning false on kontinue means that children will not be visited // returning an error will abort the visitation and return the error type Visit func(node SQLNode) (kontinue bool, err error) diff --git a/go/vt/sqlparser/ast_rewrite.go b/go/vt/sqlparser/ast_rewrite.go index fb7308aa394..cf00af4146c 100644 --- a/go/vt/sqlparser/ast_rewrite.go +++ b/go/vt/sqlparser/ast_rewrite.go @@ -1,5 +1,5 @@ /* -Copyright 2021 The Vitess Authors. +Copyright 2023 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. @@ -222,8 +222,8 @@ func (a *application) rewriteSQLNode(parent SQLNode, node SQLNode, replacer repl return a.rewriteRefOfJSONKeysExpr(parent, node, replacer) case *JSONObjectExpr: return a.rewriteRefOfJSONObjectExpr(parent, node, replacer) - case JSONObjectParam: - return a.rewriteJSONObjectParam(parent, node, replacer) + case *JSONObjectParam: + return a.rewriteRefOfJSONObjectParam(parent, node, replacer) case *JSONOverlapsExpr: return a.rewriteRefOfJSONOverlapsExpr(parent, node, replacer) case *JSONPrettyExpr: @@ -3645,7 +3645,10 @@ func (a *application) rewriteRefOfJSONObjectExpr(parent SQLNode, node *JSONObjec } return true } -func (a *application) rewriteJSONObjectParam(parent SQLNode, node JSONObjectParam, replacer replacerFunc) bool { +func (a *application) rewriteRefOfJSONObjectParam(parent SQLNode, node *JSONObjectParam, replacer replacerFunc) bool { + if node == nil { + return true + } if a.pre != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3655,12 +3658,12 @@ func (a *application) rewriteJSONObjectParam(parent SQLNode, node JSONObjectPara } } if !a.rewriteExpr(node, node.Key, func(newNode, parent SQLNode) { - panic("[BUG] tried to replace 'Key' on 'JSONObjectParam'") + parent.(*JSONObjectParam).Key = newNode.(Expr) }) { return false } if !a.rewriteExpr(node, node.Value, func(newNode, parent SQLNode) { - panic("[BUG] tried to replace 'Value' on 'JSONObjectParam'") + parent.(*JSONObjectParam).Value = newNode.(Expr) }) { return false } @@ -9100,38 +9103,6 @@ func (a *application) rewriteRefOfIdentifierCS(parent SQLNode, node *IdentifierC } return true } -func (a *application) rewriteRefOfJSONObjectParam(parent SQLNode, node *JSONObjectParam, replacer replacerFunc) bool { - if node == nil { - return true - } - if a.pre != nil { - a.cur.replacer = replacer - a.cur.parent = parent - a.cur.node = node - if !a.pre(&a.cur) { - return true - } - } - if !a.rewriteExpr(node, node.Key, func(newNode, parent SQLNode) { - parent.(*JSONObjectParam).Key = newNode.(Expr) - }) { - return false - } - if !a.rewriteExpr(node, node.Value, func(newNode, parent SQLNode) { - parent.(*JSONObjectParam).Value = newNode.(Expr) - }) { - return false - } - if a.post != nil { - a.cur.replacer = replacer - a.cur.parent = parent - a.cur.node = node - if !a.post(&a.cur) { - return false - } - } - return true -} func (a *application) rewriteRefOfRootNode(parent SQLNode, node *RootNode, replacer replacerFunc) bool { if node == nil { return true diff --git a/go/vt/sqlparser/ast_visit.go b/go/vt/sqlparser/ast_visit.go index 71e19430684..c6f107f1902 100644 --- a/go/vt/sqlparser/ast_visit.go +++ b/go/vt/sqlparser/ast_visit.go @@ -1,5 +1,5 @@ /* -Copyright 2021 The Vitess Authors. +Copyright 2023 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. @@ -222,8 +222,8 @@ func VisitSQLNode(in SQLNode, f Visit) error { return VisitRefOfJSONKeysExpr(in, f) case *JSONObjectExpr: return VisitRefOfJSONObjectExpr(in, f) - case JSONObjectParam: - return VisitJSONObjectParam(in, f) + case *JSONObjectParam: + return VisitRefOfJSONObjectParam(in, f) case *JSONOverlapsExpr: return VisitRefOfJSONOverlapsExpr(in, f) case *JSONPrettyExpr: @@ -1950,7 +1950,10 @@ func VisitRefOfJSONObjectExpr(in *JSONObjectExpr, f Visit) error { } return nil } -func VisitJSONObjectParam(in JSONObjectParam, f Visit) error { +func VisitRefOfJSONObjectParam(in *JSONObjectParam, f Visit) error { + if in == nil { + return nil + } if cont, err := f(in); err != nil || !cont { return err } @@ -4753,21 +4756,6 @@ func VisitRefOfIdentifierCS(in *IdentifierCS, f Visit) error { } return nil } -func VisitRefOfJSONObjectParam(in *JSONObjectParam, f Visit) error { - if in == nil { - return nil - } - if cont, err := f(in); err != nil || !cont { - return err - } - if err := VisitExpr(in.Key, f); err != nil { - return err - } - if err := VisitExpr(in.Value, f); err != nil { - return err - } - return nil -} func VisitRefOfRootNode(in *RootNode, f Visit) error { if in == nil { return nil diff --git a/go/vt/sqlparser/cow.go b/go/vt/sqlparser/cow.go new file mode 100644 index 00000000000..e54f99223d2 --- /dev/null +++ b/go/vt/sqlparser/cow.go @@ -0,0 +1,95 @@ +/* +Copyright 2023 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package sqlparser + +type ( + CopyOnWriteCursor struct { + node SQLNode + parent SQLNode + replaced SQLNode + stop bool + } + cow struct { + pre func(node, parent SQLNode) bool + post func(cursor *CopyOnWriteCursor) + cloned func(old, new SQLNode) + cursor CopyOnWriteCursor + } +) + +// CopyOnRewrite traverses a syntax tree recursively, starting with root, +// and calling pre and post for each node as described below. +// Rewrite returns a syntax tree, where some nodes can be shared with the +// original syntax tree. +// +// If pre is not nil, it is called for each node before the node's +// children are traversed (pre-order). If pre returns false, no +// children are traversed, but post is still called for that node. +// +// If post is not nil, and a prior call of pre didn't return false, +// post is called for each node after its children are traversed +// (post-order). +// +// In the post call, the cursor can be used to abort the current +// traversal altogether. +// +// Also in the post call, a user can replace the current node. +// When a node is replaced, all the ancestors of the node are cloned, +// so that the original syntax tree remains untouched +// +// Only fields that refer to AST nodes are considered children; +// i.e., fields of basic types (strings, []byte, etc.) are ignored. +func CopyOnRewrite(node SQLNode, pre func(node, parent SQLNode) bool, post func(cursor *CopyOnWriteCursor)) SQLNode { + parent := &RootNode{node} + + cow := cow{pre: pre, post: post, cursor: CopyOnWriteCursor{}} + out, _ := cow.copyOnRewriteSQLNode(node, parent) + return out +} + +func (c *cow) postVisit(node, parent SQLNode) (SQLNode, bool) { + c.cursor.node = node + c.cursor.parent = parent + c.cursor.replaced = nil + c.post(&c.cursor) + if c.cursor.replaced != nil { + return c.cursor.replaced, true + } + return node, false +} + +// StopTreeWalk aborts the current tree walking. No more nodes will be visited, and the rewriter will exit out early +func (c *CopyOnWriteCursor) StopTreeWalk() { + c.stop = true +} + +// Node returns the current node we are visiting +func (c *CopyOnWriteCursor) Node() SQLNode { + return c.node +} + +// Parent returns the parent of the current node. +// Note: This is the parent before any changes have been done - the parent in the output might be a copy of this +func (c *CopyOnWriteCursor) Parent() SQLNode { + return c.parent +} + +// Replace replaces the current node with the given node. +// Note: If you try to set an invalid type on a field, the field will end up with a nil and no error will be reported. +func (c *CopyOnWriteCursor) Replace(n SQLNode) { + c.replaced = n +} diff --git a/go/vt/vtgate/planbuilder/operators/union.go b/go/vt/vtgate/planbuilder/operators/union.go index 16e752fb7e8..199c76f9a0d 100644 --- a/go/vt/vtgate/planbuilder/operators/union.go +++ b/go/vt/vtgate/planbuilder/operators/union.go @@ -94,34 +94,34 @@ func (u *Union) AddPredicate(ctx *plancontext.PlanningContext, expr sqlparser.Ex } for i := range u.Sources { - // TODO copy-on-rewrite should be used here - predicate := sqlparser.CloneExpr(expr) var err error - predicate = sqlparser.SafeRewrite(predicate, nil, func(cursor *sqlparser.Cursor) bool { + predicate := sqlparser.CopyOnRewrite(expr, nil, func(cursor *sqlparser.CopyOnWriteCursor) { col, ok := cursor.Node().(*sqlparser.ColName) if !ok { - return err == nil + return } idx, ok := offsets[col.Name.Lowered()] if !ok { err = vterrors.VT13001("cannot push predicates on concatenate, missing columns from the UNION") - return false + cursor.StopTreeWalk() + return } var sel *sqlparser.Select sel, err = u.GetSelectFor(i) if err != nil { - return false + cursor.StopTreeWalk() + return } ae, ok := sel.SelectExprs[idx].(*sqlparser.AliasedExpr) if !ok { err = vterrors.VT12001("pushing non-aliased expression predicates on concatenate") - return false + cursor.StopTreeWalk() + return } cursor.Replace(ae.Expr) - return true }).(sqlparser.Expr) if err != nil { return nil, err From 8ecf6e5d0bc137e206578fa7df09e2066212bbde Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 24 Jan 2023 14:21:41 +0100 Subject: [PATCH 2/5] added more tests and started calling cloned Signed-off-by: Andres Taylor --- go/tools/asthelpergen/copy_on_rewrite_gen.go | 14 +- go/vt/sqlparser/ast_copy_on_rewrite.go | 2854 +++++++++++------- go/vt/sqlparser/ast_copy_on_rewrite_test.go | 38 +- go/vt/sqlparser/cow.go | 24 +- go/vt/vtgate/planbuilder/operators/union.go | 2 +- 5 files changed, 1868 insertions(+), 1064 deletions(-) diff --git a/go/tools/asthelpergen/copy_on_rewrite_gen.go b/go/tools/asthelpergen/copy_on_rewrite_gen.go index 365061e308b..09d00c26308 100644 --- a/go/tools/asthelpergen/copy_on_rewrite_gen.go +++ b/go/tools/asthelpergen/copy_on_rewrite_gen.go @@ -122,7 +122,7 @@ func (c *cowGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSPI) stmts = append(stmts, jen.If(jen.Id("c").Dot("cursor").Dot("stop")).Block(jen.Return(jen.Id("n"), jen.False())), ifNotNil("c.pre", jen.Id("c.pre").Params(jen.Id("n"), jen.Id("parent"))), - ifNotNil("c.post", jen.List(jen.Id("out"), jen.Id("changed")).Op("=").Id("c.postVisit").Params(jen.Id("n"), jen.Id("parent"))). + ifNotNil("c.post", jen.List(jen.Id("out"), jen.Id("changed")).Op("=").Id("c.postVisit").Params(jen.Id("n"), jen.Id("parent"), jen.Id("changed"))). Else().Block(jen.Id("out = n")), jen.Return(), ) @@ -285,7 +285,7 @@ func (c *cowGen) visitStruct(t types.Type, strct *types.Struct, spi generatorSPI var fields []jen.Code out := "out" - changed := "changed" + changed := "res" var fieldSetters []jen.Code kopy := jen.Id(changed).Op(":=") if ref { @@ -350,7 +350,11 @@ func (c *cowGen) visitStruct(t types.Type, strct *types.Struct, spi generatorSPI } - fieldSetters = append(fieldSetters, jen.Id(out).Op("=").Op("&").Id(changed)) + fieldSetters = append(fieldSetters, + jen.Id(out).Op("=").Op("&").Id(changed), + ifNotNil("c.cloned", jen.Id("c.cloned").Params(jen.Id("n, out"))), + jen.Id("changed").Op("=").True(), + ) ifChanged := jen.If(cond).Block(fieldSetters...) var stmts []jen.Code @@ -361,7 +365,7 @@ func (c *cowGen) visitStruct(t types.Type, strct *types.Struct, spi generatorSPI // handle all fields with CloneAble types var visitChildren []jen.Code visitChildren = append(visitChildren, fields...) - if len(fieldSetters) > 2 /*we add two statements always*/ { + if len(fieldSetters) > 4 /*we add three statements always*/ { visitChildren = append(visitChildren, ifChanged) } @@ -381,5 +385,5 @@ func (c *cowGen) visitStruct(t types.Type, strct *types.Struct, spi generatorSPI } func ifPostNotNilVisit(out string) *jen.Statement { - return ifNotNil("c.post", jen.List(jen.Id(out), jen.Id("changed")).Op("=").Id("c").Dot("postVisit").Params(jen.Id(out), jen.Id("parent"))) + return ifNotNil("c.post", jen.List(jen.Id(out), jen.Id("changed")).Op("=").Id("c").Dot("postVisit").Params(jen.Id(out), jen.Id("parent"), jen.Id("changed"))) } diff --git a/go/vt/sqlparser/ast_copy_on_rewrite.go b/go/vt/sqlparser/ast_copy_on_rewrite.go index 0dc7ebf0e6b..b0c9ee60cda 100644 --- a/go/vt/sqlparser/ast_copy_on_rewrite.go +++ b/go/vt/sqlparser/ast_copy_on_rewrite.go @@ -532,14 +532,18 @@ func (c *cow) copyOnRewriteRefOfAddColumns(n *AddColumns, parent SQLNode) (out S } _After, changedAfter := c.copyOnRewriteRefOfColName(n.After, n) if changedColumns || changedAfter { - changed := *n - changed.Columns = _Columns - changed.After, _ = _After.(*ColName) - out = &changed + res := *n + res.Columns = _Columns + res.After, _ = _After.(*ColName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -551,13 +555,17 @@ func (c *cow) copyOnRewriteRefOfAddConstraintDefinition(n *AddConstraintDefiniti if c.pre == nil || c.pre(n, parent) { _ConstraintDefinition, changedConstraintDefinition := c.copyOnRewriteRefOfConstraintDefinition(n.ConstraintDefinition, n) if changedConstraintDefinition { - changed := *n - changed.ConstraintDefinition, _ = _ConstraintDefinition.(*ConstraintDefinition) - out = &changed + res := *n + res.ConstraintDefinition, _ = _ConstraintDefinition.(*ConstraintDefinition) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -569,13 +577,17 @@ func (c *cow) copyOnRewriteRefOfAddIndexDefinition(n *AddIndexDefinition, parent if c.pre == nil || c.pre(n, parent) { _IndexDefinition, changedIndexDefinition := c.copyOnRewriteRefOfIndexDefinition(n.IndexDefinition, n) if changedIndexDefinition { - changed := *n - changed.IndexDefinition, _ = _IndexDefinition.(*IndexDefinition) - out = &changed + res := *n + res.IndexDefinition, _ = _IndexDefinition.(*IndexDefinition) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -588,14 +600,18 @@ func (c *cow) copyOnRewriteRefOfAliasedExpr(n *AliasedExpr, parent SQLNode) (out _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) _As, changedAs := c.copyOnRewriteIdentifierCI(n.As, n) if changedExpr || changedAs { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.As, _ = _As.(IdentifierCI) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.As, _ = _As.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -611,17 +627,21 @@ func (c *cow) copyOnRewriteRefOfAliasedTableExpr(n *AliasedTableExpr, parent SQL _Hints, changedHints := c.copyOnRewriteIndexHints(n.Hints, n) _Columns, changedColumns := c.copyOnRewriteColumns(n.Columns, n) if changedExpr || changedPartitions || changedAs || changedHints || changedColumns { - changed := *n - changed.Expr, _ = _Expr.(SimpleTableExpr) - changed.Partitions, _ = _Partitions.(Partitions) - changed.As, _ = _As.(IdentifierCS) - changed.Hints, _ = _Hints.(IndexHints) - changed.Columns, _ = _Columns.(Columns) - out = &changed + res := *n + res.Expr, _ = _Expr.(SimpleTableExpr) + res.Partitions, _ = _Partitions.(Partitions) + res.As, _ = _As.(IdentifierCS) + res.Hints, _ = _Hints.(IndexHints) + res.Columns, _ = _Columns.(Columns) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -633,7 +653,7 @@ func (c *cow) copyOnRewriteRefOfAlterCharset(n *AlterCharset, parent SQLNode) (o if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -645,13 +665,17 @@ func (c *cow) copyOnRewriteRefOfAlterCheck(n *AlterCheck, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) if changedName { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -664,14 +688,18 @@ func (c *cow) copyOnRewriteRefOfAlterColumn(n *AlterColumn, parent SQLNode) (out _Column, changedColumn := c.copyOnRewriteRefOfColName(n.Column, n) _DefaultVal, changedDefaultVal := c.copyOnRewriteExpr(n.DefaultVal, n) if changedColumn || changedDefaultVal { - changed := *n - changed.Column, _ = _Column.(*ColName) - changed.DefaultVal, _ = _DefaultVal.(Expr) - out = &changed + res := *n + res.Column, _ = _Column.(*ColName) + res.DefaultVal, _ = _DefaultVal.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -683,13 +711,17 @@ func (c *cow) copyOnRewriteRefOfAlterDatabase(n *AlterDatabase, parent SQLNode) if c.pre == nil || c.pre(n, parent) { _DBName, changedDBName := c.copyOnRewriteIdentifierCS(n.DBName, n) if changedDBName { - changed := *n - changed.DBName, _ = _DBName.(IdentifierCS) - out = &changed + res := *n + res.DBName, _ = _DBName.(IdentifierCS) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -701,13 +733,17 @@ func (c *cow) copyOnRewriteRefOfAlterIndex(n *AlterIndex, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) if changedName { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -719,13 +755,17 @@ func (c *cow) copyOnRewriteRefOfAlterMigration(n *AlterMigration, parent SQLNode if c.pre == nil || c.pre(n, parent) { _Ratio, changedRatio := c.copyOnRewriteRefOfLiteral(n.Ratio, n) if changedRatio { - changed := *n - changed.Ratio, _ = _Ratio.(*Literal) - out = &changed + res := *n + res.Ratio, _ = _Ratio.(*Literal) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -749,17 +789,21 @@ func (c *cow) copyOnRewriteRefOfAlterTable(n *AlterTable, parent SQLNode) (out S _PartitionOption, changedPartitionOption := c.copyOnRewriteRefOfPartitionOption(n.PartitionOption, n) _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) if changedTable || changedAlterOptions || changedPartitionSpec || changedPartitionOption || changedComments { - changed := *n - changed.Table, _ = _Table.(TableName) - changed.AlterOptions = _AlterOptions - changed.PartitionSpec, _ = _PartitionSpec.(*PartitionSpec) - changed.PartitionOption, _ = _PartitionOption.(*PartitionOption) - changed.Comments, _ = _Comments.(*ParsedComments) - out = &changed + res := *n + res.Table, _ = _Table.(TableName) + res.AlterOptions = _AlterOptions + res.PartitionSpec, _ = _PartitionSpec.(*PartitionSpec) + res.PartitionOption, _ = _PartitionOption.(*PartitionOption) + res.Comments, _ = _Comments.(*ParsedComments) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -775,17 +819,21 @@ func (c *cow) copyOnRewriteRefOfAlterView(n *AlterView, parent SQLNode) (out SQL _Select, changedSelect := c.copyOnRewriteSelectStatement(n.Select, n) _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) if changedViewName || changedDefiner || changedColumns || changedSelect || changedComments { - changed := *n - changed.ViewName, _ = _ViewName.(TableName) - changed.Definer, _ = _Definer.(*Definer) - changed.Columns, _ = _Columns.(Columns) - changed.Select, _ = _Select.(SelectStatement) - changed.Comments, _ = _Comments.(*ParsedComments) - out = &changed + res := *n + res.ViewName, _ = _ViewName.(TableName) + res.Definer, _ = _Definer.(*Definer) + res.Columns, _ = _Columns.(Columns) + res.Select, _ = _Select.(SelectStatement) + res.Comments, _ = _Comments.(*ParsedComments) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -808,16 +856,20 @@ func (c *cow) copyOnRewriteRefOfAlterVschema(n *AlterVschema, parent SQLNode) (o } _AutoIncSpec, changedAutoIncSpec := c.copyOnRewriteRefOfAutoIncSpec(n.AutoIncSpec, n) if changedTable || changedVindexSpec || changedVindexCols || changedAutoIncSpec { - changed := *n - changed.Table, _ = _Table.(TableName) - changed.VindexSpec, _ = _VindexSpec.(*VindexSpec) - changed.VindexCols = _VindexCols - changed.AutoIncSpec, _ = _AutoIncSpec.(*AutoIncSpec) - out = &changed + res := *n + res.Table, _ = _Table.(TableName) + res.VindexSpec, _ = _VindexSpec.(*VindexSpec) + res.VindexCols = _VindexCols + res.AutoIncSpec, _ = _AutoIncSpec.(*AutoIncSpec) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -830,14 +882,18 @@ func (c *cow) copyOnRewriteRefOfAndExpr(n *AndExpr, parent SQLNode) (out SQLNode _Left, changedLeft := c.copyOnRewriteExpr(n.Left, n) _Right, changedRight := c.copyOnRewriteExpr(n.Right, n) if changedLeft || changedRight { - changed := *n - changed.Left, _ = _Left.(Expr) - changed.Right, _ = _Right.(Expr) - out = &changed + res := *n + res.Left, _ = _Left.(Expr) + res.Right, _ = _Right.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -849,13 +905,17 @@ func (c *cow) copyOnRewriteRefOfArgumentLessWindowExpr(n *ArgumentLessWindowExpr if c.pre == nil || c.pre(n, parent) { _OverClause, changedOverClause := c.copyOnRewriteRefOfOverClause(n.OverClause, n) if changedOverClause { - changed := *n - changed.OverClause, _ = _OverClause.(*OverClause) - out = &changed + res := *n + res.OverClause, _ = _OverClause.(*OverClause) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -868,14 +928,18 @@ func (c *cow) copyOnRewriteRefOfAutoIncSpec(n *AutoIncSpec, parent SQLNode) (out _Column, changedColumn := c.copyOnRewriteIdentifierCI(n.Column, n) _Sequence, changedSequence := c.copyOnRewriteTableName(n.Sequence, n) if changedColumn || changedSequence { - changed := *n - changed.Column, _ = _Column.(IdentifierCI) - changed.Sequence, _ = _Sequence.(TableName) - out = &changed + res := *n + res.Column, _ = _Column.(IdentifierCI) + res.Sequence, _ = _Sequence.(TableName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -887,13 +951,17 @@ func (c *cow) copyOnRewriteRefOfAvg(n *Avg, parent SQLNode) (out SQLNode, change if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -905,7 +973,7 @@ func (c *cow) copyOnRewriteRefOfBegin(n *Begin, parent SQLNode) (out SQLNode, ch if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -919,15 +987,19 @@ func (c *cow) copyOnRewriteRefOfBetweenExpr(n *BetweenExpr, parent SQLNode) (out _From, changedFrom := c.copyOnRewriteExpr(n.From, n) _To, changedTo := c.copyOnRewriteExpr(n.To, n) if changedLeft || changedFrom || changedTo { - changed := *n - changed.Left, _ = _Left.(Expr) - changed.From, _ = _From.(Expr) - changed.To, _ = _To.(Expr) - out = &changed + res := *n + res.Left, _ = _Left.(Expr) + res.From, _ = _From.(Expr) + res.To, _ = _To.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -940,14 +1012,18 @@ func (c *cow) copyOnRewriteRefOfBinaryExpr(n *BinaryExpr, parent SQLNode) (out S _Left, changedLeft := c.copyOnRewriteExpr(n.Left, n) _Right, changedRight := c.copyOnRewriteExpr(n.Right, n) if changedLeft || changedRight { - changed := *n - changed.Left, _ = _Left.(Expr) - changed.Right, _ = _Right.(Expr) - out = &changed + res := *n + res.Left, _ = _Left.(Expr) + res.Right, _ = _Right.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -959,13 +1035,17 @@ func (c *cow) copyOnRewriteRefOfBitAnd(n *BitAnd, parent SQLNode) (out SQLNode, if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -977,13 +1057,17 @@ func (c *cow) copyOnRewriteRefOfBitOr(n *BitOr, parent SQLNode) (out SQLNode, ch if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -995,13 +1079,17 @@ func (c *cow) copyOnRewriteRefOfBitXor(n *BitXor, parent SQLNode) (out SQLNode, if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1014,14 +1102,18 @@ func (c *cow) copyOnRewriteRefOfCallProc(n *CallProc, parent SQLNode) (out SQLNo _Name, changedName := c.copyOnRewriteTableName(n.Name, n) _Params, changedParams := c.copyOnRewriteExprs(n.Params, n) if changedName || changedParams { - changed := *n - changed.Name, _ = _Name.(TableName) - changed.Params, _ = _Params.(Exprs) - out = &changed + res := *n + res.Name, _ = _Name.(TableName) + res.Params, _ = _Params.(Exprs) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1043,15 +1135,19 @@ func (c *cow) copyOnRewriteRefOfCaseExpr(n *CaseExpr, parent SQLNode) (out SQLNo } _Else, changedElse := c.copyOnRewriteExpr(n.Else, n) if changedExpr || changedWhens || changedElse { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.Whens = _Whens - changed.Else, _ = _Else.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.Whens = _Whens + res.Else, _ = _Else.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1064,14 +1160,18 @@ func (c *cow) copyOnRewriteRefOfCastExpr(n *CastExpr, parent SQLNode) (out SQLNo _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) _Type, changedType := c.copyOnRewriteRefOfConvertType(n.Type, n) if changedExpr || changedType { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.Type, _ = _Type.(*ConvertType) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.Type, _ = _Type.(*ConvertType) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1085,15 +1185,19 @@ func (c *cow) copyOnRewriteRefOfChangeColumn(n *ChangeColumn, parent SQLNode) (o _NewColDefinition, changedNewColDefinition := c.copyOnRewriteRefOfColumnDefinition(n.NewColDefinition, n) _After, changedAfter := c.copyOnRewriteRefOfColName(n.After, n) if changedOldColumn || changedNewColDefinition || changedAfter { - changed := *n - changed.OldColumn, _ = _OldColumn.(*ColName) - changed.NewColDefinition, _ = _NewColDefinition.(*ColumnDefinition) - changed.After, _ = _After.(*ColName) - out = &changed + res := *n + res.OldColumn, _ = _OldColumn.(*ColName) + res.NewColDefinition, _ = _NewColDefinition.(*ColumnDefinition) + res.After, _ = _After.(*ColName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1105,13 +1209,17 @@ func (c *cow) copyOnRewriteRefOfCharExpr(n *CharExpr, parent SQLNode) (out SQLNo if c.pre == nil || c.pre(n, parent) { _Exprs, changedExprs := c.copyOnRewriteExprs(n.Exprs, n) if changedExprs { - changed := *n - changed.Exprs, _ = _Exprs.(Exprs) - out = &changed + res := *n + res.Exprs, _ = _Exprs.(Exprs) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1123,13 +1231,17 @@ func (c *cow) copyOnRewriteRefOfCheckConstraintDefinition(n *CheckConstraintDefi if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1142,14 +1254,18 @@ func (c *cow) copyOnRewriteRefOfColName(n *ColName, parent SQLNode) (out SQLNode _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) _Qualifier, changedQualifier := c.copyOnRewriteTableName(n.Qualifier, n) if changedName || changedQualifier { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - changed.Qualifier, _ = _Qualifier.(TableName) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + res.Qualifier, _ = _Qualifier.(TableName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1161,13 +1277,17 @@ func (c *cow) copyOnRewriteRefOfCollateExpr(n *CollateExpr, parent SQLNode) (out if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1179,13 +1299,17 @@ func (c *cow) copyOnRewriteRefOfColumnDefinition(n *ColumnDefinition, parent SQL if c.pre == nil || c.pre(n, parent) { _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) if changedName { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1198,14 +1322,18 @@ func (c *cow) copyOnRewriteRefOfColumnType(n *ColumnType, parent SQLNode) (out S _Length, changedLength := c.copyOnRewriteRefOfLiteral(n.Length, n) _Scale, changedScale := c.copyOnRewriteRefOfLiteral(n.Scale, n) if changedLength || changedScale { - changed := *n - changed.Length, _ = _Length.(*Literal) - changed.Scale, _ = _Scale.(*Literal) - out = &changed + res := *n + res.Length, _ = _Length.(*Literal) + res.Scale, _ = _Scale.(*Literal) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1228,7 +1356,7 @@ func (c *cow) copyOnRewriteColumns(n Columns, parent SQLNode) (out SQLNode, chan } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1240,7 +1368,7 @@ func (c *cow) copyOnRewriteRefOfCommentOnly(n *CommentOnly, parent SQLNode) (out if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1252,7 +1380,7 @@ func (c *cow) copyOnRewriteRefOfCommit(n *Commit, parent SQLNode) (out SQLNode, if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1266,15 +1394,19 @@ func (c *cow) copyOnRewriteRefOfCommonTableExpr(n *CommonTableExpr, parent SQLNo _Columns, changedColumns := c.copyOnRewriteColumns(n.Columns, n) _Subquery, changedSubquery := c.copyOnRewriteRefOfSubquery(n.Subquery, n) if changedID || changedColumns || changedSubquery { - changed := *n - changed.ID, _ = _ID.(IdentifierCS) - changed.Columns, _ = _Columns.(Columns) - changed.Subquery, _ = _Subquery.(*Subquery) - out = &changed + res := *n + res.ID, _ = _ID.(IdentifierCS) + res.Columns, _ = _Columns.(Columns) + res.Subquery, _ = _Subquery.(*Subquery) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1288,15 +1420,19 @@ func (c *cow) copyOnRewriteRefOfComparisonExpr(n *ComparisonExpr, parent SQLNode _Right, changedRight := c.copyOnRewriteExpr(n.Right, n) _Escape, changedEscape := c.copyOnRewriteExpr(n.Escape, n) if changedLeft || changedRight || changedEscape { - changed := *n - changed.Left, _ = _Left.(Expr) - changed.Right, _ = _Right.(Expr) - changed.Escape, _ = _Escape.(Expr) - out = &changed + res := *n + res.Left, _ = _Left.(Expr) + res.Right, _ = _Right.(Expr) + res.Escape, _ = _Escape.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1309,14 +1445,18 @@ func (c *cow) copyOnRewriteRefOfConstraintDefinition(n *ConstraintDefinition, pa _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) _Details, changedDetails := c.copyOnRewriteConstraintInfo(n.Details, n) if changedName || changedDetails { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - changed.Details, _ = _Details.(ConstraintInfo) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + res.Details, _ = _Details.(ConstraintInfo) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1329,14 +1469,18 @@ func (c *cow) copyOnRewriteRefOfConvertExpr(n *ConvertExpr, parent SQLNode) (out _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) _Type, changedType := c.copyOnRewriteRefOfConvertType(n.Type, n) if changedExpr || changedType { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.Type, _ = _Type.(*ConvertType) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.Type, _ = _Type.(*ConvertType) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1349,14 +1493,18 @@ func (c *cow) copyOnRewriteRefOfConvertType(n *ConvertType, parent SQLNode) (out _Length, changedLength := c.copyOnRewriteRefOfLiteral(n.Length, n) _Scale, changedScale := c.copyOnRewriteRefOfLiteral(n.Scale, n) if changedLength || changedScale { - changed := *n - changed.Length, _ = _Length.(*Literal) - changed.Scale, _ = _Scale.(*Literal) - out = &changed + res := *n + res.Length, _ = _Length.(*Literal) + res.Scale, _ = _Scale.(*Literal) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1368,13 +1516,17 @@ func (c *cow) copyOnRewriteRefOfConvertUsingExpr(n *ConvertUsingExpr, parent SQL if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1386,13 +1538,17 @@ func (c *cow) copyOnRewriteRefOfCount(n *Count, parent SQLNode) (out SQLNode, ch if c.pre == nil || c.pre(n, parent) { _Args, changedArgs := c.copyOnRewriteExprs(n.Args, n) if changedArgs { - changed := *n - changed.Args, _ = _Args.(Exprs) - out = &changed + res := *n + res.Args, _ = _Args.(Exprs) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1404,7 +1560,7 @@ func (c *cow) copyOnRewriteRefOfCountStar(n *CountStar, parent SQLNode) (out SQL if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1417,14 +1573,18 @@ func (c *cow) copyOnRewriteRefOfCreateDatabase(n *CreateDatabase, parent SQLNode _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) _DBName, changedDBName := c.copyOnRewriteIdentifierCS(n.DBName, n) if changedComments || changedDBName { - changed := *n - changed.Comments, _ = _Comments.(*ParsedComments) - changed.DBName, _ = _DBName.(IdentifierCS) - out = &changed + res := *n + res.Comments, _ = _Comments.(*ParsedComments) + res.DBName, _ = _DBName.(IdentifierCS) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1439,16 +1599,20 @@ func (c *cow) copyOnRewriteRefOfCreateTable(n *CreateTable, parent SQLNode) (out _OptLike, changedOptLike := c.copyOnRewriteRefOfOptLike(n.OptLike, n) _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) if changedTable || changedTableSpec || changedOptLike || changedComments { - changed := *n - changed.Table, _ = _Table.(TableName) - changed.TableSpec, _ = _TableSpec.(*TableSpec) - changed.OptLike, _ = _OptLike.(*OptLike) - changed.Comments, _ = _Comments.(*ParsedComments) - out = &changed + res := *n + res.Table, _ = _Table.(TableName) + res.TableSpec, _ = _TableSpec.(*TableSpec) + res.OptLike, _ = _OptLike.(*OptLike) + res.Comments, _ = _Comments.(*ParsedComments) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1464,17 +1628,21 @@ func (c *cow) copyOnRewriteRefOfCreateView(n *CreateView, parent SQLNode) (out S _Select, changedSelect := c.copyOnRewriteSelectStatement(n.Select, n) _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) if changedViewName || changedDefiner || changedColumns || changedSelect || changedComments { - changed := *n - changed.ViewName, _ = _ViewName.(TableName) - changed.Definer, _ = _Definer.(*Definer) - changed.Columns, _ = _Columns.(Columns) - changed.Select, _ = _Select.(SelectStatement) - changed.Comments, _ = _Comments.(*ParsedComments) - out = &changed + res := *n + res.ViewName, _ = _ViewName.(TableName) + res.Definer, _ = _Definer.(*Definer) + res.Columns, _ = _Columns.(Columns) + res.Select, _ = _Select.(SelectStatement) + res.Comments, _ = _Comments.(*ParsedComments) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1487,14 +1655,18 @@ func (c *cow) copyOnRewriteRefOfCurTimeFuncExpr(n *CurTimeFuncExpr, parent SQLNo _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) _Fsp, changedFsp := c.copyOnRewriteExpr(n.Fsp, n) if changedName || changedFsp { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - changed.Fsp, _ = _Fsp.(Expr) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + res.Fsp, _ = _Fsp.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1507,14 +1679,18 @@ func (c *cow) copyOnRewriteRefOfDeallocateStmt(n *DeallocateStmt, parent SQLNode _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) if changedComments || changedName { - changed := *n - changed.Comments, _ = _Comments.(*ParsedComments) - changed.Name, _ = _Name.(IdentifierCI) - out = &changed + res := *n + res.Comments, _ = _Comments.(*ParsedComments) + res.Name, _ = _Name.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1526,7 +1702,7 @@ func (c *cow) copyOnRewriteRefOfDefault(n *Default, parent SQLNode) (out SQLNode if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1538,7 +1714,7 @@ func (c *cow) copyOnRewriteRefOfDefiner(n *Definer, parent SQLNode) (out SQLNode if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1557,20 +1733,24 @@ func (c *cow) copyOnRewriteRefOfDelete(n *Delete, parent SQLNode) (out SQLNode, _OrderBy, changedOrderBy := c.copyOnRewriteOrderBy(n.OrderBy, n) _Limit, changedLimit := c.copyOnRewriteRefOfLimit(n.Limit, n) if changedWith || changedComments || changedTargets || changedTableExprs || changedPartitions || changedWhere || changedOrderBy || changedLimit { - changed := *n - changed.With, _ = _With.(*With) - changed.Comments, _ = _Comments.(*ParsedComments) - changed.Targets, _ = _Targets.(TableNames) - changed.TableExprs, _ = _TableExprs.(TableExprs) - changed.Partitions, _ = _Partitions.(Partitions) - changed.Where, _ = _Where.(*Where) - changed.OrderBy, _ = _OrderBy.(OrderBy) - changed.Limit, _ = _Limit.(*Limit) - out = &changed + res := *n + res.With, _ = _With.(*With) + res.Comments, _ = _Comments.(*ParsedComments) + res.Targets, _ = _Targets.(TableNames) + res.TableExprs, _ = _TableExprs.(TableExprs) + res.Partitions, _ = _Partitions.(Partitions) + res.Where, _ = _Where.(*Where) + res.OrderBy, _ = _OrderBy.(OrderBy) + res.Limit, _ = _Limit.(*Limit) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1582,13 +1762,17 @@ func (c *cow) copyOnRewriteRefOfDerivedTable(n *DerivedTable, parent SQLNode) (o if c.pre == nil || c.pre(n, parent) { _Select, changedSelect := c.copyOnRewriteSelectStatement(n.Select, n) if changedSelect { - changed := *n - changed.Select, _ = _Select.(SelectStatement) - out = &changed + res := *n + res.Select, _ = _Select.(SelectStatement) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1600,13 +1784,17 @@ func (c *cow) copyOnRewriteRefOfDropColumn(n *DropColumn, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { _Name, changedName := c.copyOnRewriteRefOfColName(n.Name, n) if changedName { - changed := *n - changed.Name, _ = _Name.(*ColName) - out = &changed + res := *n + res.Name, _ = _Name.(*ColName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1619,14 +1807,18 @@ func (c *cow) copyOnRewriteRefOfDropDatabase(n *DropDatabase, parent SQLNode) (o _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) _DBName, changedDBName := c.copyOnRewriteIdentifierCS(n.DBName, n) if changedComments || changedDBName { - changed := *n - changed.Comments, _ = _Comments.(*ParsedComments) - changed.DBName, _ = _DBName.(IdentifierCS) - out = &changed + res := *n + res.Comments, _ = _Comments.(*ParsedComments) + res.DBName, _ = _DBName.(IdentifierCS) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1638,13 +1830,17 @@ func (c *cow) copyOnRewriteRefOfDropKey(n *DropKey, parent SQLNode) (out SQLNode if c.pre == nil || c.pre(n, parent) { _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) if changedName { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1657,14 +1853,18 @@ func (c *cow) copyOnRewriteRefOfDropTable(n *DropTable, parent SQLNode) (out SQL _FromTables, changedFromTables := c.copyOnRewriteTableNames(n.FromTables, n) _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) if changedFromTables || changedComments { - changed := *n - changed.FromTables, _ = _FromTables.(TableNames) - changed.Comments, _ = _Comments.(*ParsedComments) - out = &changed + res := *n + res.FromTables, _ = _FromTables.(TableNames) + res.Comments, _ = _Comments.(*ParsedComments) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1677,14 +1877,18 @@ func (c *cow) copyOnRewriteRefOfDropView(n *DropView, parent SQLNode) (out SQLNo _FromTables, changedFromTables := c.copyOnRewriteTableNames(n.FromTables, n) _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) if changedFromTables || changedComments { - changed := *n - changed.FromTables, _ = _FromTables.(TableNames) - changed.Comments, _ = _Comments.(*ParsedComments) - out = &changed + res := *n + res.FromTables, _ = _FromTables.(TableNames) + res.Comments, _ = _Comments.(*ParsedComments) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1706,15 +1910,19 @@ func (c *cow) copyOnRewriteRefOfExecuteStmt(n *ExecuteStmt, parent SQLNode) (out } } if changedName || changedComments || changedArguments { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - changed.Comments, _ = _Comments.(*ParsedComments) - changed.Arguments = _Arguments - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + res.Comments, _ = _Comments.(*ParsedComments) + res.Arguments = _Arguments + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1726,13 +1934,17 @@ func (c *cow) copyOnRewriteRefOfExistsExpr(n *ExistsExpr, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { _Subquery, changedSubquery := c.copyOnRewriteRefOfSubquery(n.Subquery, n) if changedSubquery { - changed := *n - changed.Subquery, _ = _Subquery.(*Subquery) - out = &changed + res := *n + res.Subquery, _ = _Subquery.(*Subquery) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1745,14 +1957,18 @@ func (c *cow) copyOnRewriteRefOfExplainStmt(n *ExplainStmt, parent SQLNode) (out _Statement, changedStatement := c.copyOnRewriteStatement(n.Statement, n) _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) if changedStatement || changedComments { - changed := *n - changed.Statement, _ = _Statement.(Statement) - changed.Comments, _ = _Comments.(*ParsedComments) - out = &changed + res := *n + res.Statement, _ = _Statement.(Statement) + res.Comments, _ = _Comments.(*ParsedComments) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1764,13 +1980,17 @@ func (c *cow) copyOnRewriteRefOfExplainTab(n *ExplainTab, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) if changedTable { - changed := *n - changed.Table, _ = _Table.(TableName) - out = &changed + res := *n + res.Table, _ = _Table.(TableName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1793,7 +2013,7 @@ func (c *cow) copyOnRewriteExprs(n Exprs, parent SQLNode) (out SQLNode, changed } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1805,13 +2025,17 @@ func (c *cow) copyOnRewriteRefOfExtractFuncExpr(n *ExtractFuncExpr, parent SQLNo if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1824,14 +2048,18 @@ func (c *cow) copyOnRewriteRefOfExtractValueExpr(n *ExtractValueExpr, parent SQL _Fragment, changedFragment := c.copyOnRewriteExpr(n.Fragment, n) _XPathExpr, changedXPathExpr := c.copyOnRewriteExpr(n.XPathExpr, n) if changedFragment || changedXPathExpr { - changed := *n - changed.Fragment, _ = _Fragment.(Expr) - changed.XPathExpr, _ = _XPathExpr.(Expr) - out = &changed + res := *n + res.Fragment, _ = _Fragment.(Expr) + res.XPathExpr, _ = _XPathExpr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1846,16 +2074,20 @@ func (c *cow) copyOnRewriteRefOfExtractedSubquery(n *ExtractedSubquery, parent S _OtherSide, changedOtherSide := c.copyOnRewriteExpr(n.OtherSide, n) _alternative, changedalternative := c.copyOnRewriteExpr(n.alternative, n) if changedOriginal || changedSubquery || changedOtherSide || changedalternative { - changed := *n - changed.Original, _ = _Original.(Expr) - changed.Subquery, _ = _Subquery.(*Subquery) - changed.OtherSide, _ = _OtherSide.(Expr) - changed.alternative, _ = _alternative.(Expr) - out = &changed + res := *n + res.Original, _ = _Original.(Expr) + res.Subquery, _ = _Subquery.(*Subquery) + res.OtherSide, _ = _OtherSide.(Expr) + res.alternative, _ = _alternative.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1869,15 +2101,19 @@ func (c *cow) copyOnRewriteRefOfFirstOrLastValueExpr(n *FirstOrLastValueExpr, pa _NullTreatmentClause, changedNullTreatmentClause := c.copyOnRewriteRefOfNullTreatmentClause(n.NullTreatmentClause, n) _OverClause, changedOverClause := c.copyOnRewriteRefOfOverClause(n.OverClause, n) if changedExpr || changedNullTreatmentClause || changedOverClause { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.NullTreatmentClause, _ = _NullTreatmentClause.(*NullTreatmentClause) - changed.OverClause, _ = _OverClause.(*OverClause) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.NullTreatmentClause, _ = _NullTreatmentClause.(*NullTreatmentClause) + res.OverClause, _ = _OverClause.(*OverClause) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1889,13 +2125,17 @@ func (c *cow) copyOnRewriteRefOfFlush(n *Flush, parent SQLNode) (out SQLNode, ch if c.pre == nil || c.pre(n, parent) { _TableNames, changedTableNames := c.copyOnRewriteTableNames(n.TableNames, n) if changedTableNames { - changed := *n - changed.TableNames, _ = _TableNames.(TableNames) - out = &changed + res := *n + res.TableNames, _ = _TableNames.(TableNames) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1907,7 +2147,7 @@ func (c *cow) copyOnRewriteRefOfForce(n *Force, parent SQLNode) (out SQLNode, ch if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1921,15 +2161,19 @@ func (c *cow) copyOnRewriteRefOfForeignKeyDefinition(n *ForeignKeyDefinition, pa _IndexName, changedIndexName := c.copyOnRewriteIdentifierCI(n.IndexName, n) _ReferenceDefinition, changedReferenceDefinition := c.copyOnRewriteRefOfReferenceDefinition(n.ReferenceDefinition, n) if changedSource || changedIndexName || changedReferenceDefinition { - changed := *n - changed.Source, _ = _Source.(Columns) - changed.IndexName, _ = _IndexName.(IdentifierCI) - changed.ReferenceDefinition, _ = _ReferenceDefinition.(*ReferenceDefinition) - out = &changed + res := *n + res.Source, _ = _Source.(Columns) + res.IndexName, _ = _IndexName.(IdentifierCI) + res.ReferenceDefinition, _ = _ReferenceDefinition.(*ReferenceDefinition) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1942,14 +2186,18 @@ func (c *cow) copyOnRewriteRefOfFrameClause(n *FrameClause, parent SQLNode) (out _Start, changedStart := c.copyOnRewriteRefOfFramePoint(n.Start, n) _End, changedEnd := c.copyOnRewriteRefOfFramePoint(n.End, n) if changedStart || changedEnd { - changed := *n - changed.Start, _ = _Start.(*FramePoint) - changed.End, _ = _End.(*FramePoint) - out = &changed + res := *n + res.Start, _ = _Start.(*FramePoint) + res.End, _ = _End.(*FramePoint) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1961,13 +2209,17 @@ func (c *cow) copyOnRewriteRefOfFramePoint(n *FramePoint, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1979,7 +2231,7 @@ func (c *cow) copyOnRewriteRefOfFromFirstLastClause(n *FromFirstLastClause, pare if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -1993,15 +2245,19 @@ func (c *cow) copyOnRewriteRefOfFuncExpr(n *FuncExpr, parent SQLNode) (out SQLNo _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) _Exprs, changedExprs := c.copyOnRewriteSelectExprs(n.Exprs, n) if changedQualifier || changedName || changedExprs { - changed := *n - changed.Qualifier, _ = _Qualifier.(IdentifierCS) - changed.Name, _ = _Name.(IdentifierCI) - changed.Exprs, _ = _Exprs.(SelectExprs) - out = &changed + res := *n + res.Qualifier, _ = _Qualifier.(IdentifierCS) + res.Name, _ = _Name.(IdentifierCI) + res.Exprs, _ = _Exprs.(SelectExprs) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2016,16 +2272,20 @@ func (c *cow) copyOnRewriteRefOfGTIDFuncExpr(n *GTIDFuncExpr, parent SQLNode) (o _Timeout, changedTimeout := c.copyOnRewriteExpr(n.Timeout, n) _Channel, changedChannel := c.copyOnRewriteExpr(n.Channel, n) if changedSet1 || changedSet2 || changedTimeout || changedChannel { - changed := *n - changed.Set1, _ = _Set1.(Expr) - changed.Set2, _ = _Set2.(Expr) - changed.Timeout, _ = _Timeout.(Expr) - changed.Channel, _ = _Channel.(Expr) - out = &changed + res := *n + res.Set1, _ = _Set1.(Expr) + res.Set2, _ = _Set2.(Expr) + res.Timeout, _ = _Timeout.(Expr) + res.Channel, _ = _Channel.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2048,7 +2308,7 @@ func (c *cow) copyOnRewriteGroupBy(n GroupBy, parent SQLNode) (out SQLNode, chan } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2062,15 +2322,19 @@ func (c *cow) copyOnRewriteRefOfGroupConcatExpr(n *GroupConcatExpr, parent SQLNo _OrderBy, changedOrderBy := c.copyOnRewriteOrderBy(n.OrderBy, n) _Limit, changedLimit := c.copyOnRewriteRefOfLimit(n.Limit, n) if changedExprs || changedOrderBy || changedLimit { - changed := *n - changed.Exprs, _ = _Exprs.(Exprs) - changed.OrderBy, _ = _OrderBy.(OrderBy) - changed.Limit, _ = _Limit.(*Limit) - out = &changed + res := *n + res.Exprs, _ = _Exprs.(Exprs) + res.OrderBy, _ = _OrderBy.(OrderBy) + res.Limit, _ = _Limit.(*Limit) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2079,7 +2343,7 @@ func (c *cow) copyOnRewriteIdentifierCI(n IdentifierCI, parent SQLNode) (out SQL if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2088,7 +2352,7 @@ func (c *cow) copyOnRewriteIdentifierCS(n IdentifierCS, parent SQLNode) (out SQL if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2100,13 +2364,17 @@ func (c *cow) copyOnRewriteRefOfIndexDefinition(n *IndexDefinition, parent SQLNo if c.pre == nil || c.pre(n, parent) { _Info, changedInfo := c.copyOnRewriteRefOfIndexInfo(n.Info, n) if changedInfo { - changed := *n - changed.Info, _ = _Info.(*IndexInfo) - out = &changed + res := *n + res.Info, _ = _Info.(*IndexInfo) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2126,13 +2394,17 @@ func (c *cow) copyOnRewriteRefOfIndexHint(n *IndexHint, parent SQLNode) (out SQL } } if changedIndexes { - changed := *n - changed.Indexes = _Indexes - out = &changed + res := *n + res.Indexes = _Indexes + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2155,7 +2427,7 @@ func (c *cow) copyOnRewriteIndexHints(n IndexHints, parent SQLNode) (out SQLNode } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2168,14 +2440,18 @@ func (c *cow) copyOnRewriteRefOfIndexInfo(n *IndexInfo, parent SQLNode) (out SQL _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) _ConstraintName, changedConstraintName := c.copyOnRewriteIdentifierCI(n.ConstraintName, n) if changedName || changedConstraintName { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - changed.ConstraintName, _ = _ConstraintName.(IdentifierCI) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + res.ConstraintName, _ = _ConstraintName.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2192,18 +2468,22 @@ func (c *cow) copyOnRewriteRefOfInsert(n *Insert, parent SQLNode) (out SQLNode, _Rows, changedRows := c.copyOnRewriteInsertRows(n.Rows, n) _OnDup, changedOnDup := c.copyOnRewriteOnDup(n.OnDup, n) if changedComments || changedTable || changedPartitions || changedColumns || changedRows || changedOnDup { - changed := *n - changed.Comments, _ = _Comments.(*ParsedComments) - changed.Table, _ = _Table.(TableName) - changed.Partitions, _ = _Partitions.(Partitions) - changed.Columns, _ = _Columns.(Columns) - changed.Rows, _ = _Rows.(InsertRows) - changed.OnDup, _ = _OnDup.(OnDup) - out = &changed + res := *n + res.Comments, _ = _Comments.(*ParsedComments) + res.Table, _ = _Table.(TableName) + res.Partitions, _ = _Partitions.(Partitions) + res.Columns, _ = _Columns.(Columns) + res.Rows, _ = _Rows.(InsertRows) + res.OnDup, _ = _OnDup.(OnDup) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2218,16 +2498,20 @@ func (c *cow) copyOnRewriteRefOfInsertExpr(n *InsertExpr, parent SQLNode) (out S _Len, changedLen := c.copyOnRewriteExpr(n.Len, n) _NewStr, changedNewStr := c.copyOnRewriteExpr(n.NewStr, n) if changedStr || changedPos || changedLen || changedNewStr { - changed := *n - changed.Str, _ = _Str.(Expr) - changed.Pos, _ = _Pos.(Expr) - changed.Len, _ = _Len.(Expr) - changed.NewStr, _ = _NewStr.(Expr) - out = &changed + res := *n + res.Str, _ = _Str.(Expr) + res.Pos, _ = _Pos.(Expr) + res.Len, _ = _Len.(Expr) + res.NewStr, _ = _NewStr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2239,13 +2523,17 @@ func (c *cow) copyOnRewriteRefOfIntervalExpr(n *IntervalExpr, parent SQLNode) (o if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2258,14 +2546,18 @@ func (c *cow) copyOnRewriteRefOfIntervalFuncExpr(n *IntervalFuncExpr, parent SQL _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) _Exprs, changedExprs := c.copyOnRewriteExprs(n.Exprs, n) if changedExpr || changedExprs { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.Exprs, _ = _Exprs.(Exprs) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.Exprs, _ = _Exprs.(Exprs) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2277,13 +2569,17 @@ func (c *cow) copyOnRewriteRefOfIntroducerExpr(n *IntroducerExpr, parent SQLNode if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2295,13 +2591,17 @@ func (c *cow) copyOnRewriteRefOfIsExpr(n *IsExpr, parent SQLNode) (out SQLNode, if c.pre == nil || c.pre(n, parent) { _Left, changedLeft := c.copyOnRewriteExpr(n.Left, n) if changedLeft { - changed := *n - changed.Left, _ = _Left.(Expr) - out = &changed + res := *n + res.Left, _ = _Left.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2313,13 +2613,17 @@ func (c *cow) copyOnRewriteRefOfJSONArrayExpr(n *JSONArrayExpr, parent SQLNode) if c.pre == nil || c.pre(n, parent) { _Params, changedParams := c.copyOnRewriteExprs(n.Params, n) if changedParams { - changed := *n - changed.Params, _ = _Params.(Exprs) - out = &changed + res := *n + res.Params, _ = _Params.(Exprs) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2332,14 +2636,18 @@ func (c *cow) copyOnRewriteRefOfJSONAttributesExpr(n *JSONAttributesExpr, parent _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) _Path, changedPath := c.copyOnRewriteExpr(n.Path, n) if changedJSONDoc || changedPath { - changed := *n - changed.JSONDoc, _ = _JSONDoc.(Expr) - changed.Path, _ = _Path.(Expr) - out = &changed + res := *n + res.JSONDoc, _ = _JSONDoc.(Expr) + res.Path, _ = _Path.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2361,15 +2669,19 @@ func (c *cow) copyOnRewriteRefOfJSONContainsExpr(n *JSONContainsExpr, parent SQL } } if changedTarget || changedCandidate || changedPathList { - changed := *n - changed.Target, _ = _Target.(Expr) - changed.Candidate, _ = _Candidate.(Expr) - changed.PathList = _PathList - out = &changed + res := *n + res.Target, _ = _Target.(Expr) + res.Candidate, _ = _Candidate.(Expr) + res.PathList = _PathList + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2391,15 +2703,19 @@ func (c *cow) copyOnRewriteRefOfJSONContainsPathExpr(n *JSONContainsPathExpr, pa } } if changedJSONDoc || changedOneOrAll || changedPathList { - changed := *n - changed.JSONDoc, _ = _JSONDoc.(Expr) - changed.OneOrAll, _ = _OneOrAll.(Expr) - changed.PathList = _PathList - out = &changed + res := *n + res.JSONDoc, _ = _JSONDoc.(Expr) + res.OneOrAll, _ = _OneOrAll.(Expr) + res.PathList = _PathList + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2420,14 +2736,18 @@ func (c *cow) copyOnRewriteRefOfJSONExtractExpr(n *JSONExtractExpr, parent SQLNo } } if changedJSONDoc || changedPathList { - changed := *n - changed.JSONDoc, _ = _JSONDoc.(Expr) - changed.PathList = _PathList - out = &changed + res := *n + res.JSONDoc, _ = _JSONDoc.(Expr) + res.PathList = _PathList + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2440,14 +2760,18 @@ func (c *cow) copyOnRewriteRefOfJSONKeysExpr(n *JSONKeysExpr, parent SQLNode) (o _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) _Path, changedPath := c.copyOnRewriteExpr(n.Path, n) if changedJSONDoc || changedPath { - changed := *n - changed.JSONDoc, _ = _JSONDoc.(Expr) - changed.Path, _ = _Path.(Expr) - out = &changed + res := *n + res.JSONDoc, _ = _JSONDoc.(Expr) + res.Path, _ = _Path.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2467,13 +2791,17 @@ func (c *cow) copyOnRewriteRefOfJSONObjectExpr(n *JSONObjectExpr, parent SQLNode } } if changedParams { - changed := *n - changed.Params = _Params - out = &changed + res := *n + res.Params = _Params + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2486,14 +2814,18 @@ func (c *cow) copyOnRewriteRefOfJSONObjectParam(n *JSONObjectParam, parent SQLNo _Key, changedKey := c.copyOnRewriteExpr(n.Key, n) _Value, changedValue := c.copyOnRewriteExpr(n.Value, n) if changedKey || changedValue { - changed := *n - changed.Key, _ = _Key.(Expr) - changed.Value, _ = _Value.(Expr) - out = &changed + res := *n + res.Key, _ = _Key.(Expr) + res.Value, _ = _Value.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2506,14 +2838,18 @@ func (c *cow) copyOnRewriteRefOfJSONOverlapsExpr(n *JSONOverlapsExpr, parent SQL _JSONDoc1, changedJSONDoc1 := c.copyOnRewriteExpr(n.JSONDoc1, n) _JSONDoc2, changedJSONDoc2 := c.copyOnRewriteExpr(n.JSONDoc2, n) if changedJSONDoc1 || changedJSONDoc2 { - changed := *n - changed.JSONDoc1, _ = _JSONDoc1.(Expr) - changed.JSONDoc2, _ = _JSONDoc2.(Expr) - out = &changed + res := *n + res.JSONDoc1, _ = _JSONDoc1.(Expr) + res.JSONDoc2, _ = _JSONDoc2.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2525,13 +2861,17 @@ func (c *cow) copyOnRewriteRefOfJSONPrettyExpr(n *JSONPrettyExpr, parent SQLNode if c.pre == nil || c.pre(n, parent) { _JSONVal, changedJSONVal := c.copyOnRewriteExpr(n.JSONVal, n) if changedJSONVal { - changed := *n - changed.JSONVal, _ = _JSONVal.(Expr) - out = &changed + res := *n + res.JSONVal, _ = _JSONVal.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2543,13 +2883,17 @@ func (c *cow) copyOnRewriteRefOfJSONQuoteExpr(n *JSONQuoteExpr, parent SQLNode) if c.pre == nil || c.pre(n, parent) { _StringArg, changedStringArg := c.copyOnRewriteExpr(n.StringArg, n) if changedStringArg { - changed := *n - changed.StringArg, _ = _StringArg.(Expr) - out = &changed + res := *n + res.StringArg, _ = _StringArg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2562,14 +2906,18 @@ func (c *cow) copyOnRewriteRefOfJSONRemoveExpr(n *JSONRemoveExpr, parent SQLNode _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) _PathList, changedPathList := c.copyOnRewriteExprs(n.PathList, n) if changedJSONDoc || changedPathList { - changed := *n - changed.JSONDoc, _ = _JSONDoc.(Expr) - changed.PathList, _ = _PathList.(Exprs) - out = &changed + res := *n + res.JSONDoc, _ = _JSONDoc.(Expr) + res.PathList, _ = _PathList.(Exprs) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2582,14 +2930,18 @@ func (c *cow) copyOnRewriteRefOfJSONSchemaValidFuncExpr(n *JSONSchemaValidFuncEx _Schema, changedSchema := c.copyOnRewriteExpr(n.Schema, n) _Document, changedDocument := c.copyOnRewriteExpr(n.Document, n) if changedSchema || changedDocument { - changed := *n - changed.Schema, _ = _Schema.(Expr) - changed.Document, _ = _Document.(Expr) - out = &changed + res := *n + res.Schema, _ = _Schema.(Expr) + res.Document, _ = _Document.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2602,14 +2954,18 @@ func (c *cow) copyOnRewriteRefOfJSONSchemaValidationReportFuncExpr(n *JSONSchema _Schema, changedSchema := c.copyOnRewriteExpr(n.Schema, n) _Document, changedDocument := c.copyOnRewriteExpr(n.Document, n) if changedSchema || changedDocument { - changed := *n - changed.Schema, _ = _Schema.(Expr) - changed.Document, _ = _Document.(Expr) - out = &changed + res := *n + res.Schema, _ = _Schema.(Expr) + res.Document, _ = _Document.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2633,17 +2989,21 @@ func (c *cow) copyOnRewriteRefOfJSONSearchExpr(n *JSONSearchExpr, parent SQLNode } } if changedJSONDoc || changedOneOrAll || changedSearchStr || changedEscapeChar || changedPathList { - changed := *n - changed.JSONDoc, _ = _JSONDoc.(Expr) - changed.OneOrAll, _ = _OneOrAll.(Expr) - changed.SearchStr, _ = _SearchStr.(Expr) - changed.EscapeChar, _ = _EscapeChar.(Expr) - changed.PathList = _PathList - out = &changed + res := *n + res.JSONDoc, _ = _JSONDoc.(Expr) + res.OneOrAll, _ = _OneOrAll.(Expr) + res.SearchStr, _ = _SearchStr.(Expr) + res.EscapeChar, _ = _EscapeChar.(Expr) + res.PathList = _PathList + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2655,13 +3015,17 @@ func (c *cow) copyOnRewriteRefOfJSONStorageFreeExpr(n *JSONStorageFreeExpr, pare if c.pre == nil || c.pre(n, parent) { _JSONVal, changedJSONVal := c.copyOnRewriteExpr(n.JSONVal, n) if changedJSONVal { - changed := *n - changed.JSONVal, _ = _JSONVal.(Expr) - out = &changed + res := *n + res.JSONVal, _ = _JSONVal.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2673,13 +3037,17 @@ func (c *cow) copyOnRewriteRefOfJSONStorageSizeExpr(n *JSONStorageSizeExpr, pare if c.pre == nil || c.pre(n, parent) { _JSONVal, changedJSONVal := c.copyOnRewriteExpr(n.JSONVal, n) if changedJSONVal { - changed := *n - changed.JSONVal, _ = _JSONVal.(Expr) - out = &changed + res := *n + res.JSONVal, _ = _JSONVal.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2702,16 +3070,20 @@ func (c *cow) copyOnRewriteRefOfJSONTableExpr(n *JSONTableExpr, parent SQLNode) } } if changedExpr || changedAlias || changedFilter || changedColumns { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.Alias, _ = _Alias.(IdentifierCS) - changed.Filter, _ = _Filter.(Expr) - changed.Columns = _Columns - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.Alias, _ = _Alias.(IdentifierCS) + res.Filter, _ = _Filter.(Expr) + res.Columns = _Columns + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2723,13 +3095,17 @@ func (c *cow) copyOnRewriteRefOfJSONUnquoteExpr(n *JSONUnquoteExpr, parent SQLNo if c.pre == nil || c.pre(n, parent) { _JSONValue, changedJSONValue := c.copyOnRewriteExpr(n.JSONValue, n) if changedJSONValue { - changed := *n - changed.JSONValue, _ = _JSONValue.(Expr) - out = &changed + res := *n + res.JSONValue, _ = _JSONValue.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2745,17 +3121,21 @@ func (c *cow) copyOnRewriteRefOfJSONValueExpr(n *JSONValueExpr, parent SQLNode) _EmptyOnResponse, changedEmptyOnResponse := c.copyOnRewriteRefOfJtOnResponse(n.EmptyOnResponse, n) _ErrorOnResponse, changedErrorOnResponse := c.copyOnRewriteRefOfJtOnResponse(n.ErrorOnResponse, n) if changedJSONDoc || changedPath || changedReturningType || changedEmptyOnResponse || changedErrorOnResponse { - changed := *n - changed.JSONDoc, _ = _JSONDoc.(Expr) - changed.Path, _ = _Path.(Expr) - changed.ReturningType, _ = _ReturningType.(*ConvertType) - changed.EmptyOnResponse, _ = _EmptyOnResponse.(*JtOnResponse) - changed.ErrorOnResponse, _ = _ErrorOnResponse.(*JtOnResponse) - out = &changed + res := *n + res.JSONDoc, _ = _JSONDoc.(Expr) + res.Path, _ = _Path.(Expr) + res.ReturningType, _ = _ReturningType.(*ConvertType) + res.EmptyOnResponse, _ = _EmptyOnResponse.(*JtOnResponse) + res.ErrorOnResponse, _ = _ErrorOnResponse.(*JtOnResponse) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2768,14 +3148,18 @@ func (c *cow) copyOnRewriteRefOfJSONValueMergeExpr(n *JSONValueMergeExpr, parent _JSONDoc, changedJSONDoc := c.copyOnRewriteExpr(n.JSONDoc, n) _JSONDocList, changedJSONDocList := c.copyOnRewriteExprs(n.JSONDocList, n) if changedJSONDoc || changedJSONDocList { - changed := *n - changed.JSONDoc, _ = _JSONDoc.(Expr) - changed.JSONDocList, _ = _JSONDocList.(Exprs) - out = &changed + res := *n + res.JSONDoc, _ = _JSONDoc.(Expr) + res.JSONDocList, _ = _JSONDocList.(Exprs) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2796,14 +3180,18 @@ func (c *cow) copyOnRewriteRefOfJSONValueModifierExpr(n *JSONValueModifierExpr, } } if changedJSONDoc || changedParams { - changed := *n - changed.JSONDoc, _ = _JSONDoc.(Expr) - changed.Params = _Params - out = &changed + res := *n + res.JSONDoc, _ = _JSONDoc.(Expr) + res.Params = _Params + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2816,14 +3204,18 @@ func (c *cow) copyOnRewriteRefOfJoinCondition(n *JoinCondition, parent SQLNode) _On, changedOn := c.copyOnRewriteExpr(n.On, n) _Using, changedUsing := c.copyOnRewriteColumns(n.Using, n) if changedOn || changedUsing { - changed := *n - changed.On, _ = _On.(Expr) - changed.Using, _ = _Using.(Columns) - out = &changed + res := *n + res.On, _ = _On.(Expr) + res.Using, _ = _Using.(Columns) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2837,15 +3229,19 @@ func (c *cow) copyOnRewriteRefOfJoinTableExpr(n *JoinTableExpr, parent SQLNode) _RightExpr, changedRightExpr := c.copyOnRewriteTableExpr(n.RightExpr, n) _Condition, changedCondition := c.copyOnRewriteRefOfJoinCondition(n.Condition, n) if changedLeftExpr || changedRightExpr || changedCondition { - changed := *n - changed.LeftExpr, _ = _LeftExpr.(TableExpr) - changed.RightExpr, _ = _RightExpr.(TableExpr) - changed.Condition, _ = _Condition.(*JoinCondition) - out = &changed + res := *n + res.LeftExpr, _ = _LeftExpr.(TableExpr) + res.RightExpr, _ = _RightExpr.(TableExpr) + res.Condition, _ = _Condition.(*JoinCondition) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2857,7 +3253,7 @@ func (c *cow) copyOnRewriteRefOfJtColumnDefinition(n *JtColumnDefinition, parent if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2869,13 +3265,17 @@ func (c *cow) copyOnRewriteRefOfJtOnResponse(n *JtOnResponse, parent SQLNode) (o if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2887,7 +3287,7 @@ func (c *cow) copyOnRewriteRefOfKeyState(n *KeyState, parent SQLNode) (out SQLNo if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2903,17 +3303,21 @@ func (c *cow) copyOnRewriteRefOfLagLeadExpr(n *LagLeadExpr, parent SQLNode) (out _OverClause, changedOverClause := c.copyOnRewriteRefOfOverClause(n.OverClause, n) _NullTreatmentClause, changedNullTreatmentClause := c.copyOnRewriteRefOfNullTreatmentClause(n.NullTreatmentClause, n) if changedExpr || changedN || changedDefault || changedOverClause || changedNullTreatmentClause { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.N, _ = _N.(Expr) - changed.Default, _ = _Default.(Expr) - changed.OverClause, _ = _OverClause.(*OverClause) - changed.NullTreatmentClause, _ = _NullTreatmentClause.(*NullTreatmentClause) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.N, _ = _N.(Expr) + res.Default, _ = _Default.(Expr) + res.OverClause, _ = _OverClause.(*OverClause) + res.NullTreatmentClause, _ = _NullTreatmentClause.(*NullTreatmentClause) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2926,14 +3330,18 @@ func (c *cow) copyOnRewriteRefOfLimit(n *Limit, parent SQLNode) (out SQLNode, ch _Offset, changedOffset := c.copyOnRewriteExpr(n.Offset, n) _Rowcount, changedRowcount := c.copyOnRewriteExpr(n.Rowcount, n) if changedOffset || changedRowcount { - changed := *n - changed.Offset, _ = _Offset.(Expr) - changed.Rowcount, _ = _Rowcount.(Expr) - out = &changed + res := *n + res.Offset, _ = _Offset.(Expr) + res.Rowcount, _ = _Rowcount.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2945,7 +3353,7 @@ func (c *cow) copyOnRewriteRefOfLiteral(n *Literal, parent SQLNode) (out SQLNode if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2957,7 +3365,7 @@ func (c *cow) copyOnRewriteRefOfLoad(n *Load, parent SQLNode) (out SQLNode, chan if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2971,15 +3379,19 @@ func (c *cow) copyOnRewriteRefOfLocateExpr(n *LocateExpr, parent SQLNode) (out S _Str, changedStr := c.copyOnRewriteExpr(n.Str, n) _Pos, changedPos := c.copyOnRewriteExpr(n.Pos, n) if changedSubStr || changedStr || changedPos { - changed := *n - changed.SubStr, _ = _SubStr.(Expr) - changed.Str, _ = _Str.(Expr) - changed.Pos, _ = _Pos.(Expr) - out = &changed + res := *n + res.SubStr, _ = _SubStr.(Expr) + res.Str, _ = _Str.(Expr) + res.Pos, _ = _Pos.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -2991,7 +3403,7 @@ func (c *cow) copyOnRewriteRefOfLockOption(n *LockOption, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3003,7 +3415,7 @@ func (c *cow) copyOnRewriteRefOfLockTables(n *LockTables, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3016,14 +3428,18 @@ func (c *cow) copyOnRewriteRefOfLockingFunc(n *LockingFunc, parent SQLNode) (out _Name, changedName := c.copyOnRewriteExpr(n.Name, n) _Timeout, changedTimeout := c.copyOnRewriteExpr(n.Timeout, n) if changedName || changedTimeout { - changed := *n - changed.Name, _ = _Name.(Expr) - changed.Timeout, _ = _Timeout.(Expr) - out = &changed + res := *n + res.Name, _ = _Name.(Expr) + res.Timeout, _ = _Timeout.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3044,14 +3460,18 @@ func (c *cow) copyOnRewriteRefOfMatchExpr(n *MatchExpr, parent SQLNode) (out SQL } _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedColumns || changedExpr { - changed := *n - changed.Columns = _Columns - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Columns = _Columns + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3063,13 +3483,17 @@ func (c *cow) copyOnRewriteRefOfMax(n *Max, parent SQLNode) (out SQLNode, change if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3082,14 +3506,18 @@ func (c *cow) copyOnRewriteRefOfMemberOfExpr(n *MemberOfExpr, parent SQLNode) (o _Value, changedValue := c.copyOnRewriteExpr(n.Value, n) _JSONArr, changedJSONArr := c.copyOnRewriteExpr(n.JSONArr, n) if changedValue || changedJSONArr { - changed := *n - changed.Value, _ = _Value.(Expr) - changed.JSONArr, _ = _JSONArr.(Expr) - out = &changed + res := *n + res.Value, _ = _Value.(Expr) + res.JSONArr, _ = _JSONArr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3101,13 +3529,17 @@ func (c *cow) copyOnRewriteRefOfMin(n *Min, parent SQLNode) (out SQLNode, change if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3120,14 +3552,18 @@ func (c *cow) copyOnRewriteRefOfModifyColumn(n *ModifyColumn, parent SQLNode) (o _NewColDefinition, changedNewColDefinition := c.copyOnRewriteRefOfColumnDefinition(n.NewColDefinition, n) _After, changedAfter := c.copyOnRewriteRefOfColName(n.After, n) if changedNewColDefinition || changedAfter { - changed := *n - changed.NewColDefinition, _ = _NewColDefinition.(*ColumnDefinition) - changed.After, _ = _After.(*ColName) - out = &changed + res := *n + res.NewColDefinition, _ = _NewColDefinition.(*ColumnDefinition) + res.After, _ = _After.(*ColName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3143,17 +3579,21 @@ func (c *cow) copyOnRewriteRefOfNTHValueExpr(n *NTHValueExpr, parent SQLNode) (o _FromFirstLastClause, changedFromFirstLastClause := c.copyOnRewriteRefOfFromFirstLastClause(n.FromFirstLastClause, n) _NullTreatmentClause, changedNullTreatmentClause := c.copyOnRewriteRefOfNullTreatmentClause(n.NullTreatmentClause, n) if changedExpr || changedN || changedOverClause || changedFromFirstLastClause || changedNullTreatmentClause { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.N, _ = _N.(Expr) - changed.OverClause, _ = _OverClause.(*OverClause) - changed.FromFirstLastClause, _ = _FromFirstLastClause.(*FromFirstLastClause) - changed.NullTreatmentClause, _ = _NullTreatmentClause.(*NullTreatmentClause) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.N, _ = _N.(Expr) + res.OverClause, _ = _OverClause.(*OverClause) + res.FromFirstLastClause, _ = _FromFirstLastClause.(*FromFirstLastClause) + res.NullTreatmentClause, _ = _NullTreatmentClause.(*NullTreatmentClause) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3165,13 +3605,17 @@ func (c *cow) copyOnRewriteRefOfNamedWindow(n *NamedWindow, parent SQLNode) (out if c.pre == nil || c.pre(n, parent) { _Windows, changedWindows := c.copyOnRewriteWindowDefinitions(n.Windows, n) if changedWindows { - changed := *n - changed.Windows, _ = _Windows.(WindowDefinitions) - out = &changed + res := *n + res.Windows, _ = _Windows.(WindowDefinitions) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3194,7 +3638,7 @@ func (c *cow) copyOnRewriteNamedWindows(n NamedWindows, parent SQLNode) (out SQL } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3206,13 +3650,17 @@ func (c *cow) copyOnRewriteRefOfNextval(n *Nextval, parent SQLNode) (out SQLNode if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3224,13 +3672,17 @@ func (c *cow) copyOnRewriteRefOfNotExpr(n *NotExpr, parent SQLNode) (out SQLNode if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3243,14 +3695,18 @@ func (c *cow) copyOnRewriteRefOfNtileExpr(n *NtileExpr, parent SQLNode) (out SQL _N, changedN := c.copyOnRewriteExpr(n.N, n) _OverClause, changedOverClause := c.copyOnRewriteRefOfOverClause(n.OverClause, n) if changedN || changedOverClause { - changed := *n - changed.N, _ = _N.(Expr) - changed.OverClause, _ = _OverClause.(*OverClause) - out = &changed + res := *n + res.N, _ = _N.(Expr) + res.OverClause, _ = _OverClause.(*OverClause) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3262,7 +3718,7 @@ func (c *cow) copyOnRewriteRefOfNullTreatmentClause(n *NullTreatmentClause, pare if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3274,7 +3730,7 @@ func (c *cow) copyOnRewriteRefOfNullVal(n *NullVal, parent SQLNode) (out SQLNode if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3286,7 +3742,7 @@ func (c *cow) copyOnRewriteRefOfOffset(n *Offset, parent SQLNode) (out SQLNode, if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3309,7 +3765,7 @@ func (c *cow) copyOnRewriteOnDup(n OnDup, parent SQLNode) (out SQLNode, changed } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3321,13 +3777,17 @@ func (c *cow) copyOnRewriteRefOfOptLike(n *OptLike, parent SQLNode) (out SQLNode if c.pre == nil || c.pre(n, parent) { _LikeTable, changedLikeTable := c.copyOnRewriteTableName(n.LikeTable, n) if changedLikeTable { - changed := *n - changed.LikeTable, _ = _LikeTable.(TableName) - out = &changed + res := *n + res.LikeTable, _ = _LikeTable.(TableName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3340,14 +3800,18 @@ func (c *cow) copyOnRewriteRefOfOrExpr(n *OrExpr, parent SQLNode) (out SQLNode, _Left, changedLeft := c.copyOnRewriteExpr(n.Left, n) _Right, changedRight := c.copyOnRewriteExpr(n.Right, n) if changedLeft || changedRight { - changed := *n - changed.Left, _ = _Left.(Expr) - changed.Right, _ = _Right.(Expr) - out = &changed + res := *n + res.Left, _ = _Left.(Expr) + res.Right, _ = _Right.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3359,13 +3823,17 @@ func (c *cow) copyOnRewriteRefOfOrder(n *Order, parent SQLNode) (out SQLNode, ch if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3388,7 +3856,7 @@ func (c *cow) copyOnRewriteOrderBy(n OrderBy, parent SQLNode) (out SQLNode, chan } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3400,13 +3868,17 @@ func (c *cow) copyOnRewriteRefOfOrderByOption(n *OrderByOption, parent SQLNode) if c.pre == nil || c.pre(n, parent) { _Cols, changedCols := c.copyOnRewriteColumns(n.Cols, n) if changedCols { - changed := *n - changed.Cols, _ = _Cols.(Columns) - out = &changed + res := *n + res.Cols, _ = _Cols.(Columns) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3418,7 +3890,7 @@ func (c *cow) copyOnRewriteRefOfOtherAdmin(n *OtherAdmin, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3430,7 +3902,7 @@ func (c *cow) copyOnRewriteRefOfOtherRead(n *OtherRead, parent SQLNode) (out SQL if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3443,14 +3915,18 @@ func (c *cow) copyOnRewriteRefOfOverClause(n *OverClause, parent SQLNode) (out S _WindowName, changedWindowName := c.copyOnRewriteIdentifierCI(n.WindowName, n) _WindowSpec, changedWindowSpec := c.copyOnRewriteRefOfWindowSpecification(n.WindowSpec, n) if changedWindowName || changedWindowSpec { - changed := *n - changed.WindowName, _ = _WindowName.(IdentifierCI) - changed.WindowSpec, _ = _WindowSpec.(*WindowSpecification) - out = &changed + res := *n + res.WindowName, _ = _WindowName.(IdentifierCI) + res.WindowSpec, _ = _WindowSpec.(*WindowSpecification) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3462,13 +3938,17 @@ func (c *cow) copyOnRewriteRefOfParenTableExpr(n *ParenTableExpr, parent SQLNode if c.pre == nil || c.pre(n, parent) { _Exprs, changedExprs := c.copyOnRewriteTableExprs(n.Exprs, n) if changedExprs { - changed := *n - changed.Exprs, _ = _Exprs.(TableExprs) - out = &changed + res := *n + res.Exprs, _ = _Exprs.(TableExprs) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3480,7 +3960,7 @@ func (c *cow) copyOnRewriteRefOfParsedComments(n *ParsedComments, parent SQLNode if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3493,14 +3973,18 @@ func (c *cow) copyOnRewriteRefOfPartitionDefinition(n *PartitionDefinition, pare _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) _Options, changedOptions := c.copyOnRewriteRefOfPartitionDefinitionOptions(n.Options, n) if changedName || changedOptions { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - changed.Options, _ = _Options.(*PartitionDefinitionOptions) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + res.Options, _ = _Options.(*PartitionDefinitionOptions) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3517,18 +4001,22 @@ func (c *cow) copyOnRewriteRefOfPartitionDefinitionOptions(n *PartitionDefinitio _IndexDirectory, changedIndexDirectory := c.copyOnRewriteRefOfLiteral(n.IndexDirectory, n) _SubPartitionDefinitions, changedSubPartitionDefinitions := c.copyOnRewriteSubPartitionDefinitions(n.SubPartitionDefinitions, n) if changedValueRange || changedComment || changedEngine || changedDataDirectory || changedIndexDirectory || changedSubPartitionDefinitions { - changed := *n - changed.ValueRange, _ = _ValueRange.(*PartitionValueRange) - changed.Comment, _ = _Comment.(*Literal) - changed.Engine, _ = _Engine.(*PartitionEngine) - changed.DataDirectory, _ = _DataDirectory.(*Literal) - changed.IndexDirectory, _ = _IndexDirectory.(*Literal) - changed.SubPartitionDefinitions, _ = _SubPartitionDefinitions.(SubPartitionDefinitions) - out = &changed + res := *n + res.ValueRange, _ = _ValueRange.(*PartitionValueRange) + res.Comment, _ = _Comment.(*Literal) + res.Engine, _ = _Engine.(*PartitionEngine) + res.DataDirectory, _ = _DataDirectory.(*Literal) + res.IndexDirectory, _ = _IndexDirectory.(*Literal) + res.SubPartitionDefinitions, _ = _SubPartitionDefinitions.(SubPartitionDefinitions) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3540,7 +4028,7 @@ func (c *cow) copyOnRewriteRefOfPartitionEngine(n *PartitionEngine, parent SQLNo if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3563,16 +4051,20 @@ func (c *cow) copyOnRewriteRefOfPartitionOption(n *PartitionOption, parent SQLNo } } if changedColList || changedExpr || changedSubPartition || changedDefinitions { - changed := *n - changed.ColList, _ = _ColList.(Columns) - changed.Expr, _ = _Expr.(Expr) - changed.SubPartition, _ = _SubPartition.(*SubPartition) - changed.Definitions = _Definitions - out = &changed + res := *n + res.ColList, _ = _ColList.(Columns) + res.Expr, _ = _Expr.(Expr) + res.SubPartition, _ = _SubPartition.(*SubPartition) + res.Definitions = _Definitions + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3595,16 +4087,20 @@ func (c *cow) copyOnRewriteRefOfPartitionSpec(n *PartitionSpec, parent SQLNode) } } if changedNames || changedNumber || changedTableName || changedDefinitions { - changed := *n - changed.Names, _ = _Names.(Partitions) - changed.Number, _ = _Number.(*Literal) - changed.TableName, _ = _TableName.(TableName) - changed.Definitions = _Definitions - out = &changed + res := *n + res.Names, _ = _Names.(Partitions) + res.Number, _ = _Number.(*Literal) + res.TableName, _ = _TableName.(TableName) + res.Definitions = _Definitions + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3616,13 +4112,17 @@ func (c *cow) copyOnRewriteRefOfPartitionValueRange(n *PartitionValueRange, pare if c.pre == nil || c.pre(n, parent) { _Range, changedRange := c.copyOnRewriteValTuple(n.Range, n) if changedRange { - changed := *n - changed.Range, _ = _Range.(ValTuple) - out = &changed + res := *n + res.Range, _ = _Range.(ValTuple) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3645,7 +4145,7 @@ func (c *cow) copyOnRewritePartitions(n Partitions, parent SQLNode) (out SQLNode } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3657,13 +4157,17 @@ func (c *cow) copyOnRewriteRefOfPerformanceSchemaFuncExpr(n *PerformanceSchemaFu if c.pre == nil || c.pre(n, parent) { _Argument, changedArgument := c.copyOnRewriteExpr(n.Argument, n) if changedArgument { - changed := *n - changed.Argument, _ = _Argument.(Expr) - out = &changed + res := *n + res.Argument, _ = _Argument.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3677,15 +4181,19 @@ func (c *cow) copyOnRewriteRefOfPrepareStmt(n *PrepareStmt, parent SQLNode) (out _Statement, changedStatement := c.copyOnRewriteExpr(n.Statement, n) _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) if changedName || changedStatement || changedComments { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - changed.Statement, _ = _Statement.(Expr) - changed.Comments, _ = _Comments.(*ParsedComments) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + res.Statement, _ = _Statement.(Expr) + res.Comments, _ = _Comments.(*ParsedComments) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3701,17 +4209,21 @@ func (c *cow) copyOnRewriteRefOfReferenceDefinition(n *ReferenceDefinition, pare _OnDelete, changedOnDelete := c.copyOnRewriteReferenceAction(n.OnDelete, n) _OnUpdate, changedOnUpdate := c.copyOnRewriteReferenceAction(n.OnUpdate, n) if changedReferencedTable || changedReferencedColumns || changedMatch || changedOnDelete || changedOnUpdate { - changed := *n - changed.ReferencedTable, _ = _ReferencedTable.(TableName) - changed.ReferencedColumns, _ = _ReferencedColumns.(Columns) - changed.Match, _ = _Match.(MatchAction) - changed.OnDelete, _ = _OnDelete.(ReferenceAction) - changed.OnUpdate, _ = _OnUpdate.(ReferenceAction) - out = &changed + res := *n + res.ReferencedTable, _ = _ReferencedTable.(TableName) + res.ReferencedColumns, _ = _ReferencedColumns.(Columns) + res.Match, _ = _Match.(MatchAction) + res.OnDelete, _ = _OnDelete.(ReferenceAction) + res.OnUpdate, _ = _OnUpdate.(ReferenceAction) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3728,18 +4240,22 @@ func (c *cow) copyOnRewriteRefOfRegexpInstrExpr(n *RegexpInstrExpr, parent SQLNo _ReturnOption, changedReturnOption := c.copyOnRewriteExpr(n.ReturnOption, n) _MatchType, changedMatchType := c.copyOnRewriteExpr(n.MatchType, n) if changedExpr || changedPattern || changedPosition || changedOccurrence || changedReturnOption || changedMatchType { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.Pattern, _ = _Pattern.(Expr) - changed.Position, _ = _Position.(Expr) - changed.Occurrence, _ = _Occurrence.(Expr) - changed.ReturnOption, _ = _ReturnOption.(Expr) - changed.MatchType, _ = _MatchType.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.Pattern, _ = _Pattern.(Expr) + res.Position, _ = _Position.(Expr) + res.Occurrence, _ = _Occurrence.(Expr) + res.ReturnOption, _ = _ReturnOption.(Expr) + res.MatchType, _ = _MatchType.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3753,15 +4269,19 @@ func (c *cow) copyOnRewriteRefOfRegexpLikeExpr(n *RegexpLikeExpr, parent SQLNode _Pattern, changedPattern := c.copyOnRewriteExpr(n.Pattern, n) _MatchType, changedMatchType := c.copyOnRewriteExpr(n.MatchType, n) if changedExpr || changedPattern || changedMatchType { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.Pattern, _ = _Pattern.(Expr) - changed.MatchType, _ = _MatchType.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.Pattern, _ = _Pattern.(Expr) + res.MatchType, _ = _MatchType.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3778,18 +4298,22 @@ func (c *cow) copyOnRewriteRefOfRegexpReplaceExpr(n *RegexpReplaceExpr, parent S _Position, changedPosition := c.copyOnRewriteExpr(n.Position, n) _MatchType, changedMatchType := c.copyOnRewriteExpr(n.MatchType, n) if changedExpr || changedPattern || changedRepl || changedOccurrence || changedPosition || changedMatchType { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.Pattern, _ = _Pattern.(Expr) - changed.Repl, _ = _Repl.(Expr) - changed.Occurrence, _ = _Occurrence.(Expr) - changed.Position, _ = _Position.(Expr) - changed.MatchType, _ = _MatchType.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.Pattern, _ = _Pattern.(Expr) + res.Repl, _ = _Repl.(Expr) + res.Occurrence, _ = _Occurrence.(Expr) + res.Position, _ = _Position.(Expr) + res.MatchType, _ = _MatchType.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3805,17 +4329,21 @@ func (c *cow) copyOnRewriteRefOfRegexpSubstrExpr(n *RegexpSubstrExpr, parent SQL _Position, changedPosition := c.copyOnRewriteExpr(n.Position, n) _MatchType, changedMatchType := c.copyOnRewriteExpr(n.MatchType, n) if changedExpr || changedPattern || changedOccurrence || changedPosition || changedMatchType { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.Pattern, _ = _Pattern.(Expr) - changed.Occurrence, _ = _Occurrence.(Expr) - changed.Position, _ = _Position.(Expr) - changed.MatchType, _ = _MatchType.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.Pattern, _ = _Pattern.(Expr) + res.Occurrence, _ = _Occurrence.(Expr) + res.Position, _ = _Position.(Expr) + res.MatchType, _ = _MatchType.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3827,13 +4355,17 @@ func (c *cow) copyOnRewriteRefOfRelease(n *Release, parent SQLNode) (out SQLNode if c.pre == nil || c.pre(n, parent) { _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) if changedName { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3846,14 +4378,18 @@ func (c *cow) copyOnRewriteRefOfRenameColumn(n *RenameColumn, parent SQLNode) (o _OldName, changedOldName := c.copyOnRewriteRefOfColName(n.OldName, n) _NewName, changedNewName := c.copyOnRewriteRefOfColName(n.NewName, n) if changedOldName || changedNewName { - changed := *n - changed.OldName, _ = _OldName.(*ColName) - changed.NewName, _ = _NewName.(*ColName) - out = &changed + res := *n + res.OldName, _ = _OldName.(*ColName) + res.NewName, _ = _NewName.(*ColName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3866,14 +4402,18 @@ func (c *cow) copyOnRewriteRefOfRenameIndex(n *RenameIndex, parent SQLNode) (out _OldName, changedOldName := c.copyOnRewriteIdentifierCI(n.OldName, n) _NewName, changedNewName := c.copyOnRewriteIdentifierCI(n.NewName, n) if changedOldName || changedNewName { - changed := *n - changed.OldName, _ = _OldName.(IdentifierCI) - changed.NewName, _ = _NewName.(IdentifierCI) - out = &changed + res := *n + res.OldName, _ = _OldName.(IdentifierCI) + res.NewName, _ = _NewName.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3885,7 +4425,7 @@ func (c *cow) copyOnRewriteRefOfRenameTable(n *RenameTable, parent SQLNode) (out if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3897,13 +4437,17 @@ func (c *cow) copyOnRewriteRefOfRenameTableName(n *RenameTableName, parent SQLNo if c.pre == nil || c.pre(n, parent) { _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) if changedTable { - changed := *n - changed.Table, _ = _Table.(TableName) - out = &changed + res := *n + res.Table, _ = _Table.(TableName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3915,13 +4459,17 @@ func (c *cow) copyOnRewriteRefOfRevertMigration(n *RevertMigration, parent SQLNo if c.pre == nil || c.pre(n, parent) { _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) if changedComments { - changed := *n - changed.Comments, _ = _Comments.(*ParsedComments) - out = &changed + res := *n + res.Comments, _ = _Comments.(*ParsedComments) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3933,7 +4481,7 @@ func (c *cow) copyOnRewriteRefOfRollback(n *Rollback, parent SQLNode) (out SQLNo if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3942,13 +4490,17 @@ func (c *cow) copyOnRewriteRootNode(n RootNode, parent SQLNode) (out SQLNode, ch if c.pre == nil || c.pre(n, parent) { _SQLNode, changedSQLNode := c.copyOnRewriteSQLNode(n.SQLNode, n) if changedSQLNode { - changed := n - changed.SQLNode, _ = _SQLNode.(SQLNode) - out = &changed + res := n + res.SQLNode, _ = _SQLNode.(SQLNode) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3960,13 +4512,17 @@ func (c *cow) copyOnRewriteRefOfSRollback(n *SRollback, parent SQLNode) (out SQL if c.pre == nil || c.pre(n, parent) { _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) if changedName { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -3978,13 +4534,17 @@ func (c *cow) copyOnRewriteRefOfSavepoint(n *Savepoint, parent SQLNode) (out SQL if c.pre == nil || c.pre(n, parent) { _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) if changedName { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4014,23 +4574,27 @@ func (c *cow) copyOnRewriteRefOfSelect(n *Select, parent SQLNode) (out SQLNode, _Limit, changedLimit := c.copyOnRewriteRefOfLimit(n.Limit, n) _Into, changedInto := c.copyOnRewriteRefOfSelectInto(n.Into, n) if changedFrom || changedComments || changedSelectExprs || changedWhere || changedWith || changedGroupBy || changedHaving || changedWindows || changedOrderBy || changedLimit || changedInto { - changed := *n - changed.From = _From - changed.Comments, _ = _Comments.(*ParsedComments) - changed.SelectExprs, _ = _SelectExprs.(SelectExprs) - changed.Where, _ = _Where.(*Where) - changed.With, _ = _With.(*With) - changed.GroupBy, _ = _GroupBy.(GroupBy) - changed.Having, _ = _Having.(*Where) - changed.Windows, _ = _Windows.(NamedWindows) - changed.OrderBy, _ = _OrderBy.(OrderBy) - changed.Limit, _ = _Limit.(*Limit) - changed.Into, _ = _Into.(*SelectInto) - out = &changed + res := *n + res.From = _From + res.Comments, _ = _Comments.(*ParsedComments) + res.SelectExprs, _ = _SelectExprs.(SelectExprs) + res.Where, _ = _Where.(*Where) + res.With, _ = _With.(*With) + res.GroupBy, _ = _GroupBy.(GroupBy) + res.Having, _ = _Having.(*Where) + res.Windows, _ = _Windows.(NamedWindows) + res.OrderBy, _ = _OrderBy.(OrderBy) + res.Limit, _ = _Limit.(*Limit) + res.Into, _ = _Into.(*SelectInto) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4053,7 +4617,7 @@ func (c *cow) copyOnRewriteSelectExprs(n SelectExprs, parent SQLNode) (out SQLNo } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4065,7 +4629,7 @@ func (c *cow) copyOnRewriteRefOfSelectInto(n *SelectInto, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4078,14 +4642,18 @@ func (c *cow) copyOnRewriteRefOfSet(n *Set, parent SQLNode) (out SQLNode, change _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) _Exprs, changedExprs := c.copyOnRewriteSetExprs(n.Exprs, n) if changedComments || changedExprs { - changed := *n - changed.Comments, _ = _Comments.(*ParsedComments) - changed.Exprs, _ = _Exprs.(SetExprs) - out = &changed + res := *n + res.Comments, _ = _Comments.(*ParsedComments) + res.Exprs, _ = _Exprs.(SetExprs) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4098,14 +4666,18 @@ func (c *cow) copyOnRewriteRefOfSetExpr(n *SetExpr, parent SQLNode) (out SQLNode _Var, changedVar := c.copyOnRewriteRefOfVariable(n.Var, n) _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedVar || changedExpr { - changed := *n - changed.Var, _ = _Var.(*Variable) - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Var, _ = _Var.(*Variable) + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4128,7 +4700,7 @@ func (c *cow) copyOnRewriteSetExprs(n SetExprs, parent SQLNode) (out SQLNode, ch } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4140,13 +4712,17 @@ func (c *cow) copyOnRewriteRefOfShow(n *Show, parent SQLNode) (out SQLNode, chan if c.pre == nil || c.pre(n, parent) { _Internal, changedInternal := c.copyOnRewriteShowInternal(n.Internal, n) if changedInternal { - changed := *n - changed.Internal, _ = _Internal.(ShowInternal) - out = &changed + res := *n + res.Internal, _ = _Internal.(ShowInternal) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4160,15 +4736,19 @@ func (c *cow) copyOnRewriteRefOfShowBasic(n *ShowBasic, parent SQLNode) (out SQL _DbName, changedDbName := c.copyOnRewriteIdentifierCS(n.DbName, n) _Filter, changedFilter := c.copyOnRewriteRefOfShowFilter(n.Filter, n) if changedTbl || changedDbName || changedFilter { - changed := *n - changed.Tbl, _ = _Tbl.(TableName) - changed.DbName, _ = _DbName.(IdentifierCS) - changed.Filter, _ = _Filter.(*ShowFilter) - out = &changed + res := *n + res.Tbl, _ = _Tbl.(TableName) + res.DbName, _ = _DbName.(IdentifierCS) + res.Filter, _ = _Filter.(*ShowFilter) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4180,13 +4760,17 @@ func (c *cow) copyOnRewriteRefOfShowCreate(n *ShowCreate, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { _Op, changedOp := c.copyOnRewriteTableName(n.Op, n) if changedOp { - changed := *n - changed.Op, _ = _Op.(TableName) - out = &changed + res := *n + res.Op, _ = _Op.(TableName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4198,13 +4782,17 @@ func (c *cow) copyOnRewriteRefOfShowFilter(n *ShowFilter, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { _Filter, changedFilter := c.copyOnRewriteExpr(n.Filter, n) if changedFilter { - changed := *n - changed.Filter, _ = _Filter.(Expr) - out = &changed + res := *n + res.Filter, _ = _Filter.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4216,13 +4804,17 @@ func (c *cow) copyOnRewriteRefOfShowMigrationLogs(n *ShowMigrationLogs, parent S if c.pre == nil || c.pre(n, parent) { _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) if changedComments { - changed := *n - changed.Comments, _ = _Comments.(*ParsedComments) - out = &changed + res := *n + res.Comments, _ = _Comments.(*ParsedComments) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4234,7 +4826,7 @@ func (c *cow) copyOnRewriteRefOfShowOther(n *ShowOther, parent SQLNode) (out SQL if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4246,7 +4838,7 @@ func (c *cow) copyOnRewriteRefOfShowThrottledApps(n *ShowThrottledApps, parent S if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4258,7 +4850,7 @@ func (c *cow) copyOnRewriteRefOfShowThrottlerStatus(n *ShowThrottlerStatus, pare if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4270,13 +4862,17 @@ func (c *cow) copyOnRewriteRefOfStarExpr(n *StarExpr, parent SQLNode) (out SQLNo if c.pre == nil || c.pre(n, parent) { _TableName, changedTableName := c.copyOnRewriteTableName(n.TableName, n) if changedTableName { - changed := *n - changed.TableName, _ = _TableName.(TableName) - out = &changed + res := *n + res.TableName, _ = _TableName.(TableName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4288,13 +4884,17 @@ func (c *cow) copyOnRewriteRefOfStd(n *Std, parent SQLNode) (out SQLNode, change if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4306,13 +4906,17 @@ func (c *cow) copyOnRewriteRefOfStdDev(n *StdDev, parent SQLNode) (out SQLNode, if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4324,13 +4928,17 @@ func (c *cow) copyOnRewriteRefOfStdPop(n *StdPop, parent SQLNode) (out SQLNode, if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4342,13 +4950,17 @@ func (c *cow) copyOnRewriteRefOfStdSamp(n *StdSamp, parent SQLNode) (out SQLNode if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4362,15 +4974,19 @@ func (c *cow) copyOnRewriteRefOfStream(n *Stream, parent SQLNode) (out SQLNode, _SelectExpr, changedSelectExpr := c.copyOnRewriteSelectExpr(n.SelectExpr, n) _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) if changedComments || changedSelectExpr || changedTable { - changed := *n - changed.Comments, _ = _Comments.(*ParsedComments) - changed.SelectExpr, _ = _SelectExpr.(SelectExpr) - changed.Table, _ = _Table.(TableName) - out = &changed + res := *n + res.Comments, _ = _Comments.(*ParsedComments) + res.SelectExpr, _ = _SelectExpr.(SelectExpr) + res.Table, _ = _Table.(TableName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4383,14 +4999,18 @@ func (c *cow) copyOnRewriteRefOfSubPartition(n *SubPartition, parent SQLNode) (o _ColList, changedColList := c.copyOnRewriteColumns(n.ColList, n) _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedColList || changedExpr { - changed := *n - changed.ColList, _ = _ColList.(Columns) - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.ColList, _ = _ColList.(Columns) + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4403,14 +5023,18 @@ func (c *cow) copyOnRewriteRefOfSubPartitionDefinition(n *SubPartitionDefinition _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) _Options, changedOptions := c.copyOnRewriteRefOfSubPartitionDefinitionOptions(n.Options, n) if changedName || changedOptions { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - changed.Options, _ = _Options.(*SubPartitionDefinitionOptions) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + res.Options, _ = _Options.(*SubPartitionDefinitionOptions) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4425,16 +5049,20 @@ func (c *cow) copyOnRewriteRefOfSubPartitionDefinitionOptions(n *SubPartitionDef _DataDirectory, changedDataDirectory := c.copyOnRewriteRefOfLiteral(n.DataDirectory, n) _IndexDirectory, changedIndexDirectory := c.copyOnRewriteRefOfLiteral(n.IndexDirectory, n) if changedComment || changedEngine || changedDataDirectory || changedIndexDirectory { - changed := *n - changed.Comment, _ = _Comment.(*Literal) - changed.Engine, _ = _Engine.(*PartitionEngine) - changed.DataDirectory, _ = _DataDirectory.(*Literal) - changed.IndexDirectory, _ = _IndexDirectory.(*Literal) - out = &changed + res := *n + res.Comment, _ = _Comment.(*Literal) + res.Engine, _ = _Engine.(*PartitionEngine) + res.DataDirectory, _ = _DataDirectory.(*Literal) + res.IndexDirectory, _ = _IndexDirectory.(*Literal) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4457,7 +5085,7 @@ func (c *cow) copyOnRewriteSubPartitionDefinitions(n SubPartitionDefinitions, pa } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4469,13 +5097,17 @@ func (c *cow) copyOnRewriteRefOfSubquery(n *Subquery, parent SQLNode) (out SQLNo if c.pre == nil || c.pre(n, parent) { _Select, changedSelect := c.copyOnRewriteSelectStatement(n.Select, n) if changedSelect { - changed := *n - changed.Select, _ = _Select.(SelectStatement) - out = &changed + res := *n + res.Select, _ = _Select.(SelectStatement) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4489,15 +5121,19 @@ func (c *cow) copyOnRewriteRefOfSubstrExpr(n *SubstrExpr, parent SQLNode) (out S _From, changedFrom := c.copyOnRewriteExpr(n.From, n) _To, changedTo := c.copyOnRewriteExpr(n.To, n) if changedName || changedFrom || changedTo { - changed := *n - changed.Name, _ = _Name.(Expr) - changed.From, _ = _From.(Expr) - changed.To, _ = _To.(Expr) - out = &changed + res := *n + res.Name, _ = _Name.(Expr) + res.From, _ = _From.(Expr) + res.To, _ = _To.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4509,13 +5145,17 @@ func (c *cow) copyOnRewriteRefOfSum(n *Sum, parent SQLNode) (out SQLNode, change if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4538,7 +5178,7 @@ func (c *cow) copyOnRewriteTableExprs(n TableExprs, parent SQLNode) (out SQLNode } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4548,14 +5188,18 @@ func (c *cow) copyOnRewriteTableName(n TableName, parent SQLNode) (out SQLNode, _Name, changedName := c.copyOnRewriteIdentifierCS(n.Name, n) _Qualifier, changedQualifier := c.copyOnRewriteIdentifierCS(n.Qualifier, n) if changedName || changedQualifier { - changed := n - changed.Name, _ = _Name.(IdentifierCS) - changed.Qualifier, _ = _Qualifier.(IdentifierCS) - out = &changed + res := n + res.Name, _ = _Name.(IdentifierCS) + res.Qualifier, _ = _Qualifier.(IdentifierCS) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4578,7 +5222,7 @@ func (c *cow) copyOnRewriteTableNames(n TableNames, parent SQLNode) (out SQLNode } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4591,7 +5235,7 @@ func (c *cow) copyOnRewriteTableOptions(n TableOptions, parent SQLNode) (out SQL c.pre(n, parent) } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4631,17 +5275,21 @@ func (c *cow) copyOnRewriteRefOfTableSpec(n *TableSpec, parent SQLNode) (out SQL _Options, changedOptions := c.copyOnRewriteTableOptions(n.Options, n) _PartitionOption, changedPartitionOption := c.copyOnRewriteRefOfPartitionOption(n.PartitionOption, n) if changedColumns || changedIndexes || changedConstraints || changedOptions || changedPartitionOption { - changed := *n - changed.Columns = _Columns - changed.Indexes = _Indexes - changed.Constraints = _Constraints - changed.Options, _ = _Options.(TableOptions) - changed.PartitionOption, _ = _PartitionOption.(*PartitionOption) - out = &changed + res := *n + res.Columns = _Columns + res.Indexes = _Indexes + res.Constraints = _Constraints + res.Options, _ = _Options.(TableOptions) + res.PartitionOption, _ = _PartitionOption.(*PartitionOption) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4653,7 +5301,7 @@ func (c *cow) copyOnRewriteRefOfTablespaceOperation(n *TablespaceOperation, pare if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4666,14 +5314,18 @@ func (c *cow) copyOnRewriteRefOfTimestampFuncExpr(n *TimestampFuncExpr, parent S _Expr1, changedExpr1 := c.copyOnRewriteExpr(n.Expr1, n) _Expr2, changedExpr2 := c.copyOnRewriteExpr(n.Expr2, n) if changedExpr1 || changedExpr2 { - changed := *n - changed.Expr1, _ = _Expr1.(Expr) - changed.Expr2, _ = _Expr2.(Expr) - out = &changed + res := *n + res.Expr1, _ = _Expr1.(Expr) + res.Expr2, _ = _Expr2.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4686,14 +5338,18 @@ func (c *cow) copyOnRewriteRefOfTrimFuncExpr(n *TrimFuncExpr, parent SQLNode) (o _TrimArg, changedTrimArg := c.copyOnRewriteExpr(n.TrimArg, n) _StringArg, changedStringArg := c.copyOnRewriteExpr(n.StringArg, n) if changedTrimArg || changedStringArg { - changed := *n - changed.TrimArg, _ = _TrimArg.(Expr) - changed.StringArg, _ = _StringArg.(Expr) - out = &changed + res := *n + res.TrimArg, _ = _TrimArg.(Expr) + res.StringArg, _ = _StringArg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4705,13 +5361,17 @@ func (c *cow) copyOnRewriteRefOfTruncateTable(n *TruncateTable, parent SQLNode) if c.pre == nil || c.pre(n, parent) { _Table, changedTable := c.copyOnRewriteTableName(n.Table, n) if changedTable { - changed := *n - changed.Table, _ = _Table.(TableName) - out = &changed + res := *n + res.Table, _ = _Table.(TableName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4723,13 +5383,17 @@ func (c *cow) copyOnRewriteRefOfUnaryExpr(n *UnaryExpr, parent SQLNode) (out SQL if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4746,18 +5410,22 @@ func (c *cow) copyOnRewriteRefOfUnion(n *Union, parent SQLNode) (out SQLNode, ch _Limit, changedLimit := c.copyOnRewriteRefOfLimit(n.Limit, n) _Into, changedInto := c.copyOnRewriteRefOfSelectInto(n.Into, n) if changedLeft || changedRight || changedOrderBy || changedWith || changedLimit || changedInto { - changed := *n - changed.Left, _ = _Left.(SelectStatement) - changed.Right, _ = _Right.(SelectStatement) - changed.OrderBy, _ = _OrderBy.(OrderBy) - changed.With, _ = _With.(*With) - changed.Limit, _ = _Limit.(*Limit) - changed.Into, _ = _Into.(*SelectInto) - out = &changed + res := *n + res.Left, _ = _Left.(SelectStatement) + res.Right, _ = _Right.(SelectStatement) + res.OrderBy, _ = _OrderBy.(OrderBy) + res.With, _ = _With.(*With) + res.Limit, _ = _Limit.(*Limit) + res.Into, _ = _Into.(*SelectInto) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4769,7 +5437,7 @@ func (c *cow) copyOnRewriteRefOfUnlockTables(n *UnlockTables, parent SQLNode) (o if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4787,19 +5455,23 @@ func (c *cow) copyOnRewriteRefOfUpdate(n *Update, parent SQLNode) (out SQLNode, _OrderBy, changedOrderBy := c.copyOnRewriteOrderBy(n.OrderBy, n) _Limit, changedLimit := c.copyOnRewriteRefOfLimit(n.Limit, n) if changedWith || changedComments || changedTableExprs || changedExprs || changedWhere || changedOrderBy || changedLimit { - changed := *n - changed.With, _ = _With.(*With) - changed.Comments, _ = _Comments.(*ParsedComments) - changed.TableExprs, _ = _TableExprs.(TableExprs) - changed.Exprs, _ = _Exprs.(UpdateExprs) - changed.Where, _ = _Where.(*Where) - changed.OrderBy, _ = _OrderBy.(OrderBy) - changed.Limit, _ = _Limit.(*Limit) - out = &changed + res := *n + res.With, _ = _With.(*With) + res.Comments, _ = _Comments.(*ParsedComments) + res.TableExprs, _ = _TableExprs.(TableExprs) + res.Exprs, _ = _Exprs.(UpdateExprs) + res.Where, _ = _Where.(*Where) + res.OrderBy, _ = _OrderBy.(OrderBy) + res.Limit, _ = _Limit.(*Limit) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4812,14 +5484,18 @@ func (c *cow) copyOnRewriteRefOfUpdateExpr(n *UpdateExpr, parent SQLNode) (out S _Name, changedName := c.copyOnRewriteRefOfColName(n.Name, n) _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedName || changedExpr { - changed := *n - changed.Name, _ = _Name.(*ColName) - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Name, _ = _Name.(*ColName) + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4842,7 +5518,7 @@ func (c *cow) copyOnRewriteUpdateExprs(n UpdateExprs, parent SQLNode) (out SQLNo } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4856,15 +5532,19 @@ func (c *cow) copyOnRewriteRefOfUpdateXMLExpr(n *UpdateXMLExpr, parent SQLNode) _XPathExpr, changedXPathExpr := c.copyOnRewriteExpr(n.XPathExpr, n) _NewXML, changedNewXML := c.copyOnRewriteExpr(n.NewXML, n) if changedTarget || changedXPathExpr || changedNewXML { - changed := *n - changed.Target, _ = _Target.(Expr) - changed.XPathExpr, _ = _XPathExpr.(Expr) - changed.NewXML, _ = _NewXML.(Expr) - out = &changed + res := *n + res.Target, _ = _Target.(Expr) + res.XPathExpr, _ = _XPathExpr.(Expr) + res.NewXML, _ = _NewXML.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4876,13 +5556,17 @@ func (c *cow) copyOnRewriteRefOfUse(n *Use, parent SQLNode) (out SQLNode, change if c.pre == nil || c.pre(n, parent) { _DBName, changedDBName := c.copyOnRewriteIdentifierCS(n.DBName, n) if changedDBName { - changed := *n - changed.DBName, _ = _DBName.(IdentifierCS) - out = &changed + res := *n + res.DBName, _ = _DBName.(IdentifierCS) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4895,14 +5579,18 @@ func (c *cow) copyOnRewriteRefOfVExplainStmt(n *VExplainStmt, parent SQLNode) (o _Statement, changedStatement := c.copyOnRewriteStatement(n.Statement, n) _Comments, changedComments := c.copyOnRewriteRefOfParsedComments(n.Comments, n) if changedStatement || changedComments { - changed := *n - changed.Statement, _ = _Statement.(Statement) - changed.Comments, _ = _Comments.(*ParsedComments) - out = &changed + res := *n + res.Statement, _ = _Statement.(Statement) + res.Comments, _ = _Comments.(*ParsedComments) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4918,17 +5606,21 @@ func (c *cow) copyOnRewriteRefOfVStream(n *VStream, parent SQLNode) (out SQLNode _Where, changedWhere := c.copyOnRewriteRefOfWhere(n.Where, n) _Limit, changedLimit := c.copyOnRewriteRefOfLimit(n.Limit, n) if changedComments || changedSelectExpr || changedTable || changedWhere || changedLimit { - changed := *n - changed.Comments, _ = _Comments.(*ParsedComments) - changed.SelectExpr, _ = _SelectExpr.(SelectExpr) - changed.Table, _ = _Table.(TableName) - changed.Where, _ = _Where.(*Where) - changed.Limit, _ = _Limit.(*Limit) - out = &changed + res := *n + res.Comments, _ = _Comments.(*ParsedComments) + res.SelectExpr, _ = _SelectExpr.(SelectExpr) + res.Table, _ = _Table.(TableName) + res.Where, _ = _Where.(*Where) + res.Limit, _ = _Limit.(*Limit) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4951,7 +5643,7 @@ func (c *cow) copyOnRewriteValTuple(n ValTuple, parent SQLNode) (out SQLNode, ch } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4963,7 +5655,7 @@ func (c *cow) copyOnRewriteRefOfValidation(n *Validation, parent SQLNode) (out S if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4986,7 +5678,7 @@ func (c *cow) copyOnRewriteValues(n Values, parent SQLNode) (out SQLNode, change } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -4998,13 +5690,17 @@ func (c *cow) copyOnRewriteRefOfValuesFuncExpr(n *ValuesFuncExpr, parent SQLNode if c.pre == nil || c.pre(n, parent) { _Name, changedName := c.copyOnRewriteRefOfColName(n.Name, n) if changedName { - changed := *n - changed.Name, _ = _Name.(*ColName) - out = &changed + res := *n + res.Name, _ = _Name.(*ColName) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5016,13 +5712,17 @@ func (c *cow) copyOnRewriteRefOfVarPop(n *VarPop, parent SQLNode) (out SQLNode, if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5034,13 +5734,17 @@ func (c *cow) copyOnRewriteRefOfVarSamp(n *VarSamp, parent SQLNode) (out SQLNode if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5052,13 +5756,17 @@ func (c *cow) copyOnRewriteRefOfVariable(n *Variable, parent SQLNode) (out SQLNo if c.pre == nil || c.pre(n, parent) { _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) if changedName { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5070,13 +5778,17 @@ func (c *cow) copyOnRewriteRefOfVariance(n *Variance, parent SQLNode) (out SQLNo if c.pre == nil || c.pre(n, parent) { _Arg, changedArg := c.copyOnRewriteExpr(n.Arg, n) if changedArg { - changed := *n - changed.Arg, _ = _Arg.(Expr) - out = &changed + res := *n + res.Arg, _ = _Arg.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5085,13 +5797,17 @@ func (c *cow) copyOnRewriteVindexParam(n VindexParam, parent SQLNode) (out SQLNo if c.pre == nil || c.pre(n, parent) { _Key, changedKey := c.copyOnRewriteIdentifierCI(n.Key, n) if changedKey { - changed := n - changed.Key, _ = _Key.(IdentifierCI) - out = &changed + res := n + res.Key, _ = _Key.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5113,15 +5829,19 @@ func (c *cow) copyOnRewriteRefOfVindexSpec(n *VindexSpec, parent SQLNode) (out S } } if changedName || changedType || changedParams { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - changed.Type, _ = _Type.(IdentifierCI) - changed.Params = _Params - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + res.Type, _ = _Type.(IdentifierCI) + res.Params = _Params + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5134,14 +5854,18 @@ func (c *cow) copyOnRewriteRefOfWeightStringFuncExpr(n *WeightStringFuncExpr, pa _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) _As, changedAs := c.copyOnRewriteRefOfConvertType(n.As, n) if changedExpr || changedAs { - changed := *n - changed.Expr, _ = _Expr.(Expr) - changed.As, _ = _As.(*ConvertType) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + res.As, _ = _As.(*ConvertType) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5154,14 +5878,18 @@ func (c *cow) copyOnRewriteRefOfWhen(n *When, parent SQLNode) (out SQLNode, chan _Cond, changedCond := c.copyOnRewriteExpr(n.Cond, n) _Val, changedVal := c.copyOnRewriteExpr(n.Val, n) if changedCond || changedVal { - changed := *n - changed.Cond, _ = _Cond.(Expr) - changed.Val, _ = _Val.(Expr) - out = &changed + res := *n + res.Cond, _ = _Cond.(Expr) + res.Val, _ = _Val.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5173,13 +5901,17 @@ func (c *cow) copyOnRewriteRefOfWhere(n *Where, parent SQLNode) (out SQLNode, ch if c.pre == nil || c.pre(n, parent) { _Expr, changedExpr := c.copyOnRewriteExpr(n.Expr, n) if changedExpr { - changed := *n - changed.Expr, _ = _Expr.(Expr) - out = &changed + res := *n + res.Expr, _ = _Expr.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5192,14 +5924,18 @@ func (c *cow) copyOnRewriteRefOfWindowDefinition(n *WindowDefinition, parent SQL _Name, changedName := c.copyOnRewriteIdentifierCI(n.Name, n) _WindowSpec, changedWindowSpec := c.copyOnRewriteRefOfWindowSpecification(n.WindowSpec, n) if changedName || changedWindowSpec { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - changed.WindowSpec, _ = _WindowSpec.(*WindowSpecification) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + res.WindowSpec, _ = _WindowSpec.(*WindowSpecification) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5222,7 +5958,7 @@ func (c *cow) copyOnRewriteWindowDefinitions(n WindowDefinitions, parent SQLNode } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5237,16 +5973,20 @@ func (c *cow) copyOnRewriteRefOfWindowSpecification(n *WindowSpecification, pare _OrderClause, changedOrderClause := c.copyOnRewriteOrderBy(n.OrderClause, n) _FrameClause, changedFrameClause := c.copyOnRewriteRefOfFrameClause(n.FrameClause, n) if changedName || changedPartitionClause || changedOrderClause || changedFrameClause { - changed := *n - changed.Name, _ = _Name.(IdentifierCI) - changed.PartitionClause, _ = _PartitionClause.(Exprs) - changed.OrderClause, _ = _OrderClause.(OrderBy) - changed.FrameClause, _ = _FrameClause.(*FrameClause) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCI) + res.PartitionClause, _ = _PartitionClause.(Exprs) + res.OrderClause, _ = _OrderClause.(OrderBy) + res.FrameClause, _ = _FrameClause.(*FrameClause) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5266,13 +6006,17 @@ func (c *cow) copyOnRewriteRefOfWith(n *With, parent SQLNode) (out SQLNode, chan } } if changedctes { - changed := *n - changed.ctes = _ctes - out = &changed + res := *n + res.ctes = _ctes + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -5285,14 +6029,18 @@ func (c *cow) copyOnRewriteRefOfXorExpr(n *XorExpr, parent SQLNode) (out SQLNode _Left, changedLeft := c.copyOnRewriteExpr(n.Left, n) _Right, changedRight := c.copyOnRewriteExpr(n.Right, n) if changedLeft || changedRight { - changed := *n - changed.Left, _ = _Left.(Expr) - changed.Right, _ = _Right.(Expr) - out = &changed + res := *n + res.Left, _ = _Left.(Expr) + res.Right, _ = _Right.(Expr) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -6010,7 +6758,7 @@ func (c *cow) copyOnRewriteAlgorithmValue(n AlgorithmValue, parent SQLNode) (out c.pre(n, parent) } if c.post != nil { - out, changed = c.postVisit(n, parent) + out, changed = c.postVisit(n, parent, changed) } else { out = n } @@ -6024,7 +6772,7 @@ func (c *cow) copyOnRewriteArgument(n Argument, parent SQLNode) (out SQLNode, ch c.pre(n, parent) } if c.post != nil { - out, changed = c.postVisit(n, parent) + out, changed = c.postVisit(n, parent, changed) } else { out = n } @@ -6038,7 +6786,7 @@ func (c *cow) copyOnRewriteBoolVal(n BoolVal, parent SQLNode) (out SQLNode, chan c.pre(n, parent) } if c.post != nil { - out, changed = c.postVisit(n, parent) + out, changed = c.postVisit(n, parent, changed) } else { out = n } @@ -6052,7 +6800,7 @@ func (c *cow) copyOnRewriteListArg(n ListArg, parent SQLNode) (out SQLNode, chan c.pre(n, parent) } if c.post != nil { - out, changed = c.postVisit(n, parent) + out, changed = c.postVisit(n, parent, changed) } else { out = n } @@ -6066,7 +6814,7 @@ func (c *cow) copyOnRewriteMatchAction(n MatchAction, parent SQLNode) (out SQLNo c.pre(n, parent) } if c.post != nil { - out, changed = c.postVisit(n, parent) + out, changed = c.postVisit(n, parent, changed) } else { out = n } @@ -6080,7 +6828,7 @@ func (c *cow) copyOnRewriteReferenceAction(n ReferenceAction, parent SQLNode) (o c.pre(n, parent) } if c.post != nil { - out, changed = c.postVisit(n, parent) + out, changed = c.postVisit(n, parent, changed) } else { out = n } @@ -6094,7 +6842,7 @@ func (c *cow) copyOnRewriteRefOfIdentifierCI(n *IdentifierCI, parent SQLNode) (o if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -6106,7 +6854,7 @@ func (c *cow) copyOnRewriteRefOfIdentifierCS(n *IdentifierCS, parent SQLNode) (o if c.pre == nil || c.pre(n, parent) { } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -6118,13 +6866,17 @@ func (c *cow) copyOnRewriteRefOfRootNode(n *RootNode, parent SQLNode) (out SQLNo if c.pre == nil || c.pre(n, parent) { _SQLNode, changedSQLNode := c.copyOnRewriteSQLNode(n.SQLNode, n) if changedSQLNode { - changed := *n - changed.SQLNode, _ = _SQLNode.(SQLNode) - out = &changed + res := *n + res.SQLNode, _ = _SQLNode.(SQLNode) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -6137,14 +6889,18 @@ func (c *cow) copyOnRewriteRefOfTableName(n *TableName, parent SQLNode) (out SQL _Name, changedName := c.copyOnRewriteIdentifierCS(n.Name, n) _Qualifier, changedQualifier := c.copyOnRewriteIdentifierCS(n.Qualifier, n) if changedName || changedQualifier { - changed := *n - changed.Name, _ = _Name.(IdentifierCS) - changed.Qualifier, _ = _Qualifier.(IdentifierCS) - out = &changed + res := *n + res.Name, _ = _Name.(IdentifierCS) + res.Qualifier, _ = _Qualifier.(IdentifierCS) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } @@ -6156,13 +6912,17 @@ func (c *cow) copyOnRewriteRefOfVindexParam(n *VindexParam, parent SQLNode) (out if c.pre == nil || c.pre(n, parent) { _Key, changedKey := c.copyOnRewriteIdentifierCI(n.Key, n) if changedKey { - changed := *n - changed.Key, _ = _Key.(IdentifierCI) - out = &changed + res := *n + res.Key, _ = _Key.(IdentifierCI) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true } } if c.post != nil { - out, changed = c.postVisit(out, parent) + out, changed = c.postVisit(out, parent, changed) } return } diff --git a/go/vt/sqlparser/ast_copy_on_rewrite_test.go b/go/vt/sqlparser/ast_copy_on_rewrite_test.go index 3bce67b929f..389b2a4bc29 100644 --- a/go/vt/sqlparser/ast_copy_on_rewrite_test.go +++ b/go/vt/sqlparser/ast_copy_on_rewrite_test.go @@ -35,17 +35,47 @@ func TestCopyOnRewrite(t *testing.T) { if col.Name.EqualString("a") { cursor.Replace(NewIntLiteral("1")) } - }) + }, nil) assert.Equal(t, "a = b", String(expr)) assert.Equal(t, "1 = b", String(out)) } +func TestCopyOnRewriteDeeper(t *testing.T) { + // rewrite an expression without changing the original. the changed happens deep in the syntax tree, + // here we are testing that all ancestors up to the root are cloned correctly + expr, err := ParseExpr("a + b * c = 12") + require.NoError(t, err) + var path []string + out := CopyOnRewrite(expr, nil, func(cursor *CopyOnWriteCursor) { + col, ok := cursor.Node().(*ColName) + if !ok { + return + } + if col.Name.EqualString("c") { + cursor.Replace(NewIntLiteral("1")) + } + }, func(before, _ SQLNode) { + path = append(path, String(before)) + }) + + assert.Equal(t, "a + b * c = 12", String(expr)) + assert.Equal(t, "a + b * 1 = 12", String(out)) + + expected := []string{ // this are all the nodes that we need to clone when changing the `c` node + "c", + "b * c", + "a + b * c", + "a + b * c = 12", + } + assert.Equal(t, expected, path) +} + func TestDontCopyWithoutRewrite(t *testing.T) { // when no rewriting happens, we want the original back expr, err := ParseExpr("a = b") require.NoError(t, err) - out := CopyOnRewrite(expr, nil, func(cursor *CopyOnWriteCursor) {}) + out := CopyOnRewrite(expr, nil, func(cursor *CopyOnWriteCursor) {}, nil) assert.Same(t, expr, out) } @@ -65,7 +95,7 @@ func TestStopTreeWalk(t *testing.T) { } cursor.Replace(NewStrLiteral(col.Name.String())) - }) + }, nil) assert.Equal(t, original, String(expr)) assert.Equal(t, "'a' = b + c", String(out)) // b + c are unchanged since they are under the + (*BinaryExpr) @@ -86,7 +116,7 @@ func TestStopTreeWalkButStillVisit(t *testing.T) { case *ColName: t.Errorf("should not visit ColName in the post") } - }) + }, nil) assert.Equal(t, original, String(expr)) assert.Equal(t, "1337 = 'johnny was here'", String(out)) // b + c are replaced diff --git a/go/vt/sqlparser/cow.go b/go/vt/sqlparser/cow.go index e54f99223d2..e5aa5b82e01 100644 --- a/go/vt/sqlparser/cow.go +++ b/go/vt/sqlparser/cow.go @@ -51,25 +51,35 @@ type ( // When a node is replaced, all the ancestors of the node are cloned, // so that the original syntax tree remains untouched // +// The `cloned` function will be called for all nodes that are cloned +// or replaced, to give the user a chance to copy any metadata that +// needs copying. +// // Only fields that refer to AST nodes are considered children; // i.e., fields of basic types (strings, []byte, etc.) are ignored. -func CopyOnRewrite(node SQLNode, pre func(node, parent SQLNode) bool, post func(cursor *CopyOnWriteCursor)) SQLNode { - parent := &RootNode{node} - - cow := cow{pre: pre, post: post, cursor: CopyOnWriteCursor{}} - out, _ := cow.copyOnRewriteSQLNode(node, parent) +func CopyOnRewrite( + node SQLNode, + pre func(node, parent SQLNode) bool, + post func(cursor *CopyOnWriteCursor), + cloned func(before, after SQLNode), +) SQLNode { + cow := cow{pre: pre, post: post, cursor: CopyOnWriteCursor{}, cloned: cloned} + out, _ := cow.copyOnRewriteSQLNode(node, nil) return out } -func (c *cow) postVisit(node, parent SQLNode) (SQLNode, bool) { +func (c *cow) postVisit(node, parent SQLNode, changed bool) (SQLNode, bool) { c.cursor.node = node c.cursor.parent = parent c.cursor.replaced = nil c.post(&c.cursor) if c.cursor.replaced != nil { + if c.cloned != nil { + c.cloned(node, c.cursor.replaced) + } return c.cursor.replaced, true } - return node, false + return node, changed } // StopTreeWalk aborts the current tree walking. No more nodes will be visited, and the rewriter will exit out early diff --git a/go/vt/vtgate/planbuilder/operators/union.go b/go/vt/vtgate/planbuilder/operators/union.go index 199c76f9a0d..ffaa03d858b 100644 --- a/go/vt/vtgate/planbuilder/operators/union.go +++ b/go/vt/vtgate/planbuilder/operators/union.go @@ -122,7 +122,7 @@ func (u *Union) AddPredicate(ctx *plancontext.PlanningContext, expr sqlparser.Ex return } cursor.Replace(ae.Expr) - }).(sqlparser.Expr) + }, nil).(sqlparser.Expr) if err != nil { return nil, err } From bf3b7ed53bebf17ebc7f509652543404a499cda6 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 24 Jan 2023 14:23:36 +0100 Subject: [PATCH 3/5] reformat Signed-off-by: Andres Taylor --- go/vt/sqlparser/cow.go | 58 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/go/vt/sqlparser/cow.go b/go/vt/sqlparser/cow.go index e5aa5b82e01..e807fdeef63 100644 --- a/go/vt/sqlparser/cow.go +++ b/go/vt/sqlparser/cow.go @@ -16,21 +16,6 @@ limitations under the License. package sqlparser -type ( - CopyOnWriteCursor struct { - node SQLNode - parent SQLNode - replaced SQLNode - stop bool - } - cow struct { - pre func(node, parent SQLNode) bool - post func(cursor *CopyOnWriteCursor) - cloned func(old, new SQLNode) - cursor CopyOnWriteCursor - } -) - // CopyOnRewrite traverses a syntax tree recursively, starting with root, // and calling pre and post for each node as described below. // Rewrite returns a syntax tree, where some nodes can be shared with the @@ -68,20 +53,6 @@ func CopyOnRewrite( return out } -func (c *cow) postVisit(node, parent SQLNode, changed bool) (SQLNode, bool) { - c.cursor.node = node - c.cursor.parent = parent - c.cursor.replaced = nil - c.post(&c.cursor) - if c.cursor.replaced != nil { - if c.cloned != nil { - c.cloned(node, c.cursor.replaced) - } - return c.cursor.replaced, true - } - return node, changed -} - // StopTreeWalk aborts the current tree walking. No more nodes will be visited, and the rewriter will exit out early func (c *CopyOnWriteCursor) StopTreeWalk() { c.stop = true @@ -103,3 +74,32 @@ func (c *CopyOnWriteCursor) Parent() SQLNode { func (c *CopyOnWriteCursor) Replace(n SQLNode) { c.replaced = n } + +func (c *cow) postVisit(node, parent SQLNode, changed bool) (SQLNode, bool) { + c.cursor.node = node + c.cursor.parent = parent + c.cursor.replaced = nil + c.post(&c.cursor) + if c.cursor.replaced != nil { + if c.cloned != nil { + c.cloned(node, c.cursor.replaced) + } + return c.cursor.replaced, true + } + return node, changed +} + +type ( + CopyOnWriteCursor struct { + node SQLNode + parent SQLNode + replaced SQLNode + stop bool + } + cow struct { + pre func(node, parent SQLNode) bool + post func(cursor *CopyOnWriteCursor) + cloned func(old, new SQLNode) + cursor CopyOnWriteCursor + } +) From fa45afb2db045fd14d02ba8bc18612a6c337ae56 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 24 Jan 2023 14:35:20 +0100 Subject: [PATCH 4/5] change uses of Clone & Rewrite to CopyOnRewrite Signed-off-by: Andres Taylor --- go/vt/vtgate/planbuilder/operators/derived.go | 5 +---- .../planbuilder/operators/expressions.go | 14 ++++++------- .../planbuilder/operators/route_planning.go | 5 +---- .../vtgate/planbuilder/projection_pushing.go | 5 +---- go/vt/vtgate/semantics/early_rewriter.go | 8 +++---- go/vt/vtgate/semantics/semantic_state.go | 21 +++++++++---------- go/vt/vtgate/vindexes/vschema.go | 1 - 7 files changed, 23 insertions(+), 36 deletions(-) diff --git a/go/vt/vtgate/planbuilder/operators/derived.go b/go/vt/vtgate/planbuilder/operators/derived.go index b0d8e30ca46..1488162bf46 100644 --- a/go/vt/vtgate/planbuilder/operators/derived.go +++ b/go/vt/vtgate/planbuilder/operators/derived.go @@ -124,10 +124,7 @@ func (d *Derived) AddPredicate(ctx *plancontext.PlanningContext, expr sqlparser. return nil, err } - newExpr, err := semantics.RewriteDerivedTableExpression(expr, tableInfo) - if err != nil { - return nil, err - } + newExpr := semantics.RewriteDerivedTableExpression(expr, tableInfo) d.Source, err = d.Source.AddPredicate(ctx, newExpr) if err != nil { return nil, err diff --git a/go/vt/vtgate/planbuilder/operators/expressions.go b/go/vt/vtgate/planbuilder/operators/expressions.go index cd57bbd659b..5a49bb3a058 100644 --- a/go/vt/vtgate/planbuilder/operators/expressions.go +++ b/go/vt/vtgate/planbuilder/operators/expressions.go @@ -30,19 +30,19 @@ func BreakExpressionInLHSandRHS( expr sqlparser.Expr, lhs semantics.TableSet, ) (bvNames []string, columns []*sqlparser.ColName, rewrittenExpr sqlparser.Expr, err error) { - rewrittenExpr = sqlparser.CloneExpr(expr) - _ = sqlparser.SafeRewrite(rewrittenExpr, nil, func(cursor *sqlparser.Cursor) bool { + rewrittenExpr = sqlparser.CopyOnRewrite(expr, nil, func(cursor *sqlparser.CopyOnWriteCursor) { node, ok := cursor.Node().(*sqlparser.ColName) if !ok { - return true + return } deps := ctx.SemTable.RecursiveDeps(node) if deps.IsEmpty() { err = vterrors.VT13001("unknown column. has the AST been copied?") - return false + cursor.StopTreeWalk() + return } if !deps.IsSolvedBy(lhs) { - return true + return } node.Qualifier.Qualifier = sqlparser.NewIdentifierCS("") @@ -54,8 +54,8 @@ func BreakExpressionInLHSandRHS( // but we don't want to lose the type information we have, so we copy it over ctx.SemTable.CopyExprInfo(node, arg) cursor.Replace(arg) - return true - }) + }, nil).(sqlparser.Expr) + if err != nil { return nil, nil, nil, err } diff --git a/go/vt/vtgate/planbuilder/operators/route_planning.go b/go/vt/vtgate/planbuilder/operators/route_planning.go index 602bb6b14a0..8bcd18a0361 100644 --- a/go/vt/vtgate/planbuilder/operators/route_planning.go +++ b/go/vt/vtgate/planbuilder/operators/route_planning.go @@ -735,10 +735,7 @@ func unwrapDerivedTables(ctx *plancontext.PlanningContext, exp sqlparser.Expr) s break } - exp, err = semantics.RewriteDerivedTableExpression(exp, tbl) - if err != nil { - return nil - } + exp = semantics.RewriteDerivedTableExpression(exp, tbl) exp = getColName(exp) if exp == nil { return nil diff --git a/go/vt/vtgate/planbuilder/projection_pushing.go b/go/vt/vtgate/planbuilder/projection_pushing.go index 72aaf5abcd5..e770ef1c9bd 100644 --- a/go/vt/vtgate/planbuilder/projection_pushing.go +++ b/go/vt/vtgate/planbuilder/projection_pushing.go @@ -328,10 +328,7 @@ func rewriteProjectionOfDerivedTable(expr *sqlparser.AliasedExpr, semTable *sema } _, isDerivedTable := ti.(*semantics.DerivedTable) if isDerivedTable { - expr.Expr, err = semantics.RewriteDerivedTableExpression(expr.Expr, ti) - if err != nil { - return err - } + expr.Expr = semantics.RewriteDerivedTableExpression(expr.Expr, ti) } return nil } diff --git a/go/vt/vtgate/semantics/early_rewriter.go b/go/vt/vtgate/semantics/early_rewriter.go index e575f78e6ee..dce0e6e2da2 100644 --- a/go/vt/vtgate/semantics/early_rewriter.go +++ b/go/vt/vtgate/semantics/early_rewriter.go @@ -233,11 +233,10 @@ func (r *earlyRewriter) rewriteOrderByExpr(node *sqlparser.Literal) (sqlparser.E // realCloneOfColNames clones all the expressions including ColName. // Since sqlparser.CloneRefOfColName does not clone col names, this method is needed. func realCloneOfColNames(expr sqlparser.Expr, union bool) sqlparser.Expr { - // todo copy-on-rewrite! - return sqlparser.SafeRewrite(sqlparser.CloneExpr(expr), nil, func(cursor *sqlparser.Cursor) bool { + return sqlparser.CopyOnRewrite(expr, nil, func(cursor *sqlparser.CopyOnWriteCursor) { exp, ok := cursor.Node().(*sqlparser.ColName) if !ok { - return true + return } newColName := *exp @@ -245,8 +244,7 @@ func realCloneOfColNames(expr sqlparser.Expr, union bool) sqlparser.Expr { newColName.Qualifier = sqlparser.TableName{} } cursor.Replace(&newColName) - return true - }).(sqlparser.Expr) + }, nil).(sqlparser.Expr) } func rewriteOrFalse(orExpr sqlparser.OrExpr) sqlparser.Expr { diff --git a/go/vt/vtgate/semantics/semantic_state.go b/go/vt/vtgate/semantics/semantic_state.go index 9d23c336610..49fcf715d2e 100644 --- a/go/vt/vtgate/semantics/semantic_state.go +++ b/go/vt/vtgate/semantics/semantic_state.go @@ -309,25 +309,24 @@ func (d ExprDependencies) dependencies(expr sqlparser.Expr) (deps TableSet) { // the expressions behind the column definition of the derived table // SELECT foo FROM (SELECT id+42 as foo FROM user) as t // We need `foo` to be translated to `id+42` on the inside of the derived table -func RewriteDerivedTableExpression(expr sqlparser.Expr, vt TableInfo) (sqlparser.Expr, error) { - newExpr := sqlparser.SafeRewrite(sqlparser.CloneExpr(expr), nil, func(cursor *sqlparser.Cursor) bool { +func RewriteDerivedTableExpression(expr sqlparser.Expr, vt TableInfo) sqlparser.Expr { + return sqlparser.CopyOnRewrite(expr, nil, func(cursor *sqlparser.CopyOnWriteCursor) { node, ok := cursor.Node().(*sqlparser.ColName) if !ok { - return true + return } exp, err := vt.getExprFor(node.Name.String()) if err == nil { cursor.Replace(exp) - } else { - // cloning the expression and removing the qualifier - col := *node - col.Qualifier = sqlparser.TableName{} - cursor.Replace(&col) + return } - return true - }) - return newExpr.(sqlparser.Expr), nil + // cloning the expression and removing the qualifier + col := *node + col.Qualifier = sqlparser.TableName{} + cursor.Replace(&col) + + }, nil).(sqlparser.Expr) } // FindSubqueryReference goes over the sub queries and searches for it by value equality instead of reference equality diff --git a/go/vt/vtgate/vindexes/vschema.go b/go/vt/vtgate/vindexes/vschema.go index 3fa654fcdc1..da2460f8196 100644 --- a/go/vt/vtgate/vindexes/vschema.go +++ b/go/vt/vtgate/vindexes/vschema.go @@ -957,7 +957,6 @@ func (vschema *VSchema) FindView(keyspace, name string) sqlparser.SelectStatemen } // We do this to make sure there is no shared state between uses of this AST - // todo copy-on-rewrite! statement = sqlparser.CloneSelectStatement(statement) sqlparser.SafeRewrite(statement, nil, func(cursor *sqlparser.Cursor) bool { col, ok := cursor.Node().(*sqlparser.ColName) From 837594e0dd36c767cb41505c6c189a05272d3cc4 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 24 Jan 2023 18:33:07 +0100 Subject: [PATCH 5/5] regenerate test code Signed-off-by: Andres Taylor --- .../asthelpergen/integration/ast_clone.go | 2 +- .../integration/ast_copy_on_rewrite.go | 391 ++++++++++++++++++ .../asthelpergen/integration/ast_equals.go | 2 +- .../asthelpergen/integration/ast_rewrite.go | 2 +- .../asthelpergen/integration/ast_visit.go | 2 +- .../asthelpergen/integration/test_helpers.go | 16 + 6 files changed, 411 insertions(+), 4 deletions(-) create mode 100644 go/tools/asthelpergen/integration/ast_copy_on_rewrite.go diff --git a/go/tools/asthelpergen/integration/ast_clone.go b/go/tools/asthelpergen/integration/ast_clone.go index 3ed3dc1be2c..d5857c89834 100644 --- a/go/tools/asthelpergen/integration/ast_clone.go +++ b/go/tools/asthelpergen/integration/ast_clone.go @@ -1,5 +1,5 @@ /* -Copyright 2021 The Vitess Authors. +Copyright 2023 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. diff --git a/go/tools/asthelpergen/integration/ast_copy_on_rewrite.go b/go/tools/asthelpergen/integration/ast_copy_on_rewrite.go new file mode 100644 index 00000000000..d48e8621692 --- /dev/null +++ b/go/tools/asthelpergen/integration/ast_copy_on_rewrite.go @@ -0,0 +1,391 @@ +/* +Copyright 2023 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// Code generated by ASTHelperGen. DO NOT EDIT. + +package integration + +func (c *cow) copyOnRewriteAST(n AST, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case BasicType: + return c.copyOnRewriteBasicType(n, parent) + case Bytes: + return c.copyOnRewriteBytes(n, parent) + case InterfaceContainer: + return c.copyOnRewriteInterfaceContainer(n, parent) + case InterfaceSlice: + return c.copyOnRewriteInterfaceSlice(n, parent) + case *Leaf: + return c.copyOnRewriteRefOfLeaf(n, parent) + case LeafSlice: + return c.copyOnRewriteLeafSlice(n, parent) + case *NoCloneType: + return c.copyOnRewriteRefOfNoCloneType(n, parent) + case *RefContainer: + return c.copyOnRewriteRefOfRefContainer(n, parent) + case *RefSliceContainer: + return c.copyOnRewriteRefOfRefSliceContainer(n, parent) + case *SubImpl: + return c.copyOnRewriteRefOfSubImpl(n, parent) + case ValueContainer: + return c.copyOnRewriteValueContainer(n, parent) + case ValueSliceContainer: + return c.copyOnRewriteValueSliceContainer(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteBytes(n Bytes, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre != nil { + c.pre(n, parent) + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteInterfaceContainer(n InterfaceContainer, parent AST) (out AST, changed bool) { + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteInterfaceSlice(n InterfaceSlice, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(InterfaceSlice, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteAST(el, n) + res[x] = this.(AST) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteRefOfLeaf(n *Leaf, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteLeafSlice(n LeafSlice, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + res := make(LeafSlice, len(n)) + for x, el := range n { + this, change := c.copyOnRewriteRefOfLeaf(el, n) + res[x] = this.(*Leaf) + if change { + changed = true + } + } + if changed { + out = res + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteRefOfNoCloneType(n *NoCloneType, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteRefOfRefContainer(n *RefContainer, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _ASTType, changedASTType := c.copyOnRewriteAST(n.ASTType, n) + _ASTImplementationType, changedASTImplementationType := c.copyOnRewriteRefOfLeaf(n.ASTImplementationType, n) + if changedASTType || changedASTImplementationType { + res := *n + res.ASTType, _ = _ASTType.(AST) + res.ASTImplementationType, _ = _ASTImplementationType.(*Leaf) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteRefOfRefSliceContainer(n *RefSliceContainer, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + var changedASTElements bool + _ASTElements := make([]AST, len(n.ASTElements)) + for x, el := range n.ASTElements { + this, changed := c.copyOnRewriteAST(el, n) + _ASTElements[x] = this.(AST) + if changed { + changedASTElements = true + } + } + var changedASTImplementationElements bool + _ASTImplementationElements := make([]*Leaf, len(n.ASTImplementationElements)) + for x, el := range n.ASTImplementationElements { + this, changed := c.copyOnRewriteRefOfLeaf(el, n) + _ASTImplementationElements[x] = this.(*Leaf) + if changed { + changedASTImplementationElements = true + } + } + if changedASTElements || changedASTImplementationElements { + res := *n + res.ASTElements = _ASTElements + res.ASTImplementationElements = _ASTImplementationElements + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteRefOfSubImpl(n *SubImpl, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _inner, changedinner := c.copyOnRewriteSubIface(n.inner, n) + if changedinner { + res := *n + res.inner, _ = _inner.(SubIface) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteValueContainer(n ValueContainer, parent AST) (out AST, changed bool) { + out = n + if c.pre == nil || c.pre(n, parent) { + _ASTType, changedASTType := c.copyOnRewriteAST(n.ASTType, n) + _ASTImplementationType, changedASTImplementationType := c.copyOnRewriteRefOfLeaf(n.ASTImplementationType, n) + if changedASTType || changedASTImplementationType { + res := n + res.ASTType, _ = _ASTType.(AST) + res.ASTImplementationType, _ = _ASTImplementationType.(*Leaf) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteValueSliceContainer(n ValueSliceContainer, parent AST) (out AST, changed bool) { + out = n + if c.pre == nil || c.pre(n, parent) { + var changedASTElements bool + _ASTElements := make([]AST, len(n.ASTElements)) + for x, el := range n.ASTElements { + this, changed := c.copyOnRewriteAST(el, n) + _ASTElements[x] = this.(AST) + if changed { + changedASTElements = true + } + } + var changedASTImplementationElements bool + _ASTImplementationElements := make([]*Leaf, len(n.ASTImplementationElements)) + for x, el := range n.ASTImplementationElements { + this, changed := c.copyOnRewriteRefOfLeaf(el, n) + _ASTImplementationElements[x] = this.(*Leaf) + if changed { + changedASTImplementationElements = true + } + } + if changedASTElements || changedASTImplementationElements { + res := n + res.ASTElements = _ASTElements + res.ASTImplementationElements = _ASTImplementationElements + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteSubIface(n SubIface, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + switch n := n.(type) { + case *SubImpl: + return c.copyOnRewriteRefOfSubImpl(n, parent) + default: + // this should never happen + return nil, false + } +} +func (c *cow) copyOnRewriteBasicType(n BasicType, parent AST) (out AST, changed bool) { + if c.cursor.stop { + return n, false + } + if c.pre != nil { + c.pre(n, parent) + } + if c.post != nil { + out, changed = c.postVisit(n, parent, changed) + } else { + out = n + } + return +} +func (c *cow) copyOnRewriteRefOfInterfaceContainer(n *InterfaceContainer, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteRefOfValueContainer(n *ValueContainer, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + _ASTType, changedASTType := c.copyOnRewriteAST(n.ASTType, n) + _ASTImplementationType, changedASTImplementationType := c.copyOnRewriteRefOfLeaf(n.ASTImplementationType, n) + if changedASTType || changedASTImplementationType { + res := *n + res.ASTType, _ = _ASTType.(AST) + res.ASTImplementationType, _ = _ASTImplementationType.(*Leaf) + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} +func (c *cow) copyOnRewriteRefOfValueSliceContainer(n *ValueSliceContainer, parent AST) (out AST, changed bool) { + if n == nil || c.cursor.stop { + return n, false + } + out = n + if c.pre == nil || c.pre(n, parent) { + var changedASTElements bool + _ASTElements := make([]AST, len(n.ASTElements)) + for x, el := range n.ASTElements { + this, changed := c.copyOnRewriteAST(el, n) + _ASTElements[x] = this.(AST) + if changed { + changedASTElements = true + } + } + var changedASTImplementationElements bool + _ASTImplementationElements := make([]*Leaf, len(n.ASTImplementationElements)) + for x, el := range n.ASTImplementationElements { + this, changed := c.copyOnRewriteRefOfLeaf(el, n) + _ASTImplementationElements[x] = this.(*Leaf) + if changed { + changedASTImplementationElements = true + } + } + if changedASTElements || changedASTImplementationElements { + res := *n + res.ASTElements = _ASTElements + res.ASTImplementationElements = _ASTImplementationElements + out = &res + if c.cloned != nil { + c.cloned(n, out) + } + changed = true + } + } + if c.post != nil { + out, changed = c.postVisit(out, parent, changed) + } + return +} diff --git a/go/tools/asthelpergen/integration/ast_equals.go b/go/tools/asthelpergen/integration/ast_equals.go index 3fc317fbae8..553851a8c97 100644 --- a/go/tools/asthelpergen/integration/ast_equals.go +++ b/go/tools/asthelpergen/integration/ast_equals.go @@ -1,5 +1,5 @@ /* -Copyright 2021 The Vitess Authors. +Copyright 2023 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. diff --git a/go/tools/asthelpergen/integration/ast_rewrite.go b/go/tools/asthelpergen/integration/ast_rewrite.go index 3741b2080cb..cf92b358862 100644 --- a/go/tools/asthelpergen/integration/ast_rewrite.go +++ b/go/tools/asthelpergen/integration/ast_rewrite.go @@ -1,5 +1,5 @@ /* -Copyright 2021 The Vitess Authors. +Copyright 2023 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. diff --git a/go/tools/asthelpergen/integration/ast_visit.go b/go/tools/asthelpergen/integration/ast_visit.go index 8fb3c89ad56..6ceec4e2fc5 100644 --- a/go/tools/asthelpergen/integration/ast_visit.go +++ b/go/tools/asthelpergen/integration/ast_visit.go @@ -1,5 +1,5 @@ /* -Copyright 2021 The Vitess Authors. +Copyright 2023 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. diff --git a/go/tools/asthelpergen/integration/test_helpers.go b/go/tools/asthelpergen/integration/test_helpers.go index db9facb3c3b..67745f19687 100644 --- a/go/tools/asthelpergen/integration/test_helpers.go +++ b/go/tools/asthelpergen/integration/test_helpers.go @@ -98,3 +98,19 @@ func Rewrite(node AST, pre, post ApplyFunc) AST { return outer.AST } + +type ( + cow struct { + pre func(node, parent AST) bool + post func(cursor *cursor) + cloned func(old, new AST) + cursor cursor + } + cursor struct { + stop bool + } +) + +func (c *cow) postVisit(a, b AST, d bool) (AST, bool) { + return a, d +}