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
… (#51094)

close #49909
  • Loading branch information
ti-chi-bot authored May 27, 2024
1 parent 4ee2b86 commit ddacd7f
Show file tree
Hide file tree
Showing 3 changed files with 20 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 @@ -1223,3 +1223,10 @@ alter table t reorganize partition p0 into (partition p01 values less than (10),
show warnings;
Level Code Message
Warning 1105 The statistics of related partitions will be outdated after reorganizing partitions. Please use 'ANALYZE TABLE' statement if you want to update it now
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;
8 changes: 8 additions & 0 deletions tests/integrationtest/t/ddl/db_integration.test
Original file line number Diff line number Diff line change
Expand Up @@ -1026,3 +1026,11 @@ create table t (id bigint, b varchar(20), index idxb(b)) partition by range(id)
alter table t reorganize partition p0 into (partition p01 values less than (10), partition p02 values less than (20));
show warnings;

# 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 ddacd7f

Please sign in to comment.