@@ -25,6 +25,7 @@ type TableAlias struct {
2525 comment string
2626 id sql.TableId
2727 cols sql.ColSet
28+ sch sql.Schema
2829}
2930
3031var _ sql.RenameableNode = (* TableAlias )(nil )
@@ -33,7 +34,18 @@ var _ sql.CollationCoercible = (*TableAlias)(nil)
3334
3435// NewTableAlias returns a new Table alias node.
3536func NewTableAlias (name string , node sql.Node ) * TableAlias {
36- ret := & TableAlias {UnaryNode : & UnaryNode {Child : node }, name : name }
37+ childSchema := node .Schema ()
38+ schema := make (sql.Schema , len (childSchema ))
39+ for i , col := range childSchema {
40+ newCol := * col
41+ newCol .Source = name
42+ schema [i ] = & newCol
43+ }
44+ ret := & TableAlias {
45+ UnaryNode : & UnaryNode {Child : node },
46+ name : name ,
47+ sch : schema ,
48+ }
3749 if tin , ok := node .(TableIdNode ); ok {
3850 ret .id = tin .Id ()
3951 ret .cols = tin .Columns ()
@@ -87,14 +99,7 @@ func (t *TableAlias) Comment() string {
8799// Schema implements the Node interface. TableAlias alters the schema of its child element to rename the source of
88100// columns to the alias.
89101func (t * TableAlias ) Schema () sql.Schema {
90- childSchema := t .Child .Schema ()
91- copy := make (sql.Schema , len (childSchema ))
92- for i , col := range childSchema {
93- colCopy := * col
94- colCopy .Source = t .name
95- copy [i ] = & colCopy
96- }
97- return copy
102+ return t .sch
98103}
99104
100105// WithChildren implements the Node interface.
@@ -118,21 +123,22 @@ func (t *TableAlias) CollationCoercibility(ctx *sql.Context) (collation sql.Coll
118123 return sql .Collation_binary , 7
119124}
120125
121- func (t TableAlias ) String () string {
126+ func (t * TableAlias ) String () string {
122127 pr := sql .NewTreePrinter ()
123128 _ = pr .WriteNode ("TableAlias(%s)" , t .name )
124129 _ = pr .WriteChildren (t .Child .String ())
125130 return pr .String ()
126131}
127132
128- func (t TableAlias ) DebugString () string {
133+ func (t * TableAlias ) DebugString () string {
129134 pr := sql .NewTreePrinter ()
130135 _ = pr .WriteNode ("TableAlias(%s)" , t .name )
131136 _ = pr .WriteChildren (sql .DebugString (t .Child ))
132137 return pr .String ()
133138}
134139
135- func (t TableAlias ) WithName (name string ) sql.Node {
136- t .name = name
137- return & t
140+ func (t * TableAlias ) WithName (name string ) sql.Node {
141+ nt := * t
142+ nt .name = name
143+ return & nt
138144}
0 commit comments