@@ -25,6 +25,7 @@ type TableAlias struct {
25
25
comment string
26
26
id sql.TableId
27
27
cols sql.ColSet
28
+ sch sql.Schema
28
29
}
29
30
30
31
var _ sql.RenameableNode = (* TableAlias )(nil )
@@ -33,7 +34,18 @@ var _ sql.CollationCoercible = (*TableAlias)(nil)
33
34
34
35
// NewTableAlias returns a new Table alias node.
35
36
func 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
+ }
37
49
if tin , ok := node .(TableIdNode ); ok {
38
50
ret .id = tin .Id ()
39
51
ret .cols = tin .Columns ()
@@ -87,14 +99,7 @@ func (t *TableAlias) Comment() string {
87
99
// Schema implements the Node interface. TableAlias alters the schema of its child element to rename the source of
88
100
// columns to the alias.
89
101
func (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
98
103
}
99
104
100
105
// WithChildren implements the Node interface.
@@ -118,21 +123,22 @@ func (t *TableAlias) CollationCoercibility(ctx *sql.Context) (collation sql.Coll
118
123
return sql .Collation_binary , 7
119
124
}
120
125
121
- func (t TableAlias ) String () string {
126
+ func (t * TableAlias ) String () string {
122
127
pr := sql .NewTreePrinter ()
123
128
_ = pr .WriteNode ("TableAlias(%s)" , t .name )
124
129
_ = pr .WriteChildren (t .Child .String ())
125
130
return pr .String ()
126
131
}
127
132
128
- func (t TableAlias ) DebugString () string {
133
+ func (t * TableAlias ) DebugString () string {
129
134
pr := sql .NewTreePrinter ()
130
135
_ = pr .WriteNode ("TableAlias(%s)" , t .name )
131
136
_ = pr .WriteChildren (sql .DebugString (t .Child ))
132
137
return pr .String ()
133
138
}
134
139
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
138
144
}
0 commit comments