Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add null as a valid constant SELECT value for vtexplain. #5624

Merged
merged 1 commit into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions go/vt/vtexplain/testdata/multi-output/selectsharded-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ select name, count(*) from user group by name /* scatter aggregate */
1 ks_sharded/c0-: select name, count(*) from user group by name limit 10001 /* scatter aggregate */

----------------------------------------------------------------------
select 1, "hello", 3.14 from user limit 10 /* select constant sql values */
select 1, "hello", 3.14, null from user limit 10 /* select constant sql values */

1 ks_sharded/-40: select 1, 'hello', 3.14 from user limit 10 /* select constant sql values */
1 ks_sharded/40-80: select 1, 'hello', 3.14 from user limit 10 /* select constant sql values */
1 ks_sharded/80-c0: select 1, 'hello', 3.14 from user limit 10 /* select constant sql values */
1 ks_sharded/c0-: select 1, 'hello', 3.14 from user limit 10 /* select constant sql values */
1 ks_sharded/-40: select 1, 'hello', 3.14, null from user limit 10 /* select constant sql values */
1 ks_sharded/40-80: select 1, 'hello', 3.14, null from user limit 10 /* select constant sql values */
1 ks_sharded/80-c0: select 1, 'hello', 3.14, null from user limit 10 /* select constant sql values */
1 ks_sharded/c0-: select 1, 'hello', 3.14, null from user limit 10 /* select constant sql values */

----------------------------------------------------------------------
select * from (select id from user) s /* scatter paren select */
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtexplain/testdata/selectsharded-queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ select count(*) from user where id = 1 /* point aggregate */;
select count(*) from user where name in ('alice','bob') /* scatter aggregate */;
select name, count(*) from user group by name /* scatter aggregate */;

select 1, "hello", 3.14 from user limit 10 /* select constant sql values */;
select 1, "hello", 3.14, null from user limit 10 /* select constant sql values */;
select * from (select id from user) s /* scatter paren select */;

select name from user where id = (select id from t1) /* non-correlated subquery as value */;
Expand All @@ -31,4 +31,4 @@ select id, case when name = 'alice' then 'ALICE' when name = 'bob' then 'BOB' en
select id, case when name = 'alice' then 'ALICE' when name = 'bob' then 'BOB' else 'OTHER' end as name from user where id = 1 /* select case */;
select id, case when substr(name, 1, 5) = 'alice' then 'ALICE' when name = 'bob' then 'BOB' else 'OTHER' end as name from user where id = 1 /* select case */;

select id, 'abc' as test from user where id = 1 union all select id, 'def' as test from user where id = 1 union all select id, 'ghi' as test from user where id = 1 /* union all */;
select id, 'abc' as test from user where id = 1 union all select id, 'def' as test from user where id = 1 union all select id, 'ghi' as test from user where id = 1 /* union all */;
3 changes: 3 additions & 0 deletions go/vt/vtexplain/vtexplain_vttablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ func inferColTypeFromExpr(node sqlparser.Expr, colTypeMap map[string]querypb.Typ
colNames, colTypes = inferColTypeFromExpr(node.Expr, colTypeMap, colNames, colTypes)
case *sqlparser.CaseExpr:
colNames, colTypes = inferColTypeFromExpr(node.Whens[0].Val, colTypeMap, colNames, colTypes)
case *sqlparser.NullVal:
colNames = append(colNames, sqlparser.String(node))
colTypes = append(colTypes, querypb.Type_NULL_TYPE)
default:
log.Errorf("vtexplain: unsupported select expression type +%v node %s", reflect.TypeOf(node), sqlparser.String(node))
}
Expand Down