mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
b7b8fd2569
mysql-test/r/partition.result: Added a number of new test cases where errors in use of VALUES LESS THAN and VALUES IN is happening for ALTER TABLE mysql-test/t/partition.test: Added a number of new test cases where errors in use of VALUES LESS THAN and VALUES IN is happening for ALTER TABLE sql/sql_partition.cc: Check for errors with VALUES * sql/sql_yacc.yy: Add state to part_type when doing ALTER TABLE for partitioning
579 lines
13 KiB
Text
579 lines
13 KiB
Text
#--disable_abort_on_error
|
|
#
|
|
# Simple test for the partition storage engine
|
|
# Taken fromm the select test
|
|
#
|
|
-- source include/have_partition.inc
|
|
|
|
--disable_warnings
|
|
drop table if exists t1;
|
|
--enable_warnings
|
|
|
|
#
|
|
# Partition by key no partition defined => OK
|
|
#
|
|
CREATE TABLE t1 (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
primary key(a,b))
|
|
partition by key (a);
|
|
|
|
#
|
|
# Bug 13323: Select count(*) on empty table returns 2
|
|
#
|
|
select count(*) from t1;
|
|
|
|
#
|
|
# Test SHOW CREATE TABLE
|
|
#
|
|
show create table t1;
|
|
|
|
drop table t1;
|
|
#
|
|
# Partition by key no partition, list of fields
|
|
#
|
|
CREATE TABLE t1 (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
primary key(a,b))
|
|
partition by key (a, b);
|
|
|
|
drop table t1;
|
|
#
|
|
# Partition by key specified 3 partitions and defined 3 => ok
|
|
#
|
|
CREATE TABLE t1 (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
primary key(a,b))
|
|
partition by key (a)
|
|
partitions 3
|
|
(partition x1, partition x2, partition x3);
|
|
|
|
drop table t1;
|
|
#
|
|
# Partition by key specifying nodegroup
|
|
#
|
|
CREATE TABLE t1 (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
primary key(a,b))
|
|
partition by key (a)
|
|
partitions 3
|
|
(partition x1 nodegroup 0,
|
|
partition x2 nodegroup 1,
|
|
partition x3 nodegroup 2);
|
|
|
|
drop table t1;
|
|
#
|
|
# Partition by key specifying engine
|
|
#
|
|
CREATE TABLE t1 (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
primary key(a,b))
|
|
partition by key (a)
|
|
partitions 3
|
|
(partition x1 engine myisam,
|
|
partition x2 engine myisam,
|
|
partition x3 engine myisam);
|
|
|
|
drop table t1;
|
|
#
|
|
# Partition by key specifying tablespace
|
|
#
|
|
CREATE TABLE t1 (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
primary key(a,b))
|
|
partition by key (a)
|
|
partitions 3
|
|
(partition x1 tablespace ts1,
|
|
partition x2 tablespace ts2,
|
|
partition x3 tablespace ts3);
|
|
|
|
CREATE TABLE t2 LIKE t1;
|
|
|
|
drop table t2;
|
|
drop table t1;
|
|
|
|
#
|
|
# Partition by key list, basic
|
|
#
|
|
CREATE TABLE t1 (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
primary key(a,b))
|
|
partition by list (a)
|
|
partitions 3
|
|
(partition x1 values in (1,2,9,4) tablespace ts1,
|
|
partition x2 values in (3, 11, 5, 7) tablespace ts2,
|
|
partition x3 values in (16, 8, 5+19, 70-43) tablespace ts3);
|
|
|
|
drop table t1;
|
|
#
|
|
# Partition by key list, list function
|
|
#
|
|
CREATE TABLE t1 (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
primary key(a,b))
|
|
partition by list (b*a)
|
|
partitions 3
|
|
(partition x1 values in (1,2,9,4) tablespace ts1,
|
|
partition x2 values in (3, 11, 5, 7) tablespace ts2,
|
|
partition x3 values in (16, 8, 5+19, 70-43) tablespace ts3);
|
|
|
|
drop table t1;
|
|
|
|
#
|
|
# Partition by key list, list function, no spec of #partitions
|
|
#
|
|
CREATE TABLE t1 (
|
|
a int not null,
|
|
b int not null,
|
|
c int not null,
|
|
primary key(a,b))
|
|
partition by list (b*a)
|
|
(partition x1 values in (1) tablespace ts1,
|
|
partition x2 values in (3, 11, 5, 7) tablespace ts2,
|
|
partition x3 values in (16, 8, 5+19, 70-43) tablespace ts3);
|
|
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug 13154: Insert crashes due to bad calculation of partition id
|
|
# for PARTITION BY KEY and SUBPARTITION BY KEY
|
|
#
|
|
CREATE TABLE t1 (
|
|
a int not null)
|
|
partition by key(a);
|
|
|
|
LOCK TABLES t1 WRITE;
|
|
insert into t1 values (1);
|
|
insert into t1 values (2);
|
|
insert into t1 values (3);
|
|
insert into t1 values (4);
|
|
UNLOCK TABLES;
|
|
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug #13644 DROP PARTITION NULL's DATE column
|
|
#
|
|
CREATE TABLE t1 (a int, name VARCHAR(50), purchased DATE)
|
|
PARTITION BY RANGE (a)
|
|
(PARTITION p0 VALUES LESS THAN (3),
|
|
PARTITION p1 VALUES LESS THAN (7),
|
|
PARTITION p2 VALUES LESS THAN (9),
|
|
PARTITION p3 VALUES LESS THAN (11));
|
|
INSERT INTO t1 VALUES
|
|
(1, 'desk organiser', '2003-10-15'),
|
|
(2, 'CD player', '1993-11-05'),
|
|
(3, 'TV set', '1996-03-10'),
|
|
(4, 'bookcase', '1982-01-10'),
|
|
(5, 'exercise bike', '2004-05-09'),
|
|
(6, 'sofa', '1987-06-05'),
|
|
(7, 'popcorn maker', '2001-11-22'),
|
|
(8, 'acquarium', '1992-08-04'),
|
|
(9, 'study desk', '1984-09-16'),
|
|
(10, 'lava lamp', '1998-12-25');
|
|
|
|
SELECT * from t1 ORDER BY a;
|
|
ALTER TABLE t1 DROP PARTITION p0;
|
|
SELECT * from t1 ORDER BY a;
|
|
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug #13442; Truncate Partitioned table doesn't work
|
|
#
|
|
|
|
CREATE TABLE t1 (a int)
|
|
PARTITION BY LIST (a)
|
|
(PARTITION p0 VALUES IN (1,2,3), PARTITION p1 VALUES IN (4,5,6));
|
|
|
|
insert into t1 values (1),(2),(3),(4),(5),(6);
|
|
select * from t1;
|
|
truncate t1;
|
|
select * from t1;
|
|
truncate t1;
|
|
select * from t1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug #13445 Partition by KEY method crashes server
|
|
#
|
|
CREATE TABLE t1 (a int, b int, primary key(a,b))
|
|
PARTITION BY KEY(b,a) PARTITIONS 4;
|
|
|
|
insert into t1 values (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6);
|
|
select * from t1 where a = 4;
|
|
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug #13438: Engine clause in PARTITION clause causes crash
|
|
#
|
|
CREATE TABLE t1 (a int)
|
|
PARTITION BY LIST (a)
|
|
PARTITIONS 1
|
|
(PARTITION x1 VALUES IN (1) ENGINE=MEMORY);
|
|
|
|
show create table t1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug #13440: REPLACE causes crash in partitioned table
|
|
#
|
|
CREATE TABLE t1 (a int, unique(a))
|
|
PARTITION BY LIST (a)
|
|
(PARTITION x1 VALUES IN (10), PARTITION x2 VALUES IN (20));
|
|
|
|
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
|
|
REPLACE t1 SET a = 4;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug #14365: Crash if value too small in list partitioned table
|
|
#
|
|
CREATE TABLE t1 (a int)
|
|
PARTITION BY LIST (a)
|
|
(PARTITION x1 VALUES IN (2), PARTITION x2 VALUES IN (3));
|
|
|
|
insert into t1 values (2), (3);
|
|
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
|
|
insert into t1 values (4);
|
|
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
|
|
insert into t1 values (1);
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug 14327: PARTITIONS clause gets lost in SHOW CREATE TABLE
|
|
#
|
|
CREATE TABLE t1 (a int)
|
|
PARTITION BY HASH(a)
|
|
PARTITIONS 5;
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug #13446: Update to value outside of list values doesn't give error
|
|
#
|
|
CREATE TABLE t1 (a int)
|
|
PARTITION BY RANGE (a)
|
|
(PARTITION x1 VALUES LESS THAN (2));
|
|
|
|
insert into t1 values (1);
|
|
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
|
|
update t1 set a = 5;
|
|
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug #13441: Analyze on partitioned table didn't work
|
|
#
|
|
CREATE TABLE t1 (a int)
|
|
PARTITION BY LIST (a)
|
|
(PARTITION x1 VALUES IN (10), PARTITION x2 VALUES IN (20));
|
|
|
|
analyze table t1;
|
|
|
|
drop table t1;
|
|
|
|
#
|
|
# BUG 14524
|
|
#
|
|
CREATE TABLE `t1` (
|
|
`id` int(11) default NULL
|
|
) ENGINE=BLACKHOLE DEFAULT CHARSET=latin1 PARTITION BY HASH (id) ;
|
|
SELECT * FROM t1;
|
|
|
|
drop table t1;
|
|
|
|
#
|
|
# BUG 14524
|
|
#
|
|
CREATE TABLE `t1` (
|
|
`id` int(11) default NULL
|
|
) ENGINE=BLACKHOLE DEFAULT CHARSET=latin1 PARTITION BY HASH (id) ;
|
|
SELECT * FROM t1;
|
|
|
|
drop table t1;
|
|
|
|
#
|
|
# BUG 15221 (Cannot reorganize with the same name)
|
|
#
|
|
create table t1
|
|
(a int)
|
|
partition by range (a)
|
|
( partition p0 values less than(10),
|
|
partition p1 values less than (20),
|
|
partition p2 values less than (25));
|
|
|
|
alter table t1 reorganize partition p2 into (partition p2 values less than (30));
|
|
show create table t1;
|
|
drop table t1;
|
|
|
|
CREATE TABLE t1 (a int, b int)
|
|
PARTITION BY RANGE (a)
|
|
(PARTITION x0 VALUES LESS THAN (2),
|
|
PARTITION x1 VALUES LESS THAN (4),
|
|
PARTITION x2 VALUES LESS THAN (6),
|
|
PARTITION x3 VALUES LESS THAN (8),
|
|
PARTITION x4 VALUES LESS THAN (10),
|
|
PARTITION x5 VALUES LESS THAN (12),
|
|
PARTITION x6 VALUES LESS THAN (14),
|
|
PARTITION x7 VALUES LESS THAN (16),
|
|
PARTITION x8 VALUES LESS THAN (18),
|
|
PARTITION x9 VALUES LESS THAN (20));
|
|
|
|
ALTER TABLE t1 REORGANIZE PARTITION x0,x1,x2 INTO
|
|
(PARTITION x1 VALUES LESS THAN (6));
|
|
show create table t1;
|
|
drop table t1;
|
|
|
|
# Testcase for BUG#15819
|
|
create table t1 (a int not null, b int not null) partition by LIST (a+b) (
|
|
partition p0 values in (12),
|
|
partition p1 values in (14)
|
|
);
|
|
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
|
|
insert into t1 values (10,1);
|
|
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#16901 Partitions: crash, SELECT, column of part.
|
|
# function=first column of primary key
|
|
#
|
|
create table t1 (f1 integer,f2 integer, f3 varchar(10), primary key(f1,f2))
|
|
partition by range(f1) subpartition by hash(f2) subpartitions 2
|
|
(partition p1 values less than (0),
|
|
partition p2 values less than (2),
|
|
partition p3 values less than (2147483647));
|
|
|
|
insert into t1 values(10,10,'10');
|
|
insert into t1 values(2,2,'2');
|
|
select * from t1 where f1 = 2;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug #16907 Partitions: crash, SELECT goes into last partition, UNIQUE INDEX
|
|
#
|
|
create table t1 (f1 integer,f2 integer, unique index(f1))
|
|
partition by range(f1 div 2)
|
|
subpartition by hash(f1) subpartitions 2
|
|
(partition partb values less than (2),
|
|
partition parte values less than (4),
|
|
partition partf values less than (10000));
|
|
insert into t1 values(10,1);
|
|
select * from t1 where f1 = 10;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug #16775: Wrong engine type stored for subpartition
|
|
#
|
|
set session storage_engine= 'memory';
|
|
create table t1 (f_int1 int(11) default null) engine = memory
|
|
partition by range (f_int1) subpartition by hash (f_int1)
|
|
(partition part1 values less than (1000)
|
|
(subpartition subpart11 engine = memory));
|
|
drop table t1;
|
|
set session storage_engine='myisam';
|
|
|
|
#
|
|
# Bug #16782: Crash using REPLACE on table with primary key
|
|
#
|
|
create table t1 (f_int1 integer, f_int2 integer, primary key (f_int1))
|
|
partition by hash(f_int1) partitions 2;
|
|
insert into t1 values (1,1),(2,2);
|
|
replace into t1 values (1,1),(2,2);
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug #17169: Partitions: out of memory if add partition and unique
|
|
#
|
|
create table t1 (s1 int, unique (s1)) partition by list (s1) (partition x1 VALUES in (10), partition x2 values in (20));
|
|
alter table t1 add partition (partition x3 values in (30));
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug #17432: Partition functions containing NULL values should return
|
|
# LONGLONG_MIN
|
|
#
|
|
CREATE TABLE t1 (
|
|
f_int1 INTEGER, f_int2 INTEGER,
|
|
f_char1 CHAR(10), f_char2 CHAR(10), f_charbig VARCHAR(1000)
|
|
)
|
|
PARTITION BY RANGE(f_int1 DIV 2)
|
|
SUBPARTITION BY HASH(f_int1)
|
|
SUBPARTITIONS 2
|
|
(PARTITION parta VALUES LESS THAN (0),
|
|
PARTITION partb VALUES LESS THAN (5),
|
|
PARTITION parte VALUES LESS THAN (10),
|
|
PARTITION partf VALUES LESS THAN (2147483647));
|
|
INSERT INTO t1 SET f_int1 = NULL , f_int2 = -20, f_char1 = CAST(-20 AS CHAR),
|
|
f_char2 = CAST(-20 AS CHAR), f_charbig = '#NULL#';
|
|
SELECT * FROM t1 WHERE f_int1 IS NULL;
|
|
SELECT * FROM t1;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug 17430: Crash when SELECT * from t1 where field IS NULL
|
|
#
|
|
|
|
CREATE TABLE t1 (
|
|
f_int1 INTEGER, f_int2 INTEGER,
|
|
f_char1 CHAR(10), f_char2 CHAR(10), f_charbig VARCHAR(1000) )
|
|
PARTITION BY LIST(MOD(f_int1,2))
|
|
SUBPARTITION BY KEY(f_int1)
|
|
(PARTITION part1 VALUES IN (-1) (SUBPARTITION sp1, SUBPARTITION sp2),
|
|
PARTITION part2 VALUES IN (0) (SUBPARTITION sp3, SUBPARTITION sp5),
|
|
PARTITION part3 VALUES IN (1) (SUBPARTITION sp4, SUBPARTITION sp6));
|
|
|
|
INSERT INTO t1 SET f_int1 = 2, f_int2 = 2, f_char1 = '2', f_char2 = '2', f_charbig = '===2===';
|
|
INSERT INTO t1 SET f_int1 = 2, f_int2 = 2, f_char1 = '2', f_char2 = '2', f_charbig = '===2===';
|
|
|
|
SELECT * FROM t1 WHERE f_int1 IS NULL;
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug#14363 Partitions: failure if create in stored procedure
|
|
#
|
|
delimiter //;
|
|
|
|
create procedure p ()
|
|
begin
|
|
create table t1 (s1 mediumint,s2 mediumint)
|
|
partition by list (s2)
|
|
(partition p1 values in (0),
|
|
partition p2 values in (1));
|
|
end//
|
|
|
|
call p()//
|
|
drop procedure p//
|
|
drop table t1;
|
|
|
|
create procedure p ()
|
|
begin
|
|
create table t1 (a int not null,b int not null,c int not null,primary key (a,b))
|
|
partition by range (a)
|
|
subpartition by hash (a+b)
|
|
(partition x1 values less than (1)
|
|
(subpartition x11,
|
|
subpartition x12),
|
|
partition x2 values less than (5)
|
|
(subpartition x21,
|
|
subpartition x22));
|
|
end//
|
|
|
|
call p()//
|
|
drop procedure p//
|
|
drop table t1//
|
|
delimiter ;//
|
|
|
|
#
|
|
# Bug #15447 Partitions: NULL is treated as zero
|
|
#
|
|
|
|
# NULL for RANGE partition
|
|
create table t1 (a int,b int,c int,key(a,b))
|
|
partition by range (a)
|
|
partitions 3
|
|
(partition x1 values less than (0) tablespace ts1,
|
|
partition x2 values less than (10) tablespace ts2,
|
|
partition x3 values less than maxvalue tablespace ts3);
|
|
|
|
insert into t1 values (NULL, 1, 1);
|
|
insert into t1 values (0, 1, 1);
|
|
insert into t1 values (12, 1, 1);
|
|
|
|
select partition_name, partition_description, table_rows
|
|
from information_schema.partitions where table_schema ='test';
|
|
drop table t1;
|
|
|
|
# NULL for LIST partition
|
|
--error 1473
|
|
create table t1 (a int,b int, c int)
|
|
partition by list(a)
|
|
partitions 2
|
|
(partition x123 values in (11,12),
|
|
partition x234 values in (1 ,NULL, NULL));
|
|
|
|
--error 1473
|
|
create table t1 (a int,b int, c int)
|
|
partition by list(a)
|
|
partitions 2
|
|
(partition x123 values in (11, NULL),
|
|
partition x234 values in (1 ,NULL));
|
|
|
|
create table t1 (a int,b int, c int)
|
|
partition by list(a)
|
|
partitions 2
|
|
(partition x123 values in (11, 12),
|
|
partition x234 values in (5, 1));
|
|
--error 1504
|
|
insert into t1 values (NULL,1,1);
|
|
drop table t1;
|
|
|
|
create table t1 (a int,b int, c int)
|
|
partition by list(a)
|
|
partitions 2
|
|
(partition x123 values in (11, 12),
|
|
partition x234 values in (NULL, 1));
|
|
|
|
insert into t1 values (11,1,6);
|
|
insert into t1 values (NULL,1,1);
|
|
|
|
select partition_name, partition_description, table_rows
|
|
from information_schema.partitions where table_schema ='test';
|
|
drop table t1;
|
|
|
|
#
|
|
# Bug 17127
|
|
#
|
|
create table t1 (a int)
|
|
partition by range (a)
|
|
(partition p0 values less than (1));
|
|
|
|
--error ER_PARTITION_WRONG_VALUES_ERROR
|
|
alter table t1 add partition (partition p1 values in (2));
|
|
--error ER_PARTITION_REQUIRES_VALUES_ERROR
|
|
alter table t1 add partition (partition p1);
|
|
|
|
drop table t1;
|
|
|
|
create table t1 (a int)
|
|
partition by list (a)
|
|
(partition p0 values in (1));
|
|
|
|
--error ER_PARTITION_WRONG_VALUES_ERROR
|
|
alter table t1 add partition (partition p1 values less than (2));
|
|
--error ER_PARTITION_REQUIRES_VALUES_ERROR
|
|
alter table t1 add partition (partition p1);
|
|
|
|
drop table t1;
|
|
|
|
create table t1 (a int)
|
|
partition by hash (a)
|
|
(partition p0);
|
|
|
|
--error ER_PARTITION_WRONG_VALUES_ERROR
|
|
alter table t1 add partition (partition p1 values less than (2));
|
|
--error ER_PARTITION_WRONG_VALUES_ERROR
|
|
alter table t1 add partition (partition p1 values in (2));
|
|
|
|
drop table t1;
|
|
|
|
--echo End of 5.1 tests
|