Skip to content
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
8 changes: 8 additions & 0 deletions data/test/vtexplain/multi-output/selectsharded-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,11 @@ select name from user where exists (select id from t1) /* non-correlated subquer
2 ks_sharded/c0-: select name from user where 1 limit 10001 /* non-correlated subquery as EXISTS */

----------------------------------------------------------------------
select * from name_info order by info /* select * and order by varchar column */

1 ks_sharded/-40: select name, info, weight_string(info) from name_info order by info asc limit 10001 /* select * and order by varchar column */
1 ks_sharded/40-80: select name, info, weight_string(info) from name_info order by info asc limit 10001 /* select * and order by varchar column */
1 ks_sharded/80-c0: select name, info, weight_string(info) from name_info order by info asc limit 10001 /* select * and order by varchar column */
1 ks_sharded/c0-: select name, info, weight_string(info) from name_info order by info asc limit 10001 /* select * and order by varchar column */

----------------------------------------------------------------------
2 changes: 2 additions & 0 deletions data/test/vtexplain/selectsharded-queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ select name from user where id = (select id from t1) /* non-correlated subquery
select name from user where id in (select id from t1) /* non-correlated subquery in IN clause */;
select name from user where id not in (select id from t1) /* non-correlated subquery in NOT IN clause */;
select name from user where exists (select id from t1) /* non-correlated subquery as EXISTS */;

select * from name_info order by info /* select * and order by varchar column */
19 changes: 15 additions & 4 deletions data/test/vtexplain/test-vschema.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"ks_unsharded": {
"Sharded": false,
"Tables": {
"sharded": false,
"tables": {
"t1": {},
"table_not_in_schema": {}
}
},
"ks_sharded": {
"Sharded": true,
"sharded": true,
"vindexes": {
"music_user_map": {
"type": "lookup_hash_unique",
Expand Down Expand Up @@ -81,7 +81,18 @@
"column": "name",
"name": "md5"
}
]
],
"columns": [
{
"name": "name",
"type": "VARCHAR"
},
{
"name": "info",
"type": "VARCHAR"
}
],
"column_list_authoritative": true
}
}
}
Expand Down
43 changes: 43 additions & 0 deletions data/test/vtgate/postprocess_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,49 @@
}
}

# ORDER BY works for select * from authoritative table
"select * from authoritative order by user_id"
{
"Original": "select * from authoritative order by user_id",
"Instructions": {
"Opcode": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "select user_id, col1, col2 from authoritative order by user_id asc",
"FieldQuery": "select user_id, col1, col2 from authoritative where 1 != 1",
"OrderBy": [
{
"Col": 0,
"Desc": false
}
]
}
}

# ORDER BY works for select * from authoritative table
"select * from authoritative order by col1"
{
"Original": "select * from authoritative order by col1",
"Instructions": {
"Opcode": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "select user_id, col1, col2, weight_string(col1) from authoritative order by col1 asc",
"FieldQuery": "select user_id, col1, col2, weight_string(col1) from authoritative where 1 != 1",
"OrderBy": [
{
"Col": 3,
"Desc": false
}
],
"TruncateColumnCount": 3
}
}

# ORDER BY on scatter with text column
"select a, textcol1, b from user order by a, textcol1, b"
{
Expand Down
21 changes: 21 additions & 0 deletions data/test/vtgate/schema_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@
}
]
},
"authoritative": {
"column_vindexes": [
{
"column": "user_id",
"name": "user_index"
}
],
"columns": [
{
"name": "user_id"
},
{
"name": "col1",
"type": "VARCHAR"
},
{
"name": "col2"
}
],
"column_list_authoritative": true
},
"multicolvin": {
"column_vindexes": [
{
Expand Down
129 changes: 123 additions & 6 deletions data/test/vtgate/select_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@
}

# fully qualified '*' expression for simple route
"select user.user.* from user"
"select user.user.* from user.user"
{
"Original": "select user.user.* from user",
"Original": "select user.user.* from user.user",
"Instructions": {
"Opcode": "SelectScatter",
"Keyspace": {
Expand All @@ -197,9 +197,84 @@
}
}

# invalid keyspace for '*' expression for simple route
"select a.user.* from user"
"cannot resolve a.user.* to keyspace user"
# select * from authoritative table
"select * from authoritative"
{
"Original": "select * from authoritative",
"Instructions": {
"Opcode": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "select user_id, col1, col2 from authoritative",
"FieldQuery": "select user_id, col1, col2 from authoritative where 1 != 1"
}
}

# select * from join of authoritative tables
"select * from authoritative a join authoritative b on a.user_id=b.user_id"
{
"Original": "select * from authoritative a join authoritative b on a.user_id=b.user_id",
"Instructions": {
"Opcode": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "select a.user_id as user_id, a.col1 as col1, a.col2 as col2, b.user_id as user_id, b.col1 as col1, b.col2 as col2 from authoritative as a join authoritative as b on a.user_id = b.user_id",
"FieldQuery": "select a.user_id as user_id, a.col1 as col1, a.col2 as col2, b.user_id as user_id, b.col1 as col1, b.col2 as col2 from authoritative as a join authoritative as b on a.user_id = b.user_id where 1 != 1"
}
}

# test table lookup failure for authoritative code path
"select a.* from authoritative"
"table a not found"

# select * from qualified authoritative table
"select a.* from authoritative a"
{
"Original": "select a.* from authoritative a",
"Instructions": {
"Opcode": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "select a.user_id, a.col1, a.col2 from authoritative as a",
"FieldQuery": "select a.user_id, a.col1, a.col2 from authoritative as a where 1 != 1"
}
}

# select * from intermixing of authoritative table with non-authoritative results in no expansion
"select * from authoritative join user on authoritative.user_id=user.id"
{
"Original": "select * from authoritative join user on authoritative.user_id=user.id",
"Instructions": {
"Opcode": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "select * from authoritative join user on authoritative.user_id = user.id",
"FieldQuery": "select * from authoritative join user on authoritative.user_id = user.id where 1 != 1"
}
}

# select authoritative.* with intermixing still expands
"select user.id, a.*, user.col1 from authoritative a join user on a.user_id=user.id"
{
"Original": "select user.id, a.*, user.col1 from authoritative a join user on a.user_id=user.id",
"Instructions": {
"Opcode": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "select user.id, a.user_id, a.col1, a.col2, user.col1 from authoritative as a join user on a.user_id = user.id",
"FieldQuery": "select user.id, a.user_id, a.col1, a.col2, user.col1 from authoritative as a join user on a.user_id = user.id where 1 != 1"
}
}

# auto-resolve anonymous columns for simple route
"select col from user join user_extra on user.id = user_extra.user_id"
Expand Down Expand Up @@ -620,6 +695,7 @@
"FieldQuery": "select * from user where 1 != 1"
}
}

# sharded limit offset
"select user_id from music order by user_id limit 10, 20"
{
Expand Down Expand Up @@ -842,9 +918,50 @@
}
}

# select * from subquery expands specific columns
"select * from (select user.id id1, user_extra.id id2 from user join user_extra) as t"
{
"Original": "select * from (select user.id id1, user_extra.id id2 from user join user_extra) as t",
"Instructions": {
"Cols": [
0,
1
],
"Subquery": {
"Opcode": "Join",
"Left": {
"Opcode": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "select user.id as id1 from user",
"FieldQuery": "select user.id as id1 from user where 1 != 1"
},
"Right": {
"Opcode": "SelectScatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "select user_extra.id as id2 from user_extra",
"FieldQuery": "select user_extra.id as id2 from user_extra where 1 != 1"
},
"Cols": [
-1,
1
]
}
}
}

# duplicate columns not allowed in subquery
"select * from (select user.id, user_extra.id from user join user_extra) as t"
"duplicate column names in subquery: id"

# non-existent symbol in cross-shard subquery
"select t.col from (select user.id from user join user_extra) as t"
"symbol t.col is referencing a non-existent column of the subquery"
"symbol t.col not found in table or subquery"

# union of information_schema
"select * from information_schema.a union select * from information_schema.b"
Expand Down
4 changes: 2 additions & 2 deletions data/test/vtgate/unsupported_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@
"select keyspace_id from user_index where 1 = id"
"unsupported: where clause for vindex function must be of the form id = <val> (lhs is not a column)"

"select keyspace_id from user_index where none = 1"
"select keyspace_id from user_index where keyspace_id = 1"
"unsupported: where clause for vindex function must be of the form id = <val> (lhs is not id)"

"select keyspace_id from user_index where id = a"
"select keyspace_id from user_index where id = id+1"
"unsupported: where clause for vindex function must be of the form id = <val> (rhs is not a value)"

"select keyspace_id from user_index"
Expand Down
37 changes: 36 additions & 1 deletion data/test/vtgate/vindex_func_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,41 @@
}
}

# vindex func select *
"select * from user_index where id = :id"
{
"Original": "select * from user_index where id = :id",
"Instructions": {
"Opcode": "VindexMap",
"Fields": [
{
"name": "id",
"type": 10262
},
{
"name": "keyspace_id",
"type": 10262
},
{
"name": "range_start",
"type": 10262
},
{
"name": "range_end",
"type": 10262
}
],
"Cols": [
0,
1,
2,
3
],
"Vindex": "user_index",
"Value": ":id"
}
}

# vindex func read with id repeated
"select id, keyspace_id, id from user_index where id = :id"
{
Expand Down Expand Up @@ -320,4 +355,4 @@
}

"select none from user_index where id = :id"
"unrecognized column none for vindex: user_index"
"symbol none not found in table or subquery"
Loading