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 (
21
21
// TableAlias is a node that acts as a table with a given name.
22
22
type TableAlias struct {
23
23
* 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
29
30
}
30
31
31
32
var _ sql.RenameableNode = (* TableAlias )(nil )
@@ -34,13 +35,7 @@ var _ sql.CollationCoercible = (*TableAlias)(nil)
34
35
35
36
// NewTableAlias returns a new Table alias node.
36
37
func 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 ()))
44
39
ret := & TableAlias {
45
40
UnaryNode : & UnaryNode {Child : node },
46
41
name : name ,
@@ -99,6 +94,14 @@ func (t *TableAlias) Comment() string {
99
94
// Schema implements the Node interface. TableAlias alters the schema of its child element to rename the source of
100
95
// columns to the alias.
101
96
func (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
+ }
102
105
return t .sch
103
106
}
104
107
You can’t perform that action at this time.
0 commit comments