ndb_partition_range.test 6.04 KB
Newer Older
jmiller@mysql.com's avatar
jmiller@mysql.com committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
-- source include/have_ndb.inc
#--disable_abort_on_error
#
# Simple test for the partition storage engine
# Focuses on range partitioning tests
# 
#-- source include/have_partition.inc

--disable_warnings
drop table if exists t1;
--enable_warnings

#
# Partition by range, basic
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b),
index (a))
engine = ndb
partition by range (a)
partitions 3
(partition x1 values less than (5),
 partition x2 values less than (10),
 partition x3 values less than (20));

# Simple insert and verify test
INSERT into t1 values (1, 1, 1);
INSERT into t1 values (6, 1, 1);
INSERT into t1 values (10, 1, 1);
INSERT into t1 values (15, 1, 1);

--replace_column 16 # 19 # 20 #
select * from information_schema.partitions where table_name= 't1';

select * from t1 order by a;

select * from t1 where a=1 order by a;
select * from t1 where a=15 and b=1 order by a;
select * from t1 where a=21 and b=1 order by a;
select * from t1 where a=21 order by a;
select * from t1 where a in (1,6,10,21) order by a;
select * from t1 where b=1 and a in (1,6,10,21) order by a;

drop table t1;

#
# Partition by range, basic
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(b),
unique (a))
engine = ndb
partition by range (b)
partitions 3
(partition x1 values less than (5),
 partition x2 values less than (10),
 partition x3 values less than (20));

# Simple insert and verify test
INSERT into t1 values (1, 1, 1);
INSERT into t1 values (2, 6, 1);
INSERT into t1 values (3, 10, 1);
INSERT into t1 values (4, 15, 1);

select * from t1 order by a;
UPDATE t1 set a = 5 WHERE b = 15;
select * from t1 order by a;
UPDATE t1 set a = 6 WHERE a = 5;
select * from t1 order by a;

select * from t1 where b=1 order by b;
select * from t1 where b=15 and a=1 order by b;
select * from t1 where b=21 and a=1 order by b;
select * from t1 where b=21 order by b;
select * from t1 where b in (1,6,10,21) order by b;
select * from t1 where a in (1,2,5,6) order by b;
select * from t1 where a=1 and b in (1,6,10,21) order by b;

DELETE from t1 WHERE b = 6;
DELETE from t1 WHERE a = 6;

#
# Test that explicit partition info _is_ shown in show create table
# result _should_ contain (PARTITION x1 ... etc)
#
show create table t1;

drop table t1;

#
# Bug #17499, #17687
#  Alter partitioned NDB table causes mysqld to core
#

CREATE TABLE t1
       (id MEDIUMINT NOT NULL,
        b1 BIT(8),
        vc VARCHAR(255),
        bc CHAR(255),
        d DECIMAL(10,4) DEFAULT 0,
        f FLOAT DEFAULT 0,
        total BIGINT UNSIGNED,
        y YEAR,
        t DATE) ENGINE=NDB
   PARTITION BY RANGE (YEAR(t))
       (PARTITION p0 VALUES LESS THAN (1901),
        PARTITION p1 VALUES LESS THAN (1946),
        PARTITION p2 VALUES LESS THAN (1966),
        PARTITION p3 VALUES LESS THAN (1986),
        PARTITION p4 VALUES LESS THAN (2005),
        PARTITION p5 VALUES LESS THAN MAXVALUE);

INSERT INTO t1 VALUES (0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
SELECT * FROM t1;
ALTER TABLE t1 ENGINE=MYISAM;
SELECT * FROM t1;
DROP TABLE t1;

CREATE LOGFILE GROUP lg1
  ADD UNDOFILE 'undofile.dat'
  INITIAL_SIZE 16M
  UNDO_BUFFER_SIZE=1M
  ENGINE=NDB;

CREATE TABLESPACE ts1
  ADD DATAFILE 'datafile.dat'
  USE LOGFILE GROUP lg1
  INITIAL_SIZE 12M
  ENGINE NDB;

CREATE TABLE test.t1 (
  a1 INT,
  a2 TEXT NOT NULL,
  a3 BIT NOT NULL,
  a4 DECIMAL(8,3),
  a5 INT NOT NULL,
  a6 INT,
  PRIMARY KEY(a1))
  TABLESPACE ts1 STORAGE DISK ENGINE=NDB
  PARTITION BY LIST (a1)
 (PARTITION p0 VALUES IN (1,2,3,4,5),
  PARTITION p1 VALUES IN (6,7,8,9, 10),
  PARTITION p2 VALUES IN (11, 12, 13, 14, 15));

# Alter table directly without any statements inbetween
ALTER TABLE test.t1 DROP COLUMN a6;
ALTER TABLE test.t1 ADD COLUMN a6 VARCHAR(255);

let $j= 15;
--disable_query_log
while ($j)
{
eval INSERT INTO test.t1 VALUES ($j, "Tested Remotely from Texas, USA",
b'1',$j.00,$j+1,"By NIK $j");
dec $j;
}
--enable_query_log
SELECT COUNT(*) FROM test.t1;

ALTER TABLE test.t1 DROP COLUMN a4;
SELECT COUNT(*) FROM test.t1;

DROP TABLE t1;

CREATE TABLE test.t1 (
  a1 INT,
  a2 TEXT NOT NULL,
  a3 BIT NOT NULL,
  a4 DECIMAL(8,3),
  a5 INT NOT NULL,
  a6 VARCHAR(255),
  PRIMARY KEY(a1))
  TABLESPACE ts1 STORAGE DISK ENGINE=NDB
  PARTITION BY HASH(a1)
  PARTITIONS 4;

let $j= 15;
--disable_query_log
while ($j)
{
eval INSERT INTO test.t1 VALUES ($j, "Tested Remotely from Texas, USA",
b'1',$j.00,$j+1,"By NIK $j");
dec $j;
}
--enable_query_log
SELECT COUNT(*) FROM test.t1;

ALTER TABLE test.t1 DROP COLUMN a4;
SELECT COUNT(*) FROM test.t1;

DROP TABLE t1;

ALTER TABLESPACE ts1 
  DROP DATAFILE 'datafile.dat' 
  ENGINE=NDB;
DROP TABLESPACE ts1 ENGINE=NDB;
DROP LOGFILE GROUP lg1 ENGINE=NDB;


#
# Bug #17701 ALTER TABLE t1 ADD PARTITION for PARTITION BY LIST hangs test
#

CREATE TABLE t1
    (id MEDIUMINT NOT NULL,
     b1 BIT(8),
     vc VARCHAR(255),
     bc CHAR(255),
     d DECIMAL(10,4) DEFAULT 0,
     f FLOAT DEFAULT 0,
     total BIGINT UNSIGNED,
     y YEAR,
     t DATE) ENGINE=NDB
  PARTITION BY LIST(id)
    (PARTITION p0 VALUES IN (2, 4),
     PARTITION p1 VALUES IN (42, 142));

INSERT INTO t1 VALUES (2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
SELECT * FROM t1;
ALTER TABLE t1 ADD PARTITION
    (PARTITION p2 VALUES IN (412));
SELECT * FROM t1;
DROP TABLE t1;

#
# Bug #17806 Update on NDB table with list partition causes mysqld to core
# Bug #16385 Partitions: crash when updating a range partitioned NDB table
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null)
partition by list(a)
partitions 2
(partition x123 values in (1,5,6),
 partition x234 values in (4,7,8));
INSERT into t1 VALUES (5,1,1);
select * from t1;
UPDATE t1 SET a=8 WHERE a=5 AND b=1;
select * from t1;
drop table t1;

CREATE TABLE t1 ( f1 INTEGER, f2 char(20)) engine=ndb
PARTITION BY RANGE(f1)
( PARTITION part1 VALUES LESS THAN (2),
PARTITION part2 VALUES LESS THAN (1000));
INSERT INTO t1 VALUES(1, '---1---');
INSERT INTO t1 VALUES(2, '---2---');
select * from t1 order by f1;
UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 2;
select * from t1 order by f1;
UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 1;
select * from t1 order by f1;
drop table t1;