Skip to content

Commit 9d1b015

Browse files
author
James Cor
committed
fix view default for filters and add join test
1 parent 0097f74 commit 9d1b015

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

enginetest/queries/information_schema_queries.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,17 +1160,25 @@ FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'mydb'`,
11601160
"drop table othertable",
11611161
"CREATE TABLE t (i int primary key, j int default (uuid_to_bin(uuid())));",
11621162
"CREATE VIEW v as select i + 1, j, j * 2, mod(i, j) from t;",
1163+
"create table tt (ii int primary key, jj int default (pow(1, 2)));",
1164+
"create view vv as select * from t join tt where i = ii;",
11631165
},
11641166
Assertions: []ScriptTestAssertion{
11651167
{
11661168
Query: "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = 'foo'",
11671169
Expected: []sql.Row{
11681170
{"def", "foo", "t", "i", uint32(1), nil, "NO", "int", nil, nil, 10, 0, nil, nil, nil, "int", "PRI", "", "insert,references,select,update", "", "", nil},
11691171
{"def", "foo", "t", "j", uint32(2), "UUID_TO_BIN(uuid())", "YES", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "DEFAULT_GENERATED", "insert,references,select,update", "", "", nil},
1172+
{"def", "foo", "tt", "ii", uint32(1), nil, "NO", "int", nil, nil, 10, 0, nil, nil, nil, "int", "PRI", "", "insert,references,select,update", "", "", nil},
1173+
{"def", "foo", "tt", "jj", uint32(2), "power(1, 2)", "YES", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "DEFAULT_GENERATED", "insert,references,select,update", "", "", nil},
11701174
{"def", "foo", "v", "i + 1", uint32(1), nil, "NO", "bigint", nil, nil, 19, 0, nil, nil, nil, "bigint", "", "", "insert,references,select,update", "", "", nil},
11711175
{"def", "foo", "v", "j", uint32(2), "UUID_TO_BIN(uuid())", "YES", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "DEFAULT_GENERATED", "insert,references,select,update", "", "", nil},
11721176
{"def", "foo", "v", "j * 2", uint32(3), nil, "YES", "bigint", nil, nil, 19, 0, nil, nil, nil, "bigint", "", "", "insert,references,select,update", "", "", nil},
11731177
{"def", "foo", "v", "mod(i, j)", uint32(4), nil, "YES", "decimal", nil, nil, 10, 0, nil, nil, nil, "decimal(10,0)", "", "", "insert,references,select,update", "", "", nil},
1178+
{"def", "foo", "vv", "i", uint32(1), nil, "NO", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "", "insert,references,select,update", "", "", nil},
1179+
{"def", "foo", "vv", "j", uint32(2), "UUID_TO_BIN(uuid())", "YES", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "DEFAULT_GENERATED", "insert,references,select,update", "", "", nil},
1180+
{"def", "foo", "vv", "ii", uint32(3), nil, "NO", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "", "insert,references,select,update", "", "", nil},
1181+
{"def", "foo", "vv", "jj", uint32(4), "power(1, 2)", "YES", "int", nil, nil, 10, 0, nil, nil, nil, "int", "", "DEFAULT_GENERATED", "insert,references,select,update", "", "", nil},
11741182
},
11751183
},
11761184
},

enginetest/queries/view_queries.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,11 @@ CREATE TABLE tab1 (
203203
SetUpScript: []string{
204204
"create table t (i int primary key, j int default 100);",
205205
"insert into t(i) values (1);",
206+
"create table tt (ii int primary key, jj int default (pow(11, 2)));",
207+
"insert into tt values (1, default), (3, 4);",
206208
"create view v as select * from t;",
207209
"create view v1 as select i, j + 10 as jj from t;",
210+
"create view vv as select i, ii, j, jj, i + ii + j + jj from t join tt where i = ii;",
208211
},
209212
Assertions: []ScriptTestAssertion{
210213
{
@@ -249,6 +252,36 @@ CREATE TABLE tab1 (
249252
{"jj", "bigint", "YES", "", nil, ""},
250253
},
251254
},
255+
{
256+
Query: "show full columns from vv;",
257+
Expected: []sql.Row{
258+
{"i", "int", nil, "NO", "", nil, "", "", ""},
259+
{"ii", "int", nil, "NO", "", nil, "", "", ""},
260+
{"j", "int", nil, "YES", "", "100", "", "", ""},
261+
{"jj", "int", nil, "YES", "", "(power(11, 2))", "DEFAULT_GENERATED", "", ""},
262+
{"i + ii + j + jj", "bigint", nil, "YES", "", nil, "", "", ""},
263+
},
264+
},
265+
{
266+
Query: "show columns from vv;",
267+
Expected: []sql.Row{
268+
{"i", "int", "NO", "", nil, ""},
269+
{"ii", "int", "NO", "", nil, ""},
270+
{"j", "int", "YES", "", "100", ""},
271+
{"jj", "int", "YES", "", "(power(11, 2))", "DEFAULT_GENERATED"},
272+
{"i + ii + j + jj", "bigint", "YES", "", nil, ""},
273+
},
274+
},
275+
{
276+
Query: "describe vv;",
277+
Expected: []sql.Row{
278+
{"i", "int", "NO", "", nil, ""},
279+
{"ii", "int", "NO", "", nil, ""},
280+
{"j", "int", "YES", "", "100", ""},
281+
{"jj", "int", "YES", "", "(power(11, 2))", "DEFAULT_GENERATED"},
282+
{"i + ii + j + jj", "bigint", "YES", "", nil, ""},
283+
},
284+
},
252285
},
253286
},
254287
}

sql/plan/project.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ func findDefault(node sql.Node, gf *expression.GetField) *sql.ColumnDefaultValue
5353
return findDefault(n.Child, gf)
5454
case *HashLookup:
5555
return findDefault(n.Child, gf)
56+
case *Filter:
57+
return findDefault(n.Child, gf)
5658
case *JoinNode:
5759
if defVal := findDefault(n.Left(), gf); defVal != nil {
5860
return defVal

0 commit comments

Comments
 (0)