Skip to content

Commit a5f5029

Browse files
committed
rename
1 parent c1ea2e9 commit a5f5029

File tree

7 files changed

+38
-19
lines changed

7 files changed

+38
-19
lines changed

expression/column.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ func (col *CorrelatedColumn) IsCorrelated() bool {
123123
return true
124124
}
125125

126-
// ReferTable implements Expression interface.
127-
func (col *CorrelatedColumn) ReferTable() bool {
128-
return true
126+
// ConstItem implements Expression interface.
127+
func (col *CorrelatedColumn) ConstItem() bool {
128+
return false
129129
}
130130

131131
// Decorrelate implements Expression interface.
@@ -302,9 +302,9 @@ func (col *Column) IsCorrelated() bool {
302302
return false
303303
}
304304

305-
// ReferTable implements Expression interface.
306-
func (col *Column) ReferTable() bool {
307-
return true
305+
// ConstItem implements Expression interface.
306+
func (col *Column) ConstItem() bool {
307+
return false
308308
}
309309

310310
// Decorrelate implements Expression interface.

expression/column_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (s *testEvaluatorSuite) TestColumn(c *C) {
4343
c.Assert(corCol.Equal(nil, corCol), IsTrue)
4444
c.Assert(corCol.Equal(nil, invalidCorCol), IsFalse)
4545
c.Assert(corCol.IsCorrelated(), IsTrue)
46-
c.Assert(corCol.ReferTable(), IsTrue)
46+
c.Assert(corCol.ConstItem(), IsFalse)
4747
c.Assert(corCol.Decorrelate(schema).Equal(nil, col), IsTrue)
4848
c.Assert(invalidCorCol.Decorrelate(schema).Equal(nil, invalidCorCol), IsTrue)
4949

expression/constant.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ func (c *Constant) IsCorrelated() bool {
311311
return false
312312
}
313313

314-
// ReferTable implements Expression interface.
315-
func (c *Constant) ReferTable() bool {
316-
return false
314+
// ConstItem implements Expression interface.
315+
func (c *Constant) ConstItem() bool {
316+
return true
317317
}
318318

319319
// Decorrelate implements Expression interface.

expression/expression.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ type Expression interface {
7979
// IsCorrelated checks if this expression has correlated key.
8080
IsCorrelated() bool
8181

82-
// ReferTable checks if this expression refers to a table.
83-
ReferTable() bool
82+
// ConstItem checks if this expression refers to a table.
83+
ConstItem() bool
8484

8585
// Decorrelate try to decorrelate the expression by schema.
8686
Decorrelate(schema *Schema) Expression

expression/expression_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (s *testEvaluatorSuite) TestConstant(c *C) {
6161

6262
sc := &stmtctx.StatementContext{TimeZone: time.Local}
6363
c.Assert(Zero.IsCorrelated(), IsFalse)
64-
c.Assert(Zero.ReferTable(), IsFalse)
64+
c.Assert(Zero.ConstItem(), IsTrue)
6565
c.Assert(Zero.Decorrelate(nil).Equal(s.ctx, Zero), IsTrue)
6666
c.Assert(Zero.HashCode(sc), DeepEquals, []byte{0x0, 0x8, 0x0})
6767
c.Assert(Zero.Equal(s.ctx, One), IsFalse)
@@ -86,6 +86,19 @@ func (s *testEvaluatorSuite) TestIsBinaryLiteral(c *C) {
8686
c.Assert(IsBinaryLiteral(con), IsFalse)
8787
}
8888

89+
func (s *testEvaluatorSuite) TestConstItem(c *C) {
90+
defer testleak.AfterTest(c)()
91+
92+
sf := newFunction(ast.Rand)
93+
c.Assert(sf.ConstItem(), Equals, false)
94+
sf = newFunction(ast.UUID)
95+
c.Assert(sf.ConstItem(), Equals, false)
96+
sf = newFunction(ast.GetParam, One)
97+
c.Assert(sf.ConstItem(), Equals, false)
98+
sf = newFunction(ast.Abs, One)
99+
c.Assert(sf.ConstItem(), Equals, true)
100+
}
101+
89102
type testTableBuilder struct {
90103
tableName string
91104
columnNames []string

expression/scalar_function.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,20 @@ func (sf *ScalarFunction) IsCorrelated() bool {
165165
return false
166166
}
167167

168-
// ReferTable implements Expression interface.
169-
func (sf *ScalarFunction) ReferTable() bool {
168+
// ConstItem implements Expression interface.
169+
func (sf *ScalarFunction) ConstItem() bool {
170+
if _, ok := DeferredFunctions[sf.FuncName.L]; ok {
171+
return false
172+
}
173+
if sf.FuncName.L == ast.GetParam {
174+
return false
175+
}
170176
for _, arg := range sf.GetArgs() {
171-
if arg.ReferTable() {
172-
return true
177+
if !arg.ConstItem() {
178+
return false
173179
}
174180
}
175-
return false
181+
return true
176182
}
177183

178184
// Decorrelate implements Expression interface.

expression/scalar_function_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (s *testEvaluatorSuite) TestScalarFunction(c *C) {
4040
c.Assert(err, IsNil)
4141
c.Assert(res, DeepEquals, []byte{0x22, 0x6c, 0x74, 0x28, 0x66, 0x65, 0x69, 0x2e, 0x68, 0x61, 0x6e, 0x2c, 0x20, 0x31, 0x29, 0x22})
4242
c.Assert(sf.IsCorrelated(), IsFalse)
43-
c.Assert(sf.ReferTable(), IsTrue)
43+
c.Assert(sf.ConstItem(), IsFalse)
4444
c.Assert(sf.Decorrelate(nil).Equal(s.ctx, sf), IsTrue)
4545
c.Assert(sf.HashCode(sc), DeepEquals, []byte{0x3, 0x4, 0x6c, 0x74, 0x1, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x5, 0xbf, 0xf0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0})
4646

0 commit comments

Comments
 (0)