Skip to content

Commit a0c87df

Browse files
author
James Cor
committed
even fewer allocs
1 parent dade765 commit a0c87df

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

memory/index.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@ func (idx *Index) Reversible() bool {
298298
return true
299299
}
300300

301-
func (idx Index) copy() *Index {
302-
return &idx
301+
func (idx *Index) copy() *Index {
302+
newIdx := *idx
303+
return &newIdx
303304
}
304305

305306
// columnIndexes returns the indexes in the given schema for the fields in this index

sql/plan/project.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ type Project struct {
3636
IncludesNestedIters bool
3737
deps sql.ColSet
3838

39-
sch sql.Schema
40-
cachedSch bool
39+
sch sql.Schema
4140
}
4241

4342
var _ sql.Expressioner = (*Project)(nil)
@@ -50,7 +49,6 @@ func NewProject(expressions []sql.Expression, child sql.Node) *Project {
5049
return &Project{
5150
UnaryNode: UnaryNode{child},
5251
Projections: expressions,
53-
sch: make(sql.Schema, len(expressions)),
5452
}
5553
}
5654

@@ -126,8 +124,8 @@ func ExprDeps(exprs ...sql.Expression) sql.ColSet {
126124

127125
// Schema implements the Node interface.
128126
func (p *Project) Schema() sql.Schema {
129-
if !p.cachedSch {
130-
p.cachedSch = true
127+
if p.sch == nil {
128+
p.sch = make(sql.Schema, len(p.Projections))
131129
for i, expr := range p.Projections {
132130
p.sch[i] = transform.ExpressionToColumn(expr, AliasSubqueryString(expr))
133131
if gf := unwrapGetField(expr); gf != nil {

sql/plan/tablealias.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ var _ sql.CollationCoercible = (*TableAlias)(nil)
3535

3636
// NewTableAlias returns a new Table alias node.
3737
func NewTableAlias(name string, node sql.Node) *TableAlias {
38-
schema := make(sql.Schema, len(node.Schema()))
3938
ret := &TableAlias{
4039
UnaryNode: &UnaryNode{Child: node},
4140
name: name,
42-
sch: schema,
4341
}
4442
if tin, ok := node.(TableIdNode); ok {
4543
ret.id = tin.Id()
@@ -94,13 +92,14 @@ func (t *TableAlias) Comment() string {
9492
// Schema implements the Node interface. TableAlias alters the schema of its child element to rename the source of
9593
// columns to the alias.
9694
func (t *TableAlias) Schema() sql.Schema {
97-
if !t.cachedSch {
98-
for i, col := range t.Child.Schema() {
95+
if t.sch == nil {
96+
childSchema := t.Child.Schema()
97+
t.sch = make(sql.Schema, len(childSchema))
98+
for i, col := range childSchema {
9999
newCol := *col
100100
newCol.Source = t.name
101101
t.sch[i] = &newCol
102102
}
103-
t.cachedSch = true
104103
}
105104
return t.sch
106105
}

0 commit comments

Comments
 (0)