File tree Expand file tree Collapse file tree 1 file changed +15
-12
lines changed Expand file tree Collapse file tree 1 file changed +15
-12
lines changed Original file line number Diff line number Diff line change @@ -21,11 +21,12 @@ import (
2121// TableAlias is a node that acts as a table with a given name.
2222type TableAlias struct {
2323 * UnaryNode
24- name string
25- comment string
26- id sql.TableId
27- cols sql.ColSet
28- sch sql.Schema
24+ name string
25+ comment string
26+ id sql.TableId
27+ cols sql.ColSet
28+ sch sql.Schema
29+ cachedSch bool
2930}
3031
3132var _ sql.RenameableNode = (* TableAlias )(nil )
@@ -34,13 +35,7 @@ var _ sql.CollationCoercible = (*TableAlias)(nil)
3435
3536// NewTableAlias returns a new Table alias node.
3637func NewTableAlias (name string , node sql.Node ) * TableAlias {
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- }
38+ schema := make (sql.Schema , len (node .Schema ()))
4439 ret := & TableAlias {
4540 UnaryNode : & UnaryNode {Child : node },
4641 name : name ,
@@ -99,6 +94,14 @@ func (t *TableAlias) Comment() string {
9994// Schema implements the Node interface. TableAlias alters the schema of its child element to rename the source of
10095// columns to the alias.
10196func (t * TableAlias ) Schema () sql.Schema {
97+ if ! t .cachedSch {
98+ for i , col := range t .Child .Schema () {
99+ newCol := * col
100+ newCol .Source = t .name
101+ t .sch [i ] = & newCol
102+ }
103+ t .cachedSch = true
104+ }
102105 return t .sch
103106}
104107
You can’t perform that action at this time.
0 commit comments