Skip to content

Commit

Permalink
test: add tests using aggregation and last_insert_id
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Dec 10, 2024
1 parent a48ced7 commit ae9c5a8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ from (select id, count(*) as num_segments from t1 group by 1 order by 2 desc lim
join t2 u on u.id = t.id;

select name
from (select name from t1 group by name having count(t1.id) > 1) t1;
from (select name from t1 group by name having count(t1.id) > 1) t1;

# this query uses last_insert_id with a column argument to show that this works well
select id, last_insert_id(count(*)) as num_segments from t1 group by id;
28 changes: 28 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/aggr_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -4134,6 +4134,34 @@
]
}
},
{
"comment": "Save the count in last_insert_id",
"query": "select id, last_insert_id(count(*)) as num_segments from user group by id",
"plan": {
"QueryType": "SELECT",
"Original": "select id, last_insert_id(count(*)) as num_segments from user group by id",
"Instructions": {
"OperatorType": "SaveToSession",
"Offset": "_vt_column_1",
"Inputs": [
{
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select id, last_insert_id(count(*)) as num_segments from `user` where 1 != 1 group by id",
"Query": "select id, last_insert_id(count(*)) as num_segments from `user` group by id",
"Table": "`user`"
}
]
},
"TablesUsed": [
"user.user"
]
}
},
{
"comment": "Aggregations from derived table used in arithmetic outside derived table",
"query": "select A.a, A.b, (A.a / A.b) as d from (select sum(a) as a, sum(b) as b from user) A",
Expand Down

0 comments on commit ae9c5a8

Please sign in to comment.