forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX group by+聚合函数报错问题 (vitessio#101)
1.修复聚合函数+groupby执行报错的问题 在ctx中保存原始select SQL的AST,方便后续TruncateColumnCount生成 2.优化Limit operator生成逻辑 当Limit之下为Aggregator,且分片Plan中已生成LimitPlan可下推
- Loading branch information
wangwei1207
committed
Oct 26, 2023
1 parent
df6a9f8
commit 5b074c2
Showing
10 changed files
with
205 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package split_table | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestIssue(t *testing.T) { | ||
mcmp, closer := start(t) | ||
defer closer() | ||
mcmp.Exec("use user") | ||
|
||
mcmp.Exec("insert into t_user(id,col,f_key,f_tinyint,f_int,name) values (1, 'a', 'aaa', 1, false, 'li'),(2, 'b', 'bbb', 2, false, 'zh'),(3, 'c', 'ccc', 3, false, 'kk')") | ||
mcmp.Exec("insert into t_user(id,col,f_key,f_tinyint,f_int,name) values (4, 'ab', 'aaa', 10, true, 'li'),(5, 'bx', 'bbb', 4, false, 'zhsd'),(6, 'cdx', 'ccc', 34, true, 'kk')") | ||
mcmp.Exec("insert into t_user(id,col,f_key,f_tinyint,f_int,name) values (7, 'ac', 'aaa', 100, false, 'li'),(8, 'bx', 'bbb', 25, true, 'zhff'),(9, 'cd', 'ccc', 33, false, 'kggk')") | ||
mcmp.Exec("insert into t_user(id,col,f_key,f_tinyint,f_int,name) values (11, 'ad', 'aaa', 2, true, 'li'),(12, 'ba', 'bbb', 26, false, 'zdfh'),(13, 'cc', 'ccc', 13, true, 'kzzk')") | ||
mcmp.Exec("insert into t_user(id,col,f_key,f_tinyint,f_int,name) values (14, 'ae', 'aaa', 3, false, 'a'),(15, 'bd', 'bbb', 27, true, 'zhdf'),(16, 'fdfc', 'ccc', 64, true, 'xxxxx')") | ||
mcmp.Exec("insert into t_user(id,col,f_key,f_tinyint,f_int,name) values (17, 'a', 'aaa', 1, false, 'li'),(18, 'b', 'bbb', 2, false, 'zh'),(19, 'c', 'ccc', 3, false, 'kk')") | ||
mcmp.Exec("insert into t_user(id,col,f_key,f_tinyint,f_int,name) values (20, 'ab', 'aaa', 10, true, 'li'),(21, 'bx', 'bbb', 4, false, 'zhsd'),(22, 'cdx', 'ccc', 34, true, 'kk')") | ||
mcmp.Exec("insert into t_user(id,col,f_key,f_tinyint,f_int,name) values (23, 'ac', 'aaa', 100, false, 'li'),(24, 'bx', 'bbb', 25, true, 'zhff'),(25, 'cd', 'ccc', 33, false, 'kggk')") | ||
mcmp.Exec("insert into t_user(id,col,f_key,f_tinyint,f_int,name) values (26, 'ad', 'aaa', 2, true, 'li'),(27, 'ba', 'bbb', 26, false, 'zdfh'),(28, 'cc', 'ccc', 13, true, 'kzzk')") | ||
|
||
// table_issue.json | ||
mcmp.ExecWithColumnCompare("select max(f_int),min(`name`) from t_user group by id,f_tinyint order by f_tinyint desc limit 20") | ||
mcmp.ExecWithColumnCompare("select max(f_int),min(`name`) from t_user group by id,f_tinyint order by f_tinyint asc") | ||
mcmp.ExecWithColumnCompare("select max(f_int),min(`name`) from t_user group by col order by f_tinyint asc") | ||
mcmp.ExecWithColumnCompare("select max(f_int),min(`name`) from t_user group by col,id order by f_tinyint asc") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
[ | ||
{ | ||
"comment": "aggregate function and group by with limit", | ||
"query": "select max(f_int),min(name) from t_user group by id,f_tinyint order by f_tinyint desc limit 20", | ||
"plan": { | ||
"QueryType": "SELECT", | ||
"Original": "select max(f_int),min(name) from t_user group by id,f_tinyint order by f_tinyint desc limit 20", | ||
"Instructions": { | ||
"OperatorType": "Limit", | ||
"Count": "INT64(20)", | ||
"Inputs": [ | ||
{ | ||
"OperatorType": "Aggregate", | ||
"Variant": "Ordered", | ||
"Aggregates": "max(0) AS max(f_int), min(1) AS min(`name`), random(3) AS weight_string(f_tinyint)", | ||
"GroupBy": "(2|3), (4|5)", | ||
"ResultColumns": 2, | ||
"Inputs": [ | ||
{ | ||
"OperatorType": "TableRoute", | ||
"Variant": "Scatter-Scatter", | ||
"Keyspace": { | ||
"Name": "user", | ||
"Sharded": true | ||
}, | ||
"FieldQuery": "select max(f_int), min(`name`), f_tinyint, weight_string(f_tinyint), id, weight_string(id) from t_user_0 where 1 != 1 group by id, f_tinyint, weight_string(id)", | ||
"OrderBy": "(2|3) DESC, (4|5) ASC", | ||
"Query": "select max(f_int), min(`name`), f_tinyint, weight_string(f_tinyint), id, weight_string(id) from t_user group by id, f_tinyint, weight_string(id) order by f_tinyint desc, id asc limit :__upper_limit", | ||
"Table": "t_user" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"TablesUsed": [ | ||
"user.t_user" | ||
] | ||
} | ||
}, | ||
{ | ||
"comment": "aggregate function and group by", | ||
"query": "select max(f_int),min(name) from t_user group by id,f_tinyint order by f_tinyint asc", | ||
"plan": { | ||
"QueryType": "SELECT", | ||
"Original": "select max(f_int),min(name) from t_user group by id,f_tinyint order by f_tinyint asc", | ||
"Instructions": { | ||
"OperatorType": "Aggregate", | ||
"Variant": "Ordered", | ||
"Aggregates": "max(0) AS max(f_int), min(1) AS min(`name`), random(3) AS weight_string(f_tinyint)", | ||
"GroupBy": "(2|3), (4|5)", | ||
"ResultColumns": 2, | ||
"Inputs": [ | ||
{ | ||
"OperatorType": "TableRoute", | ||
"Variant": "Scatter-Scatter", | ||
"Keyspace": { | ||
"Name": "user", | ||
"Sharded": true | ||
}, | ||
"FieldQuery": "select max(f_int), min(`name`), f_tinyint, weight_string(f_tinyint), id, weight_string(id) from t_user_0 where 1 != 1 group by id, f_tinyint, weight_string(id)", | ||
"OrderBy": "(2|3) ASC, (4|5) ASC", | ||
"Query": "select max(f_int), min(`name`), f_tinyint, weight_string(f_tinyint), id, weight_string(id) from t_user group by id, f_tinyint, weight_string(id) order by f_tinyint asc, id asc", | ||
"Table": "t_user" | ||
} | ||
] | ||
}, | ||
"TablesUsed": [ | ||
"user.t_user" | ||
] | ||
} | ||
}, | ||
{ | ||
"comment": "aggregate function and group by tableVindex", | ||
"query": "select max(f_int),min(name) from t_user group by col order by f_tinyint asc", | ||
"plan": { | ||
"QueryType": "SELECT", | ||
"Original": "select max(f_int),min(name) from t_user group by col order by f_tinyint asc", | ||
"Instructions": { | ||
"OperatorType": "Sort", | ||
"Variant": "Memory", | ||
"OrderBy": "(2|3) ASC", | ||
"ResultColumns": 2, | ||
"Inputs": [ | ||
{ | ||
"OperatorType": "Aggregate", | ||
"Variant": "Ordered", | ||
"Aggregates": "max(0) AS max(f_int), min(1) AS min(`name`), random(2) AS f_tinyint, random(3)", | ||
"GroupBy": "4", | ||
"Inputs": [ | ||
{ | ||
"OperatorType": "TableRoute", | ||
"Variant": "Scatter-Scatter", | ||
"Keyspace": { | ||
"Name": "user", | ||
"Sharded": true | ||
}, | ||
"FieldQuery": "select max(f_int), min(`name`), f_tinyint, weight_string(f_tinyint), col from t_user_0 where 1 != 1 group by col", | ||
"OrderBy": "4 ASC", | ||
"Query": "select max(f_int), min(`name`), f_tinyint, weight_string(f_tinyint), col from t_user group by col order by col asc", | ||
"Table": "t_user" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"TablesUsed": [ | ||
"user.t_user" | ||
] | ||
} | ||
}, | ||
{ | ||
"comment": "aggregate function and group by tableVindex & Vindex", | ||
"query": "select max(f_int),min(name) from t_user group by col,id order by f_tinyint asc", | ||
"plan": { | ||
"QueryType": "SELECT", | ||
"Original": "select max(f_int),min(name) from t_user group by col,id order by f_tinyint asc", | ||
"Instructions": { | ||
"OperatorType": "TableRoute", | ||
"Variant": "Scatter-Scatter", | ||
"Keyspace": { | ||
"Name": "user", | ||
"Sharded": true | ||
}, | ||
"FieldQuery": "select max(f_int), min(`name`), f_tinyint, weight_string(f_tinyint) from t_user_0 where 1 != 1 group by col, id", | ||
"OrderBy": "(2|3) ASC", | ||
"Query": "select max(f_int), min(`name`), f_tinyint, weight_string(f_tinyint) from t_user group by col, id order by f_tinyint asc", | ||
"ResultColumns": 2, | ||
"Table": "t_user" | ||
}, | ||
"TablesUsed": [ | ||
"user.t_user" | ||
] | ||
} | ||
} | ||
] |