Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#49930
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
jiyfhust authored and ti-chi-bot committed Feb 10, 2024
1 parent 3506917 commit 1595e7d
Show file tree
Hide file tree
Showing 3 changed files with 191 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
85 changes: 85 additions & 0 deletions tests/integrationtest/r/ddl/db_integration.result
Original file line number Diff line number Diff line change
Expand Up @@ -1216,3 +1216,88 @@ 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
<<<<<<< HEAD
=======
drop table if exists t;
create table t (a int, b real);
alter table t add primary key ((a+b)) nonclustered;
Error 3756 (HY000): The primary key cannot be an expression index
create table t(a int, index((cast(a as JSON))));
Error 3753 (HY000): Cannot create an expression index on a function that returns a JSON or GEOMETRY value
drop table if exists t;
create table t (a int, b real);
alter table t add primary key ((a+b)) nonclustered;
Error 3756 (HY000): The primary key cannot be an expression index
alter table t add index ((rand()));
Error 3758 (HY000): Expression of expression index 'expression_index' contains a disallowed function
alter table t add index ((now()+1));
Error 3758 (HY000): Expression of expression index 'expression_index' contains a disallowed function
alter table t add column (_V$_idx_0 int);
alter table t add index idx((a+1));
Error 1060 (42S21): Duplicate column name '_V$_idx_0'
alter table t drop column _V$_idx_0;
alter table t add index idx((a+1));
alter table t add column (_V$_idx_0 int);
Error 1060 (42S21): Duplicate column name '_V$_idx_0'
alter table t drop index idx;
alter table t add column (_V$_idx_0 int);
alter table t add column (_V$_expression_index_0 int);
alter table t add index ((a+1));
Error 1060 (42S21): Duplicate column name '_V$_expression_index_0'
alter table t drop column _V$_expression_index_0;
alter table t add index ((a+1));
alter table t drop column _V$_expression_index_0;
Error 1091 (42000): Can't DROP '_V$_expression_index_0'; check that column/key exists
alter table t add column e int as (_V$_expression_index_0 + 1);
Error 1054 (42S22): Unknown column '_v$_expression_index_0' in 'generated column function'
drop table if exists t;
create table t (j json, key k (((j,j))));
Error 3800 (HY000): Expression of expression index 'k' cannot refer to a row value
create table t (j json, key k ((j+1),(j+1)));
create table t1 (col1 int, index ((concat(''))));
Error 3761 (HY000): The used storage engine cannot index the expression 'concat(_utf8mb4'')'
CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED);
Error 3756 (HY000): The primary key cannot be an expression index
drop table if exists t;
create table t(id char(10) primary key, short_name char(10), name char(10), key n((upper(`name`))));
update t t1 set t1.short_name='a' where t1.id='1';
set @@tidb_enable_strict_double_type_check = 'ON';
drop table if exists double_type_check;
create table double_type_check(id int, c double(10));
Error 1149 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
set @@tidb_enable_strict_double_type_check = 'OFF';
create table double_type_check(id int, c double(10));
set @@tidb_enable_strict_double_type_check = default;
drop table if exists t1, t2, tt;
begin;
create temporary table t1(id int primary key, v int);
select * from t1;
id v
insert into t1 values(123, 456);
select * from t1 where id=123;
id v
123 456
truncate table t1;
select * from t1 where id=123;
id v
commit;
create table tt(id int);
begin;
create temporary table t1(id int);
insert into tt select * from t1;
drop table tt;
create table t2(id int primary key, v int);
insert into t2 values(234, 567);
begin;
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;
>>>>>>> 400bb2c3d74 (ddl: forbid create `Generated column` with `Grouping` function (#49930))
101 changes: 101 additions & 0 deletions tests/integrationtest/t/ddl/db_integration.test
Original file line number Diff line number Diff line change
Expand Up @@ -1019,3 +1019,104 @@ 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;

<<<<<<< HEAD
=======

# TestCreateExpressionIndexError
drop table if exists t;
create table t (a int, b real);
-- error 3756
alter table t add primary key ((a+b)) nonclustered;
-- error 3753
create table t(a int, index((cast(a as JSON))));
drop table if exists t;
create table t (a int, b real);
-- error 3756
alter table t add primary key ((a+b)) nonclustered;
-- error 3758
alter table t add index ((rand()));
-- error 3758
alter table t add index ((now()+1));
alter table t add column (_V$_idx_0 int);
-- error 1060
alter table t add index idx((a+1));
alter table t drop column _V$_idx_0;
alter table t add index idx((a+1));
-- error 1060
alter table t add column (_V$_idx_0 int);
alter table t drop index idx;
alter table t add column (_V$_idx_0 int);
alter table t add column (_V$_expression_index_0 int);
-- error 1060
alter table t add index ((a+1));
alter table t drop column _V$_expression_index_0;
alter table t add index ((a+1));
-- error 1091
alter table t drop column _V$_expression_index_0;
-- error 1054
alter table t add column e int as (_V$_expression_index_0 + 1);

## NOTE (#18150): In creating expression index, row value is not allowed.
drop table if exists t;
-- error 3800
create table t (j json, key k (((j,j))));
create table t (j json, key k ((j+1),(j+1)));
-- error 3761
create table t1 (col1 int, index ((concat(''))));
-- error 3756
CREATE TABLE t1 (col1 INT, PRIMARY KEY ((ABS(col1))) NONCLUSTERED);

## For issue 26349
drop table if exists t;
create table t(id char(10) primary key, short_name char(10), name char(10), key n((upper(`name`))));
update t t1 set t1.short_name='a' where t1.id='1';


# TestStrictDoubleTypeCheck
set @@tidb_enable_strict_double_type_check = 'ON';
drop table if exists double_type_check;
--error 1149
create table double_type_check(id int, c double(10));
set @@tidb_enable_strict_double_type_check = 'OFF';
create table double_type_check(id int, c double(10));
set @@tidb_enable_strict_double_type_check = default;


# TestCreateTempTableInTxn
# https://github.com/pingcap/tidb/issues/35644
drop table if exists t1, t2, tt;
begin;
create temporary table t1(id int primary key, v int);
select * from t1;
insert into t1 values(123, 456);
select * from t1 where id=123;
truncate table t1;
select * from t1 where id=123;
commit;

connect (conn1, localhost, root,, ddl__db_integration);
create table tt(id int);
begin;
create temporary table t1(id int);
insert into tt select * from t1;
drop table tt;
disconnect conn1;

connect (conn1, localhost, root,, ddl__db_integration);
create table t2(id int primary key, v int);
insert into t2 values(234, 567);
begin;
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;
>>>>>>> 400bb2c3d74 (ddl: forbid create `Generated column` with `Grouping` function (#49930))

0 comments on commit 1595e7d

Please sign in to comment.