Skip to content

Commit

Permalink
ddl: forbid create Generated column with Grouping function (#49930)
Browse files Browse the repository at this point in the history
close #49909
  • Loading branch information
jiyfhust authored Feb 10, 2024
1 parent a29bbb5 commit 400bb2c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/ddl/generated_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ type illegalFunctionChecker struct {
func (c *illegalFunctionChecker) Enter(inNode ast.Node) (outNode ast.Node, skipChildren bool) {
switch node := inNode.(type) {
case *ast.FuncCallExpr:
// Grouping function is not allowed, issue #49909.
if node.FnName.L == ast.Grouping {
c.hasAggFunc = true
return inNode, true
}
// Blocked functions & non-builtin functions is not allowed
_, isFunctionBlocked := expression.IllegalFunctions4GeneratedColumns[node.FnName.L]
if isFunctionBlocked || !expression.IsFunctionSupported(node.FnName.L) {
Expand Down
7 changes: 7 additions & 0 deletions tests/integrationtest/r/ddl/db_integration.result
Original file line number Diff line number Diff line change
Expand Up @@ -1291,3 +1291,10 @@ create temporary table t2(id int primary key, v int);
select * from t2 where id=234;
id v
commit;
drop table if exists t;
create table t(a int, b int as ((grouping(a))) stored);
Error 1111 (HY000): Invalid use of group function
create table t(a int);
alter table t add column b int as ((grouping(a))) stored;
Error 1111 (HY000): Invalid use of group function
drop table t;
9 changes: 9 additions & 0 deletions tests/integrationtest/t/ddl/db_integration.test
Original file line number Diff line number Diff line change
Expand Up @@ -1108,3 +1108,12 @@ create temporary table t2(id int primary key, v int);
select * from t2 where id=234;
commit;
disconnect conn1;

# Test Generated column use Grouping function, issue #49909.
drop table if exists t;
--error 1111
create table t(a int, b int as ((grouping(a))) stored);
create table t(a int);
--error 1111
alter table t add column b int as ((grouping(a))) stored;
drop table t;

0 comments on commit 400bb2c

Please sign in to comment.