diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:00:34 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 18:00:34 +0000 |
commit | 3f619478f796eddbba6e39502fe941b285dd97b1 (patch) | |
tree | e2c7b5777f728320e5b5542b6213fd3591ba51e2 /mysql-test/suite/engines/iuds/t | |
parent | Initial commit. (diff) | |
download | mariadb-upstream.tar.xz mariadb-upstream.zip |
Adding upstream version 1:10.11.6.upstream/1%10.11.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mysql-test/suite/engines/iuds/t')
18 files changed, 40968 insertions, 0 deletions
diff --git a/mysql-test/suite/engines/iuds/t/delete_decimal.test b/mysql-test/suite/engines/iuds/t/delete_decimal.test new file mode 100644 index 00000000..053fc781 --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/delete_decimal.test @@ -0,0 +1,383 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3,t4; +--enable_warnings + +######## Running DELETE tests for DECIMAL ######## + +# Create tables +CREATE TABLE t1(c1 DECIMAL(10,5) UNSIGNED NOT NULL, c2 DECIMAL(10,5) SIGNED NULL, c3 DECIMAL, c4 INT, UNIQUE INDEX idx(c1,c4)); + +# Inserting data into table t1 + +# Trailing zeroes are not stripped, D=5 +INSERT INTO t1 VALUES('00100.05000','-00100.05000','00100119',1),('11111.00009','-9999.99999','9999999',2); + +# DECIMAL := DECIMAL(10,0); Decimal values in c3 will be stripped; +INSERT IGNORE INTO t1 VALUES('1000000','10000000','1000000000.0001',3); + +# c1, c2, c3 will be rounded automatically +INSERT INTO t1 values('100.000001','1000.999999','9999.999999',4); + +# Inserting maximum values +INSERT INTO t1 VALUES('99999.99999','-99999.99999','9999999999',5); + +# Test insert leading zero, +/- signs, overflow handling +INSERT INTO t1 VALUES ("0.0","0.0","0.0",6),("01.0","01.0","01.0",7); +INSERT IGNORE INTO t1 VALUES ("-.1","-.1","-.1",8); +INSERT IGNORE INTO t1 VALUES ("+111111111.11","+111111111.11","+111111111.11",9); + +# Inserting in scientific notations +INSERT INTO t1 VALUES('1.0e+4','1.0e-5','1.0e+9',10); +#INSERT INTO t1 VALUES('0.9999999999e+4','-.999999999e+4,'0.9999999999e+10',11); + +--sorted_result +SELECT * FROM t1; + +# Deletion starts here + +# Delete by order by limit +DELETE FROM t1 WHERE c2 > 100 ORDER BY c2 LIMIT 1; +--sorted_result +SELECT c1,c2 FROM t1; + +# Delete using range values +DELETE FROM t1 WHERE c3=1 AND c4=7; +--sorted_result +SELECT * FROM t1; +DELETE FROM t1 WHERE c3=9999999999 OR c2=1.0e-5; +--sorted_result +SELECT * FROM t1 WHERE c1=1.2e+2; +DELETE FROM t1 WHERE c4 IN (4,5,6); +--sorted_result +SELECT * FROM t1; + +TRUNCATE t1; +INSERT INTO t1 VALUES ('11111.11111','-11111.11111','1111111111',1),('22222.22222','-22222.22222','2222222222',2),('33333.33333','-33333.33333','3333333333',3),('44444.44444','-44444.44444','4444444444',4),('55555.55555','-55555.55555','5555555555',5),('66666.66666','-66666.66666','6666666666',6),('77777.77777','-77777.77777','7777777777',7),('88888.88888','-88888.88888','8888888888',8),('99999.99999','-99999.99999','9999999999',9); +--sorted_result +SELECT * FROM t1; + +SELECT c1 FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1; +DELETE FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1; +--sorted_result +SELECT * FROM t1; + +# Multi table delete +CREATE TABLE t2(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT, UNIQUE INDEX idx2(c1,c3)); +CREATE TABLE t3(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT, UNIQUE INDEX idx3(c1,c3)); +CREATE TABLE t4(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT, UNIQUE INDEX idx4(c1,c3)); +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6); +INSERT INTO t4 VALUES ('77777.77777','7777777777',7),('88888.88888','8888888888',8),('99999.99999','9999999999',9); +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +DELETE t1,t2,t3,t4 FROM t1,t2,t3,t4 WHERE t1.c2 >'1111111111' AND t4.c2 < '8888888888'; +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t1; + +# Delete using various access methods +TRUNCATE t2; +TRUNCATE t3; +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6); + +# Delete using Const +# EXPLAIN SELECT * FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2; +DELETE FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2; +--sorted_result +SELECT * FROM t2; + +# Delete using range +# EXPLAIN SELECT * FROM t2 WHERE c1 BETWEEN '11111' AND '44444'; +DELETE FROM t2 WHERE c1 BETWEEN '11111' AND '44444'; +--sorted_result +SELECT * FROM t2; +# EXPLAIN SELECT * FROM t2 WHERE c1 IN ('44444.44444','99999.99999'); +DELETE FROM t2 WHERE c1 IN ('44444.44444','99999.99999'); +--sorted_result +SELECT * FROM t2; + +# Delete using eq_ref +DROP TABLE t2,t3; +CREATE TABLE t2(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT); +CREATE TABLE t3(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT, UNIQUE INDEX idx3(c1)); +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('11111.11111','4444444444',1),('55555.55555','5555555555',2),('66666.66666','6666666666',3); +# EXPLAIN SELECT * FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; +DELETE t2,t3 FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +# Droping the tables +--disable_warnings +DROP TABLES IF EXISTS t1,t2,t3,t4; +--enable_warnings + +######## Running DELETE tests for FLOAT ######## + +# Create tables +CREATE TABLE t1(c1 FLOAT(10,5) UNSIGNED NOT NULL, c2 FLOAT(10,5) SIGNED NULL, c3 FLOAT, c4 INT, UNIQUE INDEX idx(c1,c4)); + +# Inserting data into table t1 + +# Trailing zeroes are not stripped, D=5 +INSERT INTO t1 VALUES('00100.05000','-00100.05000','00100119',1),('11111.00009','-9999.99999','9999999',2); + +# DECIMAL := DECIMAL(10,0); Decimal values in c3 will be stripped; +INSERT IGNORE INTO t1 VALUES('1000000','10000000','1000000000.0001',3); + +# c1, c2, c3 will be rounded automatically +INSERT INTO t1 values('100.000001','1000.999999','9999.999999',4); + +# Inserting maximum values +INSERT INTO t1 VALUES('99999.99999','-99999.99999','9999999999',5); + +# Test insert leading zero, +/- signs, overflow handling +INSERT INTO t1 VALUES ("0.0","0.0","0.0",6),("01.0","01.0","01.0",7); +INSERT IGNORE INTO t1 VALUES ("-.1","-.1","-.1",8); +INSERT IGNORE INTO t1 VALUES ("+111111111.11","+111111111.11","+111111111.11",9); + +# Inserting in scientific notations +INSERT INTO t1 VALUES('1.0e+4','1.0e-5','1.0e+9',10); +#INSERT INTO t1 VALUES('0.9999999999e+4','-.999999999e+4,'0.9999999999e+10',11); + +--sorted_result +SELECT * FROM t1; + +# Deletion starts here + +# Delete by order by limit +DELETE FROM t1 WHERE c2 > 100 ORDER BY c2 LIMIT 1; +--sorted_result +SELECT c1,c2 FROM t1; + +# Delete using range values +DELETE FROM t1 WHERE c3=1 AND c4=7; +--sorted_result +SELECT * FROM t1; +DELETE FROM t1 WHERE c3=9999999999 OR c2=1.0e-5; +--sorted_result +SELECT * FROM t1 WHERE c1=1.2e+2; +DELETE FROM t1 WHERE c4 IN (4,5,6); +--sorted_result +SELECT * FROM t1; + +TRUNCATE t1; +INSERT INTO t1 VALUES ('11111.11111','-11111.11111','1111111111',1),('22222.22222','-22222.22222','2222222222',2),('33333.33333','-33333.33333','3333333333',3),('44444.44444','-44444.44444','4444444444',4),('55555.55555','-55555.55555','5555555555',5),('66666.66666','-66666.66666','6666666666',6),('77777.77777','-77777.77777','7777777777',7),('88888.88888','-88888.88888','8888888888',8),('99999.99999','-99999.99999','9999999999',9); +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t1; + +SELECT c1 FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1; +DELETE FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t1; + +# Multi table delete +CREATE TABLE t2(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT, UNIQUE INDEX idx2(c1,c3)); +CREATE TABLE t3(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT, UNIQUE INDEX idx3(c1,c3)); +CREATE TABLE t4(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT, UNIQUE INDEX idx4(c1,c3)); +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6); +INSERT INTO t4 VALUES ('77777.77777','7777777777',7),('88888.88888','8888888888',8),('99999.99999','9999999999',9); +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t4; +DELETE t1,t2,t3,t4 FROM t1,t2,t3,t4 WHERE t1.c2 >'1111111111' AND t4.c2 < '8888888888'; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t1; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t1; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t1; + +# Delete using various access methods +TRUNCATE t2; +TRUNCATE t3; +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6); + +# Delete using Const +# EXPLAIN SELECT * FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2; +DELETE FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2; +--sorted_result +SELECT * FROM t2; + +# Delete using range +# EXPLAIN SELECT * FROM t2 WHERE c1 BETWEEN '11111' AND '44444'; +DELETE FROM t2 WHERE c1 BETWEEN '11111' AND '44444'; +--sorted_result +SELECT * FROM t2; +# EXPLAIN SELECT * FROM t2 WHERE c1 IN ('44444.44444','99999.99999'); +DELETE FROM t2 WHERE c1 IN ('44444.44444','99999.99999'); +--sorted_result +SELECT * FROM t2; + +# Delete using eq_ref +DROP TABLE t2,t3; +CREATE TABLE t2(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT); +CREATE TABLE t3(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT, UNIQUE INDEX idx3(c1)); +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('11111.11111','4444444444',1),('55555.55555','5555555555',2),('66666.66666','6666666666',3); +# EXPLAIN SELECT * FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; +DELETE t2,t3 FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t4; +# Droping the tables +--disable_warnings +DROP TABLES IF EXISTS t1,t2,t3,t4; +--enable_warnings + +######## Running DELETE tests for DOUBLE ######## + +# Create tables +CREATE TABLE t1(c1 DOUBLE(10,5) UNSIGNED NOT NULL, c2 DOUBLE(10,5) SIGNED NULL, c3 DOUBLE, c4 INT, UNIQUE INDEX idx(c1,c4)); + +# Inserting data into table t1 + +# Trailing zeroes are not stripped, D=5 +INSERT INTO t1 VALUES('00100.05000','-00100.05000','00100119',1),('11111.00009','-9999.99999','9999999',2); + +# DECIMAL := DECIMAL(10,0); Decimal values in c3 will be stripped; +INSERT IGNORE INTO t1 VALUES('1000000','10000000','1000000000.0001',3); + +# c1, c2, c3 will be rounded automatically +INSERT INTO t1 values('100.000001','1000.999999','9999.999999',4); + +# Inserting maximum values +INSERT INTO t1 VALUES('99999.99999','-99999.99999','9999999999',5); + +# Test insert leading zero, +/- signs, overflow handling +INSERT INTO t1 VALUES ("0.0","0.0","0.0",6),("01.0","01.0","01.0",7); +INSERT IGNORE INTO t1 VALUES ("-.1","-.1","-.1",8); +INSERT IGNORE INTO t1 VALUES ("+111111111.11","+111111111.11","+111111111.11",9); + +# Inserting in scientific notations +INSERT INTO t1 VALUES('1.0e+4','1.0e-5','1.0e+9',10); +#INSERT INTO t1 VALUES('0.9999999999e+4','-.999999999e+4,'0.9999999999e+10',11); + +--sorted_result +SELECT * FROM t1; + +# Deletion starts here + +# Delete by order by limit +DELETE FROM t1 WHERE c2 > 100 ORDER BY c2 LIMIT 1; +--sorted_result +SELECT c1,c2 FROM t1; + +# Delete using range values +DELETE FROM t1 WHERE c3=1 AND c4=7; +--sorted_result +SELECT * FROM t1; +DELETE FROM t1 WHERE c3=9999999999 OR c2=1.0e-5; +--sorted_result +SELECT * FROM t1 WHERE c1=1.2e+2; +DELETE FROM t1 WHERE c4 IN (4,5,6); +--sorted_result +SELECT * FROM t1; + +TRUNCATE t1; +INSERT INTO t1 VALUES ('11111.11111','-11111.11111','1111111111',1),('22222.22222','-22222.22222','2222222222',2),('33333.33333','-33333.33333','3333333333',3),('44444.44444','-44444.44444','4444444444',4),('55555.55555','-55555.55555','5555555555',5),('66666.66666','-66666.66666','6666666666',6),('77777.77777','-77777.77777','7777777777',7),('88888.88888','-88888.88888','8888888888',8),('99999.99999','-99999.99999','9999999999',9); +--sorted_result +SELECT * FROM t1; + +SELECT c1 FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1; +DELETE FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1; +--sorted_result +SELECT * FROM t1; + +# Multi table delete +CREATE TABLE t2(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT, UNIQUE INDEX idx2(c1,c3)); +CREATE TABLE t3(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT, UNIQUE INDEX idx3(c1,c3)); +CREATE TABLE t4(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT, UNIQUE INDEX idx4(c1,c3)); +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6); +INSERT INTO t4 VALUES ('77777.77777','7777777777',7),('88888.88888','8888888888',8),('99999.99999','9999999999',9); +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +DELETE t1,t2,t3,t4 FROM t1,t2,t3,t4 WHERE t1.c2 >'1111111111' AND t4.c2 < '8888888888'; +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t1; + +# Delete using various access methods +TRUNCATE t2; +TRUNCATE t3; +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6); + +# Delete using Const +# EXPLAIN SELECT * FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2; +DELETE FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2; +--sorted_result +SELECT * FROM t2; + +# Delete using range +# EXPLAIN SELECT * FROM t2 WHERE c1 BETWEEN '11111' AND '44444'; +DELETE FROM t2 WHERE c1 BETWEEN '11111' AND '44444'; +--sorted_result +SELECT * FROM t2; +# EXPLAIN SELECT * FROM t2 WHERE c1 IN ('44444.44444','99999.99999'); +DELETE FROM t2 WHERE c1 IN ('44444.44444','99999.99999'); +--sorted_result +SELECT * FROM t2; + +# Delete using eq_ref +DROP TABLE t2,t3; +CREATE TABLE t2(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT); +CREATE TABLE t3(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT, UNIQUE INDEX idx3(c1)); +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('11111.11111','4444444444',1),('55555.55555','5555555555',2),('66666.66666','6666666666',3); +# EXPLAIN SELECT * FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; +DELETE t2,t3 FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +# Droping the tables +--disable_warnings +DROP TABLES IF EXISTS t1,t2,t3,t4; +--enable_warnings + diff --git a/mysql-test/suite/engines/iuds/t/delete_time.test b/mysql-test/suite/engines/iuds/t/delete_time.test new file mode 100644 index 00000000..113502a4 --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/delete_time.test @@ -0,0 +1,122 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3,t4; +--enable_warnings +# Create tables +CREATE TABLE t1(c1 TIME NOT NULL, c2 TIME NULL, PRIMARY KEY(c1)); +CREATE TABLE t2(c1 TIME NOT NULL, c2 TIME NULL, PRIMARY KEY(c1,c2)); +CREATE TABLE t3(c1 TIME NOT NULL, c2 TIME NULL, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t4(c1 TIME NOT NULL, c2 TIME NULL); + +# As a string in 'D HH:MM:SS.fraction' format + +INSERT INTO t1 VALUES ('00:00:00.00','00:00:00.00'),('01:01:01.01','01:01:01.00'),('838:59:59.00','838:59:59.00'),('00:00:01','00:00:01'),('02:02:02','02:02:02'),('838:59:58','838:59:58'),('-838:59:59','-838:59:59'),('00:03','00:03'),('03:03','03:03'),('838:58','838:58'),('00 00:00:04','00 00:00:04'),('04 04:04:04','04 04:04:04'),('34 22:59:57','34 22:59:57'),('00 00:04','00 00:04'),('05 05:05','05 05:05'),('34 22:56','34 22:56'),('05 05','05 05'),('06 06','06 06'),('34 22','34 22'),('07','07'),('59','59'); +INSERT INTO t2 VALUES ('00:00:00.00','00:00:00.00'),('01:01:01.01','01:01:01.00'),('838:59:59.00','838:59:59.00'),('00:00:01','00:00:01'),('02:02:02','02:02:02'),('838:59:58','838:59:58'),('-838:59:59','-838:59:59'),('00:03','00:03'),('03:03','03:03'),('838:58','838:58'),('00 00:00:04','00 00:00:04'),('04 04:04:04','04 04:04:04'),('34 22:59:57','34 22:59:57'),('00 00:04','00 00:04'),('05 05:05','05 05:05'),('34 22:56','34 22:56'),('05 05','05 05'),('06 06','06 06'),('34 22','34 22'),('07','07'),('59','59'); +INSERT INTO t3 VALUES ('00:00:00.00','00:00:00.00'),('01:01:01.01','01:01:01.00'),('838:59:59.00','838:59:59.00'),('00:00:01','00:00:01'),('02:02:02','02:02:02'),('838:59:58','838:59:58'),('-838:59:59','-838:59:59'),('00:03','00:03'),('03:03','03:03'),('838:58','838:58'),('00 00:00:04','00 00:00:04'),('04 04:04:04','04 04:04:04'),('34 22:59:57','34 22:59:57'),('00 00:04','00 00:04'),('05 05:05','05 05:05'),('34 22:56','34 22:56'),('05 05','05 05'),('06 06','06 06'),('34 22','34 22'),('07','07'),('59','59'); +INSERT INTO t4 VALUES ('00:00:00.00','00:00:00.00'),('01:01:01.01','01:01:01.00'),('838:59:59.00','838:59:59.00'),('00:00:01','00:00:01'),('02:02:02','02:02:02'),('838:59:58','838:59:58'),('-838:59:59','-838:59:59'),('00:03','00:03'),('03:03','03:03'),('838:58','838:58'),('00 00:00:04','00 00:00:04'),('04 04:04:04','04 04:04:04'),('34 22:59:57','34 22:59:57'),('00 00:04','00 00:04'),('05 05:05','05 05:05'),('34 22:56','34 22:56'),('05 05','05 05'),('06 06','06 06'),('34 22','34 22'),('07','07'),('59','59'); + +#As a string with no delimiters in 'HHMMSS' format + +INSERT INTO t1 VALUES('000008','000008'),('080808','080808'),('8385955','8385955'),('-8385955','-8385955'),('0009','0009'),('0909','0909'),('5454','5454'),('10','10'),('53','53'); +INSERT INTO t2 VALUES('000008','000008'),('080808','080808'),('8385955','8385955'),('-8385955','-8385955'),('0009','0009'),('0909','0909'),('5454','5454'),('10','10'),('53','53'); +INSERT INTO t3 VALUES('000008','000008'),('080808','080808'),('8385955','8385955'),('-8385955','-8385955'),('0009','0009'),('0909','0909'),('5454','5454'),('10','10'),('53','53'); +INSERT INTO t4 VALUES('000008','000008'),('080808','080808'),('8385955','8385955'),('-8385955','-8385955'),('0009','0009'),('0909','0909'),('5454','5454'),('10','10'),('53','53'); + +#As a number in HHMMSS format + +INSERT INTO t1 VALUES (000011.00,000011.00),(111111.11,111111.11),(8385952.00,8385952.00),(000012,000012),(121212,121212),(8385951,8385951),(1313,1313),(5151,5151),(14,14),(50,50); +INSERT INTO t2 VALUES (000011.00,000011.00),(111111.11,111111.11),(8385952.00,8385952.00),(000012,000012),(121212,121212),(8385951,8385951),(1313,1313),(5151,5151),(14,14),(50,50); +INSERT INTO t3 VALUES (000011.00,000011.00),(111111.11,111111.11),(8385952.00,8385952.00),(000012,000012),(121212,121212),(8385951,8385951),(1313,1313),(5151,5151),(14,14),(50,50); +INSERT INTO t4 VALUES (000011.00,000011.00),(111111.11,111111.11),(8385952.00,8385952.00),(000012,000012),(121212,121212),(8385951,8385951),(1313,1313),(5151,5151),(14,14),(50,50); + +#As the result of a function that returns a value that is acceptable in a TIME context +SET TIMESTAMP=1233216687; # 2009-01-29 13:41:27 +INSERT INTO t1 VALUES(CURRENT_TIME(),CURRENT_TIME()); +INSERT INTO t2 VALUES(CURRENT_TIME(),CURRENT_TIME()); +INSERT INTO t3 VALUES(CURRENT_TIME(),CURRENT_TIME()); +INSERT INTO t4 VALUES(CURRENT_TIME(),CURRENT_TIME()); +#Insert permissible NULLs +INSERT INTO t1 VALUES('123456',null); +#INSERT INTO t2 VALUES('123456',null); +INSERT INTO t3 VALUES('123456',null); +INSERT INTO t4 VALUES('123456',null); +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +#Deleting the table rows +--sorted_result +SELECT c1 FROM t1 WHERE c1='00:00:07'; +DELETE FROM t1 WHERE c1='00:00:07'; +--sorted_result +SELECT c1 FROM t1; +--sorted_result +SELECT c1 FROM t2 WHERE c1='-838:59:59' AND c2='-838:59:59'; +DELETE FROM t2 WHERE c1='-838:59:59' AND c2='-838:59:59'; +--sorted_result +SELECT c1 FROM t2; + +#Deleting rowa with NULL attributes +--sorted_result +SELECT c2 FROM t3 WHERE c2=null; +DELETE FROM t3 WHERE c2=null; +--sorted_result +SELECT c2 FROM t3; + +#Delete by order by limit +--sorted_result +SELECT c1 FROM t4 WHERE c1 < '000009'; +DELETE FROM t4 WHERE c1 < '000009' ORDER BY c1 LIMIT 3; +--sorted_result +SELECT c1 FROM t4; + +#Delete by range values +DELETE FROM t1 WHERE c1='00:00:09' AND c1='01:01:01'; +--sorted_result +SELECT c2 FROM t1; +DELETE FROM t2 WHERE c2=000400 OR c2= 000900; +--sorted_result +SELECT c1 FROM t2; +DELETE FROM t2 WHERE c1 IN ('100:04:04',005454,'2:2:2',111111) ORDER BY c1 LIMIT 2; +--sorted_result +SELECT c2 FROM t2; + +#Multi table delete +DELETE t1,t2,t3,t4 FROM t1,t2,t3,t4 WHERE t1.c1='00:13:13' AND t2.c1=080808 AND t4.c1='00:04:00' AND t3.c2=020202; + +#Delete using various access methods + +# Delete using Const +# EXPLAIN SELECT * FROM t1 WHERE c1='00:09:09' AND c2='00:09:09'; +DELETE FROM t1 WHERE c1='00:09:09' AND c2='00:09:09'; +--sorted_result +SELECT * FROM t1; + +# Delete using range +# EXPLAIN SELECT * FROM t1 WHERE c1 BETWEEN 080000 AND 100000; +DELETE FROM t1 WHERE c1 BETWEEN 080000 AND 100000; +--sorted_result +SELECT * FROM t1; +# EXPLAIN SELECT * FROM t1 WHERE c1 IN (222222,8385959,1500000); +DELETE FROM t1 WHERE c1 IN (222222,8385959,1500000); +--sorted_result +SELECT * FROM t1; + +# Delete using eq_ref +# EXPLAIN SELECT * FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; +DELETE t1,t2 FROM t1,t2 WHERE t1.c1=t2.c1 AND t1.c2=t2.c2; + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +#Drop tables; +DROP TABLE IF EXISTS t1,t2,t3,t4; + diff --git a/mysql-test/suite/engines/iuds/t/delete_year.test b/mysql-test/suite/engines/iuds/t/delete_year.test new file mode 100644 index 00000000..2cbe11ab --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/delete_year.test @@ -0,0 +1,110 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3,t4; +--enable_warnings +# Create tables +CREATE TABLE t1(c1 YEAR NOT NULL,c2 YEAR, PRIMARY KEY(c1)); +CREATE TABLE t2(c1 YEAR NOT NULL, c2 YEAR, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t3(c1 YEAR(2) NOT NULL,c2 YEAR(2), PRIMARY KEY(c1)); +CREATE TABLE t4(c1 YEAR(2), c2 YEAR(2), UNIQUE INDEX idx(c1,c2)); +#Insert as 4-digit number format in the range '1901' to '2155' +INSERT INTO t1 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); +INSERT INTO t2 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); +INSERT INTO t3 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); +INSERT INTO t4 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); +#Insert as 4-digit string format in the range '1901' to '2155' +INSERT INTO t1 VALUES ('1902','1902'),('1971','1971'),('1998','1998'),('2001','2001'),('2154','2154'); +INSERT INTO t2 VALUES ('1902','1902'),('1971','1971'),('1998','1998'),('2001','2001'),('2154','2154'); +INSERT INTO t3 VALUES ('1902','1902'),('1971','1971'),('1998','1998'),('2001','2001'),('2154','2154'); +INSERT INTO t4 VALUES ('1902','1902'),('1971','1971'),('1998','1998'),('2001','2001'),('2154','2154'); +#Insert as 2-digit number format +INSERT INTO t1 VALUES (04,04),(64,64),(69,69),(97,97); +INSERT INTO t2 VALUES (04,04),(64,64),(69,69),(97,97); +INSERT INTO t3 VALUES (04,04),(64,64),(69,69),(97,97); +INSERT INTO t4 VALUES (04,04),(64,64),(69,69),(97,97); +#Insert as 2-digit string format +INSERT INTO t1 VALUES ('05','05'),('65','65'),('75','75'),('95','95'); +INSERT INTO t2 VALUES ('05','05'),('65','65'),('75','75'),('95','95'); +INSERT INTO t3 VALUES ('05','05'),('65','65'),('75','75'),('95','95'); +INSERT INTO t4 VALUES ('05','05'),('65','65'),('75','75'),('95','95'); +#Insert permissible NULLs +INSERT INTO t1 VALUES ('09',null),('61',null),('79',null),('96',null); +INSERT INTO t2 VALUES ('09',null),('61',null),('79',null),('96',null); +INSERT INTO t3 VALUES ('09',null),('61',null),('79',null),('96',null); +INSERT INTO t4 VALUES ('09',null),('61',null),('79',null),('96',null); +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +#Deleting the specified rows +--sorted_result +SELECT c1 FROM t1 WHERE c1='2005'; +DELETE FROM t1 WHERE c1='2005'; +--sorted_result +SELECT c1 FROM t1; + +# Delete rows with null attributes +--sorted_result +SELECT c2 FROM t2 WHERE c2=null; +DELETE FROM t2 WHERE c2=null LIMIT 2; +--sorted_result +SELECT c2 FROM t2; + +#Delete order by limit +--sorted_result +SELECT c1 FROM t4 WHERE c1 < '55'; +DELETE FROM t4 WHERE c1 < '65' ORDER BY c1 LIMIT 5; +--sorted_result +SELECT c1 FROM t4; + +#Delete by range values +DELETE FROM t2 WHERE c1=2009 AND c2=null; +--sorted_result +SELECT c2 FROM t2; +DELETE FROM t1 WHERE c1=1979 OR c1=2154; +--sorted_result +SELECT c2 FROM t1; +DELETE FROM t4 WHERE c2 IN (01,54,65,69,null) LIMIT 2; +--sorted_result +SELECT c1 FROM t4; + +#Multi table delete +DELETE t3,t4 FROM t3,t4 WHERE t3.c1=61 AND t4.c2=4; + +# Delete using various access methods + +# Delete using Const +# EXPLAIN SELECT * FROM t1 WHERE c1=2064 AND c2=2064; +DELETE FROM t1 WHERE c1=2064 AND c2=2064; +--sorted_result +SELECT * FROM t1; + +# Delete using range +# EXPLAIN SELECT * FROM t1 WHERE c1 BETWEEN 2000 AND 2010; +DELETE FROM t1 WHERE c1 BETWEEN 2000 AND 2010 LIMIT 2; +--sorted_result +SELECT * FROM t1; +# EXPLAIN SELECT * FROM t1 WHERE c1 IN (2155,2009,1975); +DELETE FROM t1 WHERE c1 IN (2155,2009,1975) LIMIT 2; +--sorted_result +SELECT * FROM t1; + +# Delete using eq_ref +# EXPLAIN SELECT * FROM t1,t2 WHERE t1.c1=t2.c1 AND t1.c2=t2.c2; +DELETE t1,t2 FROM t1,t2 WHERE t1.c1=t2.c1 AND t1.c2=t2.c2; + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; + +#Drop tables +DROP TABLE IF EXISTS t1,t2,t3,t4; + diff --git a/mysql-test/suite/engines/iuds/t/hindi.txt b/mysql-test/suite/engines/iuds/t/hindi.txt new file mode 100644 index 00000000..190ffdcc --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/hindi.txt @@ -0,0 +1,50 @@ +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. +यह हिन्दी में एक वाक्य है. diff --git a/mysql-test/suite/engines/iuds/t/insert_calendar.test b/mysql-test/suite/engines/iuds/t/insert_calendar.test new file mode 100644 index 00000000..5d8380a1 --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/insert_calendar.test @@ -0,0 +1,5983 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3; +--enable_warnings + +######## Running INSERT tests for DATE ######## + +# Create tables +CREATE TABLE t1(c1 DATE NOT NULL, c2 DATE NULL, c3 DATETIME, c4 TIMESTAMP, PRIMARY KEY(c1), UNIQUE INDEX(c2)); +CREATE TABLE t2(c1 DATE NOT NULL, c2 DATE NULL, c3 DATETIME, c4 TIMESTAMP, PRIMARY KEY(c1,c2)); +CREATE TABLE t3(c1 DATE NOT NULL, c2 DATE NULL, c3 DATETIME, c4 TIMESTAMP, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t4(c1 DATE NOT NULL, c2 DATE NULL, c3 DATETIME, c4 TIMESTAMP); + +# Insert some rows with targeted values + +# As a string in either 'YYYY-MM-DD HH:MM:SS', 'YY-MM-DD HH:MM:SS', 'YYYY-MM-DD' or 'YY-MM-DD' format +INSERT INTO t1 VALUES('98-12-31 11:30:45','98.12.31 11+30+45','98-12-31 11:30:45','98.12.31 11+30+45'),('98/12/30 11*30*45','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'),('98-12-29','98.12.29','98-12-29','98.12.29'),('98/12/28','98@12@28','98/12/28','98@12@28'); +INSERT INTO t2 VALUES('98-12-31 11:30:45','98.12.31 11+30+45','98-12-31 11:30:45','98.12.31 11+30+45'),('98/12/30 11*30*45','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'),('98-12-29','98.12.29','98-12-29','98.12.29'),('98/12/28','98@12@28','98/12/28','98@12@28'); +INSERT INTO t3 VALUES('98-12-31 11:30:45','98.12.31 11+30+45','98-12-31 11:30:45','98.12.31 11+30+45'),('98/12/30 11*30*45','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'),('98-12-29','98.12.29','98-12-29','98.12.29'),('98/12/28','98@12@28','98/12/28','98@12@28'); +INSERT INTO t4 VALUES('98-12-31 11:30:45','98.12.31 11+30+45','98-12-31 11:30:45','98.12.31 11+30+45'),('98/12/30 11*30*45','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'),('98-12-29','98.12.29','98-12-29','98.12.29'),('98/12/28','98@12@28','98/12/28','98@12@28'); + +# As a string with no delimiters in either 'YYYYMMDDHHMMSS', 'YYMMDDHHMMSS', 'YYYYMMDD' or 'YYMMDD' format +INSERT INTO t1 VALUES('20070523091528','070523091528','20070524091528','070524091528'),('20070525','070525','20070526','070526'); +INSERT INTO t2 VALUES('20070523091528','070523091528','20070524091528','070524091528'),('20070525','070525','20070526','070526'); +INSERT INTO t3 VALUES('20070523091528','070523091528','20070524091528','070524091528'),('20070525','070525','20070526','070526'); +INSERT INTO t4 VALUES('20070523091528','070523091528','20070524091528','070524091528'),('20070525','070525','20070526','070526'); + +# As a number in either YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD or YYMMDD format +INSERT INTO t1 VALUES(19830905132800,830905132800,19830906132800,830906132800),(19830907,830907,19830908,830908); +INSERT INTO t2 VALUES(19830905132800,830905132800,19830906132800,830906132800),(19830907,830907,19830908,830908); +INSERT INTO t3 VALUES(19830905132800,830905132800,19830906132800,830906132800),(19830907,830907,19830908,830908); +INSERT INTO t4 VALUES(19830905132800,830905132800,19830906132800,830906132800),(19830907,830907,19830908,830908); + +# As the result of a function +SET TIMESTAMP=1233216687; # 2009-01-29 13:41:27 +INSERT INTO t1 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT INTO t2 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT INTO t3 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT INTO t4 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); + +# Insert duplicates for parts of the clustered key/unique index +INSERT INTO t2 VALUES('98-12-31 11:30:45','98@12@30 11^30^45','98-12-31 11:30:45','98.12.31 11+30+45'),('98-12-29','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'); +INSERT INTO t3 VALUES('98-12-31 11:30:45','98@12@30 11^30^45','98-12-31 11:30:45','98.12.31 11+30+45'),('98-12-29','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'); + +# Insert permissible NULLs +INSERT INTO t1 VALUES('2008-01-01',NULL,'08-01-02','08/01/03'); +INSERT INTO t3 VALUES('2008-01-01',NULL,'08-01-02','08/01/03'); +INSERT INTO t4 VALUES('2008-01-01',NULL,'08-01-02','08/01/03'); + +# Insert duplicate NULLs to unique column +INSERT INTO t1(c1,c2) VALUES('08/01/17',NULL); +DELETE FROM t1 WHERE c1='08/01/17' AND c2 IS NULL; + +# Insert empty string '', would be converted to zero value of the appropriate type +INSERT INTO t1 VALUES('','','08-01-04','08/01/05') /* Inserts zero dates for '' strings */; + +# Insert invalid dates, would be converted to zero value of the appropriate type +INSERT INTO t2 VALUES('2008-04-31','2008-04-31','08-01-06','08/01/07') /* Inserts zero dates for invalid dates */; +INSERT INTO t3 VALUES('10:45:15','10:45:15','08-01-08','08/1/9') /* Inserts zero dates for invalid dates */; + +# Insert zero dates +INSERT INTO t2 VALUES('0000-00-00','08-01-06','08-01-06','08/01/07'); +INSERT INTO t3 VALUES('08-01-06','00-00-00','08-01-08','08/1/9'); + +# Insert non-date value(absurd values), would be converted to zero value of the appropriate type +INSERT INTO t4 VALUES('abcd','abcd','08-01-10','08/01/11'),(1234,1234,'08-01-12','08/01/13') /* Inserts zero dates for absurd dates */; + +# Now select using various table access methods (full table scan, range scan, index scan etc.) +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; + +# Select from table with single column primary key and single column index, with column values zero, NULL +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2007-05-24'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '1998-12-29 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '1998-12-29 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','1998-12-29 00:00:00') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','1998-12-29 00:00:00') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '1998-12-29 00:00:00' AND c2 = '1983-09-07 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '1998-12-29 00:00:00' AND c2 = '1983-09-07 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '1998-12-29 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '1998-12-29 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','1998-12-29 00:00:00') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','1998-12-29 00:00:00') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '1998-12-29 00:00:00' AND c2 = '1983-09-07 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '1998-12-29 00:00:00' AND c2 = '1983-09-07 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2007-05-26'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c4 = '2007-05-26 00:00:00'; + +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t1; + +## Backward index scan, covering ## +SELECT c2 FROM t1 ORDER BY c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 = '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 = '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <> '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 > '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 < '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <= '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <=> '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-31 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-31 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-31 11:30:45') ORDER BY c2; +SELECT * FROM t1 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-31 11:30:45') ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-31 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-31 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <> '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 > '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 < '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <= '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-31 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-31 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-31 11:30:45') ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-31 11:30:45') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-31 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-31 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC LIMIT 2; + +# Select from table with clustered primary key, with column values zero, NULL +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2008-01-06'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1983-09-07 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '1983-09-07 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1983-09-07 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('1983-09-07 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1983-09-07 00:00:00' AND c1 < '2007-05-23 09:15:28' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1983-09-07 00:00:00' AND c1 < '2007-05-23 09:15:28' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1983-09-07 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '1983-09-07 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1983-09-07 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('1983-09-07 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1983-09-07 00:00:00' AND c1 < '2007-05-23 09:15:28' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1983-09-07 00:00:00' AND c1 < '2007-05-23 09:15:28' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '2007-05-23 09:15:28' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '2007-05-23 09:15:28' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '2007-05-23 09:15:28' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '2007-05-23 09:15:28' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c4 = '2007-05-24 09:15:28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('0000-00-00 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN ('0000-00-00 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '2007-05-23 09:15:28' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '2007-05-23 09:15:28' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('0000-00-00 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN ('0000-00-00 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '2007-05-23 09:15:28' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '2007-05-23 09:15:28' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Select from table with clustered index, with column values zero, NULL +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2007-05-24'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1998-12-31 11:30:45' AND '2008-01-06 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '1998-12-31 11:30:45' AND '2008-01-06 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1998-12-31 11:30:45','2008-01-06 00:00:00') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('1998-12-31 11:30:45','2008-01-06 00:00:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1998-12-31 11:30:45' AND c1 < '2008-01-06 00:00:00' AND c2 = '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1998-12-31 11:30:45' AND c1 < '2008-01-06 00:00:00' AND c2 = '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1998-12-31 11:30:45' AND '2008-01-06 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '1998-12-31 11:30:45' AND '2008-01-06 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1998-12-31 11:30:45','2008-01-06 00:00:00') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('1998-12-31 11:30:45','2008-01-06 00:00:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1998-12-31 11:30:45' AND c1 < '2008-01-06 00:00:00' AND c2 = '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1998-12-31 11:30:45' AND c1 < '2008-01-06 00:00:00' AND c2 = '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c4 = '2007-05-24 09:15:28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-30 11:30:45' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-30 11:30:45' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-30 11:30:45') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-30 11:30:45') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-30 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-30 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-30 11:30:45' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-30 11:30:45' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-30 11:30:45') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-30 11:30:45') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-30 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-30 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Test Error conditions- PK constraint violation, Unique constraint violation + +# Insert duplicate value to pk column +--error ER_DUP_ENTRY +INSERT INTO t1(c1,c2) VALUES('20070525','070523091528') /* Row with c1='20070525' exists */; + +# Insert duplicate value to clustered pk, throws error +--error ER_DUP_ENTRY +INSERT INTO t2(c1,c2) VALUES(19830907,830907) /* Row with c1=19830907,c2=830907 exists */; + +# Insert duplicate value to unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t1(c1,c2) VALUES(19840905,830907) /* Row with c2=830907 exists */; + +# Insert duplicate value to clustered unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t3(c1,c2) VALUES(19830907,830907) /* Row with c1=19830907,c2=830907 exists */; + +# Test 'INSERT IGNORE' with the same rows that reported constraint violation above +# Ignore pk constraint +INSERT IGNORE INTO t1(c1,c2) VALUES('20070525','20070527') /* doesn't throw error */; +INSERT IGNORE INTO t2(c1,c2) VALUES(19830907,830907) /* doesn't throw error */; +# Ignore unique constraint +INSERT IGNORE INTO t1(c1,c2) VALUES(19840905,830907) /* doesn't throw error */; +INSERT IGNORE INTO t3(c1,c2) VALUES(19830907,830907) /* doesn't throw error */; +# Test that the rows are same +SELECT * FROM t1 WHERE c1='20070525' /* Returns 1 row with c1=2007-05-25 */; +SELECT * FROM t2 WHERE c1=19830907 AND c2=830907 /* Returns 1 row with c1=1983-09-07 and c2=1983-09-07 */; +SELECT * FROM t1 WHERE c2=830907 /* Returns 1 row with c2=1983-09-07 */; +SELECT * FROM t3 WHERE c1=19830907 AND c2=830907 /* Returns 1 row with c1=1983-09-07 and c2=1983-09-07 */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with single column PK +SELECT * FROM t1 WHERE c1='20070527' /* Returns no rows */; +INSERT INTO t1(c1) VALUES('20070525') ON DUPLICATE KEY UPDATE c1='20070527'; +SELECT * FROM t1 WHERE c1='20070527' /* Returns 1 row with c1=2007-05-27 */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with multi-column PK +SELECT * FROM t2 WHERE c1=19830909 AND c2=830910 /* Returns no rows */; +INSERT INTO t2(c1,c2) VALUES(19830907,830907) ON DUPLICATE KEY UPDATE c1=19830909,c2=830910; +SELECT * FROM t2 WHERE c1=19830909 AND c2=830910 /* Returns 1 row with c1=19830909,c2=830910 */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with single column unique +SELECT * FROM t1 WHERE c1=19830909 AND c2=830910 /* Returns no rows */; +INSERT INTO t1(c1,c2) VALUES(19840905,830907) ON DUPLICATE KEY UPDATE c1=19830909,c2=830910; +SELECT * FROM t1 WHERE c1=19830909 AND c2=830910 /* Returns 1 row */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with multi-column unique +SELECT * FROM t3 WHERE c1=19830909 AND c2=830910 /* Returns no rows */; +INSERT INTO t3(c1,c2) VALUES(19830907,830907) ON DUPLICATE KEY UPDATE c1=19830909,c2=830910; +SELECT * FROM t3 WHERE c1=19830909 AND c2=830910 /* Returns 1 row */; + +# Test 'INSERT SET' +INSERT INTO t1 SET c1='1999-01-01',c2='1999-01-01'; +INSERT INTO t2 SET c1='1999-01-01',c2='1999-01-01'; +INSERT INTO t3 SET c1='1999-01-01'; +INSERT INTO t4 SET c2='1999-01-01'; +SELECT * FROM t1 WHERE c1='1999-01-01' AND c2='1999-01-01' /* Returns 1 row with values for other column as NULL */; +SELECT * FROM t2 WHERE c1='1999-01-01' AND c2='1999-01-01' /* Returns 1 row with values for other column as NULL */; +SELECT * FROM t3 WHERE c1='1999-01-01' /* Returns 1 row with values for other column as NULL */; +SELECT * FROM t4 WHERE c2='1999-01-01' /* Returns 1 row with values for other column as NULL */; + +# Test 'INSERT INTO SELECT FROM' +CREATE TABLE t5(c1 DATE NOT NULL, c2 DATE NULL, c3 DATETIME, c4 TIMESTAMP, INDEX idx(c1,c2)); +INSERT INTO t5 SELECT * FROM t1 WHERE c1 >=0 AND c1 < '20070523091528'; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +INSERT INTO t5 SELECT * FROM t2 WHERE c1 >='98-12-31 11:30:45' AND c1 < '20070523091528' AND c2 <> '070525'; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +INSERT INTO t5 SELECT * FROM t3 WHERE c2 BETWEEN 0 AND '1998-12-30 11:30:45'; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +DROP TABLE t5; + +# Test Specific values to column types + +# Test insert values across range to 'DATE' columns +INSERT INTO t1 VALUES('1000-01-01','2000-01-01','2009-01-01','2009-01-02'),('3000-01-01','4000-01-01','2009-01-03','2009-01-04'),('5000-01-01','6000-01-01','2009-01-05','2009-01-06'),('7000-01-01','8000-01-01','2009-01-07','2009-01-08'),('9000-01-01','9000-01-01','2009-01-09','2009-01-10'),('9999-12-31','9999-12-31','2009-01-11','2009-01-12'); +INSERT INTO t2 VALUES('1000-01-01','2000-01-01','2009-01-01','2009-01-02'),('3000-01-01','4000-01-01','2009-01-03','2009-01-04'),('5000-01-01','6000-01-01','2009-01-05','2009-01-06'),('7000-01-01','8000-01-01','2009-01-07','2009-01-08'),('9000-01-01','9000-01-01','2009-01-09','2009-01-10'),('9999-12-31','9999-12-31','2009-01-11','2009-01-12'); +INSERT INTO t3 VALUES('1000-01-01','2000-01-01','2009-01-01','2009-01-02'),('3000-01-01','4000-01-01','2009-01-03','2009-01-04'),('5000-01-01','6000-01-01','2009-01-05','2009-01-06'),('7000-01-01','8000-01-01','2009-01-07','2009-01-08'),('9000-01-01','9000-01-01','2009-01-09','2009-01-10'),('9999-12-31','9999-12-31','2009-01-11','2009-01-12'); +INSERT INTO t4 VALUES('1000-01-01','2000-01-01','2009-01-01','2009-01-02'),('3000-01-01','4000-01-01','2009-01-03','2009-01-04'),('5000-01-01','6000-01-01','2009-01-05','2009-01-06'),('7000-01-01','8000-01-01','2009-01-07','2009-01-08'),('9000-01-01','9000-01-01','2009-01-09','2009-01-10'),('9999-12-31','9999-12-31','2009-01-11','2009-01-12'); + +# Insert valid dates containing a zero for the month or for the day +INSERT INTO t1(c1,c2) VALUES('2010-00-01','2010-10-00'); +INSERT INTO t2(c1,c2) VALUES('2010-00-01','2010-10-00'); +INSERT INTO t3(c1,c2) VALUES('2010-00-01','2010-10-00'); +INSERT INTO t4(c1,c2) VALUES('2010-00-01','2010-10-00'); + +# Insert invalid dates, inserts zero values +INSERT INTO t4(c1) VALUES('2009-02-30'),('2009-04-31'),('2009-06-31'),('2009-09-31'),('2009-11-31'),('2009-13-01'),('2009-12-32'); + +# Test insert NULL to non-null column +--error ER_BAD_NULL_ERROR +INSERT INTO t1(c1) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t2(c1) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t3 VALUES(NULL,'2008-01-14','08-01-15','08/01/16'); +--error ER_BAD_NULL_ERROR +INSERT INTO t4 VALUES(NULL,'2008-01-14','08-01-15','08/01/16'); + +# Test INSERT SET with no default for not null column +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_NO_DEFAULT_FOR_FIELD +INSERT INTO t4 SET c2='1999-01-01' /* NOT NULL column will not get the default value */; +SET SQL_MODE=''; + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +# Now select using various table access methods +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2007-05-24 09:15:28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '1000-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '1000-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '1000-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '1000-00-01' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '1000-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '1000-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '1000-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '1000-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1000-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '1000-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '1000-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '1000-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '1000-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '1000-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '1000-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '1000-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('1000-00-01','9999-12-31') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('1000-00-01','9999-12-31') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1000-00-01' AND c1 < '9999-12-31' AND c2 = '1000-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '1000-00-01' AND c1 < '9999-12-31' AND c2 = '1000-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '1000-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '1000-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '1000-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '1000-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1000-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '1000-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '1000-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '1000-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '1000-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '1000-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '1000-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '1000-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('1000-00-01','9999-12-31') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('1000-00-01','9999-12-31') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1000-00-01' AND c1 < '9999-12-31' AND c2 = '1000-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '1000-00-01' AND c1 < '9999-12-31' AND c2 = '1000-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2007-05-26 00:00:00'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','9999-12-31') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','9999-12-31') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31' AND c2 = '2010-10-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31' AND c2 = '2010-10-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','9999-12-31') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','9999-12-31') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31' AND c2 = '2010-10-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31' AND c2 = '2010-10-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '1998-12-28 00:00:00'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '2010-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '2010-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '2010-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '2010-00-01' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '2010-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '2010-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '2010-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '2010-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '2010-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '2010-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '2010-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '2010-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '2010-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '2010-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '2010-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '2010-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2010-00-01') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2010-00-01') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01' AND c2 = '2010-10-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01' AND c2 = '2010-10-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '2010-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '2010-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '2010-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '2010-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '2010-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '2010-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '2010-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '2010-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '2010-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '2010-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '2010-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '2010-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2010-00-01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2010-00-01') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01' AND c2 = '2010-10-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01' AND c2 = '2010-10-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c4 = '2009-01-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t1; + +## Backward index scan, covering ## +SELECT c2 FROM t1 ORDER BY c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '9999-12-31' ORDER BY c2; +SELECT * FROM t1 WHERE c2 = '9999-12-31' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '9999-12-31' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 = '9999-12-31' ORDER BY c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '9999-12-31' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <> '9999-12-31' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '9999-12-31' ORDER BY c2; +SELECT * FROM t1 WHERE c2 > '9999-12-31' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '9999-12-31' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '9999-12-31' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '9999-12-31' ORDER BY c2; +SELECT * FROM t1 WHERE c2 < '9999-12-31' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '9999-12-31' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <= '9999-12-31' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '9999-12-31' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <=> '9999-12-31' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c2; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01','9999-12-31') ORDER BY c2; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01','9999-12-31') ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1000-00-01' AND c2 < '9999-12-31' AND c1 = '9999-12-31' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '1000-00-01' AND c2 < '9999-12-31' AND c1 = '9999-12-31' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '9999-12-31' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <> '9999-12-31' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '9999-12-31' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 > '9999-12-31' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '9999-12-31' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '9999-12-31' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '9999-12-31' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 < '9999-12-31' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '9999-12-31' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <= '9999-12-31' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '9999-12-31' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '9999-12-31' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01','9999-12-31') ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01','9999-12-31') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1000-00-01' AND c2 < '9999-12-31' AND c1 = '9999-12-31' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '1000-00-01' AND c2 < '9999-12-31' AND c1 = '9999-12-31' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c4 = '2008-01-05'; + +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t1; + +## Backward index scan, covering ## +SELECT c2 FROM t1 ORDER BY c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '2010-10-00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 = '2010-10-00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '2010-10-00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 = '2010-10-00' ORDER BY c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '2010-10-00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <> '2010-10-00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '2010-10-00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 > '2010-10-00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '2010-10-00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '2010-10-00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '2010-10-00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 < '2010-10-00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '2010-10-00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <= '2010-10-00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '2010-10-00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <=> '2010-10-00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01' AND '2010-10-00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01' AND '2010-10-00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01','2010-10-00') ORDER BY c2; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01','2010-10-00') ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1000-00-01' AND c2 < '2010-10-00' AND c1 = '2010-00-01' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '1000-00-01' AND c2 < '2010-10-00' AND c1 = '2010-00-01' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '2010-10-00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <> '2010-10-00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '2010-10-00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 > '2010-10-00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '2010-10-00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '2010-10-00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '2010-10-00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 < '2010-10-00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '2010-10-00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <= '2010-10-00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '2010-10-00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '2010-10-00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01' AND '2010-10-00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01' AND '2010-10-00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01','2010-10-00') ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01','2010-10-00') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1000-00-01' AND c2 < '2010-10-00' AND c1 = '2010-00-01' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '1000-00-01' AND c2 < '2010-10-00' AND c1 = '2010-00-01' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC LIMIT 2; + +# Using Index-merge +--sorted_result +SELECT * FROM t1 WHERE c1='1000-00-01' OR c2='9999-12-31'; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t1 GROUP BY c2; + +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2007-05-24 09:15:28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1000-00-01' AND c1 < '9999-12-31' AND c2 = '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1000-00-01' AND c1 < '9999-12-31' AND c2 = '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1000-00-01' AND c1 < '9999-12-31' AND c2 = '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1000-00-01' AND c1 < '9999-12-31' AND c2 = '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2007-05-26 00:00:00'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','9999-12-31') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','9999-12-31') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31' AND c2 = '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31' AND c2 = '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','9999-12-31') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','9999-12-31') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31' AND c2 = '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31' AND c2 = '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-28 00:00:00'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2010-00-01') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2010-00-01') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01' AND c2 = '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01' AND c2 = '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2010-00-01') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2010-00-01') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01' AND c2 = '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01' AND c2 = '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c4 = '2009-01-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1000-00-01' AND c2 < '9999-12-31' AND c1 = '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '1000-00-01' AND c2 < '9999-12-31' AND c1 = '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1000-00-01' AND c2 < '9999-12-31' AND c1 = '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '1000-00-01' AND c2 < '9999-12-31' AND c1 = '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c4 = '2008-01-07'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01' AND '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01' AND '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01','2010-10-00') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01','2010-10-00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1000-00-01' AND c2 < '2010-10-00' AND c1 = '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '1000-00-01' AND c2 < '2010-10-00' AND c1 = '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01' AND '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01' AND '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01','2010-10-00') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01','2010-10-00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1000-00-01' AND c2 < '2010-10-00' AND c1 = '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '1000-00-01' AND c2 < '2010-10-00' AND c1 = '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2007-05-24 09:15:28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1000-00-01' AND c1 < '9999-12-31' AND c2 = '1000-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1000-00-01' AND c1 < '9999-12-31' AND c2 = '1000-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1000-00-01' AND c1 < '9999-12-31' AND c2 = '1000-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1000-00-01' AND c1 < '9999-12-31' AND c2 = '1000-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2007-05-26 00:00:00'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','9999-12-31') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','9999-12-31') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31' AND c2 = '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31' AND c2 = '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','9999-12-31') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','9999-12-31') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31' AND c2 = '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31' AND c2 = '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-28 00:00:00'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2010-00-01') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2010-00-01') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01' AND c2 = '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01' AND c2 = '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2010-00-01') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2010-00-01') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01' AND c2 = '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01' AND c2 = '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c4 = '2009-01-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1000-00-01' AND c2 < '9999-12-31' AND c1 = '9999-12-31' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '1000-00-01' AND c2 < '9999-12-31' AND c1 = '9999-12-31' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01' AND '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01','9999-12-31') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1000-00-01' AND c2 < '9999-12-31' AND c1 = '9999-12-31' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '1000-00-01' AND c2 < '9999-12-31' AND c1 = '9999-12-31' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c4 = '2008-01-09'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01' AND '2010-10-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01' AND '2010-10-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01','2010-10-00') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01','2010-10-00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1000-00-01' AND c2 < '2010-10-00' AND c1 = '2010-00-01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '1000-00-01' AND c2 < '2010-10-00' AND c1 = '2010-00-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01' AND '2010-10-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01' AND '2010-10-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01','2010-10-00') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01','2010-10-00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1000-00-01' AND c2 < '2010-10-00' AND c1 = '2010-00-01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '1000-00-01' AND c2 < '2010-10-00' AND c1 = '2010-00-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c1 FROM t3 GROUP BY c1; +--sorted_result +SELECT DISTINCT c1 FROM t3; +--sorted_result +SELECT c1,MIN(c2) FROM t3 GROUP BY c1; +DROP TABLE t1,t2,t3,t4; + +######## Running INSERT tests for DATETIME ######## + +# Create tables +CREATE TABLE t1(c1 DATETIME NOT NULL, c2 DATETIME NULL, c3 DATE, c4 TIMESTAMP, PRIMARY KEY(c1), UNIQUE INDEX(c2)); +CREATE TABLE t2(c1 DATETIME NOT NULL, c2 DATETIME NULL, c3 DATE, c4 TIMESTAMP, PRIMARY KEY(c1,c2)); +CREATE TABLE t3(c1 DATETIME NOT NULL, c2 DATETIME NULL, c3 DATE, c4 TIMESTAMP, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t4(c1 DATETIME NOT NULL, c2 DATETIME NULL, c3 DATE, c4 TIMESTAMP); + +# Insert some rows with targeted values + +# As a string in either 'YYYY-MM-DD HH:MM:SS', 'YY-MM-DD HH:MM:SS', 'YYYY-MM-DD' or 'YY-MM-DD' format +INSERT INTO t1 VALUES('98-12-31 11:30:45','98.12.31 11+30+45','98-12-31 11:30:45','98.12.31 11+30+45'),('98/12/30 11*30*45','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'),('98-12-29','98.12.29','98-12-29','98.12.29'),('98/12/28','98@12@28','98/12/28','98@12@28'); +INSERT INTO t2 VALUES('98-12-31 11:30:45','98.12.31 11+30+45','98-12-31 11:30:45','98.12.31 11+30+45'),('98/12/30 11*30*45','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'),('98-12-29','98.12.29','98-12-29','98.12.29'),('98/12/28','98@12@28','98/12/28','98@12@28'); +INSERT INTO t3 VALUES('98-12-31 11:30:45','98.12.31 11+30+45','98-12-31 11:30:45','98.12.31 11+30+45'),('98/12/30 11*30*45','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'),('98-12-29','98.12.29','98-12-29','98.12.29'),('98/12/28','98@12@28','98/12/28','98@12@28'); +INSERT INTO t4 VALUES('98-12-31 11:30:45','98.12.31 11+30+45','98-12-31 11:30:45','98.12.31 11+30+45'),('98/12/30 11*30*45','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'),('98-12-29','98.12.29','98-12-29','98.12.29'),('98/12/28','98@12@28','98/12/28','98@12@28'); + +# As a string with no delimiters in either 'YYYYMMDDHHMMSS', 'YYMMDDHHMMSS', 'YYYYMMDD' or 'YYMMDD' format +INSERT INTO t1 VALUES('20070523091528','070523091528','20070524091528','070524091528'),('20070525','070525','20070526','070526'); +INSERT INTO t2 VALUES('20070523091528','070523091528','20070524091528','070524091528'),('20070525','070525','20070526','070526'); +INSERT INTO t3 VALUES('20070523091528','070523091528','20070524091528','070524091528'),('20070525','070525','20070526','070526'); +INSERT INTO t4 VALUES('20070523091528','070523091528','20070524091528','070524091528'),('20070525','070525','20070526','070526'); + +# As a number in either YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD or YYMMDD format +INSERT INTO t1 VALUES(19830905132800,830905132800,19830906132800,830906132800),(19830907,830907,19830908,830908); +INSERT INTO t2 VALUES(19830905132800,830905132800,19830906132800,830906132800),(19830907,830907,19830908,830908); +INSERT INTO t3 VALUES(19830905132800,830905132800,19830906132800,830906132800),(19830907,830907,19830908,830908); +INSERT INTO t4 VALUES(19830905132800,830905132800,19830906132800,830906132800),(19830907,830907,19830908,830908); + +# As the result of a function +SET TIMESTAMP=1233216687; # 2009-01-29 13:41:27 +INSERT INTO t1 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT INTO t2 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT INTO t3 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT INTO t4 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); + +# Insert duplicates for parts of the clustered key/unique index +INSERT INTO t2 VALUES('98-12-31 11:30:45','98@12@30 11^30^45','98-12-31 11:30:45','98.12.31 11+30+45'),('98-12-29','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'); +INSERT INTO t3 VALUES('98-12-31 11:30:45','98@12@30 11^30^45','98-12-31 11:30:45','98.12.31 11+30+45'),('98-12-29','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'); + +# Insert permissible NULLs +INSERT INTO t1 VALUES('2008-01-01',NULL,'08-01-02','08/01/03'); +INSERT INTO t3 VALUES('2008-01-01',NULL,'08-01-02','08/01/03'); +INSERT INTO t4 VALUES('2008-01-01',NULL,'08-01-02','08/01/03'); + +# Insert duplicate NULLs to unique column +INSERT INTO t1(c1,c2) VALUES('08/01/17',NULL); +DELETE FROM t1 WHERE c1='08/01/17' AND c2 IS NULL; + +# Insert empty string '', would be converted to zero value of the appropriate type +INSERT INTO t1 VALUES('','','08-01-04','08/01/05') /* Inserts zero dates for '' strings */; + +# Insert invalid dates, would be converted to zero value of the appropriate type +INSERT INTO t2 VALUES('2008-04-31','2008-04-31','08-01-06','08/01/07') /* Inserts zero dates for invalid dates */; +INSERT INTO t3 VALUES('10:45:15','10:45:15','08-01-08','08/1/9') /* Inserts zero dates for invalid dates */; + +# Insert zero dates +INSERT INTO t2 VALUES('0000-00-00','08-01-06','08-01-06','08/01/07'); +INSERT INTO t3 VALUES('08-01-06','00-00-00','08-01-08','08/1/9'); + +# Insert non-date value(absurd values), would be converted to zero value of the appropriate type +INSERT INTO t4 VALUES('abcd','abcd','08-01-10','08/01/11'),(1234,1234,'08-01-12','08/01/13') /* Inserts zero dates for absurd dates */; + +# Now select using various table access methods (full table scan, range scan, index scan etc.) +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; + +# Select from table with single column primary key and single column index, with column values zero, NULL +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2007-05-24'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '1998-12-29 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '1998-12-29 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','1998-12-29 00:00:00') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','1998-12-29 00:00:00') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '1998-12-29 00:00:00' AND c2 = '1983-09-07 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '1998-12-29 00:00:00' AND c2 = '1983-09-07 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '1998-12-29 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '1998-12-29 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','1998-12-29 00:00:00') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','1998-12-29 00:00:00') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '1998-12-29 00:00:00' AND c2 = '1983-09-07 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '1998-12-29 00:00:00' AND c2 = '1983-09-07 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2007-05-26'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c4 = '2007-05-26 00:00:00'; + +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t1; + +## Backward index scan, covering ## +SELECT c2 FROM t1 ORDER BY c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 = '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 = '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <> '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 > '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 < '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <= '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <=> '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-31 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-31 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-31 11:30:45') ORDER BY c2; +SELECT * FROM t1 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-31 11:30:45') ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-31 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-31 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <> '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 > '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 < '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <= '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-31 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-31 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-31 11:30:45') ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-31 11:30:45') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-31 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-31 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC LIMIT 2; + +# Select from table with clustered primary key, with column values zero, NULL +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2008-01-06'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1983-09-07 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '1983-09-07 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1983-09-07 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('1983-09-07 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1983-09-07 00:00:00' AND c1 < '2007-05-23 09:15:28' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1983-09-07 00:00:00' AND c1 < '2007-05-23 09:15:28' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1983-09-07 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '1983-09-07 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1983-09-07 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('1983-09-07 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1983-09-07 00:00:00' AND c1 < '2007-05-23 09:15:28' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1983-09-07 00:00:00' AND c1 < '2007-05-23 09:15:28' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '2007-05-23 09:15:28' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '2007-05-23 09:15:28' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '2007-05-23 09:15:28' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '2007-05-23 09:15:28' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c4 = '2007-05-24 09:15:28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('0000-00-00 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN ('0000-00-00 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '2007-05-23 09:15:28' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '2007-05-23 09:15:28' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('0000-00-00 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN ('0000-00-00 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '2007-05-23 09:15:28' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '2007-05-23 09:15:28' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Select from table with clustered index, with column values zero, NULL +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2007-05-24'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1998-12-31 11:30:45' AND '2008-01-06 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '1998-12-31 11:30:45' AND '2008-01-06 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1998-12-31 11:30:45','2008-01-06 00:00:00') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('1998-12-31 11:30:45','2008-01-06 00:00:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1998-12-31 11:30:45' AND c1 < '2008-01-06 00:00:00' AND c2 = '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1998-12-31 11:30:45' AND c1 < '2008-01-06 00:00:00' AND c2 = '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1998-12-31 11:30:45' AND '2008-01-06 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '1998-12-31 11:30:45' AND '2008-01-06 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1998-12-31 11:30:45','2008-01-06 00:00:00') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('1998-12-31 11:30:45','2008-01-06 00:00:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1998-12-31 11:30:45' AND c1 < '2008-01-06 00:00:00' AND c2 = '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1998-12-31 11:30:45' AND c1 < '2008-01-06 00:00:00' AND c2 = '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c4 = '2007-05-24 09:15:28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-30 11:30:45' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-30 11:30:45' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-30 11:30:45') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-30 11:30:45') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-30 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-30 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-30 11:30:45' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-30 11:30:45' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-30 11:30:45') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-30 11:30:45') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-30 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-30 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Test Error conditions- PK constraint violation, Unique constraint violation + +# Insert duplicate value to pk column +--error ER_DUP_ENTRY +INSERT INTO t1(c1,c2) VALUES('20070525','070523091528') /* Row with c1='20070525' exists */; + +# Insert duplicate value to clustered pk, throws error +--error ER_DUP_ENTRY +INSERT INTO t2(c1,c2) VALUES(19830907,830907) /* Row with c1=19830907,c2=830907 exists */; + +# Insert duplicate value to unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t1(c1,c2) VALUES(19840905,830907) /* Row with c2=830907 exists */; + +# Insert duplicate value to clustered unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t3(c1,c2) VALUES(19830907,830907) /* Row with c1=19830907,c2=830907 exists */; + +# Test 'INSERT IGNORE' with the same rows that reported constraint violation above +# Ignore pk constraint +INSERT IGNORE INTO t1(c1,c2) VALUES('20070525','20070527') /* doesn't throw error */; +INSERT IGNORE INTO t2(c1,c2) VALUES(19830907,830907) /* doesn't throw error */; +# Ignore unique constraint +INSERT IGNORE INTO t1(c1,c2) VALUES(19840905,830907) /* doesn't throw error */; +INSERT IGNORE INTO t3(c1,c2) VALUES(19830907,830907) /* doesn't throw error */; +# Test that the rows are same +SELECT * FROM t1 WHERE c1='20070525' /* Returns 1 row with c1=2007-05-25 */; +SELECT * FROM t2 WHERE c1=19830907 AND c2=830907 /* Returns 1 row with c1=1983-09-07 and c2=1983-09-07 */; +SELECT * FROM t1 WHERE c2=830907 /* Returns 1 row with c2=1983-09-07 */; +SELECT * FROM t3 WHERE c1=19830907 AND c2=830907 /* Returns 1 row with c1=1983-09-07 and c2=1983-09-07 */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with single column PK +SELECT * FROM t1 WHERE c1='20070527' /* Returns no rows */; +INSERT INTO t1(c1) VALUES('20070525') ON DUPLICATE KEY UPDATE c1='20070527'; +SELECT * FROM t1 WHERE c1='20070527' /* Returns 1 row with c1=2007-05-27 */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with multi-column PK +SELECT * FROM t2 WHERE c1=19830909 AND c2=830910 /* Returns no rows */; +INSERT INTO t2(c1,c2) VALUES(19830907,830907) ON DUPLICATE KEY UPDATE c1=19830909,c2=830910; +SELECT * FROM t2 WHERE c1=19830909 AND c2=830910 /* Returns 1 row with c1=19830909,c2=830910 */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with single column unique +SELECT * FROM t1 WHERE c1=19830909 AND c2=830910 /* Returns no rows */; +INSERT INTO t1(c1,c2) VALUES(19840905,830907) ON DUPLICATE KEY UPDATE c1=19830909,c2=830910; +SELECT * FROM t1 WHERE c1=19830909 AND c2=830910 /* Returns 1 row */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with multi-column unique +SELECT * FROM t3 WHERE c1=19830909 AND c2=830910 /* Returns no rows */; +INSERT INTO t3(c1,c2) VALUES(19830907,830907) ON DUPLICATE KEY UPDATE c1=19830909,c2=830910; +SELECT * FROM t3 WHERE c1=19830909 AND c2=830910 /* Returns 1 row */; + +# Test 'INSERT SET' +INSERT INTO t1 SET c1='1999-01-01',c2='1999-01-01'; +INSERT INTO t2 SET c1='1999-01-01',c2='1999-01-01'; +INSERT INTO t3 SET c1='1999-01-01'; +INSERT INTO t4 SET c2='1999-01-01'; +SELECT * FROM t1 WHERE c1='1999-01-01' AND c2='1999-01-01' /* Returns 1 row with values for other column as NULL */; +SELECT * FROM t2 WHERE c1='1999-01-01' AND c2='1999-01-01' /* Returns 1 row with values for other column as NULL */; +SELECT * FROM t3 WHERE c1='1999-01-01' /* Returns 1 row with values for other column as NULL */; +SELECT * FROM t4 WHERE c2='1999-01-01' /* Returns 1 row with values for other column as NULL */; + +# Test 'INSERT INTO SELECT FROM' +CREATE TABLE t5(c1 DATETIME NOT NULL, c2 DATETIME NULL, c3 DATE, c4 TIMESTAMP, INDEX idx(c1,c2)); +INSERT INTO t5 SELECT * FROM t1 WHERE c1 >=0 AND c1 < '20070523091528'; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +INSERT INTO t5 SELECT * FROM t2 WHERE c1 >='98-12-31 11:30:45' AND c1 < '20070523091528' AND c2 <> '070525'; +#Following query produces different results +#for differenct engine/platform +--disable_result_log +--sorted_result +SELECT * FROM t5; +--enable_result_log +TRUNCATE TABLE t5; +INSERT INTO t5 SELECT * FROM t3 WHERE c2 BETWEEN 0 AND '1998-12-30 11:30:45'; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +DROP TABLE t5; + +# Test Specific values to column types + +# Test insert range values to 'DATETIME' columns +INSERT INTO t1 VALUES('1000-01-01 00:00:00','2000-01-01 00:00:00','2009-01-01','2009-01-02'),('3000-01-01 00:00:00','4000-01-01 00:00:00','2009-01-03','2009-01-04'),('5000-01-01 00:00:00','6000-01-01 00:00:00','2009-01-05','2009-01-06'),('7000-01-01 00:00:00','8000-01-01 00:00:00','2009-01-07','2009-01-08'),('9000-01-01 00:00:00','9000-01-01 00:00:00','2009-01-09','2009-01-10'),('9999-12-31 23:59:59','9999-12-31 23:59:59','2009-01-11','2009-01-12'); +INSERT INTO t2 VALUES('1000-01-01 00:00:00','2000-01-01 00:00:00','2009-01-01','2009-01-02'),('3000-01-01 00:00:00','4000-01-01 00:00:00','2009-01-03','2009-01-04'),('5000-01-01 00:00:00','6000-01-01 00:00:00','2009-01-05','2009-01-06'),('7000-01-01 00:00:00','8000-01-01 00:00:00','2009-01-07','2009-01-08'),('9000-01-01 00:00:00','9000-01-01 00:00:00','2009-01-09','2009-01-10'),('9999-12-31 23:59:59','9999-12-31 23:59:59','2009-01-11','2009-01-12'); +INSERT INTO t3 VALUES('1000-01-01 00:00:00','2000-01-01 00:00:00','2009-01-01','2009-01-02'),('3000-01-01 00:00:00','4000-01-01 00:00:00','2009-01-03','2009-01-04'),('5000-01-01 00:00:00','6000-01-01 00:00:00','2009-01-05','2009-01-06'),('7000-01-01 00:00:00','8000-01-01 00:00:00','2009-01-07','2009-01-08'),('9000-01-01 00:00:00','9000-01-01 00:00:00','2009-01-09','2009-01-10'),('9999-12-31 23:59:59','9999-12-31 23:59:59','2009-01-11','2009-01-12'); +INSERT INTO t4 VALUES('1000-01-01 00:00:00','2000-01-01 00:00:00','2009-01-01','2009-01-02'),('3000-01-01 00:00:00','4000-01-01 00:00:00','2009-01-03','2009-01-04'),('5000-01-01 00:00:00','6000-01-01 00:00:00','2009-01-05','2009-01-06'),('7000-01-01 00:00:00','8000-01-01 00:00:00','2009-01-07','2009-01-08'),('9000-01-01 00:00:00','9000-01-01 00:00:00','2009-01-09','2009-01-10'),('9999-12-31 23:59:59','9999-12-31 23:59:59','2009-01-11','2009-01-12'); + +# Insert valid dates containing a zero for the month or for the day +INSERT INTO t1(c1,c2) VALUES('2010-00-01','2010-10-00'); +INSERT INTO t2(c1,c2) VALUES('2010-00-01','2010-10-00'); +INSERT INTO t3(c1,c2) VALUES('2010-00-01','2010-10-00'); +INSERT INTO t4(c1,c2) VALUES('2010-00-01','2010-10-00'); + +# Insert invalid dates, inserts zero values +INSERT INTO t4(c1) VALUES('2009-02-30'),('2009-04-31'),('2009-06-31'),('2009-09-31'),('2009-11-31'),('2009-13-01'),('2009-12-32'),('2009-01-01 23:60:60'),('2009-01-01 24:59:59'),('2009-01-01 23:59:60'); + +# Test insert NULL to non-null column +--error ER_BAD_NULL_ERROR +INSERT INTO t1(c1) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t2(c1) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t3 VALUES(NULL,'2008-01-14 00:00:00','08-01-15','08/01/16'); +--error ER_BAD_NULL_ERROR +INSERT INTO t4 VALUES(NULL,'2008-01-14 00:00:00','08-01-15','08/01/16'); + +# Test INSERT SET with no default for not null column +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_NO_DEFAULT_FOR_FIELD +INSERT INTO t4 SET c2='1999-01-01' /* NOT NULL column will not get the default value */; +SET SQL_MODE=''; + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +# Now select using various table access methods +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2007-05-24'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '1000-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '1000-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '1000-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '1000-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '1000-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '1000-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '1000-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '1000-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1000-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '1000-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '1000-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '1000-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '1000-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '1000-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1000-00-01 00:00:00' AND c1 < '9999-12-31 23:59:59' AND c2 = '1000-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '1000-00-01 00:00:00' AND c1 < '9999-12-31 23:59:59' AND c2 = '1000-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '1000-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '1000-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '1000-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '1000-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1000-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '1000-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '1000-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '1000-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '1000-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '1000-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1000-00-01 00:00:00' AND c1 < '9999-12-31 23:59:59' AND c2 = '1000-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '1000-00-01 00:00:00' AND c1 < '9999-12-31 23:59:59' AND c2 = '1000-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2007-05-26'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31 23:59:59' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31 23:59:59' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','9999-12-31 23:59:59') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','9999-12-31 23:59:59') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31 23:59:59' AND c2 = '2010-10-00 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31 23:59:59' AND c2 = '2010-10-00 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31 23:59:59' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31 23:59:59' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','9999-12-31 23:59:59') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','9999-12-31 23:59:59') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31 23:59:59' AND c2 = '2010-10-00 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31 23:59:59' AND c2 = '2010-10-00 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '1998-12-28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:' AND c2 = '2010-10-00 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:' AND c2 = '2010-10-00 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:' AND c2 = '2010-10-00 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:' AND c2 = '2010-10-00 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c4 = '2009-01-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t1; + +## Backward index scan, covering ## +SELECT c2 FROM t1 ORDER BY c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '9999-12-31 23:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 = '9999-12-31 23:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '9999-12-31 23:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 = '9999-12-31 23:59:59' ORDER BY c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '9999-12-31 23:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <> '9999-12-31 23:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '9999-12-31 23:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 > '9999-12-31 23:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '9999-12-31 23:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '9999-12-31 23:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '9999-12-31 23:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 < '9999-12-31 23:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '9999-12-31 23:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <= '9999-12-31 23:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '9999-12-31 23:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <=> '9999-12-31 23:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c2; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '9999-12-31 23:59:59' AND c1 = '9999-12-31 23:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '9999-12-31 23:59:59' AND c1 = '9999-12-31 23:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '9999-12-31 23:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <> '9999-12-31 23:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '9999-12-31 23:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 > '9999-12-31 23:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '9999-12-31 23:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '9999-12-31 23:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '9999-12-31 23:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 < '9999-12-31 23:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '9999-12-31 23:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <= '9999-12-31 23:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '9999-12-31 23:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '9999-12-31 23:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '9999-12-31 23:59:59' AND c1 = '9999-12-31 23:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '9999-12-31 23:59:59' AND c1 = '9999-12-31 23:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c4 = '2008-01-05'; + +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t1; + +## Backward index scan, covering ## +SELECT c2 FROM t1 ORDER BY c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '2010-10-00 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 = '2010-10-00 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '2010-10-00 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 = '2010-10-00 00:00:00' ORDER BY c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '2010-10-00 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <> '2010-10-00 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '2010-10-00 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 > '2010-10-00 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '2010-10-00 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '2010-10-00 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '2010-10-00 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 < '2010-10-00 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '2010-10-00 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <= '2010-10-00 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '2010-10-00 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <=> '2010-10-00 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '2010-10-00 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '2010-10-00 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01 00:00:00','2010-10-00 00:00:00') ORDER BY c2; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01 00:00:00','2010-10-00 00:00:00') ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '2010-10-00 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <> '2010-10-00 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '2010-10-00 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 > '2010-10-00 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '2010-10-00 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '2010-10-00 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '2010-10-00 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 < '2010-10-00 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '2010-10-00 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <= '2010-10-00 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '2010-10-00 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '2010-10-00 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '2010-10-00 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '2010-10-00 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01 00:00:00','2010-10-00 00:00:00') ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('1000-00-01 00:00:00','2010-10-00 00:00:00') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC LIMIT 2; + +# Using Index-merge +--sorted_result +SELECT * FROM t1 WHERE c1='1000-00-01 00:00:00' OR c2='9999-12-31 23:59:59'; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t1 GROUP BY c2; + +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2007-05-24'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1000-00-01 00:00:00' AND c1 < '9999-12-31 23:59:59' AND c2 = '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1000-00-01 00:00:00' AND c1 < '9999-12-31 23:59:59' AND c2 = '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1000-00-01 00:00:00' AND c1 < '9999-12-31 23:59:59' AND c2 = '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1000-00-01 00:00:00' AND c1 < '9999-12-31 23:59:59' AND c2 = '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2007-05-26'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','9999-12-31 23:59:59') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','9999-12-31 23:59:59') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31 23:59:59' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31 23:59:59' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','9999-12-31 23:59:59') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','9999-12-31 23:59:59') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31 23:59:59' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31 23:59:59' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c4 = '2009-01-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '9999-12-31 23:59:59' AND c1 = '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '9999-12-31 23:59:59' AND c1 = '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '9999-12-31 23:59:59' AND c1 = '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '9999-12-31 23:59:59' AND c1 = '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c4 = '2008-01-07'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01 00:00:00','2010-10-00 00:00:00') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01 00:00:00','2010-10-00 00:00:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01 00:00:00','2010-10-00 00:00:00') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN ('1000-00-01 00:00:00','2010-10-00 00:00:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2007-05-24'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1000-00-01 00:00:00' AND c1 < '9999-12-31 23:59:59' AND c2 = '1000-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1000-00-01 00:00:00' AND c1 < '9999-12-31 23:59:59' AND c2 = '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1000-00-01 00:00:00' AND c1 < '9999-12-31 23:59:59' AND c2 = '1000-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1000-00-01 00:00:00' AND c1 < '9999-12-31 23:59:59' AND c2 = '1000-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2007-05-26'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','9999-12-31 23:59:59') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','9999-12-31 23:59:59') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31 23:59:59' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31 23:59:59' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','9999-12-31 23:59:59') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','9999-12-31 23:59:59') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31 23:59:59' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '9999-12-31 23:59:59' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c4 = '2009-01-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '9999-12-31 23:59:59' AND c1 = '9999-12-31 23:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '9999-12-31 23:59:59' AND c1 = '9999-12-31 23:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01 00:00:00','9999-12-31 23:59:59') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '9999-12-31 23:59:59' AND c1 = '9999-12-31 23:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '9999-12-31 23:59:59' AND c1 = '9999-12-31 23:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c4 = '2008-01-09'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01 00:00:00','2010-10-00 00:00:00') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01 00:00:00','2010-10-00 00:00:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN '1000-00-01 00:00:00' AND '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01 00:00:00','2010-10-00 00:00:00') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN ('1000-00-01 00:00:00','2010-10-00 00:00:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '1000-00-01 00:00:00' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c1 FROM t3 GROUP BY c1; +--sorted_result +SELECT DISTINCT c1 FROM t3; +--sorted_result +SELECT c1,MIN(c2) FROM t3 GROUP BY c1; +DROP TABLE t1,t2,t3,t4; + +######## Running INSERT tests for TIMESTAMP ######## + +# Create tables +CREATE TABLE t1(c1 TIMESTAMP NOT NULL, c2 TIMESTAMP NULL, c3 DATE, c4 DATETIME, PRIMARY KEY(c1), UNIQUE INDEX(c2)); +CREATE TABLE t2(c1 TIMESTAMP NOT NULL, c2 TIMESTAMP NULL, c3 DATE, c4 DATETIME, PRIMARY KEY(c1,c2)); +CREATE TABLE t3(c1 TIMESTAMP NOT NULL, c2 TIMESTAMP NULL, c3 DATE, c4 DATETIME, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t4(c1 TIMESTAMP NOT NULL, c2 TIMESTAMP NULL, c3 DATE, c4 DATETIME); + +# Insert some rows with targeted values + +# As a string in either 'YYYY-MM-DD HH:MM:SS', 'YY-MM-DD HH:MM:SS', 'YYYY-MM-DD' or 'YY-MM-DD' format +INSERT INTO t1 VALUES('98-12-31 11:30:45','98.12.31 11+30+45','98-12-31 11:30:45','98.12.31 11+30+45'),('98/12/30 11*30*45','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'),('98-12-29','98.12.29','98-12-29','98.12.29'),('98/12/28','98@12@28','98/12/28','98@12@28'); +INSERT INTO t2 VALUES('98-12-31 11:30:45','98.12.31 11+30+45','98-12-31 11:30:45','98.12.31 11+30+45'),('98/12/30 11*30*45','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'),('98-12-29','98.12.29','98-12-29','98.12.29'),('98/12/28','98@12@28','98/12/28','98@12@28'); +INSERT INTO t3 VALUES('98-12-31 11:30:45','98.12.31 11+30+45','98-12-31 11:30:45','98.12.31 11+30+45'),('98/12/30 11*30*45','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'),('98-12-29','98.12.29','98-12-29','98.12.29'),('98/12/28','98@12@28','98/12/28','98@12@28'); +INSERT INTO t4 VALUES('98-12-31 11:30:45','98.12.31 11+30+45','98-12-31 11:30:45','98.12.31 11+30+45'),('98/12/30 11*30*45','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'),('98-12-29','98.12.29','98-12-29','98.12.29'),('98/12/28','98@12@28','98/12/28','98@12@28'); + +# As a string with no delimiters in either 'YYYYMMDDHHMMSS', 'YYMMDDHHMMSS', 'YYYYMMDD' or 'YYMMDD' format +INSERT INTO t1 VALUES('20070523091528','070523091528','20070524091528','070524091528'),('20070525','070525','20070526','070526'); +INSERT INTO t2 VALUES('20070523091528','070523091528','20070524091528','070524091528'),('20070525','070525','20070526','070526'); +INSERT INTO t3 VALUES('20070523091528','070523091528','20070524091528','070524091528'),('20070525','070525','20070526','070526'); +INSERT INTO t4 VALUES('20070523091528','070523091528','20070524091528','070524091528'),('20070525','070525','20070526','070526'); + +# As a number in either YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD or YYMMDD format +INSERT INTO t1 VALUES(19830905132800,830905132800,19830906132800,830906132800),(19830907,830907,19830908,830908); +INSERT INTO t2 VALUES(19830905132800,830905132800,19830906132800,830906132800),(19830907,830907,19830908,830908); +INSERT INTO t3 VALUES(19830905132800,830905132800,19830906132800,830906132800),(19830907,830907,19830908,830908); +INSERT INTO t4 VALUES(19830905132800,830905132800,19830906132800,830906132800),(19830907,830907,19830908,830908); + +# As the result of a function +SET TIMESTAMP=1233216687; # 2009-01-29 13:41:27 +INSERT INTO t1 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT INTO t2 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT INTO t3 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT INTO t4 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); + +# Insert duplicates for parts of the clustered key/unique index +INSERT INTO t2 VALUES('98-12-31 11:30:45','98@12@30 11^30^45','98-12-31 11:30:45','98.12.31 11+30+45'),('98-12-29','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'); +INSERT INTO t3 VALUES('98-12-31 11:30:45','98@12@30 11^30^45','98-12-31 11:30:45','98.12.31 11+30+45'),('98-12-29','98@12@30 11^30^45','98/12/30 11*30*45','98@12@30 11^30^45'); + +# Insert permissible NULLs +INSERT INTO t1 VALUES('2008-01-01',NULL,'08-01-02','08/01/03'); +INSERT INTO t3 VALUES('2008-01-01',NULL,'08-01-02','08/01/03'); +INSERT INTO t4 VALUES('2008-01-01',NULL,'08-01-02','08/01/03'); + +# Insert duplicate NULLs to unique column +INSERT INTO t1(c1,c2) VALUES('08/01/17',NULL); +DELETE FROM t1 WHERE c1='08/01/17' AND c2 IS NULL; + +# Insert empty string '', would be converted to zero value of the appropriate type +INSERT INTO t1 VALUES('','','08-01-04','08/01/05') /* Inserts zero dates for '' strings */; + +# Insert invalid dates, would be converted to zero value of the appropriate type +INSERT INTO t2 VALUES('2008-04-31','2008-04-31','08-01-06','08/01/07') /* Inserts zero dates for invalid dates */; +INSERT INTO t3 VALUES('10:45:15','10:45:15','08-01-08','08/1/9') /* Inserts zero dates for invalid dates */; + +# Insert zero dates +INSERT INTO t2 VALUES('0000-00-00','08-01-06','08-01-06','08/01/07'); +INSERT INTO t3 VALUES('08-01-06','00-00-00','08-01-08','08/1/9'); + +# Insert non-date value(absurd values), would be converted to zero value of the appropriate type +INSERT INTO t4 VALUES('abcd','abcd','08-01-10','08/01/11'),(1234,1234,'08-01-12','08/01/13') /* Inserts zero dates for absurd dates */; + +# Now select using various table access methods (full table scan, range scan, index scan etc.) +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; + +# Select from table with single column primary key and single column index, with column values zero, NULL +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2007-05-24'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '1998-12-29 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '1998-12-29 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','1998-12-29 00:00:00') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','1998-12-29 00:00:00') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '1998-12-29 00:00:00' AND c2 = '1983-09-07 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '1998-12-29 00:00:00' AND c2 = '1983-09-07 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '1998-12-29 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '1998-12-29 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','1998-12-29 00:00:00') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','1998-12-29 00:00:00') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '1998-12-29 00:00:00' AND c2 = '1983-09-07 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '1998-12-29 00:00:00' AND c2 = '1983-09-07 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2007-05-26'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '0000-00-00' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-31 11:30:45' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-31 11:30:45' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-31 11:30:45' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-31 11:30:45' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c4 = '2007-05-26 00:00:00'; + +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t1; + +## Backward index scan, covering ## +SELECT c2 FROM t1 ORDER BY c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 = '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 = '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <> '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 > '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 < '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <= '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '1998-12-30 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <=> '1998-12-30 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-31 11:30:45' ORDER BY c2; +SELECT * FROM t1 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-31 11:30:45' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-31 11:30:45') ORDER BY c2; +SELECT * FROM t1 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-31 11:30:45') ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-31 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-31 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <> '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 > '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 < '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <= '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '1998-12-30 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '1998-12-30 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-31 11:30:45' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-31 11:30:45' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-31 11:30:45') ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-31 11:30:45') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-31 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-31 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC LIMIT 2; + +# Select from table with clustered primary key, with column values zero, NULL +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2008-01-06'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1983-09-07 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '1983-09-07 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1983-09-07 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('1983-09-07 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1983-09-07 00:00:00' AND c1 < '2007-05-23 09:15:28' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1983-09-07 00:00:00' AND c1 < '2007-05-23 09:15:28' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1983-09-07 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '1983-09-07 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1983-09-07 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('1983-09-07 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1983-09-07 00:00:00' AND c1 < '2007-05-23 09:15:28' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1983-09-07 00:00:00' AND c1 < '2007-05-23 09:15:28' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '2007-05-23 09:15:28' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '2007-05-23 09:15:28' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '2007-05-23 09:15:28' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '2007-05-23 09:15:28' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c4 = '2007-05-24 09:15:28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '1983-09-05 13:28:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> '1983-09-05 13:28:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('0000-00-00 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN ('0000-00-00 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '2007-05-23 09:15:28' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '2007-05-23 09:15:28' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '1983-09-05 13:28:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> '1983-09-05 13:28:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '2007-05-23 09:15:28' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('0000-00-00 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN ('0000-00-00 00:00:00','2007-05-23 09:15:28') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '2007-05-23 09:15:28' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '2007-05-23 09:15:28' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Select from table with clustered index, with column values zero, NULL +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2007-05-24'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1998-12-31 11:30:45' AND '2008-01-06 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '1998-12-31 11:30:45' AND '2008-01-06 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1998-12-31 11:30:45','2008-01-06 00:00:00') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('1998-12-31 11:30:45','2008-01-06 00:00:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1998-12-31 11:30:45' AND c1 < '2008-01-06 00:00:00' AND c2 = '1998-12-28 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1998-12-31 11:30:45' AND c1 < '2008-01-06 00:00:00' AND c2 = '1998-12-28 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1998-12-31 11:30:45' AND '2008-01-06 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '1998-12-31 11:30:45' AND '2008-01-06 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1998-12-31 11:30:45','2008-01-06 00:00:00') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('1998-12-31 11:30:45','2008-01-06 00:00:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1998-12-31 11:30:45' AND c1 < '2008-01-06 00:00:00' AND c2 = '1998-12-28 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1998-12-31 11:30:45' AND c1 < '2008-01-06 00:00:00' AND c2 = '1998-12-28 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2009-01-29' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2009-01-29') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2009-01-29' AND c2 = '1998-12-30 11:30:45' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c4 = '2007-05-24 09:15:28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '1998-12-29 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-30 11:30:45' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-30 11:30:45' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-30 11:30:45') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-30 11:30:45') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-30 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-30 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> '1998-12-29 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-30 11:30:45' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN '0000-00-00 00:00:00' AND '1998-12-30 11:30:45' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-30 11:30:45') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN ('0000-00-00 00:00:00','1998-12-30 11:30:45') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-30 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '0000-00-00 00:00:00' AND c2 < '1998-12-30 11:30:45' AND c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Test Error conditions- PK constraint violation, Unique constraint violation + +# Insert duplicate value to pk column +--error ER_DUP_ENTRY +INSERT INTO t1(c1,c2) VALUES('20070525','070523091528') /* Row with c1='20070525' exists */; + +# Insert duplicate value to clustered pk, throws error +--error ER_DUP_ENTRY +INSERT INTO t2(c1,c2) VALUES(19830907,830907) /* Row with c1=19830907,c2=830907 exists */; + +# Insert duplicate value to unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t1(c1,c2) VALUES(19840905,830907) /* Row with c2=830907 exists */; + +# Insert duplicate value to clustered unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t3(c1,c2) VALUES(19830907,830907) /* Row with c1=19830907,c2=830907 exists */; + +# Test 'INSERT IGNORE' with the same rows that reported constraint violation above +# Ignore pk constraint +INSERT IGNORE INTO t1(c1,c2) VALUES('20070525','20070527') /* doesn't throw error */; +INSERT IGNORE INTO t2(c1,c2) VALUES(19830907,830907) /* doesn't throw error */; +# Ignore unique constraint +INSERT IGNORE INTO t1(c1,c2) VALUES(19840905,830907) /* doesn't throw error */; +INSERT IGNORE INTO t3(c1,c2) VALUES(19830907,830907) /* doesn't throw error */; +# Test that the rows are same +SELECT * FROM t1 WHERE c1='20070525' /* Returns 1 row with c1=2007-05-25 */; +SELECT * FROM t2 WHERE c1=19830907 AND c2=830907 /* Returns 1 row with c1=1983-09-07 and c2=1983-09-07 */; +SELECT * FROM t1 WHERE c2=830907 /* Returns 1 row with c2=1983-09-07 */; +SELECT * FROM t3 WHERE c1=19830907 AND c2=830907 /* Returns 1 row with c1=1983-09-07 and c2=1983-09-07 */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with single column PK +SELECT * FROM t1 WHERE c1='20070527' /* Returns no rows */; +INSERT INTO t1(c1) VALUES('20070525') ON DUPLICATE KEY UPDATE c1='20070527'; +SELECT * FROM t1 WHERE c1='20070527' /* Returns 1 row with c1=2007-05-27 */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with multi-column PK +SELECT * FROM t2 WHERE c1=19830909 AND c2=830910 /* Returns no rows */; +INSERT INTO t2(c1,c2) VALUES(19830907,830907) ON DUPLICATE KEY UPDATE c1=19830909,c2=830910; +SELECT * FROM t2 WHERE c1=19830909 AND c2=830910 /* Returns 1 row with c1=19830909,c2=830910 */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with single column unique +SELECT * FROM t1 WHERE c1=19830909 AND c2=830910 /* Returns no rows */; +INSERT INTO t1(c1,c2) VALUES(19840905,830907) ON DUPLICATE KEY UPDATE c1=19830909,c2=830910; +SELECT * FROM t1 WHERE c1=19830909 AND c2=830910 /* Returns 1 row */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with multi-column unique +SELECT * FROM t3 WHERE c1=19830909 AND c2=830910 /* Returns no rows */; +INSERT INTO t3(c1,c2) VALUES(19830907,830907) ON DUPLICATE KEY UPDATE c1=19830909,c2=830910; +SELECT * FROM t3 WHERE c1=19830909 AND c2=830910 /* Returns 1 row */; + +# Test 'INSERT SET' +INSERT INTO t1 SET c1='1999-01-01',c2='1999-01-01'; +INSERT INTO t2 SET c1='1999-01-01',c2='1999-01-01'; +INSERT INTO t3 SET c1='1999-01-01'; +INSERT INTO t4 SET c2='1999-01-01'; +SELECT * FROM t1 WHERE c1='1999-01-01' AND c2='1999-01-01' /* Returns 1 row with values for other column as NULL */; +SELECT * FROM t2 WHERE c1='1999-01-01' AND c2='1999-01-01' /* Returns 1 row with values for other column as NULL */; +SELECT * FROM t3 WHERE c1='1999-01-01' /* Returns 1 row with values for other column as NULL */; +SELECT * FROM t4 WHERE c2='1999-01-01' /* Returns 1 row with values for other column as NULL */; + +# Test 'INSERT INTO SELECT FROM' +CREATE TABLE t5(c1 TIMESTAMP NOT NULL, c2 TIMESTAMP NULL, c3 DATE, c4 DATETIME, INDEX idx(c1,c2)); +INSERT INTO t5 SELECT * FROM t1 WHERE c1 >=0 AND c1 < '20070523091528'; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +INSERT INTO t5 SELECT * FROM t2 WHERE c1 >='98-12-31 11:30:45' AND c1 < '20070523091528' AND c2 <> '070525'; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +INSERT INTO t5 SELECT * FROM t3 WHERE c2 BETWEEN 0 AND '1998-12-30 11:30:45'; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +DROP TABLE t5; + +# Test Specific values to column types + +# Test insert range values to 'TIMESTAMP' columns +INSERT INTO t1 VALUES('1971-01-01 00:00:01','1980-01-01 00:00:01','2009-01-01','2009-01-02'),('1990-01-01 00:00:01','2000-01-01 00:00:01','2009-01-03','2009-01-04'),('2038-01-09 03:14:07','2038-01-09 03:14:07','2009-01-05','2009-01-06'); +INSERT INTO t2 VALUES('1971-01-01 00:00:01','1980-01-01 00:00:01','2009-01-01','2009-01-02'),('1990-01-01 00:00:01','2000-01-01 00:00:01','2009-01-03','2009-01-04'),('2038-01-09 03:14:07','2038-01-09 03:14:07','2009-01-05','2009-01-06'); +INSERT INTO t3 VALUES('1971-01-01 00:00:01','1980-01-01 00:00:01','2009-01-01','2009-01-02'),('1990-01-01 00:00:01','2000-01-01 00:00:01','2009-01-03','2009-01-04'),('2038-01-09 03:14:07','2038-01-09 03:14:07','2009-01-05','2009-01-06'); +INSERT INTO t4 VALUES('1971-01-01 00:00:01','1980-01-01 00:00:01','2009-01-01','2009-01-02'),('1990-01-01 00:00:01','2000-01-01 00:00:01','2009-01-03','2009-01-04'),('2038-01-09 03:14:07','2038-01-09 03:14:07','2009-01-05','2009-01-06'); + +# Insert dates containing a zero for the month or for the day, convert to zero +INSERT INTO t4(c1,c2) VALUES('2010-00-01','2010-10-00'); + +# Insert invalid dates, inserts zero values +INSERT INTO t4(c1) VALUES('2009-02-30'),('2009-04-31'),('2009-06-31'),('2009-09-31'),('2009-11-31'),('2009-13-01'),('2009-12-32'),('2009-01-01 23:60:60'),('2009-01-01 24:59:59'),('2009-01-01 23:59:60'); + +# Test insert NULL to non-null column +# Inserting NULL to TIMESTAMP NOT NULL field doesn't throw error, but records the current/set timestamp + +DELETE FROM t1 WHERE c1=NOW() /* because the row with current timestamp exists */; +INSERT INTO t1 VALUES(NULL,NOW(),NOW(),NOW()); +SELECT * FROM t1 WHERE c1 IS NULL /* returns no rows */; +SELECT * FROM t1 WHERE c1=NOW() /* returns 1 row */; +INSERT INTO t2(c1) VALUES(NULL); +INSERT INTO t3 VALUES(NULL,'2008-01-14 00:00:00','08-01-15','08/01/16'); +INSERT INTO t4 VALUES(NULL,'2008-01-14 00:00:00','08-01-15','08/01/16'); + +# Test INSERT SET with no default for not null column +SET SQL_MODE=STRICT_ALL_TABLES; +INSERT INTO t4 SET c2='1999-01-01' /* NOT NULL column will get the default value as current timestamp */; +SET SQL_MODE=''; + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +# Now select using various table access methods +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2007-05-24'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '1971-01-01 00:00:01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '1971-01-01 00:00:01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '1971-01-01 00:00:01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '1971-01-01 00:00:01' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '1971-01-01 00:00:01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '1971-01-01 00:00:01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '1971-01-01 00:00:01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '1971-01-01 00:00:01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1971-01-01 00:00:01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '1971-01-01 00:00:01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '1971-01-01 00:00:01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '1971-01-01 00:00:01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '1971-01-01 00:00:01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '1971-01-01 00:00:01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '1971-01-01 00:00:01' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '1971-01-01 00:00:01' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1971-01-01 00:00:01' AND c1 < '2038-01-09 03:14:07' AND c2 = '2038-01-09 03:14:07' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '1971-01-01 00:00:01' AND c1 < '2038-01-09 03:14:07' AND c2 = '2038-01-09 03:14:07' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '1971-01-01 00:00:01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '1971-01-01 00:00:01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '1971-01-01 00:00:01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '1971-01-01 00:00:01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1971-01-01 00:00:01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '1971-01-01 00:00:01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '1971-01-01 00:00:01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '1971-01-01 00:00:01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '1971-01-01 00:00:01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '1971-01-01 00:00:01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '1971-01-01 00:00:01' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '1971-01-01 00:00:01' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '1971-01-01 00:00:01' AND c1 < '2038-01-09 03:14:07' AND c2 = '2038-01-09 03:14:07' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '1971-01-01 00:00:01' AND c1 < '2038-01-09 03:14:07' AND c2 = '2038-01-09 03:14:07' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2007-05-26'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '0000-00-00 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '0000-00-00 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '0000-00-00 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '0000-00-00 00:00:00' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '0000-00-00 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '0000-00-00 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0000-00-00 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '0000-00-00 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0000-00-00 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '0000-00-00 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0000-00-00 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '0000-00-00 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '2038-01-09 03:14:07' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '2038-01-09 03:14:07' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','2038-01-09 03:14:07') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','2038-01-09 03:14:07') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '2038-01-09 03:14:07' AND c2 = '2010-10-00 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '2038-01-09 03:14:07' AND c2 = '2010-10-00 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '0000-00-00 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '0000-00-00 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0000-00-00 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '0000-00-00 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0000-00-00 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '0000-00-00 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0000-00-00 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '0000-00-00 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '0000-00-00 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '2038-01-09 03:14:07' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '2038-01-09 03:14:07' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','2038-01-09 03:14:07') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00 00:00:00','2038-01-09 03:14:07') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '2038-01-09 03:14:07' AND c2 = '2010-10-00 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '2038-01-09 03:14:07' AND c2 = '2010-10-00 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '1998-12-28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:00') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:00') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:00' AND c2 = '2010-10-00 00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:00' AND c2 = '2010-10-00 00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:00') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:00') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:00' AND c2 = '2010-10-00 00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:00' AND c2 = '2010-10-00 00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c4 = '2009-01-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t1; + +## Backward index scan, covering ## +SELECT c2 FROM t1 ORDER BY c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '2038-01-09 03:14:07' ORDER BY c2; +SELECT * FROM t1 WHERE c2 = '2038-01-09 03:14:07' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '2038-01-09 03:14:07' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 = '2038-01-09 03:14:07' ORDER BY c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '2038-01-09 03:14:07' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <> '2038-01-09 03:14:07' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '2038-01-09 03:14:07' ORDER BY c2; +SELECT * FROM t1 WHERE c2 > '2038-01-09 03:14:07' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '2038-01-09 03:14:07' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '2038-01-09 03:14:07' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '2038-01-09 03:14:07' ORDER BY c2; +SELECT * FROM t1 WHERE c2 < '2038-01-09 03:14:07' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '2038-01-09 03:14:07' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <= '2038-01-09 03:14:07' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '2038-01-09 03:14:07' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <=> '2038-01-09 03:14:07' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c2; +SELECT * FROM t1 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c2; +SELECT * FROM t1 WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2038-01-09 03:14:07' AND c1 = '2038-01-09 03:14:07' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2038-01-09 03:14:07' AND c1 = '2038-01-09 03:14:07' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '2038-01-09 03:14:07' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <> '2038-01-09 03:14:07' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '2038-01-09 03:14:07' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 > '2038-01-09 03:14:07' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '2038-01-09 03:14:07' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '2038-01-09 03:14:07' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '2038-01-09 03:14:07' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 < '2038-01-09 03:14:07' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '2038-01-09 03:14:07' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <= '2038-01-09 03:14:07' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '2038-01-09 03:14:07' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '2038-01-09 03:14:07' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2038-01-09 03:14:07' AND c1 = '2038-01-09 03:14:07' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2038-01-09 03:14:07' AND c1 = '2038-01-09 03:14:07' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c4 = '2008-01-05'; + +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t1; + +## Backward index scan, covering ## +SELECT c2 FROM t1 ORDER BY c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '2010-10-01 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 = '2010-10-01 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '2010-10-01 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 = '2010-10-01 00:00:00' ORDER BY c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '2010-10-01 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <> '2010-10-01 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '2010-10-01 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 > '2010-10-01 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '2010-10-01 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '2010-10-01 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '2010-10-01 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 < '2010-10-01 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '2010-10-01 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <= '2010-10-01 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '2010-10-01 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <=> '2010-10-01 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2010-10-00 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2010-10-00 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('1971-01-01 00:00:01','2010-10-00 00:00:00') ORDER BY c2; +SELECT * FROM t1 WHERE c2 IN ('1971-01-01 00:00:01','2010-10-00 00:00:00') ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '2010-10-01 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <> '2010-10-01 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '2010-10-01 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 > '2010-10-01 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '2010-10-01 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '2010-10-01 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '2010-10-01 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 < '2010-10-01 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '2010-10-01 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <= '2010-10-01 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '2010-10-01 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '2010-10-01 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2010-10-00 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2010-10-00 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('1971-01-01 00:00:01','2010-10-00 00:00:00') ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('1971-01-01 00:00:01','2010-10-00 00:00:00') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC LIMIT 2; + +# Using Index-merge +--sorted_result +SELECT * FROM t1 WHERE c1='1971-01-01 00:00:01' OR c2='2038-01-09 03:14:07'; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t1 GROUP BY c2; + +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2007-05-24'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1971-01-01 00:00:01' AND c1 < '2038-01-09 03:14:07' AND c2 = '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1971-01-01 00:00:01' AND c1 < '2038-01-09 03:14:07' AND c2 = '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1971-01-01 00:00:01' AND c1 < '2038-01-09 03:14:07' AND c2 = '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1971-01-01 00:00:01' AND c1 < '2038-01-09 03:14:07' AND c2 = '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2007-05-26'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00 00:00:00','2038-01-09 03:14:07') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00 00:00:00','2038-01-09 03:14:07') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '2038-01-09 03:14:07' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '2038-01-09 03:14:07' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00 00:00:00','2038-01-09 03:14:07') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00 00:00:00','2038-01-09 03:14:07') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '2038-01-09 03:14:07' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '2038-01-09 03:14:07' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:00') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:00' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:00' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:00') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:00' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:00' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c4 = '2009-01-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2038-01-09 03:14:07' AND c1 = '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2038-01-09 03:14:07' AND c1 = '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2038-01-09 03:14:07' AND c1 = '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2038-01-09 03:14:07' AND c1 = '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c4 = '2008-01-07'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1971-01-01 00:00:01','2010-10-00 00:00:00') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN ('1971-01-01 00:00:01','2010-10-00 00:00:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1971-01-01 00:00:01','2010-10-00 00:00:00') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN ('1971-01-01 00:00:01','2010-10-00 00:00:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2007-05-24'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1971-01-01 00:00:01' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '1971-01-01 00:00:01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1971-01-01 00:00:01' AND c1 < '2038-01-09 03:14:07' AND c2 = '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1971-01-01 00:00:01' AND c1 < '2038-01-09 03:14:07' AND c2 = '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1971-01-01 00:00:01' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '1971-01-01 00:00:01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1971-01-01 00:00:01' AND c1 < '2038-01-09 03:14:07' AND c2 = '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1971-01-01 00:00:01' AND c1 < '2038-01-09 03:14:07' AND c2 = '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2007-05-26'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00 00:00:00','2038-01-09 03:14:07') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00 00:00:00','2038-01-09 03:14:07') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '2038-01-09 03:14:07' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '2038-01-09 03:14:07' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '0000-00-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00 00:00:00' AND '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00 00:00:00','2038-01-09 03:14:07') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00 00:00:00','2038-01-09 03:14:07') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '2038-01-09 03:14:07' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00 00:00:00' AND c1 < '2038-01-09 03:14:07' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-28'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:00') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:00' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:00' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:00') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('0000-00-00','2010-00-01 00:00:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:00' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '0000-00-00' AND c1 < '2010-00-01 00:00:00' AND c2 = '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c4 = '2009-01-29'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2038-01-09 03:14:07' AND c1 = '2038-01-09 03:14:07' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2038-01-09 03:14:07' AND c1 = '2038-01-09 03:14:07' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN ('1971-01-01 00:00:01','2038-01-09 03:14:07') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2038-01-09 03:14:07' AND c1 = '2038-01-09 03:14:07' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2038-01-09 03:14:07' AND c1 = '2038-01-09 03:14:07' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c4 = '2008-01-09'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '2010-10-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> '2010-10-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2010-10-00 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2010-10-00 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('1971-01-01 00:00:01','2010-10-00 00:00:00') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN ('1971-01-01 00:00:01','2010-10-00 00:00:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '2010-10-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> '2010-10-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2010-10-00 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN '1971-01-01 00:00:01' AND '2010-10-00 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('1971-01-01 00:00:01','2010-10-00 00:00:00') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN ('1971-01-01 00:00:01','2010-10-00 00:00:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '1971-01-01 00:00:01' AND c2 < '2010-10-00 00:00:00' AND c1 = '2010-00-01 00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c1 FROM t3 GROUP BY c1; +--sorted_result +SELECT DISTINCT c1 FROM t3; +--sorted_result +SELECT c1,MIN(c2) FROM t3 GROUP BY c1; +DROP TABLE t1,t2,t3,t4; + diff --git a/mysql-test/suite/engines/iuds/t/insert_decimal.test b/mysql-test/suite/engines/iuds/t/insert_decimal.test new file mode 100644 index 00000000..c75fa195 --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/insert_decimal.test @@ -0,0 +1,976 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2; +--enable_warnings + +######## Running INSERT tests for DECIMAL ######## + +# Create tables +CREATE TABLE t1(c1 DECIMAL(10,5) UNSIGNED NOT NULL, c2 DECIMAL(10,5) SIGNED NULL, c3 DECIMAL, c4 INT, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t2(c1 DECIMAL(10,0) SIGNED NOT NULL, c2 DECIMAL(10) UNSIGNED NULL, c3 DECIMAL, c4 INT); + +# Test insert values, trailing zeroes are not stripped +INSERT INTO t1 VALUES('00100.05000','-00100.05000','00100.05000',1); +INSERT INTO t2 VALUES('-1000000000','1000000000','1000000000',2); + +# Test no approximation +INSERT INTO t1(c1) VALUES('12345.000009'); + +# Test insert max values +INSERT INTO t1 VALUES('99999.99999','-99999.99999','99999.99999',3); +INSERT IGNORE INTO t2 VALUES('-9999999999','-9999999999','9999999999',4); + +# Test insert outside max value, would be clipped to closest endpoint +--sorted_result +SELECT * FROM t1; +--error ER_DUP_ENTRY +SET STATEMENT sql_mode = '' FOR +INSERT INTO t1 VALUES('100000.000002','-100000.000002','100000.000002',5); +DELETE FROM t1 WHERE c1='99999.99999' AND c2='-99999.99999'; +--sorted_result +SELECT * FROM t1; +INSERT IGNORE INTO t1 VALUES('100000.000002','-100000.000002','100000.000002',5); +INSERT IGNORE INTO t2 VALUES('10000000000','-10000000000','10000000000',6); + +# Test insert leading zero, +/- signs, overflow handling +insert into t1 values ("0.0","0.0","0.0",7),("01.0","01.0","01.0",10); +insert ignore into t1 values ("-.1","-.1","-.1",13); +insert ignore into t1 values ("+111111111.11","+111111111.11","+111111111.11",19); +insert ignore into t2 values ("0.0","0.0","0.0",7),("-0.0","-0.0","-0.0",8),("+0.0","+0.0","+0.0",9),("01.0","01.0","01.0",10),("+01.0","+01.0","+01.0",11),("-01.0","-01.0","-01.0",12); +insert ignore into t2 values ("-.1","-.1","-.1",13),("+.1","+.1","+.1",14),(".1",".1",".1",15); +insert ignore into t2 values ("00000000000001","00000000000001","00000000000001",16),("+0000000000001","+0000000000001","+0000000000001",17),("-0000000000001","-0000000000001","-0000000000001",18); +insert ignore into t2 values ("+111111111.11","+111111111.11","+111111111.11",19),("111111111.11","111111111.11","111111111.11",20),("-11111111.11","-11111111.11","-11111111.11",21); +insert ignore into t2 values ("-111111111.11","-111111111.11","-111111111.11",22),("+1111111111.11","+1111111111.11","+1111111111.11",23),("1111111111.11","1111111111.11","1111111111.11",24); +insert ignore into t2 values ("1e+1000","1e+1000","1e+1000",25),("1e-1000","1e-1000","1e-1000",26),("-1e+1000","-1e+1000","-1e+1000",27); +insert ignore into t2 values ("1e+4294967296","1e+4294967296","1e+4294967296",28),("1e-4294967296","1e-4294967296","1e-4294967296",29); +insert ignore into t2 values ("1e+18446744073709551615","1e+18446744073709551615","1e+18446744073709551615",30),("1e+18446744073709551616","1e+18446744073709551616","1e+18446744073709551616",31),("1e-9223372036854775807","1e-9223372036854775807","1e-9223372036854775807",32),("1e-9223372036854775809","1e-9223372036854775809","1e-9223372036854775809",33); + +# Now Select +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t1; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t1; +SELECT count(*) as total_rows, min(c3) as min_value, max(c3) as max_value, sum(c3) as sum, avg(c3) as avg FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t2; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t2; +SELECT count(*) as total_rows, min(c3) as min_value, max(c3) as max_value, sum(c3) as sum, avg(c3) as avg FROM t2; + +# Select using various access methods +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '0.0'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t1; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t1 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 = '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 = '0.0' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <> '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 > '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 >= '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 < '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <= '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <=> '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0.0' AND '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 BETWEEN '0.0' AND '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0.0','99999.99999') ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IN ('0.0','99999.99999') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0.0' AND c1 < '99999.99999' AND c2 = '1.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 >= '0.0' AND c1 < '99999.99999' AND c2 = '1.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <> '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 > '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 >= '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 < '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <= '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <=> '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0.0' AND '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0.0' AND '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0.0','99999.99999') ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IN ('0.0','99999.99999') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0.0' AND c1 < '99999.99999' AND c2 = '1.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 >= '0.0' AND c1 < '99999.99999' AND c2 = '1.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '-0.0'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t1; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t1 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 = '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 = '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <> '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 > '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 >= '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 < '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <= '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <=> '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '100.05' AND '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 BETWEEN '100.05' AND '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('100.05','99999.99999') ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IN ('100.05','99999.99999') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '100.05' AND c1 < '99999.99999' AND c2 = '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 >= '100.05' AND c1 < '99999.99999' AND c2 = '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <> '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 > '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 >= '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 < '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <= '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <=> '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '100.05' AND '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '100.05' AND '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('100.05','99999.99999') ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IN ('100.05','99999.99999') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '100.05' AND c1 < '99999.99999' AND c2 = '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 >= '100.05' AND c1 < '99999.99999' AND c2 = '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '-0.0'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t1; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t1 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 = '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 = '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 <> '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 > '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 < '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 <= '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 <=> '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '-99999.99999' AND '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 BETWEEN '-99999.99999' AND '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('-99999.99999','0.0') ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 IN ('-99999.99999','0.0') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' AND c2 < '0.0' AND c1 = '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' AND c2 < '0.0' AND c1 = '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 <> '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 > '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 < '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 <= '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '-99999.99999' AND '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '-99999.99999' AND '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('-99999.99999','0.0') ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('-99999.99999','0.0') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' AND c2 < '0.0' AND c1 = '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' AND c2 < '0.0' AND c1 = '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c1 FROM t1 GROUP BY c1; +--sorted_result +SELECT DISTINCT c1 FROM t1; +--sorted_result +SELECT c1,MIN(c2) FROM t1 GROUP BY c1; + +# Test extremes +CREATE TABLE t5(c1 DECIMAL(65,0) UNSIGNED NOT NULL, c2 DECIMAL(65,0) SIGNED NULL, c3 DECIMAL, c4 INT, INDEX idx(c1,c2)); +INSERT IGNORE INTO t5 VALUES('1e+64','-1e+64','1e+64',1),('1e-64','-1e-64','1e-64',2); +INSERT IGNORE INTO t5 VALUES('1.2e+65','-1.2e+65','1.2e+65',3),('1.2e-65','-1.2e-65','1.2e-65',4); +--sorted_result +SELECT * FROM t5; +DROP TABLE t5; + +# Test encoding to various bytes +CREATE TABLE t5(c1 DECIMAL(18,9) UNSIGNED, c2 DECIMAL(18,9) SIGNED) /* requires 8 bytes */; +INSERT INTO t5 VALUES(123456789.123456789,-123456789.123456789); +--sorted_result +SELECT c1,c2 FROM t5; +ALTER TABLE t5 CHANGE c1 c1 DECIMAL(19,9) UNSIGNED, CHANGE c2 c2 DECIMAL(19,9) SIGNED /* requires 9 bytes */; +INSERT INTO t5 VALUES(1234567891.123456789,-1234567891.123456789); +--sorted_result +SELECT c1,c2 FROM t5; +ALTER TABLE t5 CHANGE c1 c1 DECIMAL(21,10) UNSIGNED, CHANGE c2 c2 DECIMAL(21,10) SIGNED /* requires 10 bytes */; +INSERT INTO t5 VALUES(12345678912.1234567891,-12345678912.1234567891); +--sorted_result +SELECT c1,c2 FROM t5; +ALTER TABLE t5 CHANGE c1 c1 DECIMAL(23,11) UNSIGNED, CHANGE c2 c2 DECIMAL(23,11) SIGNED /* requires 11 bytes */; +INSERT INTO t5 VALUES(123456789123.12345678912,-123456789123.12345678912); +--sorted_result +SELECT c1,c2 FROM t5; +ALTER TABLE t5 CHANGE c1 c1 DECIMAL(25,12) UNSIGNED, CHANGE c2 c2 DECIMAL(25,12) SIGNED /* requires 12 bytes */; +INSERT INTO t5 VALUES(1234567891234.123456789123,-1234567891234.123456789123); +--sorted_result +SELECT c1,c2 FROM t5; +SELECT SUM(c1),SUM(c2) FROM t5; +DROP TABLE t5; + +# Test ROUND() and TRUNCATE() +CREATE TABLE t5(c1 DECIMAL(16,6), c2 tinyint); +INSERT INTO t5 VALUES(1.1325,3); +SELECT ROUND(c1,c2),TRUNCATE(c1,c2) FROM t5; +DROP TABLE t5; + +# Test wrong decimal types +--error ER_TOO_BIG_PRECISION +CREATE TABLE t7(c1 DECIMAL(66,0)); +--error ER_M_BIGGER_THAN_D +CREATE TABLE t7(c1 DECIMAL(5,10)); +DROP TABLE t1,t2; + +######## Running INSERT tests for FLOAT ######## + +# Create tables +CREATE TABLE t1(c1 FLOAT(10,5) UNSIGNED NOT NULL, c2 FLOAT(10,5) SIGNED NULL, c3 FLOAT, c4 INT, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t2(c1 FLOAT(10,0) SIGNED NOT NULL, c2 FLOAT(10,0) UNSIGNED NULL, c3 FLOAT, c4 INT); + +# Test insert values, trailing zeroes are not stripped +INSERT INTO t1 VALUES('00100.05000','-00100.05000','00100.05000',1); +INSERT INTO t2 VALUES('-1000000000','1000000000','1000000000',2); + +# Test approximation +INSERT INTO t1(c1) VALUES('12345.000009'); + +# Test insert max values +INSERT INTO t1 VALUES('99999.99999','-99999.99999','99999.99999',3); +INSERT IGNORE INTO t2 VALUES('-9999999999','-9999999999','9999999999',4); + +# Test insert outside max value, would be clipped to closest endpoint +SELECT * FROM t1; +--error ER_DUP_ENTRY +SET STATEMENT sql_mode = '' FOR +INSERT INTO t1 VALUES('100000.000002','-100000.000002','100000.000002',5); +DELETE FROM t1 WHERE c1='100000.00000' AND c2='-100000.00000'; +INSERT IGNORE INTO t1 VALUES('100000.000002','-100000.000002','100000.000002',5); +INSERT IGNORE INTO t2 VALUES('10000000000','-10000000000','10000000000',6); + +# Test insert leading zero, +/- signs, overflow handling +insert into t1 values ("0.0","0.0","0.0",7),("01.0","01.0","01.0",10); +insert ignore into t1 values ("-.1","-.1","-.1",13); +insert ignore into t1 values ("+111111111.11","+111111111.11","+111111111.11",19); +insert ignore into t2 values ("0.0","0.0","0.0",7),("-0.0","-0.0","-0.0",8),("+0.0","+0.0","+0.0",9),("01.0","01.0","01.0",10),("+01.0","+01.0","+01.0",11),("-01.0","-01.0","-01.0",12); +insert ignore into t2 values ("-.1","-.1","-.1",13),("+.1","+.1","+.1",14),(".1",".1",".1",15); +insert ignore into t2 values ("00000000000001","00000000000001","00000000000001",16),("+0000000000001","+0000000000001","+0000000000001",17),("-0000000000001","-0000000000001","-0000000000001",18); +insert ignore into t2 values ("+111111111.11","+111111111.11","+111111111.11",19),("111111111.11","111111111.11","111111111.11",20),("-11111111.11","-11111111.11","-11111111.11",21); +insert ignore into t2 values ("-111111111.11","-111111111.11","-111111111.11",22),("+1111111111.11","+1111111111.11","+1111111111.11",23),("1111111111.11","1111111111.11","1111111111.11",24); +insert ignore into t2 values ("1e+1000","1e+1000","1e+1000",25),("1e-1000","1e-1000","1e-1000",26),("-1e+1000","-1e+1000","-1e+1000",27); +insert ignore into t2 values ("1e+4294967296","1e+4294967296","1e+4294967296",28),("1e-4294967296","1e-4294967296","1e-4294967296",29); +insert ignore into t2 values ("1e+18446744073709551615","1e+18446744073709551615","1e+18446744073709551615",30),("1e+18446744073709551616","1e+18446744073709551616","1e+18446744073709551616",31),("1e-9223372036854775807","1e-9223372036854775807","1e-9223372036854775807",32),("1e-9223372036854775809","1e-9223372036854775809","1e-9223372036854775809",33); + +# Now Select +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t1; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t1; +SELECT count(*) as total_rows, min(c3) as min_value, max(c3) as max_value, sum(c3) as sum, avg(c3) as avg FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t2; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t2; +SELECT count(*) as total_rows, min(c3) as min_value, max(c3) as max_value, sum(c3) as sum, avg(c3) as avg FROM t2; + +# Select using various access methods +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '0.0'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t1; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t1 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 = '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 = '0.0' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <> '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 > '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 >= '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 < '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <= '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <=> '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0.0' AND '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 BETWEEN '0.0' AND '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0.0','99999.99999') ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IN ('0.0','99999.99999') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0.0' AND c1 < '99999.99999' AND c2 = '1.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 >= '0.0' AND c1 < '99999.99999' AND c2 = '1.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <> '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 > '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 >= '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 < '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <= '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <=> '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0.0' AND '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0.0' AND '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0.0','99999.99999') ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IN ('0.0','99999.99999') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0.0' AND c1 < '99999.99999' AND c2 = '1.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 >= '0.0' AND c1 < '99999.99999' AND c2 = '1.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '-0.0'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t1; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t1 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 = '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 = '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <> '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 > '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 >= '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 < '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <= '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <=> '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '100.05' AND '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 BETWEEN '100.05' AND '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('100.05','99999.99999') ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IN ('100.05','99999.99999') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '100.05' AND c1 < '99999.99999' AND c2 = '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 >= '100.05' AND c1 < '99999.99999' AND c2 = '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <> '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 > '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 >= '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 < '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <= '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <=> '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '100.05' AND '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '100.05' AND '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('100.05','99999.99999') ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IN ('100.05','99999.99999') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '100.05' AND c1 < '99999.99999' AND c2 = '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 >= '100.05' AND c1 < '99999.99999' AND c2 = '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '-0.0'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t1; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t1 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 = '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 = '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 <> '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 > '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 < '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 <= '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 <=> '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '-99999.99999' AND '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 BETWEEN '-99999.99999' AND '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('-99999.99999','0.0') ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 IN ('-99999.99999','0.0') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' AND c2 < '0.0' AND c1 = '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' AND c2 < '0.0' AND c1 = '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 <> '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 > '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 < '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 <= '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '-99999.99999' AND '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '-99999.99999' AND '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('-99999.99999','0.0') ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('-99999.99999','0.0') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' AND c2 < '0.0' AND c1 = '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' AND c2 < '0.0' AND c1 = '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c1 FROM t1 GROUP BY c1; +--sorted_result +SELECT DISTINCT c1 FROM t1; +--sorted_result +SELECT c1,MIN(c2) FROM t1 GROUP BY c1; + +# Test encoding to 4 or 8 bytes +CREATE TABLE t5(c1 FLOAT(23,0) UNSIGNED NOT NULL, c2 FLOAT(23,0) SIGNED NULL, c3 FLOAT, c4 INT, INDEX idx(c1,c2)); +INSERT INTO t5 VALUES('1e+22','-1e+22','1e+22',1),('1e-22','-1e-22','1e-22',2); +#Output is platform dependent +--disable_result_log +--sorted_result +SELECT * FROM t5; +--enable_result_log +SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR +ALTER TABLE t5 CHANGE c1 c1 FLOAT(24,0) SIGNED NOT NULL, CHANGE c2 c2 FLOAT(24,0) UNSIGNED NULL; +INSERT INTO t5 VALUES('-1e+23','1e+23','1e+23',3),('-1e-23','1e-23','1e-23',4); +#Output is platform dependent +--disable_result_log +--sorted_result +SELECT * FROM t5; +--enable_result_log +SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR +ALTER TABLE t5 CHANGE c1 c1 FLOAT(53,0) UNSIGNED, CHANGE c2 c2 FLOAT(53,0) SIGNED; +INSERT IGNORE INTO t5 VALUES('1e+52','-1e+52','1e+52',5),('1e-52','-1e-52','1e-52',6); +INSERT IGNORE INTO t5 VALUES('1e+53','-1e+53','1e+53',7),('1e-53','-1e-53','1e-53',8); + +#Output is platform dependent +--replace_column 1 # 2 # +--sorted_result +SELECT * FROM t5; +DROP TABLE t5; + +# Test ROUND() and TRUNCATE() +CREATE TABLE t5(c1 FLOAT(16,6), c2 tinyint); +INSERT INTO t5 VALUES(1.1325,3); +SELECT ROUND(c1,c2),TRUNCATE(c1,c2) FROM t5; +DROP TABLE t5; + +# Test wrong decimal types +--error ER_M_BIGGER_THAN_D +CREATE TABLE t7(c1 FLOAT(5,10)); +DROP TABLE t1,t2; + +######## Running INSERT tests for DOUBLE ######## + +# Create tables +CREATE TABLE t1(c1 DOUBLE(10,5) UNSIGNED NOT NULL, c2 DOUBLE(10,5) SIGNED NULL, c3 DOUBLE, c4 INT, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t2(c1 DOUBLE(10,0) SIGNED NOT NULL, c2 DOUBLE(10,0) UNSIGNED NULL, c3 DOUBLE, c4 INT); + +# Test insert values, trailing zeroes are not stripped +INSERT INTO t1 VALUES('00100.05000','-00100.05000','00100.05000',1); +INSERT INTO t2 VALUES('-1000000000','1000000000','1000000000',2); + +# Test approximation +INSERT INTO t1(c1) VALUES('12345.000009'); + +# Test insert max values +INSERT INTO t1 VALUES('99999.99999','-99999.99999','99999.99999',3); +INSERT IGNORE INTO t2 VALUES('-9999999999','-9999999999','9999999999',4); + +# Test insert outside max value, would be clipped to closest endpoint +SELECT * FROM t1; +--error ER_DUP_ENTRY +SET STATEMENT sql_mode = '' FOR +INSERT INTO t1 VALUES('100000.000002','-100000.000002','100000.000002',5); +DELETE FROM t1 WHERE c1='99999.99999' AND c2='-99999.99999'; +INSERT IGNORE INTO t1 VALUES('100000.000002','-100000.000002','100000.000002',5); +INSERT IGNORE INTO t2 VALUES('10000000000','-10000000000','10000000000',6); + +# Test insert leading zero, +/- signs, overflow handling +insert into t1 values ("0.0","0.0","0.0",7),("01.0","01.0","01.0",10); +insert ignore into t1 values ("-.1","-.1","-.1",13); +insert ignore into t1 values ("+111111111.11","+111111111.11","+111111111.11",19); +insert ignore into t2 values ("0.0","0.0","0.0",7),("-0.0","-0.0","-0.0",8),("+0.0","+0.0","+0.0",9),("01.0","01.0","01.0",10),("+01.0","+01.0","+01.0",11),("-01.0","-01.0","-01.0",12); +insert ignore into t2 values ("-.1","-.1","-.1",13),("+.1","+.1","+.1",14),(".1",".1",".1",15); +insert ignore into t2 values ("00000000000001","00000000000001","00000000000001",16),("+0000000000001","+0000000000001","+0000000000001",17),("-0000000000001","-0000000000001","-0000000000001",18); +insert ignore into t2 values ("+111111111.11","+111111111.11","+111111111.11",19),("111111111.11","111111111.11","111111111.11",20),("-11111111.11","-11111111.11","-11111111.11",21); +insert ignore into t2 values ("-111111111.11","-111111111.11","-111111111.11",22),("+1111111111.11","+1111111111.11","+1111111111.11",23),("1111111111.11","1111111111.11","1111111111.11",24); +insert ignore into t2 values ("1e+1000","1e+1000","1e+1000",25),("1e-1000","1e-1000","1e-1000",26),("-1e+1000","-1e+1000","-1e+1000",27); +insert ignore into t2 values ("1e+4294967296","1e+4294967296","1e+4294967296",28),("1e-4294967296","1e-4294967296","1e-4294967296",29); +insert ignore into t2 values ("1e+18446744073709551615","1e+18446744073709551615","1e+18446744073709551615",30),("1e+18446744073709551616","1e+18446744073709551616","1e+18446744073709551616",31),("1e-9223372036854775807","1e-9223372036854775807","1e-9223372036854775807",32),("1e-9223372036854775809","1e-9223372036854775809","1e-9223372036854775809",33); + +# Now Select +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t1; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t1; +SELECT count(*) as total_rows, min(c3) as min_value, max(c3) as max_value, sum(c3) as sum, avg(c3) as avg FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t2; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t2; +#SELECT below outputs 'inf' and 'infinity' for Linux/SunOS respectively +--replace_column 4 inf 5 inf +SELECT count(*) as total_rows, min(c3) as min_value, max(c3) as max_value, sum(c3) as sum, avg(c3) as avg FROM t2; + +# Select using various access methods +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '0.0'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t1; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t1 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 = '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 = '0.0' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <> '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 > '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 >= '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 < '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <= '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <=> '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0.0' AND '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 BETWEEN '0.0' AND '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0.0','99999.99999') ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IN ('0.0','99999.99999') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0.0' AND c1 < '99999.99999' AND c2 = '1.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 >= '0.0' AND c1 < '99999.99999' AND c2 = '1.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <> '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 > '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 >= '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 < '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <= '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <=> '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '0.0' AND '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '0.0' AND '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('0.0','99999.99999') ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IN ('0.0','99999.99999') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '0.0' AND c1 < '99999.99999' AND c2 = '1.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 >= '0.0' AND c1 < '99999.99999' AND c2 = '1.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '-0.0'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t1; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t1 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 = '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 = '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <> '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 > '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 >= '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 < '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <= '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 <=> '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '100.05' AND '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 BETWEEN '100.05' AND '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('100.05','99999.99999') ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IN ('100.05','99999.99999') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '100.05' AND c1 < '99999.99999' AND c2 = '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 >= '100.05' AND c1 < '99999.99999' AND c2 = '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <> '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 > '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 >= '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 < '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <= '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <=> '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '100.05' AND '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '100.05' AND '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('100.05','99999.99999') ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IN ('100.05','99999.99999') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '100.05' AND c1 < '99999.99999' AND c2 = '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 >= '100.05' AND c1 < '99999.99999' AND c2 = '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '-0.0'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t1; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t1 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 = '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 = '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 <> '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 > '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 < '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 <= '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '-99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 <=> '-99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '-99999.99999' AND '0.0' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 BETWEEN '-99999.99999' AND '0.0' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('-99999.99999','0.0') ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 IN ('-99999.99999','0.0') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' AND c2 < '0.0' AND c1 = '99999.99999' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' AND c2 < '0.0' AND c1 = '99999.99999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 <> '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 > '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 < '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 <= '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '-99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '-99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '-99999.99999' AND '0.0' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '-99999.99999' AND '0.0' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('-99999.99999','0.0') ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('-99999.99999','0.0') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' AND c2 < '0.0' AND c1 = '99999.99999' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 >= '-99999.99999' AND c2 < '0.0' AND c1 = '99999.99999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c1 FROM t1 GROUP BY c1; +--sorted_result +SELECT DISTINCT c1 FROM t1; +--sorted_result +SELECT c1,MIN(c2) FROM t1 GROUP BY c1; + +# Test encoding to 4 or 8 bytes +CREATE TABLE t5(c1 DOUBLE(23,0) UNSIGNED NOT NULL, c2 DOUBLE(23,0) SIGNED NULL, c3 DOUBLE, c4 INT, INDEX idx(c1,c2)); +INSERT INTO t5 VALUES('1e+22','-1e+22','1e+22',1),('1e-22','-1e-22','1e-22',2); +--sorted_result +SELECT * FROM t5; +SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR +ALTER TABLE t5 CHANGE c1 c1 DOUBLE(24,0) SIGNED NOT NULL, CHANGE c2 c2 DOUBLE(24,0) UNSIGNED NULL; +INSERT INTO t5 VALUES('-1e+23','1e+23','1e+23',3),('-1e-23','1e-23','1e-23',4); +#Output is platform dependent +--disable_result_log +--sorted_result +SELECT * FROM t5; +--enable_result_log +SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR +ALTER TABLE t5 CHANGE c1 c1 DOUBLE(53,0) UNSIGNED, CHANGE c2 c2 DOUBLE(53,0) SIGNED; +INSERT INTO t5 VALUES('1e+52','-1e+52','1e+52',5),('1e-52','-1e-52','1e-52',6); +INSERT INTO t5 VALUES('1e+53','-1e+53','1e+53',7),('1e-53','-1e-53','1e-53',8); +#Output is platform dependent +--disable_result_log +--sorted_result +SELECT * FROM t5; +--enable_result_log +DROP TABLE t5; + +# Test ROUND() and TRUNCATE() +CREATE TABLE t5(c1 DOUBLE(16,6), c2 tinyint); +INSERT INTO t5 VALUES(1.1325,3); +SELECT ROUND(c1,c2),TRUNCATE(c1,c2) FROM t5; +DROP TABLE t5; + +# Test wrong decimal types +--error ER_M_BIGGER_THAN_D +CREATE TABLE t7(c1 DOUBLE(5,10)); +DROP TABLE t1,t2; + diff --git a/mysql-test/suite/engines/iuds/t/insert_number.test b/mysql-test/suite/engines/iuds/t/insert_number.test new file mode 100644 index 00000000..9e4a971d --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/insert_number.test @@ -0,0 +1,8164 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3,t4,t5; +--enable_warnings + +######## Running INSERT tests for TINYINT ######## + +# Create tables +CREATE TABLE t1(c1 TINYINT UNSIGNED NOT NULL, c2 TINYINT NULL, c3 SMALLINT, c4 MEDIUMINT , c5 INT, c6 INTEGER, c7 BIGINT); +CREATE TABLE t2(c1 TINYINT UNSIGNED NOT NULL, c2 TINYINT NULL, c3 SMALLINT, c4 MEDIUMINT , c5 INT, c6 INTEGER, c7 BIGINT, PRIMARY KEY(c1,c6)); +CREATE TABLE t3(c1 TINYINT UNSIGNED NOT NULL, c2 TINYINT NULL, c3 SMALLINT, c4 MEDIUMINT , c5 INT, c6 INTEGER, c7 BIGINT, index idx(c2,c7)); + +# Insert some rows with targeted values +INSERT INTO t1 VALUES(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); +INSERT INTO t2 VALUES(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); +INSERT INTO t3 VALUES(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); + +# Insert duplicates for parts of the clustered key +INSERT INTO t2 VALUES(108,-109,110,111,112,101,114),(108,-109,110,111,112,102,114),(102,-109,110,111,112,113,114),(103,-109,110,111,112,113,114); +INSERT INTO t3 VALUES(101,-102,103,104,105,106,101),(101,-102,103,104,105,106,102),(101,-103,103,104,105,106,107),(101,-104,103,104,105,106,107); + +# Insert permissible NULLs +INSERT INTO t1 VALUES(105,NULL,102,103,104,105,106); +INSERT INTO t2 VALUES(105,NULL,102,103,104,105,106); +INSERT INTO t3 VALUES(105,NULL,102,103,104,105,106); + +# Insert empty string '' +INSERT IGNORE INTO t1 VALUES('','',17,18,19,20,21); +INSERT IGNORE INTO t2 VALUES('','',17,18,19,20,21); +INSERT IGNORE INTO t3 VALUES('','',17,18,19,20,21); + +# Insert negative value to unsigned integer, positive value to signed integer, zero values +INSERT IGNORE INTO t1 VALUES(-1,124,22,23,24,25,26); +INSERT IGNORE INTO t2 VALUES(-1,124,22,23,24,25,26); +INSERT IGNORE INTO t3 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t1 VALUES(0,124,27,28,29,30,31); +INSERT INTO t2 VALUES(0,124,27,28,29,30,31); +INSERT INTO t3 VALUES(0,124,27,28,29,30,31); +INSERT INTO t1 VALUES(0,0,32,32,34,35,36); +INSERT INTO t2 VALUES(0,0,32,32,34,35,36); +INSERT INTO t3 VALUES(0,0,32,32,34,35,36); + +# Insert non-numeric value to numeric column, would be converted to 0 or numeric value (if contains part) +INSERT IGNORE INTO t1 VALUES('101.34 a','a',37,38,39,40,41); +INSERT IGNORE INTO t2 VALUES('101.34 a','a',37,38,39,40,41); +INSERT IGNORE INTO t3 VALUES('101.34 a','a',37,38,39,40,41); + +--sorted_result +SELECT * FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t1; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t2; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t2; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t3; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t3; + +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 102; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 102; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 108; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 108; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t3 GROUP BY c2; +--sorted_result +SELECT DISTINCT c2 FROM t3; +--sorted_result +SELECT c2,MIN(c7) FROM t3 GROUP BY c2; + +# Create tables with AUTO_INCREMENT columns and unique indexes +CREATE TABLE t4(c1 TINYINT SIGNED NOT NULL AUTO_INCREMENT, c2 TINYINT UNSIGNED NULL, c3 TINYINT UNSIGNED NOT NULL, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 INTEGER, c8 BIGINT, PRIMARY KEY(c1), UNIQUE INDEX idx(c2,c3)); +CREATE TABLE t5(c1 TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, c2 TINYINT SIGNED NULL, c3 TINYINT SIGNED NOT NULL, c4 SMALLINT, c5 MEDIUMINT, c6 INT, c7 INTEGER, c8 BIGINT, PRIMARY KEY(c1,c2), UNIQUE INDEX(c3)); + +# Test with AUTO_INCREMENT columns +# Insert some rows +INSERT INTO t4 VALUES(-101,102,103,104,105,106,107,108),(-108,109,110,111,112,113,114,115); +INSERT INTO t5 VALUES(101,-102,-103,-104,105,106,107,108),(108,-109,-110,111,112,113,114,115); +# Insert 0 values, increments the value +INSERT INTO t4 VALUES(0,32,33,34,35,36,37,38); +--let $auto_value=`SELECT LAST_INSERT_ID()=1 AND c1=1 FROM t4 WHERE c2=32 AND c3=33;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on 0" +} +INSERT INTO t5 VALUES(0,-32,-32,33,34,35,36,37); +--let $auto_value=`SELECT LAST_INSERT_ID()=109 AND c1=109 FROM t5 WHERE c2=-32 AND c3=-32;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on 0" +} +# Insert NULL, no error, increments the value +INSERT INTO t4(c1,c3,c4) VALUES(NULL,104,LAST_INSERT_ID()); +--let $auto_value=`SELECT LAST_INSERT_ID()=2 AND c1=2 FROM t4 WHERE c3=104;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on NULL" +} +INSERT IGNORE INTO t5(c1,c3,c4) VALUES(NULL,-104,LAST_INSERT_ID()); +--let $auto_value=`SELECT LAST_INSERT_ID()=110 AND c1=110 FROM t5 WHERE c3=-104;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on NULL" +} +# Insert empty strings, increments the value +INSERT IGNORE INTO t4 VALUES('','',17,18,19,20,21,22); +--let $auto_value=`SELECT LAST_INSERT_ID()=3 AND c1=3 FROM t4 WHERE c2=0 AND c3=17;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on ''" +} +INSERT IGNORE INTO t5 VALUES('','',-17,18,19,20,21,22); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=111 FROM t5 WHERE c2=0 AND c3=-17;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on ''" +} +# Insert strings with numeric part, inserts the numeric part of the string +INSERT IGNORE INTO t4 VALUES('102.34 a','a','a',37,38,39,40,41); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=102 FROM t4 WHERE c2=0 AND c3=0;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on invalid strings with numeric part" +} +INSERT IGNORE INTO t5 VALUES('102.34 a','a','a',37,38,39,40,41); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=102 FROM t5 WHERE c2=0 AND c3=0;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on invalid strings with numeric part" +} +# Insert negative values unsigned & positive value to signed +INSERT INTO t4 VALUES(4,7,8,9,10,11,12,13); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=4 FROM t4 WHERE c2=7 AND c3=8;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work on negative value" +} +INSERT IGNORE INTO t5 VALUES(-1,-1,-1,8,9,10,11,12); +--let $auto_value=`SELECT LAST_INSERT_ID()=112 AND c1=112 FROM t5 WHERE c2=-1 AND c3=-1;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work for negative value on unsigned" +} +# Insert some rows with no values assigned to AUTO_INCREMENT columns, increments value +INSERT INTO t4(c2,c3,c4,c5,c6,c7,c8) VALUES(101,102,104,105,106,107,108),(108,109,111,112,113,114,115),(115,116,118,119,120,121,122),(122,123,125,126,127,128,128); +--let $auto_value=`SELECT LAST_INSERT_ID()=103 AND c1=103 FROM t4 WHERE c2=101 AND c3=102;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well" +} +INSERT INTO t5(c2,c3,c4,c5,c6,c7,c8) VALUES(-101,-102,104,105,106,107,108),(-108,-109,111,112,113,114,115),(-115,-116,118,119,120,121,122),(-122,-123,125,126,127,128,128); +--let $auto_value=`SELECT LAST_INSERT_ID()=113 AND c1=113 FROM t5 WHERE c2=-101 AND c3=-102;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well" +} + +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t4; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t5; +# Now select using various table access methods on auto-incremented pk value(full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t4; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t4; +--sorted_result +SELECT * FROM t4 WHERE c4 = 104; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t4; + +## Backward index scan, covering ## +SELECT c1 FROM t4 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t4; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t4; +--sorted_result +SELECT * FROM t4 WHERE c4 = 104; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t4; + +## Backward index scan, covering ## +SELECT c1 FROM t4 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT * FROM t5 WHERE c5 = 112; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t5; + +## Backward index scan, covering ## +SELECT c1 FROM t5 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; + +# Index-merge access +--sorted_result +SELECT * FROM t4 WHERE c1=1 OR c2=109; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t4 GROUP BY c2; +--sorted_result +SELECT DISTINCT c2 FROM t4; +--sorted_result +SELECT c2,MIN(c3) FROM t4 GROUP BY c2; + +# Test Error conditions- NULL into not null col, PK constraint violation, Unique constraint violation + +# Insert NULL to non-null column +--error ER_BAD_NULL_ERROR +SET STATEMENT sql_mode = '' FOR +INSERT INTO t2(c1) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t3 VALUES(NULL,1,2,3,4,5,6); +--error ER_BAD_NULL_ERROR +INSERT INTO t4(c3) VALUES(NULL); +--error ER_BAD_NULL_ERROR +SET STATEMENT sql_mode = '' FOR +INSERT INTO t5(c3) VALUES(NULL); + +# Insert duplicate value to pk +--error ER_DUP_ENTRY +INSERT INTO t4(c1,c3) VALUES(-101,105) /*throws error as the row with c1=-101 exists */; + +# Insert duplicate value to clustered pk, throws error +--error ER_DUP_ENTRY +INSERT INTO t2(c1,c6) VALUES(101,106) /*throws error as the row with c1=101,c6=106 exists */; +--error ER_DUP_ENTRY +INSERT INTO t5(c1,c2,c3) VALUES(101,-102,4) /*throws error as the row with c1=101,c2=-102 exists */; + +# Insert duplicate value to unique column, throws error +--error ER_DUP_ENTRY +SET STATEMENT sql_mode = '' FOR +INSERT INTO t5(c3) VALUES(-103) /*throws error as the row with c3=-103 exists */; +--error ER_DUP_ENTRY +# Insert duplicate value to clustered unique column, throws error +INSERT INTO t4(c2,c3) VALUES(102,103) /*throws error as the row with c2=102,c3=103 exists */; + +# Test 'INSERT INTO SELECT FROM' +CREATE TABLE t6(c1 TINYINT UNSIGNED NOT NULL, c2 TINYINT NULL, c3 SMALLINT, c4 MEDIUMINT , c5 INT, c6 INTEGER, c7 BIGINT); +INSERT INTO t6 SELECT * FROM t2 where c1 >= 109; +--sorted_result +SELECT * FROM t6; +TRUNCATE TABLE t6; +INSERT INTO t6 SELECT * FROM t3 where c2 <= -116; +--sorted_result +SELECT * FROM t6; +TRUNCATE TABLE t6; +# Test 'INSERT INTO SELECT FROM' primary key constraint violation +CREATE TABLE t7(c1 TINYINT UNSIGNED NOT NULL PRIMARY KEY, c2 TINYINT NULL, c3 SMALLINT, c4 MEDIUMINT , c5 INT, c6 INTEGER, c7 BIGINT); +CREATE TABLE t8(c1 TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 TINYINT NULL, c3 SMALLINT, c4 MEDIUMINT , c5 INT, c6 INTEGER, c7 BIGINT); +INSERT INTO t6 VALUES(1,-2,2,2,2,2,2),(1,-3,3,3,3,3,3); +INSERT INTO t7(c1) SELECT t6.c1 FROM t6 LIMIT 1; +--sorted_result +SELECT * FROM t7; +INSERT INTO t8(c1) SELECT t6.c1 FROM t6 LIMIT 1; +--sorted_result +SELECT * FROM t8; +--error ER_DUP_ENTRY +INSERT INTO t7(c1) SELECT t6.c1 FROM t6 /* throws error as t6 contains duplicate rows for c1=1 */; +--sorted_result +SELECT c1 FROM t7; +--error ER_DUP_ENTRY +INSERT INTO t8(c1) SELECT t6.c1 FROM t6 /* throws error as t6 contains duplicate rows for c1=1 */; +--sorted_result +SELECT c1 FROM t8; +TRUNCATE TABLE t6; +TRUNCATE TABLE t7; +INSERT INTO t6(c1) VALUES(0),(1),(2),(3),(3),(4),(4),(5); +--error ER_DUP_ENTRY +INSERT INTO t7(c1) SELECT c1 FROM t6; +TRUNCATE TABLE t6; + +# Test 'INSERT INTO SELECT FROM' with AUTO_INCREMENT and inserting 0,NULL +INSERT IGNORE INTO t6 VALUES(5,-1,1,1,1,1,1),(6,-2,2,2,2,2,2),(0,-4,4,4,4,4,4),(NULL,-5,5,5,5,5,5); +INSERT INTO t8 SELECT * FROM t6; +SELECT LAST_INSERT_ID() AS last_insert_id; +--sorted_result +SELECT * FROM t8; +TRUNCATE TABLE t8; +INSERT INTO t8(c2) SELECT c2 FROM t6 WHERE c1 >= 6; +--sorted_result +SELECT * FROM t8; +DROP TABLE t6,t7,t8; + +# Test 'INSERT SET' +INSERT IGNORE INTO t2 SET c3=5,c4=6; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_NO_DEFAULT_FOR_FIELD +INSERT INTO t2 SET c3=5,c4=6; +SET SQL_MODE=''; + +# Test insert allowable bigger values to 'TINYINT' columns +INSERT INTO t1 VALUES(0,-128,1,2,3,4,5),(255,127,6,7,8,9,10); +INSERT INTO t2 VALUES(0,-128,1,2,3,4,5),(255,127,6,7,8,9,10); +INSERT INTO t3 VALUES(0,-128,1,2,3,4,5),(255,127,6,7,8,9,10); +INSERT INTO t4 VALUES(-128,0,1,2,3,4,5,5),(127,255,6,7,8,9,10,10); +INSERT INTO t5 VALUES(0,-128,1,2,3,4,5,5),(255,127,6,7,8,9,10,10); +--error 167 +INSERT INTO t4(c2,c3) VALUES(31,32) /* tries to increment out of range */; +--error 167 +INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */; +--sorted_result +SELECT * FROM t4; + +# Insert signed value to unsigned 'TINYINT', outside range values to signed/unsigned columns +INSERT INTO t1 VALUES(-255,-129,26,27,28,29,30),(256,128,31,32,33,34,35); +INSERT INTO t2 VALUES(-255,-129,26,27,28,29,30),(256,128,31,32,33,34,35); +INSERT INTO t3 VALUES(-255,-129,26,27,28,29,30),(256,128,31,32,33,34,35); +# Insert into t4, t5 (TBD) + +# Now select using various table access methods +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = -128; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,255) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,255) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 255 AND c6 = 4 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 255 AND c6 = 4 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,255) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,255) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 255 AND c6 = 4 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 255 AND c6 = 4 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 127; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 255 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,255) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,255) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 255 AND c6 = 4 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 255 AND c6 = 4 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,255) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,255) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 255 AND c6 = 4 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 255 AND c6 = 4 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = -129; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 256 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 256 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,256) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (-255,256) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 256 AND c6 = 29 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 256 AND c6 = 29 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 256 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 256 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,256) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (-255,256) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 256 AND c6 = 29 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 256 AND c6 = 29 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 128; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 256 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 256 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 256 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 256 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 256 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 256 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 256 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 256 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 256 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 256 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 256 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 256 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 256 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 256 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 256 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 256 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 256 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 256 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,256) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (-255,256) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 256 AND c6 = 29 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 256 AND c6 = 29 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 256 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 256 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 256 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 256 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 256 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 256 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 256 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 256 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 256 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 256 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 256 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 256 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 256 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 256 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,256) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (-255,256) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 256 AND c6 = 29 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 256 AND c6 = 29 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 0; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -128 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -128 AND 127 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -128 AND 127 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-128,127) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-128,127) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -128 AND c2 < 127 AND c7 = 5 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -128 AND c2 < 127 AND c7 = 5 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -128 AND 127 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -128 AND 127 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-128,127) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-128,127) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -128 AND c2 < 127 AND c7 = 5 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -128 AND c2 < 127 AND c7 = 5 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 255; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 127 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = 127 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 127 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = 127 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 127 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> 127 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 127 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > 127 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 127 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= 127 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 127 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < 127 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 127 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= 127 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 127 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> 127 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -128 AND 127 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -128 AND 127 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-128,127) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-128,127) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -128 AND c2 < 127 AND c7 = 5 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -128 AND c2 < 127 AND c7 = 5 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 127 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> 127 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 127 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > 127 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 127 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= 127 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 127 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < 127 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 127 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= 127 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 127 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> 127 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -128 AND 127 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -128 AND 127 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-128,127) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-128,127) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -128 AND c2 < 127 AND c7 = 5 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -128 AND c2 < 127 AND c7 = 5 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = -255; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -129 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -129 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -129 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -129 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -129 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -129 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -129 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -129 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -129 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -129 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -129 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -129 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -129 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -129 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -129 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -129 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -129 AND 128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -129 AND 128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-129,128) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-129,128) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -129 AND c2 < 128 AND c7 = 30 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -129 AND c2 < 128 AND c7 = 30 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -129 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -129 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -129 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -129 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -129 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -129 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -129 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -129 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -129 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -129 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -129 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -129 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -129 AND 128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -129 AND 128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-129,128) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-129,128) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -129 AND c2 < 128 AND c7 = 30 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -129 AND c2 < 128 AND c7 = 30 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 256; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = 128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = 128 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> 128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > 128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= 128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < 128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= 128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> 128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -129 AND 128 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -129 AND 128 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-129,128) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-129,128) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -129 AND c2 < 128 AND c7 = 30 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -129 AND c2 < 128 AND c7 = 30 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> 128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > 128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= 128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < 128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= 128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> 128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -129 AND 128 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -129 AND 128 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-129,128) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-129,128) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -129 AND c2 < 128 AND c7 = 30 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -129 AND c2 < 128 AND c7 = 30 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +DROP TABLE t1,t2,t3,t4,t5; + +######## Running INSERT tests for SMALLINT ######## + +# Create tables +CREATE TABLE t1(c1 SMALLINT UNSIGNED NOT NULL, c2 SMALLINT NULL, c3 TINYINT, c4 MEDIUMINT , c5 INT, c6 INTEGER, c7 BIGINT); +CREATE TABLE t2(c1 SMALLINT UNSIGNED NOT NULL, c2 SMALLINT NULL, c3 TINYINT, c4 MEDIUMINT , c5 INT, c6 INTEGER, c7 BIGINT, PRIMARY KEY(c1,c6)); +CREATE TABLE t3(c1 SMALLINT UNSIGNED NOT NULL, c2 SMALLINT NULL, c3 TINYINT, c4 MEDIUMINT , c5 INT, c6 INTEGER, c7 BIGINT, index idx(c2,c7)); + +# Insert some rows with targeted values +INSERT INTO t1 VALUES(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); +INSERT INTO t2 VALUES(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); +INSERT INTO t3 VALUES(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); + +# Insert duplicates for parts of the clustered key +INSERT INTO t2 VALUES(108,-109,110,111,112,101,114),(108,-109,110,111,112,102,114),(102,-109,110,111,112,113,114),(103,-109,110,111,112,113,114); +INSERT INTO t3 VALUES(101,-102,103,104,105,106,101),(101,-102,103,104,105,106,102),(101,-103,103,104,105,106,107),(101,-104,103,104,105,106,107); + +# Insert permissible NULLs +INSERT INTO t1 VALUES(105,NULL,102,103,104,105,106); +INSERT INTO t2 VALUES(105,NULL,102,103,104,105,106); +INSERT INTO t3 VALUES(105,NULL,102,103,104,105,106); + +# Insert empty string '' +INSERT INTO t1 VALUES('','',17,18,19,20,21); +INSERT INTO t2 VALUES('','',17,18,19,20,21); +INSERT INTO t3 VALUES('','',17,18,19,20,21); + +# Insert negative value to unsigned integer, positive value to signed integer, zero values +INSERT INTO t1 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t2 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t3 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t1 VALUES(0,124,27,28,29,30,31); +INSERT INTO t2 VALUES(0,124,27,28,29,30,31); +INSERT INTO t3 VALUES(0,124,27,28,29,30,31); +INSERT INTO t1 VALUES(0,0,32,32,34,35,36); +INSERT INTO t2 VALUES(0,0,32,32,34,35,36); +INSERT INTO t3 VALUES(0,0,32,32,34,35,36); + +# Insert non-numeric value to numeric column, would be converted to 0 or numeric value (if contains part) +INSERT INTO t1 VALUES('101.34 a','a',37,38,39,40,41); +INSERT INTO t2 VALUES('101.34 a','a',37,38,39,40,41); +INSERT INTO t3 VALUES('101.34 a','a',37,38,39,40,41); + +--sorted_result +SELECT * FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t1; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t2; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t2; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t3; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t3; + +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 102; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 102; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 108; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 108; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t3 GROUP BY c2; +--sorted_result +SELECT DISTINCT c2 FROM t3; +--sorted_result +SELECT c2,MIN(c7) FROM t3 GROUP BY c2; + +# Create tables with AUTO_INCREMENT columns and unique indexes +CREATE TABLE t4(c1 SMALLINT SIGNED NOT NULL AUTO_INCREMENT, c2 SMALLINT UNSIGNED NULL, c3 SMALLINT UNSIGNED NOT NULL, c4 TINYINT , c5 MEDIUMINT, c6 INT, c7 INTEGER, c8 BIGINT, PRIMARY KEY(c1), UNIQUE INDEX idx(c2,c3)); +CREATE TABLE t5(c1 SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, c2 SMALLINT SIGNED NULL, c3 SMALLINT SIGNED NOT NULL, c4 TINYINT, c5 MEDIUMINT, c6 INT, c7 INTEGER, c8 BIGINT, PRIMARY KEY(c1,c2), UNIQUE INDEX(c3)); + +# Test with AUTO_INCREMENT columns +# Insert some rows +INSERT INTO t4 VALUES(-101,102,103,104,105,106,107,108),(-108,109,110,111,112,113,114,115); +INSERT INTO t5 VALUES(101,-102,-103,-104,105,106,107,108),(108,-109,-110,111,112,113,114,115); +# Insert 0 values, increments the value +INSERT INTO t4 VALUES(0,32,33,34,35,36,37,38); +--let $auto_value=`SELECT LAST_INSERT_ID()=1 AND c1=1 FROM t4 WHERE c2=32 AND c3=33;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on 0" +} +INSERT INTO t5 VALUES(0,-32,-32,33,34,35,36,37); +--let $auto_value=`SELECT LAST_INSERT_ID()=109 AND c1=109 FROM t5 WHERE c2=-32 AND c3=-32;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on 0" +} +# Insert NULL, no error, increments the value +INSERT INTO t4(c1,c3,c4) VALUES(NULL,104,LAST_INSERT_ID()); +--let $auto_value=`SELECT LAST_INSERT_ID()=2 AND c1=2 FROM t4 WHERE c3=104;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on NULL" +} +INSERT INTO t5(c1,c3,c4) VALUES(NULL,-104,LAST_INSERT_ID()); +--let $auto_value=`SELECT LAST_INSERT_ID()=110 AND c1=110 FROM t5 WHERE c3=-104;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on NULL" +} +# Insert empty strings, increments the value +INSERT INTO t4 VALUES('','',17,18,19,20,21,22); +--let $auto_value=`SELECT LAST_INSERT_ID()=3 AND c1=3 FROM t4 WHERE c2=0 AND c3=17;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on ''" +} +INSERT INTO t5 VALUES('','',-17,18,19,20,21,22); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=111 FROM t5 WHERE c2=0 AND c3=-17;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on ''" +} +# Insert strings with numeric part, inserts the numeric part of the string +INSERT INTO t4 VALUES('102.34 a','a','a',37,38,39,40,41); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=102 FROM t4 WHERE c2=0 AND c3=0;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on invalid strings with numeric part" +} +INSERT INTO t5 VALUES('102.34 a','a','a',37,38,39,40,41); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=102 FROM t5 WHERE c2=0 AND c3=0;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on invalid strings with numeric part" +} +# Insert negative values unsigned & positive value to signed +INSERT INTO t4 VALUES(4,7,8,9,10,11,12,13); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=4 FROM t4 WHERE c2=7 AND c3=8;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work on negative value" +} +INSERT INTO t5 VALUES(-1,-1,-1,8,9,10,11,12); +--let $auto_value=`SELECT LAST_INSERT_ID()=112 AND c1=112 FROM t5 WHERE c2=-1 AND c3=-1;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work for negative value on unsigned" +} +# Insert some rows with no values assigned to AUTO_INCREMENT columns, increments value +INSERT INTO t4(c2,c3,c4,c5,c6,c7,c8) VALUES(101,102,104,105,106,107,108),(108,109,111,112,113,114,115),(115,116,118,119,120,121,122),(122,123,125,126,127,128,128); +--let $auto_value=`SELECT LAST_INSERT_ID()=103 AND c1=103 FROM t4 WHERE c2=101 AND c3=102;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well" +} +INSERT INTO t5(c2,c3,c4,c5,c6,c7,c8) VALUES(-101,-102,104,105,106,107,108),(-108,-109,111,112,113,114,115),(-115,-116,118,119,120,121,122),(-122,-123,125,126,127,128,128); +--let $auto_value=`SELECT LAST_INSERT_ID()=113 AND c1=113 FROM t5 WHERE c2=-101 AND c3=-102;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well" +} + +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t4; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t5; +# Now select using various table access methods on auto-incremented pk value(full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t4; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t4; +--sorted_result +SELECT * FROM t4 WHERE c4 = 104; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t4; + +## Backward index scan, covering ## +SELECT c1 FROM t4 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t4; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t4; +--sorted_result +SELECT * FROM t4 WHERE c4 = 104; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t4; + +## Backward index scan, covering ## +SELECT c1 FROM t4 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT * FROM t5 WHERE c5 = 112; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t5; + +## Backward index scan, covering ## +SELECT c1 FROM t5 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; + +# Index-merge access +--sorted_result +SELECT * FROM t4 WHERE c1=1 OR c2=109; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t4 GROUP BY c2; +--sorted_result +SELECT DISTINCT c2 FROM t4; +--sorted_result +SELECT c2,MIN(c3) FROM t4 GROUP BY c2; + +# Test Error conditions- NULL into not null col, PK constraint violation, Unique constraint violation + +# Insert NULL to non-null column +--error ER_BAD_NULL_ERROR +INSERT INTO t2(c1) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t3 VALUES(NULL,1,2,3,4,5,6); +--error ER_BAD_NULL_ERROR +INSERT INTO t4(c3) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t5(c3) VALUES(NULL); + +# Insert duplicate value to pk +--error ER_DUP_ENTRY +INSERT INTO t4(c1,c3) VALUES(-101,105) /*throws error as the row with c1=-101 exists */; + +# Insert duplicate value to clustered pk, throws error +--error ER_DUP_ENTRY +INSERT INTO t2(c1,c6) VALUES(101,106) /*throws error as the row with c1=101,c6=106 exists */; +--error ER_DUP_ENTRY +INSERT INTO t5(c1,c2,c3) VALUES(101,-102,4) /*throws error as the row with c1=101,c2=-102 exists */; + +# Insert duplicate value to unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t5(c3) VALUES(-103) /*throws error as the row with c3=-103 exists */; +--error ER_DUP_ENTRY +# Insert duplicate value to clustered unique column, throws error +INSERT INTO t4(c2,c3) VALUES(102,103) /*throws error as the row with c2=102,c3=103 exists */; + +# Test 'INSERT INTO SELECT FROM' +CREATE TABLE t6(c1 SMALLINT UNSIGNED NOT NULL, c2 SMALLINT NULL, c3 TINYINT, c4 MEDIUMINT , c5 INT, c6 INTEGER, c7 BIGINT); +INSERT INTO t6 SELECT * FROM t2 where c1 >= 109; +--sorted_result +SELECT * FROM t6; +TRUNCATE TABLE t6; +INSERT INTO t6 SELECT * FROM t3 where c2 <= -116; +--sorted_result +SELECT * FROM t6; +TRUNCATE TABLE t6; +# Test 'INSERT INTO SELECT FROM' primary key constraint violation +CREATE TABLE t7(c1 SMALLINT UNSIGNED NOT NULL PRIMARY KEY, c2 SMALLINT NULL, c3 TINYINT, c4 MEDIUMINT , c5 INT, c6 INTEGER, c7 BIGINT); +CREATE TABLE t8(c1 SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 SMALLINT NULL, c3 TINYINT, c4 MEDIUMINT , c5 INT, c6 INTEGER, c7 BIGINT); +INSERT INTO t6 VALUES(1,-2,2,2,2,2,2),(1,-3,3,3,3,3,3); +INSERT INTO t7(c1) SELECT t6.c1 FROM t6 LIMIT 1; +--sorted_result +SELECT * FROM t7; +INSERT INTO t8(c1) SELECT t6.c1 FROM t6 LIMIT 1; +--sorted_result +SELECT * FROM t8; +--error ER_DUP_ENTRY +INSERT INTO t7(c1) SELECT t6.c1 FROM t6 /* throws error as t6 contains duplicate rows for c1=1 */; +--error ER_DUP_ENTRY +INSERT INTO t8(c1) SELECT t6.c1 FROM t6 /* throws error as t6 contains duplicate rows for c1=1 */; +TRUNCATE TABLE t6; + +# Test 'INSERT INTO SELECT FROM' with AUTO_INCREMENT and inserting 0,NULL +INSERT INTO t6 VALUES(5,-1,1,1,1,1,1),(6,-2,2,2,2,2,2),(0,-4,4,4,4,4,4),(NULL,-5,5,5,5,5,5); +INSERT INTO t8 SELECT * FROM t6; +SELECT LAST_INSERT_ID() AS last_insert_id; +--sorted_result +SELECT * FROM t8; +TRUNCATE TABLE t8; +INSERT INTO t8(c2) SELECT c2 FROM t6 WHERE c1 >= 6; +--sorted_result +SELECT * FROM t8; +DROP TABLE t6,t7,t8; + +# Test 'INSERT SET' +INSERT INTO t2 SET c3=5,c4=6; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_NO_DEFAULT_FOR_FIELD +INSERT INTO t2 SET c3=5,c4=6; +SET SQL_MODE=''; + +# Test insert allowable bigger values to 'SMALLINT' columns +INSERT INTO t1 VALUES(0,-32768,1,2,3,4,5),(255,-128,6,7,8,9,10),(65535,32767,11,12,13,14,15); +INSERT INTO t2 VALUES(0,-32768,1,2,3,4,5),(255,-128,6,7,8,9,10),(65535,32767,11,12,13,14,15); +INSERT INTO t3 VALUES(0,-32768,1,2,3,4,5),(255,-128,6,7,8,9,10),(65535,32767,11,12,13,14,15); +INSERT INTO t4 VALUES(-32768,0,1,2,3,4,5,5),(-128,255,6,7,8,9,10,10),(32767,65535,11,12,13,14,15,15); +INSERT INTO t5 VALUES(0,-32768,1,2,3,4,5,5),(255,-128,6,7,8,9,10,10),(65535,32767,11,12,13,14,15,15); +--error 167 +INSERT INTO t4(c2,c3) VALUES(31,32) /* tries to increment out of range */; +--error 167 +INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */; +--sorted_result +SELECT * FROM t4; + +# Insert signed value to unsigned 'SMALLINT', outside range values to signed/unsigned columns +INSERT INTO t1 VALUES(-255,-32769,26,27,28,29,30),(65536,32768,31,32,33,34,35); +INSERT INTO t2 VALUES(-255,-32769,26,27,28,29,30),(65536,32768,31,32,33,34,35); +INSERT INTO t3 VALUES(-255,-32769,26,27,28,29,30),(65536,32768,31,32,33,34,35); +# Insert into t4, t5 (TBD) + +# Now select using various table access methods +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = -32768; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 65535 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 65535 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,65535) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,65535) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 65535 AND c6 = 9 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 65535 AND c6 = 9 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 65535 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 65535 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,65535) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,65535) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 65535 AND c6 = 9 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 65535 AND c6 = 9 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 32767; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 65535 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 65535 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 65535 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 65535 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 65535 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 65535 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 65535 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 65535 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 65535 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 65535 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 65535 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 65535 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 65535 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 65535 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 65535 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 65535 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 65535 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 65535 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,65535) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,65535) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 65535 AND c6 = 9 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 65535 AND c6 = 9 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 65535 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 65535 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 65535 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 65535 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 65535 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 65535 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 65535 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 65535 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 65535 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 65535 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 65535 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 65535 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 65535 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 65535 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,65535) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,65535) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 65535 AND c6 = 9 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 65535 AND c6 = 9 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = -32769; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 65536 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 65536 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,65536) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (-255,65536) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 65536 AND c6 = 29 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 65536 AND c6 = 29 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 65536 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 65536 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,65536) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (-255,65536) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 65536 AND c6 = 29 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 65536 AND c6 = 29 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 32768; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 65536 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 65536 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 65536 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 65536 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 65536 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 65536 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 65536 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 65536 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 65536 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 65536 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 65536 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 65536 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 65536 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 65536 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 65536 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 65536 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 65536 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 65536 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,65536) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (-255,65536) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 65536 AND c6 = 29 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 65536 AND c6 = 29 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 65536 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 65536 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 65536 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 65536 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 65536 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 65536 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 65536 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 65536 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 65536 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 65536 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 65536 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 65536 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 65536 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 65536 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,65536) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (-255,65536) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 65536 AND c6 = 29 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 65536 AND c6 = 29 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 0; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -32768 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -32768 AND 32767 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -32768 AND 32767 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-32768,32767) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-32768,32767) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -32768 AND c2 < 32767 AND c7 = 10 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -32768 AND c2 < 32767 AND c7 = 10 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -32768 AND 32767 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -32768 AND 32767 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-32768,32767) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-32768,32767) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -32768 AND c2 < 32767 AND c7 = 10 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -32768 AND c2 < 32767 AND c7 = 10 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 65535; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 32767 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = 32767 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 32767 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = 32767 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 32767 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> 32767 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 32767 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > 32767 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 32767 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= 32767 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 32767 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < 32767 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 32767 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= 32767 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 32767 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> 32767 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -32768 AND 32767 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -32768 AND 32767 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-32768,32767) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-32768,32767) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -32768 AND c2 < 32767 AND c7 = 10 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -32768 AND c2 < 32767 AND c7 = 10 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 32767 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> 32767 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 32767 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > 32767 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 32767 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= 32767 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 32767 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < 32767 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 32767 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= 32767 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 32767 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> 32767 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -32768 AND 32767 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -32768 AND 32767 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-32768,32767) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-32768,32767) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -32768 AND c2 < 32767 AND c7 = 10 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -32768 AND c2 < 32767 AND c7 = 10 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = -255; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -32769 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -32769 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -32769 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -32769 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -32769 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -32769 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -32769 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -32769 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -32769 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -32769 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -32769 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -32769 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -32769 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -32769 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -32769 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -32769 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -32769 AND 32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -32769 AND 32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-32769,32768) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-32769,32768) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -32769 AND c2 < 32768 AND c7 = 30 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -32769 AND c2 < 32768 AND c7 = 30 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -32769 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -32769 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -32769 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -32769 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -32769 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -32769 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -32769 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -32769 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -32769 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -32769 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -32769 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -32769 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -32769 AND 32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -32769 AND 32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-32769,32768) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-32769,32768) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -32769 AND c2 < 32768 AND c7 = 30 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -32769 AND c2 < 32768 AND c7 = 30 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 65536; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = 32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = 32768 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> 32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > 32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= 32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < 32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= 32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> 32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -32769 AND 32768 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -32769 AND 32768 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-32769,32768) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-32769,32768) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -32769 AND c2 < 32768 AND c7 = 30 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -32769 AND c2 < 32768 AND c7 = 30 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> 32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > 32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= 32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < 32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= 32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> 32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -32769 AND 32768 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -32769 AND 32768 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-32769,32768) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-32769,32768) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -32769 AND c2 < 32768 AND c7 = 30 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -32769 AND c2 < 32768 AND c7 = 30 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +DROP TABLE t1,t2,t3,t4,t5; + +######## Running INSERT tests for MEDIUMINT ######## + +# Create tables +CREATE TABLE t1(c1 MEDIUMINT UNSIGNED NOT NULL, c2 MEDIUMINT NULL, c3 TINYINT, c4 SMALLINT , c5 INT, c6 INTEGER, c7 BIGINT); +CREATE TABLE t2(c1 MEDIUMINT UNSIGNED NOT NULL, c2 MEDIUMINT NULL, c3 TINYINT, c4 SMALLINT , c5 INT, c6 INTEGER, c7 BIGINT, PRIMARY KEY(c1,c6)); +CREATE TABLE t3(c1 MEDIUMINT UNSIGNED NOT NULL, c2 MEDIUMINT NULL, c3 TINYINT, c4 SMALLINT , c5 INT, c6 INTEGER, c7 BIGINT, index idx(c2,c7)); + +# Insert some rows with targeted values +INSERT INTO t1 VALUES(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); +INSERT INTO t2 VALUES(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); +INSERT INTO t3 VALUES(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); + +# Insert duplicates for parts of the clustered key +INSERT INTO t2 VALUES(108,-109,110,111,112,101,114),(108,-109,110,111,112,102,114),(102,-109,110,111,112,113,114),(103,-109,110,111,112,113,114); +INSERT INTO t3 VALUES(101,-102,103,104,105,106,101),(101,-102,103,104,105,106,102),(101,-103,103,104,105,106,107),(101,-104,103,104,105,106,107); + +# Insert permissible NULLs +INSERT INTO t1 VALUES(105,NULL,102,103,104,105,106); +INSERT INTO t2 VALUES(105,NULL,102,103,104,105,106); +INSERT INTO t3 VALUES(105,NULL,102,103,104,105,106); + +# Insert empty string '' +INSERT INTO t1 VALUES('','',17,18,19,20,21); +INSERT INTO t2 VALUES('','',17,18,19,20,21); +INSERT INTO t3 VALUES('','',17,18,19,20,21); + +# Insert negative value to unsigned integer, positive value to signed integer, zero values +INSERT INTO t1 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t2 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t3 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t1 VALUES(0,124,27,28,29,30,31); +INSERT INTO t2 VALUES(0,124,27,28,29,30,31); +INSERT INTO t3 VALUES(0,124,27,28,29,30,31); +INSERT INTO t1 VALUES(0,0,32,32,34,35,36); +INSERT INTO t2 VALUES(0,0,32,32,34,35,36); +INSERT INTO t3 VALUES(0,0,32,32,34,35,36); + +# Insert non-numeric value to numeric column, would be converted to 0 or numeric value (if contains part) +INSERT INTO t1 VALUES('101.34 a','a',37,38,39,40,41); +INSERT INTO t2 VALUES('101.34 a','a',37,38,39,40,41); +INSERT INTO t3 VALUES('101.34 a','a',37,38,39,40,41); + +--sorted_result +SELECT * FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t1; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t2; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t2; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t3; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t3; + +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 102; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 102; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 108; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 108; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t3 GROUP BY c2; +--sorted_result +SELECT DISTINCT c2 FROM t3; +--sorted_result +SELECT c2,MIN(c7) FROM t3 GROUP BY c2; + +# Create tables with AUTO_INCREMENT columns and unique indexes +CREATE TABLE t4(c1 MEDIUMINT SIGNED NOT NULL AUTO_INCREMENT, c2 MEDIUMINT UNSIGNED NULL, c3 MEDIUMINT UNSIGNED NOT NULL, c4 TINYINT , c5 SMALLINT, c6 INT, c7 INTEGER, c8 BIGINT, PRIMARY KEY(c1), UNIQUE INDEX idx(c2,c3)); +CREATE TABLE t5(c1 MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, c2 MEDIUMINT SIGNED NULL, c3 MEDIUMINT SIGNED NOT NULL, c4 TINYINT, c5 SMALLINT, c6 INT, c7 INTEGER, c8 BIGINT, PRIMARY KEY(c1,c2), UNIQUE INDEX(c3)); + +# Test with AUTO_INCREMENT columns +# Insert some rows +INSERT INTO t4 VALUES(-101,102,103,104,105,106,107,108),(-108,109,110,111,112,113,114,115); +INSERT INTO t5 VALUES(101,-102,-103,-104,105,106,107,108),(108,-109,-110,111,112,113,114,115); +# Insert 0 values, increments the value +INSERT INTO t4 VALUES(0,32,33,34,35,36,37,38); +--let $auto_value=`SELECT LAST_INSERT_ID()=1 AND c1=1 FROM t4 WHERE c2=32 AND c3=33;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on 0" +} +INSERT INTO t5 VALUES(0,-32,-32,33,34,35,36,37); +--let $auto_value=`SELECT LAST_INSERT_ID()=109 AND c1=109 FROM t5 WHERE c2=-32 AND c3=-32;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on 0" +} +# Insert NULL, no error, increments the value +INSERT INTO t4(c1,c3,c4) VALUES(NULL,104,LAST_INSERT_ID()); +--let $auto_value=`SELECT LAST_INSERT_ID()=2 AND c1=2 FROM t4 WHERE c3=104;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on NULL" +} +INSERT INTO t5(c1,c3,c4) VALUES(NULL,-104,LAST_INSERT_ID()); +--let $auto_value=`SELECT LAST_INSERT_ID()=110 AND c1=110 FROM t5 WHERE c3=-104;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on NULL" +} +# Insert empty strings, increments the value +INSERT INTO t4 VALUES('','',17,18,19,20,21,22); +--let $auto_value=`SELECT LAST_INSERT_ID()=3 AND c1=3 FROM t4 WHERE c2=0 AND c3=17;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on ''" +} +INSERT INTO t5 VALUES('','',-17,18,19,20,21,22); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=111 FROM t5 WHERE c2=0 AND c3=-17;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on ''" +} +# Insert strings with numeric part, inserts the numeric part of the string +INSERT INTO t4 VALUES('102.34 a','a','a',37,38,39,40,41); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=102 FROM t4 WHERE c2=0 AND c3=0;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on invalid strings with numeric part" +} +INSERT INTO t5 VALUES('102.34 a','a','a',37,38,39,40,41); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=102 FROM t5 WHERE c2=0 AND c3=0;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on invalid strings with numeric part" +} +# Insert negative values unsigned & positive value to signed +INSERT INTO t4 VALUES(4,7,8,9,10,11,12,13); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=4 FROM t4 WHERE c2=7 AND c3=8;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work on negative value" +} +INSERT INTO t5 VALUES(-1,-1,-1,8,9,10,11,12); +--let $auto_value=`SELECT LAST_INSERT_ID()=112 AND c1=112 FROM t5 WHERE c2=-1 AND c3=-1;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work for negative value on unsigned" +} +# Insert some rows with no values assigned to AUTO_INCREMENT columns, increments value +INSERT INTO t4(c2,c3,c4,c5,c6,c7,c8) VALUES(101,102,104,105,106,107,108),(108,109,111,112,113,114,115),(115,116,118,119,120,121,122),(122,123,125,126,127,128,128); +--let $auto_value=`SELECT LAST_INSERT_ID()=103 AND c1=103 FROM t4 WHERE c2=101 AND c3=102;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well" +} +INSERT INTO t5(c2,c3,c4,c5,c6,c7,c8) VALUES(-101,-102,104,105,106,107,108),(-108,-109,111,112,113,114,115),(-115,-116,118,119,120,121,122),(-122,-123,125,126,127,128,128); +--let $auto_value=`SELECT LAST_INSERT_ID()=113 AND c1=113 FROM t5 WHERE c2=-101 AND c3=-102;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well" +} + +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t4; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t5; +# Now select using various table access methods on auto-incremented pk value(full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t4; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t4; +--sorted_result +SELECT * FROM t4 WHERE c4 = 104; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t4; + +## Backward index scan, covering ## +SELECT c1 FROM t4 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t4; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t4; +--sorted_result +SELECT * FROM t4 WHERE c4 = 104; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t4; + +## Backward index scan, covering ## +SELECT c1 FROM t4 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT * FROM t5 WHERE c5 = 112; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t5; + +## Backward index scan, covering ## +SELECT c1 FROM t5 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; + +# Index-merge access +--sorted_result +SELECT * FROM t4 WHERE c1=1 OR c2=109; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t4 GROUP BY c2; +--sorted_result +SELECT DISTINCT c2 FROM t4; +--sorted_result +SELECT c2,MIN(c3) FROM t4 GROUP BY c2; + +# Test Error conditions- NULL into not null col, PK constraint violation, Unique constraint violation + +# Insert NULL to non-null column +--error ER_BAD_NULL_ERROR +INSERT INTO t2(c1) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t3 VALUES(NULL,1,2,3,4,5,6); +--error ER_BAD_NULL_ERROR +INSERT INTO t4(c3) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t5(c3) VALUES(NULL); + +# Insert duplicate value to pk +--error ER_DUP_ENTRY +INSERT INTO t4(c1,c3) VALUES(-101,105) /*throws error as the row with c1=-101 exists */; + +# Insert duplicate value to clustered pk, throws error +--error ER_DUP_ENTRY +INSERT INTO t2(c1,c6) VALUES(101,106) /*throws error as the row with c1=101,c6=106 exists */; +--error ER_DUP_ENTRY +INSERT INTO t5(c1,c2,c3) VALUES(101,-102,4) /*throws error as the row with c1=101,c2=-102 exists */; + +# Insert duplicate value to unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t5(c3) VALUES(-103) /*throws error as the row with c3=-103 exists */; +--error ER_DUP_ENTRY +# Insert duplicate value to clustered unique column, throws error +INSERT INTO t4(c2,c3) VALUES(102,103) /*throws error as the row with c2=102,c3=103 exists */; + +# Test 'INSERT INTO SELECT FROM' +CREATE TABLE t6(c1 MEDIUMINT UNSIGNED NOT NULL, c2 MEDIUMINT NULL, c3 TINYINT, c4 SMALLINT , c5 INT, c6 INTEGER, c7 BIGINT); +INSERT INTO t6 SELECT * FROM t2 where c1 >= 109; +--sorted_result +SELECT * FROM t6; +TRUNCATE TABLE t6; +INSERT INTO t6 SELECT * FROM t3 where c2 <= -116; +--sorted_result +SELECT * FROM t6; +TRUNCATE TABLE t6; +# Test 'INSERT INTO SELECT FROM' primary key constraint violation +CREATE TABLE t7(c1 MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY, c2 MEDIUMINT NULL, c3 TINYINT, c4 SMALLINT , c5 INT, c6 INTEGER, c7 BIGINT); +CREATE TABLE t8(c1 MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 MEDIUMINT NULL, c3 TINYINT, c4 SMALLINT , c5 INT, c6 INTEGER, c7 BIGINT); +INSERT INTO t6 VALUES(1,-2,2,2,2,2,2),(1,-3,3,3,3,3,3); +INSERT INTO t7(c1) SELECT t6.c1 FROM t6 LIMIT 1; +--sorted_result +SELECT * FROM t7; +INSERT INTO t8(c1) SELECT t6.c1 FROM t6 LIMIT 1; +--sorted_result +SELECT * FROM t8; +--error ER_DUP_ENTRY +INSERT INTO t7(c1) SELECT t6.c1 FROM t6 /* throws error as t6 contains duplicate rows for c1=1 */; +--error ER_DUP_ENTRY +INSERT INTO t8(c1) SELECT t6.c1 FROM t6 /* throws error as t6 contains duplicate rows for c1=1 */; +TRUNCATE TABLE t6; + +# Test 'INSERT INTO SELECT FROM' with AUTO_INCREMENT and inserting 0,NULL +INSERT INTO t6 VALUES(5,-1,1,1,1,1,1),(6,-2,2,2,2,2,2),(0,-4,4,4,4,4,4),(NULL,-5,5,5,5,5,5); +INSERT INTO t8 SELECT * FROM t6; +SELECT LAST_INSERT_ID() AS last_insert_id; +--sorted_result +SELECT * FROM t8; +TRUNCATE TABLE t8; +INSERT INTO t8(c2) SELECT c2 FROM t6 WHERE c1 >= 6; +--sorted_result +SELECT * FROM t8; +DROP TABLE t6,t7,t8; + +# Test 'INSERT SET' +INSERT INTO t2 SET c3=5,c4=6; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_NO_DEFAULT_FOR_FIELD +INSERT INTO t2 SET c3=5,c4=6; +SET SQL_MODE=''; + +# Test insert allowable bigger values to 'MEDIUMINT' columns +INSERT INTO t1 VALUES(0,-8388608,1,2,3,4,5),(255,-32768,6,7,8,9,10),(65535,-128,11,12,13,14,15),(16777215,8388607,16,17,18,19,20); +INSERT INTO t2 VALUES(0,-8388608,1,2,3,4,5),(255,-32768,6,7,8,9,10),(65535,-128,11,12,13,14,15),(16777215,8388607,16,17,18,19,20); +INSERT INTO t3 VALUES(0,-8388608,1,2,3,4,5),(255,-32768,6,7,8,9,10),(65535,-128,11,12,13,14,15),(16777215,8388607,16,17,18,19,20); +INSERT INTO t4 VALUES(-8388608,0,1,2,3,4,5,5),(-32768,255,6,7,8,9,10,10),(-128,65535,11,12,13,14,15,15),(8388607,16777215,16,17,18,19,20,20); +INSERT INTO t5 VALUES(0,-8388608,1,2,3,4,5,5),(255,-32768,6,7,8,9,10,10),(65535,-128,11,12,13,14,15,15),(16777215,8388607,16,17,18,19,20,20); +--error 167 +INSERT INTO t4(c2,c3) VALUES(31,32) /* tries to increment out of range */; +--error 167 +INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */; +--sorted_result +SELECT * FROM t4; + +# Insert signed value to unsigned 'MEDIUMINT', outside range values to signed/unsigned columns +INSERT INTO t1 VALUES(-255,-8388609,26,27,28,29,30),(16777216,8388608,31,32,33,34,35); +INSERT INTO t2 VALUES(-255,-8388609,26,27,28,29,30),(16777216,8388608,31,32,33,34,35); +INSERT INTO t3 VALUES(-255,-8388609,26,27,28,29,30),(16777216,8388608,31,32,33,34,35); +# Insert into t4, t5 (TBD) + +# Now select using various table access methods +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = -8388608; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 16777215 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 16777215 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,16777215) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,16777215) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 16777215 AND c6 = 9 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 16777215 AND c6 = 9 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 16777215 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 16777215 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,16777215) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,16777215) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 16777215 AND c6 = 9 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 16777215 AND c6 = 9 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 8388607; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 16777215 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 16777215 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 16777215 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 16777215 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 16777215 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 16777215 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 16777215 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 16777215 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 16777215 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 16777215 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 16777215 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 16777215 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 16777215 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 16777215 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 16777215 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 16777215 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 16777215 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 16777215 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,16777215) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,16777215) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 16777215 AND c6 = 9 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 16777215 AND c6 = 9 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 16777215 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 16777215 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 16777215 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 16777215 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 16777215 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 16777215 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 16777215 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 16777215 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 16777215 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 16777215 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 16777215 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 16777215 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 16777215 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 16777215 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,16777215) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,16777215) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 16777215 AND c6 = 9 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 16777215 AND c6 = 9 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = -8388609; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 16777216 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 16777216 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,16777216) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (-255,16777216) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 16777216 AND c6 = 29 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 16777216 AND c6 = 29 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 16777216 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 16777216 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,16777216) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (-255,16777216) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 16777216 AND c6 = 29 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 16777216 AND c6 = 29 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 8388608; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 16777216 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 16777216 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 16777216 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 16777216 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 16777216 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 16777216 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 16777216 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 16777216 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 16777216 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 16777216 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 16777216 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 16777216 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 16777216 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 16777216 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 16777216 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 16777216 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 16777216 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 16777216 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,16777216) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (-255,16777216) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 16777216 AND c6 = 29 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 16777216 AND c6 = 29 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 16777216 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 16777216 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 16777216 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 16777216 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 16777216 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 16777216 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 16777216 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 16777216 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 16777216 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 16777216 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 16777216 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 16777216 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 16777216 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 16777216 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,16777216) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (-255,16777216) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 16777216 AND c6 = 29 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 16777216 AND c6 = 29 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 0; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -8388608 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -8388608 AND 8388607 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -8388608 AND 8388607 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-8388608,8388607) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-8388608,8388607) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -8388608 AND c2 < 8388607 AND c7 = 15 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -8388608 AND c2 < 8388607 AND c7 = 15 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -8388608 AND 8388607 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -8388608 AND 8388607 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-8388608,8388607) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-8388608,8388607) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -8388608 AND c2 < 8388607 AND c7 = 15 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -8388608 AND c2 < 8388607 AND c7 = 15 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 16777215; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 8388607 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = 8388607 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 8388607 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = 8388607 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 8388607 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> 8388607 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 8388607 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > 8388607 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 8388607 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= 8388607 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 8388607 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < 8388607 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 8388607 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= 8388607 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 8388607 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> 8388607 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -8388608 AND 8388607 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -8388608 AND 8388607 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-8388608,8388607) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-8388608,8388607) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -8388608 AND c2 < 8388607 AND c7 = 15 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -8388608 AND c2 < 8388607 AND c7 = 15 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 8388607 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> 8388607 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 8388607 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > 8388607 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 8388607 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= 8388607 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 8388607 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < 8388607 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 8388607 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= 8388607 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 8388607 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> 8388607 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -8388608 AND 8388607 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -8388608 AND 8388607 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-8388608,8388607) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-8388608,8388607) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -8388608 AND c2 < 8388607 AND c7 = 15 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -8388608 AND c2 < 8388607 AND c7 = 15 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = -255; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -8388609 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -8388609 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -8388609 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -8388609 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -8388609 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -8388609 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -8388609 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -8388609 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -8388609 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -8388609 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -8388609 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -8388609 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -8388609 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -8388609 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -8388609 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -8388609 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -8388609 AND 8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -8388609 AND 8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-8388609,8388608) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-8388609,8388608) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -8388609 AND c2 < 8388608 AND c7 = 30 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -8388609 AND c2 < 8388608 AND c7 = 30 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -8388609 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -8388609 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -8388609 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -8388609 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -8388609 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -8388609 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -8388609 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -8388609 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -8388609 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -8388609 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -8388609 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -8388609 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -8388609 AND 8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -8388609 AND 8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-8388609,8388608) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-8388609,8388608) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -8388609 AND c2 < 8388608 AND c7 = 30 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -8388609 AND c2 < 8388608 AND c7 = 30 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 16777216; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = 8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = 8388608 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> 8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > 8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= 8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < 8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= 8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> 8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -8388609 AND 8388608 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -8388609 AND 8388608 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-8388609,8388608) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-8388609,8388608) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -8388609 AND c2 < 8388608 AND c7 = 30 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -8388609 AND c2 < 8388608 AND c7 = 30 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> 8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > 8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= 8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < 8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= 8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> 8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -8388609 AND 8388608 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -8388609 AND 8388608 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-8388609,8388608) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-8388609,8388608) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -8388609 AND c2 < 8388608 AND c7 = 30 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -8388609 AND c2 < 8388608 AND c7 = 30 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +DROP TABLE t1,t2,t3,t4,t5; + +######## Running INSERT tests for INT ######## + +# Create tables +CREATE TABLE t1(c1 INT UNSIGNED NOT NULL, c2 INT NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INTEGER, c7 BIGINT); +CREATE TABLE t2(c1 INT UNSIGNED NOT NULL, c2 INT NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INTEGER, c7 BIGINT, PRIMARY KEY(c1,c6)); +CREATE TABLE t3(c1 INT UNSIGNED NOT NULL, c2 INT NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INTEGER, c7 BIGINT, index idx(c2,c7)); + +# Insert some rows with targeted values +INSERT INTO t1 VALUES(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); +INSERT INTO t2 VALUES(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); +INSERT INTO t3 VALUES(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); + +# Insert duplicates for parts of the clustered key +INSERT INTO t2 VALUES(108,-109,110,111,112,101,114),(108,-109,110,111,112,102,114),(102,-109,110,111,112,113,114),(103,-109,110,111,112,113,114); +INSERT INTO t3 VALUES(101,-102,103,104,105,106,101),(101,-102,103,104,105,106,102),(101,-103,103,104,105,106,107),(101,-104,103,104,105,106,107); + +# Insert permissible NULLs +INSERT INTO t1 VALUES(105,NULL,102,103,104,105,106); +INSERT INTO t2 VALUES(105,NULL,102,103,104,105,106); +INSERT INTO t3 VALUES(105,NULL,102,103,104,105,106); + +# Insert empty string '' +INSERT INTO t1 VALUES('','',17,18,19,20,21); +INSERT INTO t2 VALUES('','',17,18,19,20,21); +INSERT INTO t3 VALUES('','',17,18,19,20,21); + +# Insert negative value to unsigned integer, positive value to signed integer, zero values +INSERT INTO t1 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t2 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t3 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t1 VALUES(0,124,27,28,29,30,31); +INSERT INTO t2 VALUES(0,124,27,28,29,30,31); +INSERT INTO t3 VALUES(0,124,27,28,29,30,31); +INSERT INTO t1 VALUES(0,0,32,32,34,35,36); +INSERT INTO t2 VALUES(0,0,32,32,34,35,36); +INSERT INTO t3 VALUES(0,0,32,32,34,35,36); + +# Insert non-numeric value to numeric column, would be converted to 0 or numeric value (if contains part) +INSERT INTO t1 VALUES('101.34 a','a',37,38,39,40,41); +INSERT INTO t2 VALUES('101.34 a','a',37,38,39,40,41); +INSERT INTO t3 VALUES('101.34 a','a',37,38,39,40,41); + +--sorted_result +SELECT * FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t1; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t2; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t2; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t3; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t3; + +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 102; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 102; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 108; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 108; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t3 GROUP BY c2; +--sorted_result +SELECT DISTINCT c2 FROM t3; +--sorted_result +SELECT c2,MIN(c7) FROM t3 GROUP BY c2; + +# Create tables with AUTO_INCREMENT columns and unique indexes +CREATE TABLE t4(c1 INT SIGNED NOT NULL AUTO_INCREMENT, c2 INT UNSIGNED NULL, c3 INT UNSIGNED NOT NULL, c4 TINYINT , c5 SMALLINT, c6 MEDIUMINT, c7 INTEGER, c8 BIGINT, PRIMARY KEY(c1), UNIQUE INDEX idx(c2,c3)); +CREATE TABLE t5(c1 INT UNSIGNED NOT NULL AUTO_INCREMENT, c2 INT SIGNED NULL, c3 INT SIGNED NOT NULL, c4 TINYINT, c5 SMALLINT, c6 MEDIUMINT, c7 INTEGER, c8 BIGINT, PRIMARY KEY(c1,c2), UNIQUE INDEX(c3)); + +# Test with AUTO_INCREMENT columns +# Insert some rows +INSERT INTO t4 VALUES(-101,102,103,104,105,106,107,108),(-108,109,110,111,112,113,114,115); +INSERT INTO t5 VALUES(101,-102,-103,-104,105,106,107,108),(108,-109,-110,111,112,113,114,115); +# Insert 0 values, increments the value +INSERT INTO t4 VALUES(0,32,33,34,35,36,37,38); +--let $auto_value=`SELECT LAST_INSERT_ID()=1 AND c1=1 FROM t4 WHERE c2=32 AND c3=33;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on 0" +} +INSERT INTO t5 VALUES(0,-32,-32,33,34,35,36,37); +--let $auto_value=`SELECT LAST_INSERT_ID()=109 AND c1=109 FROM t5 WHERE c2=-32 AND c3=-32;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on 0" +} +# Insert NULL, no error, increments the value +INSERT INTO t4(c1,c3,c4) VALUES(NULL,104,LAST_INSERT_ID()); +--let $auto_value=`SELECT LAST_INSERT_ID()=2 AND c1=2 FROM t4 WHERE c3=104;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on NULL" +} +INSERT INTO t5(c1,c3,c4) VALUES(NULL,-104,LAST_INSERT_ID()); +--let $auto_value=`SELECT LAST_INSERT_ID()=110 AND c1=110 FROM t5 WHERE c3=-104;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on NULL" +} +# Insert empty strings, increments the value +INSERT INTO t4 VALUES('','',17,18,19,20,21,22); +--let $auto_value=`SELECT LAST_INSERT_ID()=3 AND c1=3 FROM t4 WHERE c2=0 AND c3=17;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on ''" +} +INSERT INTO t5 VALUES('','',-17,18,19,20,21,22); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=111 FROM t5 WHERE c2=0 AND c3=-17;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on ''" +} +# Insert strings with numeric part, inserts the numeric part of the string +INSERT INTO t4 VALUES('102.34 a','a','a',37,38,39,40,41); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=102 FROM t4 WHERE c2=0 AND c3=0;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on invalid strings with numeric part" +} +INSERT INTO t5 VALUES('102.34 a','a','a',37,38,39,40,41); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=102 FROM t5 WHERE c2=0 AND c3=0;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on invalid strings with numeric part" +} +# Insert negative values unsigned & positive value to signed +INSERT INTO t4 VALUES(4,7,8,9,10,11,12,13); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=4 FROM t4 WHERE c2=7 AND c3=8;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work on negative value" +} +INSERT INTO t5 VALUES(-1,-1,-1,8,9,10,11,12); +--let $auto_value=`SELECT LAST_INSERT_ID()=112 AND c1=112 FROM t5 WHERE c2=-1 AND c3=-1;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work for negative value on unsigned" +} +# Insert some rows with no values assigned to AUTO_INCREMENT columns, increments value +INSERT INTO t4(c2,c3,c4,c5,c6,c7,c8) VALUES(101,102,104,105,106,107,108),(108,109,111,112,113,114,115),(115,116,118,119,120,121,122),(122,123,125,126,127,128,128); +--let $auto_value=`SELECT LAST_INSERT_ID()=103 AND c1=103 FROM t4 WHERE c2=101 AND c3=102;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well" +} +INSERT INTO t5(c2,c3,c4,c5,c6,c7,c8) VALUES(-101,-102,104,105,106,107,108),(-108,-109,111,112,113,114,115),(-115,-116,118,119,120,121,122),(-122,-123,125,126,127,128,128); +--let $auto_value=`SELECT LAST_INSERT_ID()=113 AND c1=113 FROM t5 WHERE c2=-101 AND c3=-102;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well" +} + +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t4; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t5; +# Now select using various table access methods on auto-incremented pk value(full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t4; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t4; +--sorted_result +SELECT * FROM t4 WHERE c4 = 104; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t4; + +## Backward index scan, covering ## +SELECT c1 FROM t4 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t4; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t4; +--sorted_result +SELECT * FROM t4 WHERE c4 = 104; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t4; + +## Backward index scan, covering ## +SELECT c1 FROM t4 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT * FROM t5 WHERE c5 = 112; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t5; + +## Backward index scan, covering ## +SELECT c1 FROM t5 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; + +# Index-merge access +--sorted_result +SELECT * FROM t4 WHERE c1=1 OR c2=109; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t4 GROUP BY c2; +--sorted_result +SELECT DISTINCT c2 FROM t4; +--sorted_result +SELECT c2,MIN(c3) FROM t4 GROUP BY c2; + +# Test Error conditions- NULL into not null col, PK constraint violation, Unique constraint violation + +# Insert NULL to non-null column +--error ER_BAD_NULL_ERROR +INSERT INTO t2(c1) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t3 VALUES(NULL,1,2,3,4,5,6); +--error ER_BAD_NULL_ERROR +INSERT INTO t4(c3) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t5(c3) VALUES(NULL); + +# Insert duplicate value to pk +--error ER_DUP_ENTRY +INSERT INTO t4(c1,c3) VALUES(-101,105) /*throws error as the row with c1=-101 exists */; + +# Insert duplicate value to clustered pk, throws error +--error ER_DUP_ENTRY +INSERT INTO t2(c1,c6) VALUES(101,106) /*throws error as the row with c1=101,c6=106 exists */; +--error ER_DUP_ENTRY +INSERT INTO t5(c1,c2,c3) VALUES(101,-102,4) /*throws error as the row with c1=101,c2=-102 exists */; + +# Insert duplicate value to unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t5(c3) VALUES(-103) /*throws error as the row with c3=-103 exists */; +--error ER_DUP_ENTRY +# Insert duplicate value to clustered unique column, throws error +INSERT INTO t4(c2,c3) VALUES(102,103) /*throws error as the row with c2=102,c3=103 exists */; + +# Test 'INSERT INTO SELECT FROM' +CREATE TABLE t6(c1 INT UNSIGNED NOT NULL, c2 INT NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INTEGER, c7 BIGINT); +INSERT INTO t6 SELECT * FROM t2 where c1 >= 109; +--sorted_result +SELECT * FROM t6; +TRUNCATE TABLE t6; +INSERT INTO t6 SELECT * FROM t3 where c2 <= -116; +--sorted_result +SELECT * FROM t6; +TRUNCATE TABLE t6; +# Test 'INSERT INTO SELECT FROM' primary key constraint violation +CREATE TABLE t7(c1 INT UNSIGNED NOT NULL PRIMARY KEY, c2 INT NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INTEGER, c7 BIGINT); +CREATE TABLE t8(c1 INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 INT NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INTEGER, c7 BIGINT); +INSERT INTO t6 VALUES(1,-2,2,2,2,2,2),(1,-3,3,3,3,3,3); +INSERT INTO t7(c1) SELECT t6.c1 FROM t6 LIMIT 1; +--sorted_result +SELECT * FROM t7; +INSERT INTO t8(c1) SELECT t6.c1 FROM t6 LIMIT 1; +--sorted_result +SELECT * FROM t8; +--error ER_DUP_ENTRY +INSERT INTO t7(c1) SELECT t6.c1 FROM t6 /* throws error as t6 contains duplicate rows for c1=1 */; +--error ER_DUP_ENTRY +INSERT INTO t8(c1) SELECT t6.c1 FROM t6 /* throws error as t6 contains duplicate rows for c1=1 */; +TRUNCATE TABLE t6; + +# Test 'INSERT INTO SELECT FROM' with AUTO_INCREMENT and inserting 0,NULL +INSERT INTO t6 VALUES(5,-1,1,1,1,1,1),(6,-2,2,2,2,2,2),(0,-4,4,4,4,4,4),(NULL,-5,5,5,5,5,5); +INSERT INTO t8 SELECT * FROM t6; +SELECT LAST_INSERT_ID() AS last_insert_id; +--sorted_result +SELECT * FROM t8; +TRUNCATE TABLE t8; +INSERT INTO t8(c2) SELECT c2 FROM t6 WHERE c1 >= 6; +--sorted_result +SELECT * FROM t8; +DROP TABLE t6,t7,t8; + +# Test 'INSERT SET' +INSERT INTO t2 SET c3=5,c4=6; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_NO_DEFAULT_FOR_FIELD +INSERT INTO t2 SET c3=5,c4=6; +SET SQL_MODE=''; + +# Test insert allowable bigger values to 'INT' columns +INSERT INTO t1 VALUES(0,-2147483648,1,2,3,4,5),(255,-8388608,6,7,8,9,10),(65535,-32768,11,12,13,14,15),(16777215,-128,16,17,18,19,20),(4294967295,2147483647,21,22,23,24,25); +INSERT INTO t2 VALUES(0,-2147483648,1,2,3,4,5),(255,-8388608,6,7,8,9,10),(65535,-32768,11,12,13,14,15),(16777215,-128,16,17,18,19,20),(4294967295,2147483647,21,22,23,24,25); +INSERT INTO t3 VALUES(0,-2147483648,1,2,3,4,5),(255,-8388608,6,7,8,9,10),(65535,-32768,11,12,13,14,15),(16777215,-128,16,17,18,19,20),(4294967295,2147483647,21,22,23,24,25); +INSERT INTO t4 VALUES(-2147483648,0,1,2,3,4,5,5),(-8388608,255,6,7,8,9,10,10),(-32768,65535,11,12,13,14,15,15),(-128,16777215,16,17,18,19,20,20),(2147483647,4294967295,21,22,23,24,25,25); +INSERT INTO t5 VALUES(0,-2147483648,1,2,3,4,5,5),(255,-8388608,6,7,8,9,10,10),(65535,-32768,11,12,13,14,15,15),(16777215,-128,16,17,18,19,20,20),(4294967295,2147483647,21,22,23,24,25,25); +--error 167 +INSERT INTO t4(c2,c3) VALUES(31,32) /* tries to increment out of range */; +--error 167 +INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */; +--sorted_result +SELECT * FROM t4; + +# Insert signed value to unsigned 'INT', outside range values to signed/unsigned columns +INSERT INTO t1 VALUES(-255,-2147483649,26,27,28,29,30),(4294967296,2147483648,31,32,33,34,35); +INSERT INTO t2 VALUES(-255,-2147483649,26,27,28,29,30),(4294967296,2147483648,31,32,33,34,35); +INSERT INTO t3 VALUES(-255,-2147483649,26,27,28,29,30),(4294967296,2147483648,31,32,33,34,35); +# Insert into t4, t5 (TBD) + +# Now select using various table access methods +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = -2147483648; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 2147483647; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 4294967295 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = -2147483649; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 2147483648; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 4294967296 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 0; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -2147483648 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 4294967295; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = 2147483647 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = -255; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -2147483649 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -2147483649 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -2147483649 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -2147483649 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -2147483649 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -2147483649 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -2147483649 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 4294967296; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = 2147483648 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +DROP TABLE t1,t2,t3,t4,t5; + +######## Running INSERT tests for INTEGER ######## + +# Create tables +CREATE TABLE t1(c1 INTEGER UNSIGNED NOT NULL, c2 INTEGER NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 BIGINT); +CREATE TABLE t2(c1 INTEGER UNSIGNED NOT NULL, c2 INTEGER NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 BIGINT, PRIMARY KEY(c1,c6)); +CREATE TABLE t3(c1 INTEGER UNSIGNED NOT NULL, c2 INTEGER NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 BIGINT, index idx(c2,c7)); + +# Insert some rows with targeted values +INSERT INTO t1 VALUES(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); +INSERT INTO t2 VALUES(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); +INSERT INTO t3 VALUES(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); + +# Insert duplicates for parts of the clustered key +INSERT INTO t2 VALUES(108,-109,110,111,112,101,114),(108,-109,110,111,112,102,114),(102,-109,110,111,112,113,114),(103,-109,110,111,112,113,114); +INSERT INTO t3 VALUES(101,-102,103,104,105,106,101),(101,-102,103,104,105,106,102),(101,-103,103,104,105,106,107),(101,-104,103,104,105,106,107); + +# Insert permissible NULLs +INSERT INTO t1 VALUES(105,NULL,102,103,104,105,106); +INSERT INTO t2 VALUES(105,NULL,102,103,104,105,106); +INSERT INTO t3 VALUES(105,NULL,102,103,104,105,106); + +# Insert empty string '' +INSERT INTO t1 VALUES('','',17,18,19,20,21); +INSERT INTO t2 VALUES('','',17,18,19,20,21); +INSERT INTO t3 VALUES('','',17,18,19,20,21); + +# Insert negative value to unsigned integer, positive value to signed integer, zero values +INSERT INTO t1 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t2 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t3 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t1 VALUES(0,124,27,28,29,30,31); +INSERT INTO t2 VALUES(0,124,27,28,29,30,31); +INSERT INTO t3 VALUES(0,124,27,28,29,30,31); +INSERT INTO t1 VALUES(0,0,32,32,34,35,36); +INSERT INTO t2 VALUES(0,0,32,32,34,35,36); +INSERT INTO t3 VALUES(0,0,32,32,34,35,36); + +# Insert non-numeric value to numeric column, would be converted to 0 or numeric value (if contains part) +INSERT INTO t1 VALUES('101.34 a','a',37,38,39,40,41); +INSERT INTO t2 VALUES('101.34 a','a',37,38,39,40,41); +INSERT INTO t3 VALUES('101.34 a','a',37,38,39,40,41); + +--sorted_result +SELECT * FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t1; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t2; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t2; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t3; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t3; + +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 102; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 102; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 108; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 108; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t3 GROUP BY c2; +--sorted_result +SELECT DISTINCT c2 FROM t3; +--sorted_result +SELECT c2,MIN(c7) FROM t3 GROUP BY c2; + +# Create tables with AUTO_INCREMENT columns and unique indexes +CREATE TABLE t4(c1 INTEGER SIGNED NOT NULL AUTO_INCREMENT, c2 INTEGER UNSIGNED NULL, c3 INTEGER UNSIGNED NOT NULL, c4 TINYINT , c5 SMALLINT, c6 MEDIUMINT, c7 INT, c8 BIGINT, PRIMARY KEY(c1), UNIQUE INDEX idx(c2,c3)); +CREATE TABLE t5(c1 INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, c2 INTEGER SIGNED NULL, c3 INTEGER SIGNED NOT NULL, c4 TINYINT, c5 SMALLINT, c6 MEDIUMINT, c7 INT, c8 BIGINT, PRIMARY KEY(c1,c2), UNIQUE INDEX(c3)); + +# Test with AUTO_INCREMENT columns +# Insert some rows +INSERT INTO t4 VALUES(-101,102,103,104,105,106,107,108),(-108,109,110,111,112,113,114,115); +INSERT INTO t5 VALUES(101,-102,-103,-104,105,106,107,108),(108,-109,-110,111,112,113,114,115); +# Insert 0 values, increments the value +INSERT INTO t4 VALUES(0,32,33,34,35,36,37,38); +--let $auto_value=`SELECT LAST_INSERT_ID()=1 AND c1=1 FROM t4 WHERE c2=32 AND c3=33;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on 0" +} +INSERT INTO t5 VALUES(0,-32,-32,33,34,35,36,37); +--let $auto_value=`SELECT LAST_INSERT_ID()=109 AND c1=109 FROM t5 WHERE c2=-32 AND c3=-32;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on 0" +} +# Insert NULL, no error, increments the value +INSERT INTO t4(c1,c3,c4) VALUES(NULL,104,LAST_INSERT_ID()); +--let $auto_value=`SELECT LAST_INSERT_ID()=2 AND c1=2 FROM t4 WHERE c3=104;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on NULL" +} +INSERT INTO t5(c1,c3,c4) VALUES(NULL,-104,LAST_INSERT_ID()); +--let $auto_value=`SELECT LAST_INSERT_ID()=110 AND c1=110 FROM t5 WHERE c3=-104;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on NULL" +} +# Insert empty strings, increments the value +INSERT INTO t4 VALUES('','',17,18,19,20,21,22); +--let $auto_value=`SELECT LAST_INSERT_ID()=3 AND c1=3 FROM t4 WHERE c2=0 AND c3=17;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on ''" +} +INSERT INTO t5 VALUES('','',-17,18,19,20,21,22); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=111 FROM t5 WHERE c2=0 AND c3=-17;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on ''" +} +# Insert strings with numeric part, inserts the numeric part of the string +INSERT INTO t4 VALUES('102.34 a','a','a',37,38,39,40,41); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=102 FROM t4 WHERE c2=0 AND c3=0;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on invalid strings with numeric part" +} +INSERT INTO t5 VALUES('102.34 a','a','a',37,38,39,40,41); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=102 FROM t5 WHERE c2=0 AND c3=0;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on invalid strings with numeric part" +} +# Insert negative values unsigned & positive value to signed +INSERT INTO t4 VALUES(4,7,8,9,10,11,12,13); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=4 FROM t4 WHERE c2=7 AND c3=8;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work on negative value" +} +INSERT INTO t5 VALUES(-1,-1,-1,8,9,10,11,12); +--let $auto_value=`SELECT LAST_INSERT_ID()=112 AND c1=112 FROM t5 WHERE c2=-1 AND c3=-1;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work for negative value on unsigned" +} +# Insert some rows with no values assigned to AUTO_INCREMENT columns, increments value +INSERT INTO t4(c2,c3,c4,c5,c6,c7,c8) VALUES(101,102,104,105,106,107,108),(108,109,111,112,113,114,115),(115,116,118,119,120,121,122),(122,123,125,126,127,128,128); +--let $auto_value=`SELECT LAST_INSERT_ID()=103 AND c1=103 FROM t4 WHERE c2=101 AND c3=102;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well" +} +INSERT INTO t5(c2,c3,c4,c5,c6,c7,c8) VALUES(-101,-102,104,105,106,107,108),(-108,-109,111,112,113,114,115),(-115,-116,118,119,120,121,122),(-122,-123,125,126,127,128,128); +--let $auto_value=`SELECT LAST_INSERT_ID()=113 AND c1=113 FROM t5 WHERE c2=-101 AND c3=-102;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well" +} + +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t4; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t5; +# Now select using various table access methods on auto-incremented pk value(full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t4; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t4; +--sorted_result +SELECT * FROM t4 WHERE c4 = 104; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t4; + +## Backward index scan, covering ## +SELECT c1 FROM t4 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t4; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t4; +--sorted_result +SELECT * FROM t4 WHERE c4 = 104; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t4; + +## Backward index scan, covering ## +SELECT c1 FROM t4 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT * FROM t5 WHERE c5 = 112; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t5; + +## Backward index scan, covering ## +SELECT c1 FROM t5 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; + +# Index-merge access +--sorted_result +SELECT * FROM t4 WHERE c1=1 OR c2=109; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t4 GROUP BY c2; +--sorted_result +SELECT DISTINCT c2 FROM t4; +--sorted_result +SELECT c2,MIN(c3) FROM t4 GROUP BY c2; + +# Test Error conditions- NULL into not null col, PK constraint violation, Unique constraint violation + +# Insert NULL to non-null column +--error ER_BAD_NULL_ERROR +INSERT INTO t2(c1) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t3 VALUES(NULL,1,2,3,4,5,6); +--error ER_BAD_NULL_ERROR +INSERT INTO t4(c3) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t5(c3) VALUES(NULL); + +# Insert duplicate value to pk +--error ER_DUP_ENTRY +INSERT INTO t4(c1,c3) VALUES(-101,105) /*throws error as the row with c1=-101 exists */; + +# Insert duplicate value to clustered pk, throws error +--error ER_DUP_ENTRY +INSERT INTO t2(c1,c6) VALUES(101,106) /*throws error as the row with c1=101,c6=106 exists */; +--error ER_DUP_ENTRY +INSERT INTO t5(c1,c2,c3) VALUES(101,-102,4) /*throws error as the row with c1=101,c2=-102 exists */; + +# Insert duplicate value to unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t5(c3) VALUES(-103) /*throws error as the row with c3=-103 exists */; +--error ER_DUP_ENTRY +# Insert duplicate value to clustered unique column, throws error +INSERT INTO t4(c2,c3) VALUES(102,103) /*throws error as the row with c2=102,c3=103 exists */; + +# Test 'INSERT INTO SELECT FROM' +CREATE TABLE t6(c1 INTEGER UNSIGNED NOT NULL, c2 INTEGER NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 BIGINT); +INSERT INTO t6 SELECT * FROM t2 where c1 >= 109; +--sorted_result +SELECT * FROM t6; +TRUNCATE TABLE t6; +INSERT INTO t6 SELECT * FROM t3 where c2 <= -116; +--sorted_result +SELECT * FROM t6; +TRUNCATE TABLE t6; +# Test 'INSERT INTO SELECT FROM' primary key constraint violation +CREATE TABLE t7(c1 INTEGER UNSIGNED NOT NULL PRIMARY KEY, c2 INTEGER NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 BIGINT); +CREATE TABLE t8(c1 INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 INTEGER NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 BIGINT); +INSERT INTO t6 VALUES(1,-2,2,2,2,2,2),(1,-3,3,3,3,3,3); +INSERT INTO t7(c1) SELECT t6.c1 FROM t6 LIMIT 1; +--sorted_result +SELECT * FROM t7; +INSERT INTO t8(c1) SELECT t6.c1 FROM t6 LIMIT 1; +--sorted_result +SELECT * FROM t8; +--error ER_DUP_ENTRY +INSERT INTO t7(c1) SELECT t6.c1 FROM t6 /* throws error as t6 contains duplicate rows for c1=1 */; +--error ER_DUP_ENTRY +INSERT INTO t8(c1) SELECT t6.c1 FROM t6 /* throws error as t6 contains duplicate rows for c1=1 */; +TRUNCATE TABLE t6; + +# Test 'INSERT INTO SELECT FROM' with AUTO_INCREMENT and inserting 0,NULL +INSERT INTO t6 VALUES(5,-1,1,1,1,1,1),(6,-2,2,2,2,2,2),(0,-4,4,4,4,4,4),(NULL,-5,5,5,5,5,5); +INSERT INTO t8 SELECT * FROM t6; +SELECT LAST_INSERT_ID() AS last_insert_id; +--sorted_result +SELECT * FROM t8; +TRUNCATE TABLE t8; +INSERT INTO t8(c2) SELECT c2 FROM t6 WHERE c1 >= 6; +--sorted_result +SELECT * FROM t8; +DROP TABLE t6,t7,t8; + +# Test 'INSERT SET' +INSERT INTO t2 SET c3=5,c4=6; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_NO_DEFAULT_FOR_FIELD +INSERT INTO t2 SET c3=5,c4=6; +SET SQL_MODE=''; + +# Test insert allowable bigger values to 'INTEGER' columns +INSERT INTO t1 VALUES(0,-2147483648,1,2,3,4,5),(255,-8388608,6,7,8,9,10),(65535,-32768,11,12,13,14,15),(16777215,-128,16,17,18,19,20),(4294967295,2147483647,21,22,23,24,25); +INSERT INTO t2 VALUES(0,-2147483648,1,2,3,4,5),(255,-8388608,6,7,8,9,10),(65535,-32768,11,12,13,14,15),(16777215,-128,16,17,18,19,20),(4294967295,2147483647,21,22,23,24,25); +INSERT INTO t3 VALUES(0,-2147483648,1,2,3,4,5),(255,-8388608,6,7,8,9,10),(65535,-32768,11,12,13,14,15),(16777215,-128,16,17,18,19,20),(4294967295,2147483647,21,22,23,24,25); +INSERT INTO t4 VALUES(-2147483648,0,1,2,3,4,5,5),(-8388608,255,6,7,8,9,10,10),(-32768,65535,11,12,13,14,15,15),(-128,16777215,16,17,18,19,20,20),(2147483647,4294967295,21,22,23,24,25,25); +INSERT INTO t5 VALUES(0,-2147483648,1,2,3,4,5,5),(255,-8388608,6,7,8,9,10,10),(65535,-32768,11,12,13,14,15,15),(16777215,-128,16,17,18,19,20,20),(4294967295,2147483647,21,22,23,24,25,25); +--error 167 +INSERT INTO t4(c2,c3) VALUES(31,32) /* tries to increment out of range */; +--error 167 +INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */; +--sorted_result +SELECT * FROM t4; + +# Insert signed value to unsigned 'INTEGER', outside range values to signed/unsigned columns +INSERT INTO t1 VALUES(-255,-2147483649,26,27,28,29,30),(4294967296,2147483648,31,32,33,34,35); +INSERT INTO t2 VALUES(-255,-2147483649,26,27,28,29,30),(4294967296,2147483648,31,32,33,34,35); +INSERT INTO t3 VALUES(-255,-2147483649,26,27,28,29,30),(4294967296,2147483648,31,32,33,34,35); + +# Now select using various table access methods +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = -2147483648; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 2147483647; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 4294967295 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 4294967295 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,4294967295) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 4294967295 AND c6 = 9 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = -2147483649; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = -255 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> -255 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 2147483648; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 4294967296 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN -255 AND 4294967296 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (-255,4294967296) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -255 AND c1 < 4294967296 AND c6 = 29 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 0; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -2147483648 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 4294967295; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = 2147483647 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483648 AND 2147483647 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-2147483648,2147483647) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -2147483648 AND c2 < 2147483647 AND c7 = 20 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = -255; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -2147483649 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -2147483649 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -2147483649 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -2147483649 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -2147483649 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -2147483649 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -2147483649 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -2147483649 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -2147483649 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -2147483649 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 4294967296; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = 2147483648 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -2147483649 AND 2147483648 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-2147483649,2147483648) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -2147483649 AND c2 < 2147483648 AND c7 = 30 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +DROP TABLE t1,t2,t3,t4,t5; + +######## Running INSERT tests for BIGINT ######## + +# Create tables +CREATE TABLE t1(c1 BIGINT UNSIGNED NOT NULL, c2 BIGINT NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 INTEGER); +CREATE TABLE t2(c1 BIGINT UNSIGNED NOT NULL, c2 BIGINT NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 INTEGER, PRIMARY KEY(c1,c6)); +CREATE TABLE t3(c1 BIGINT UNSIGNED NOT NULL, c2 BIGINT NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 INTEGER, index idx(c2,c7)); + +# Insert some rows with targeted values +INSERT INTO t1 VALUES(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); +INSERT INTO t2 VALUES(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); +INSERT INTO t3 VALUES(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); + +# Insert duplicates for parts of the clustered key +INSERT INTO t2 VALUES(108,-109,110,111,112,101,114),(108,-109,110,111,112,102,114),(102,-109,110,111,112,113,114),(103,-109,110,111,112,113,114); +INSERT INTO t3 VALUES(101,-102,103,104,105,106,101),(101,-102,103,104,105,106,102),(101,-103,103,104,105,106,107),(101,-104,103,104,105,106,107); + +# Insert permissible NULLs +INSERT INTO t1 VALUES(105,NULL,102,103,104,105,106); +INSERT INTO t2 VALUES(105,NULL,102,103,104,105,106); +INSERT INTO t3 VALUES(105,NULL,102,103,104,105,106); + +# Insert empty string '' +INSERT INTO t1 VALUES('','',17,18,19,20,21); +INSERT INTO t2 VALUES('','',17,18,19,20,21); +INSERT INTO t3 VALUES('','',17,18,19,20,21); + +# Insert negative value to unsigned integer, positive value to signed integer, zero values +INSERT INTO t1 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t2 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t3 VALUES(-1,124,22,23,24,25,26); +INSERT INTO t1 VALUES(0,124,27,28,29,30,31); +INSERT INTO t2 VALUES(0,124,27,28,29,30,31); +INSERT INTO t3 VALUES(0,124,27,28,29,30,31); +INSERT INTO t1 VALUES(0,0,32,32,34,35,36); +INSERT INTO t2 VALUES(0,0,32,32,34,35,36); +INSERT INTO t3 VALUES(0,0,32,32,34,35,36); + +# Insert non-numeric value to numeric column, would be converted to 0 or numeric value (if contains part) +INSERT INTO t1 VALUES('101.34 a','a',37,38,39,40,41); +INSERT INTO t2 VALUES('101.34 a','a',37,38,39,40,41); +INSERT INTO t3 VALUES('101.34 a','a',37,38,39,40,41); + +--sorted_result +SELECT * FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t1; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t1; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t2; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t2; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t3; +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) as max_value, sum(c2) as sum, avg(c2) as avg FROM t3; + +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 102; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 108 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 108 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 101 AND 115 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (101,115) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 101 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 102; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 115 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,115) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 115 AND c6 = 113 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 108; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -102 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -102 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -123 AND 0 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-123,0) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -123 AND c2 < 0 AND c7 = 121 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 108; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND -123 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (NULL,-123) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < -123 AND c7 = 121 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t3 GROUP BY c2; +--sorted_result +SELECT DISTINCT c2 FROM t3; +--sorted_result +SELECT c2,MIN(c7) FROM t3 GROUP BY c2; + +# Create tables with AUTO_INCREMENT columns and unique indexes +CREATE TABLE t4(c1 BIGINT SIGNED NOT NULL AUTO_INCREMENT, c2 BIGINT UNSIGNED NULL, c3 BIGINT UNSIGNED NOT NULL, c4 TINYINT , c5 SMALLINT, c6 MEDIUMINT, c7 INT, c8 INTEGER, PRIMARY KEY(c1), UNIQUE INDEX idx(c2,c3)); +CREATE TABLE t5(c1 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, c2 BIGINT SIGNED NULL, c3 BIGINT SIGNED NOT NULL, c4 TINYINT, c5 SMALLINT, c6 MEDIUMINT, c7 INT, c8 INTEGER, PRIMARY KEY(c1,c2), UNIQUE INDEX(c3)); + +# Test with AUTO_INCREMENT columns +# Insert some rows +INSERT INTO t4 VALUES(-101,102,103,104,105,106,107,108),(-108,109,110,111,112,113,114,115); +INSERT INTO t5 VALUES(101,-102,-103,-104,105,106,107,108),(108,-109,-110,111,112,113,114,115); +# Insert 0 values, increments the value +INSERT INTO t4 VALUES(0,32,33,34,35,36,37,38); +--let $auto_value=`SELECT LAST_INSERT_ID()=1 AND c1=1 FROM t4 WHERE c2=32 AND c3=33;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on 0" +} +INSERT INTO t5 VALUES(0,-32,-32,33,34,35,36,37); +--let $auto_value=`SELECT LAST_INSERT_ID()=109 AND c1=109 FROM t5 WHERE c2=-32 AND c3=-32;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on 0" +} +# Insert NULL, no error, increments the value +INSERT INTO t4(c1,c3,c4) VALUES(NULL,104,LAST_INSERT_ID()); +--let $auto_value=`SELECT LAST_INSERT_ID()=2 AND c1=2 FROM t4 WHERE c3=104;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on NULL" +} +INSERT INTO t5(c1,c3,c4) VALUES(NULL,-104,LAST_INSERT_ID()); +--let $auto_value=`SELECT LAST_INSERT_ID()=110 AND c1=110 FROM t5 WHERE c3=-104;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on NULL" +} +# Insert empty strings, increments the value +INSERT INTO t4 VALUES('','',17,18,19,20,21,22); +--let $auto_value=`SELECT LAST_INSERT_ID()=3 AND c1=3 FROM t4 WHERE c2=0 AND c3=17;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on ''" +} +INSERT INTO t5 VALUES('','',-17,18,19,20,21,22); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=111 FROM t5 WHERE c2=0 AND c3=-17;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on ''" +} +# Insert strings with numeric part, inserts the numeric part of the string +INSERT INTO t4 VALUES('102.34 a','a','a',37,38,39,40,41); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=102 FROM t4 WHERE c2=0 AND c3=0;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on invalid strings with numeric part" +} +INSERT INTO t5 VALUES('102.34 a','a','a',37,38,39,40,41); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=102 FROM t5 WHERE c2=0 AND c3=0;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well on invalid strings with numeric part" +} +# Insert negative values unsigned & positive value to signed +INSERT INTO t4 VALUES(4,7,8,9,10,11,12,13); +--let $auto_value=`SELECT LAST_INSERT_ID()=111 AND c1=4 FROM t4 WHERE c2=7 AND c3=8;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work on negative value" +} +INSERT INTO t5 VALUES(-1,-1,-1,8,9,10,11,12); +--let $auto_value=`SELECT LAST_INSERT_ID()=112 AND c1=112 FROM t5 WHERE c2=-1 AND c3=-1;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work for negative value on unsigned" +} +# Insert some rows with no values assigned to AUTO_INCREMENT columns, increments value +INSERT INTO t4(c2,c3,c4,c5,c6,c7,c8) VALUES(101,102,104,105,106,107,108),(108,109,111,112,113,114,115),(115,116,118,119,120,121,122),(122,123,125,126,127,128,128); +--let $auto_value=`SELECT LAST_INSERT_ID()=103 AND c1=103 FROM t4 WHERE c2=101 AND c3=102;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well" +} +INSERT INTO t5(c2,c3,c4,c5,c6,c7,c8) VALUES(-101,-102,104,105,106,107,108),(-108,-109,111,112,113,114,115),(-115,-116,118,119,120,121,122),(-122,-123,125,126,127,128,128); +--let $auto_value=`SELECT LAST_INSERT_ID()=113 AND c1=113 FROM t5 WHERE c2=-101 AND c3=-102;` +--if (!$auto_value) { +--die "AUTO_INCREMENT didn't work well" +} + +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t4; +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) as max_value, sum(c1) as sum, avg(c1) as avg FROM t5; +# Now select using various table access methods on auto-incremented pk value(full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t4; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t4; +--sorted_result +SELECT * FROM t4 WHERE c4 = 104; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t4; + +## Backward index scan, covering ## +SELECT c1 FROM t4 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 = 1 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <> 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 > 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 < 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <= 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <=> 1 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t4; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t4; +--sorted_result +SELECT * FROM t4 WHERE c4 = 104; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t4; + +## Backward index scan, covering ## +SELECT c1 FROM t4 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t4 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 = 0 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <> 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 > 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 < 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 <=> 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 BETWEEN -101 AND 4 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IN (-101,4) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 >= -101 AND c1 < 4 AND c3 = 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t4 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT * FROM t5 WHERE c5 = 112; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t5; + +## Backward index scan, covering ## +SELECT c1 FROM t5 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 = 109 ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <> 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 > 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 >= 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 < 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <= 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 <=> 109 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 BETWEEN 0 AND 112 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IN (0,112) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 >= 0 AND c1 < 112 AND c2 = -108 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; + +# Index-merge access +--sorted_result +SELECT * FROM t4 WHERE c1=1 OR c2=109; + +# Using index for group-by +--sorted_result +SELECT c2 FROM t4 GROUP BY c2; +--sorted_result +SELECT DISTINCT c2 FROM t4; +--sorted_result +SELECT c2,MIN(c3) FROM t4 GROUP BY c2; + +# Test Error conditions- NULL into not null col, PK constraint violation, Unique constraint violation + +# Insert NULL to non-null column +--error ER_BAD_NULL_ERROR +INSERT INTO t2(c1) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t3 VALUES(NULL,1,2,3,4,5,6); +--error ER_BAD_NULL_ERROR +INSERT INTO t4(c3) VALUES(NULL); +--error ER_BAD_NULL_ERROR +INSERT INTO t5(c3) VALUES(NULL); + +# Insert duplicate value to pk +--error ER_DUP_ENTRY +INSERT INTO t4(c1,c3) VALUES(-101,105) /*throws error as the row with c1=-101 exists */; + +# Insert duplicate value to clustered pk, throws error +--error ER_DUP_ENTRY +INSERT INTO t2(c1,c6) VALUES(101,106) /*throws error as the row with c1=101,c6=106 exists */; +--error ER_DUP_ENTRY +INSERT INTO t5(c1,c2,c3) VALUES(101,-102,4) /*throws error as the row with c1=101,c2=-102 exists */; + +# Insert duplicate value to unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t5(c3) VALUES(-103) /*throws error as the row with c3=-103 exists */; +--error ER_DUP_ENTRY +# Insert duplicate value to clustered unique column, throws error +INSERT INTO t4(c2,c3) VALUES(102,103) /*throws error as the row with c2=102,c3=103 exists */; + +# Test 'INSERT INTO SELECT FROM' +CREATE TABLE t6(c1 BIGINT UNSIGNED NOT NULL, c2 BIGINT NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 INTEGER); +INSERT INTO t6 SELECT * FROM t2 where c1 >= 109; +--sorted_result +SELECT * FROM t6; +TRUNCATE TABLE t6; +INSERT INTO t6 SELECT * FROM t3 where c2 <= -116; +--sorted_result +SELECT * FROM t6; +TRUNCATE TABLE t6; +# Test 'INSERT INTO SELECT FROM' primary key constraint violation +CREATE TABLE t7(c1 BIGINT UNSIGNED NOT NULL PRIMARY KEY, c2 BIGINT NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 INTEGER); +CREATE TABLE t8(c1 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 BIGINT NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 INTEGER); +INSERT INTO t6 VALUES(1,-2,2,2,2,2,2),(1,-3,3,3,3,3,3); +INSERT INTO t7(c1) SELECT t6.c1 FROM t6 LIMIT 1; +--sorted_result +SELECT * FROM t7; +INSERT INTO t8(c1) SELECT t6.c1 FROM t6 LIMIT 1; +--sorted_result +SELECT * FROM t8; +--error ER_DUP_ENTRY +INSERT INTO t7(c1) SELECT t6.c1 FROM t6 /* throws error as t6 contains duplicate rows for c1=1 */; +--error ER_DUP_ENTRY +INSERT INTO t8(c1) SELECT t6.c1 FROM t6 /* throws error as t6 contains duplicate rows for c1=1 */; +TRUNCATE TABLE t6; + +# Test 'INSERT INTO SELECT FROM' with AUTO_INCREMENT and inserting 0,NULL +INSERT INTO t6 VALUES(5,-1,1,1,1,1,1),(6,-2,2,2,2,2,2),(0,-4,4,4,4,4,4),(NULL,-5,5,5,5,5,5); +INSERT INTO t8 SELECT * FROM t6; +SELECT LAST_INSERT_ID() AS last_insert_id; +--sorted_result +SELECT * FROM t8; +TRUNCATE TABLE t8; +INSERT INTO t8(c2) SELECT c2 FROM t6 WHERE c1 >= 6; +--sorted_result +SELECT * FROM t8; +DROP TABLE t6,t7,t8; + +# Test 'INSERT SET' +INSERT INTO t2 SET c3=5,c4=6; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_NO_DEFAULT_FOR_FIELD +INSERT INTO t2 SET c3=5,c4=6; +SET SQL_MODE=''; + +# Test insert allowable bigger values to 'BIGINT' columns +INSERT INTO t1 VALUES(0,-9223372036854775808,1,2,3,4,5),(255,-2147483648,6,7,8,9,10),(65535,-8388608,11,12,13,14,15),(16777215,-32768,16,17,18,19,20),(4294967295,-128,21,22,23,24,25),(18446744073709551615,9223372036854775807,26,27,28,29,30); +INSERT INTO t2 VALUES(0,-9223372036854775808,1,2,3,4,5),(255,-2147483648,6,7,8,9,10),(65535,-8388608,11,12,13,14,15),(16777215,-32768,16,17,18,19,20),(4294967295,-128,21,22,23,24,25),(18446744073709551615,9223372036854775807,26,27,28,29,30); +INSERT INTO t3 VALUES(0,-9223372036854775808,1,2,3,4,5),(255,-2147483648,6,7,8,9,10),(65535,-8388608,11,12,13,14,15),(16777215,-32768,16,17,18,19,20),(4294967295,-128,21,22,23,24,25),(18446744073709551615,9223372036854775807,26,27,28,29,30); +INSERT INTO t4 VALUES(-9223372036854775808,0,1,2,3,4,5,5),(-2147483648,255,6,7,8,9,10,10),(-8388608,65535,11,12,13,14,15,15),(-32768,16777215,16,17,18,19,20,20),(-128,4294967295,21,22,23,24,25,25),(9223372036854775807,18446744073709551615,26,27,28,29,30,30); +INSERT INTO t5 VALUES(0,-9223372036854775808,1,2,3,4,5,5),(255,-2147483648,6,7,8,9,10,10),(65535,-8388608,11,12,13,14,15,15),(16777215,-32768,16,17,18,19,20,20),(4294967295,-128,21,22,23,24,25,25),(18446744073709551615,9223372036854775807,26,27,28,29,30,30); +--error 167 +INSERT INTO t4(c2,c3) VALUES(31,32) /* tries to increment out of range */; +--error ER_AUTOINC_READ_FAILED +INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */; +--sorted_result +SELECT * FROM t4; + +# Insert signed value to unsigned 'BIGINT', outside range values to signed/unsigned columns +INSERT INTO t1 VALUES(-128,-9223372036854775809,31,32,33,34,35),(18446744073709551616,9223372036854775808,36,37,38,39,40); +INSERT INTO t2 VALUES(-128,-9223372036854775809,31,32,33,34,35),(18446744073709551616,9223372036854775808,36,37,38,39,40); +INSERT INTO t3 VALUES(-128,-9223372036854775809,31,32,33,34,35),(18446744073709551616,9223372036854775808,36,37,38,39,40); + +# Now select using various table access methods +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = -9223372036854775808; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 0 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 18446744073709551615 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 18446744073709551615 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,18446744073709551615) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,18446744073709551615) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 18446744073709551615 AND c6 = 14 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 18446744073709551615 AND c6 = 14 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 0 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 18446744073709551615 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 18446744073709551615 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,18446744073709551615) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,18446744073709551615) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 18446744073709551615 AND c6 = 14 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 18446744073709551615 AND c6 = 14 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 9223372036854775807; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = 18446744073709551615 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 18446744073709551615 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 18446744073709551615 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 18446744073709551615 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 18446744073709551615 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 18446744073709551615 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 18446744073709551615 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 18446744073709551615 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 18446744073709551615 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 18446744073709551615 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 18446744073709551615 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 18446744073709551615 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 18446744073709551615 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 18446744073709551615 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 18446744073709551615 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 18446744073709551615 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 18446744073709551615 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 18446744073709551615 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,18446744073709551615) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (0,18446744073709551615) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 18446744073709551615 AND c6 = 14 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 18446744073709551615 AND c6 = 14 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 18446744073709551615 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 18446744073709551615 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 18446744073709551615 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 18446744073709551615 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 18446744073709551615 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 18446744073709551615 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 18446744073709551615 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 18446744073709551615 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 18446744073709551615 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 18446744073709551615 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 18446744073709551615 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 18446744073709551615 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 18446744073709551615 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN 0 AND 18446744073709551615 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (0,18446744073709551615) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (0,18446744073709551615) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 18446744073709551615 AND c6 = 14 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 0 AND c1 < 18446744073709551615 AND c6 = 14 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = -9223372036854775809; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = -128 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = -128 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = -128 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = -128 ORDER BY c1,c6 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> -128 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> -128 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > -128 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > -128 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < -128 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < -128 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -128 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= -128 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -128 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> -128 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 18446744073709551616 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 18446744073709551616 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-128,18446744073709551616) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (-128,18446744073709551616) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -128 AND c1 < 18446744073709551616 AND c6 = 34 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -128 AND c1 < 18446744073709551616 AND c6 = 34 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> -128 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> -128 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -128 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > -128 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < -128 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < -128 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -128 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= -128 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -128 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> -128 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 18446744073709551616 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 18446744073709551616 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-128,18446744073709551616) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (-128,18446744073709551616) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -128 AND c1 < 18446744073709551616 AND c6 = 34 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -128 AND c1 < 18446744073709551616 AND c6 = 34 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c2 = 9223372036854775808; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c6 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c6 FROM t2 ORDER BY c1,c6 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c6 DESC LIMIT 2; + +## ref type access +--disable_warnings +SELECT * FROM t2 WHERE c1 = 18446744073709551616 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 = 18446744073709551616 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 = 18446744073709551616 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 = 18446744073709551616 ORDER BY c1,c6 DESC LIMIT 2; +--enable_warnings + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> 18446744073709551616 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <> 18446744073709551616 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 > 18446744073709551616 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 > 18446744073709551616 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 18446744073709551616 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= 18446744073709551616 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 18446744073709551616 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 < 18446744073709551616 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 18446744073709551616 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <= 18446744073709551616 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 18446744073709551616 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 <=> 18446744073709551616 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 18446744073709551616 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 18446744073709551616 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-128,18446744073709551616) ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IN (-128,18446744073709551616) ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -128 AND c1 < 18446744073709551616 AND c6 = 34 ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 >= -128 AND c1 < 18446744073709551616 AND c6 = 34 ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> 18446744073709551616 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <> 18446744073709551616 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > 18446744073709551616 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 > 18446744073709551616 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 18446744073709551616 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= 18446744073709551616 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < 18446744073709551616 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 < 18446744073709551616 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 18446744073709551616 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <= 18446744073709551616 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> 18446744073709551616 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 <=> 18446744073709551616 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 18446744073709551616 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 18446744073709551616 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN (-128,18446744073709551616) ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IN (-128,18446744073709551616) ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -128 AND c1 < 18446744073709551616 AND c6 = 34 ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 >= -128 AND c1 < 18446744073709551616 AND c6 = 34 ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c6 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c6 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 0; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775808 AND 9223372036854775807 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775808 AND 9223372036854775807 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775808,9223372036854775807) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775808,9223372036854775807) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -9223372036854775808 AND c2 < 9223372036854775807 AND c7 = 20 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -9223372036854775808 AND c2 < 9223372036854775807 AND c7 = 20 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775808 AND 9223372036854775807 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775808 AND 9223372036854775807 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775808,9223372036854775807) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775808,9223372036854775807) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -9223372036854775808 AND c2 < 9223372036854775807 AND c7 = 20 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -9223372036854775808 AND c2 < 9223372036854775807 AND c7 = 20 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 18446744073709551615; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 9223372036854775807 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = 9223372036854775807 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 9223372036854775807 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = 9223372036854775807 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 9223372036854775807 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> 9223372036854775807 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 9223372036854775807 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > 9223372036854775807 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 9223372036854775807 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= 9223372036854775807 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 9223372036854775807 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < 9223372036854775807 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 9223372036854775807 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= 9223372036854775807 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 9223372036854775807 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> 9223372036854775807 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775808 AND 9223372036854775807 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775808 AND 9223372036854775807 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775808,9223372036854775807) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775808,9223372036854775807) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -9223372036854775808 AND c2 < 9223372036854775807 AND c7 = 20 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -9223372036854775808 AND c2 < 9223372036854775807 AND c7 = 20 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 9223372036854775807 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> 9223372036854775807 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 9223372036854775807 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > 9223372036854775807 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 9223372036854775807 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= 9223372036854775807 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 9223372036854775807 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < 9223372036854775807 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 9223372036854775807 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= 9223372036854775807 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 9223372036854775807 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> 9223372036854775807 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775808 AND 9223372036854775807 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775808 AND 9223372036854775807 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775808,9223372036854775807) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775808,9223372036854775807) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -9223372036854775808 AND c2 < 9223372036854775807 AND c7 = 20 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -9223372036854775808 AND c2 < 9223372036854775807 AND c7 = 20 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = -128; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = -9223372036854775809 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = -9223372036854775809 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = -9223372036854775809 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = -9223372036854775809 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> -9223372036854775809 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> -9223372036854775809 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > -9223372036854775809 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > -9223372036854775809 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -9223372036854775809 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -9223372036854775809 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < -9223372036854775809 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < -9223372036854775809 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -9223372036854775809 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= -9223372036854775809 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -9223372036854775809 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> -9223372036854775809 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775809 AND 9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775809 AND 9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775809,9223372036854775808) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775809,9223372036854775808) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -9223372036854775809 AND c2 < 9223372036854775808 AND c7 = 35 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -9223372036854775809 AND c2 < 9223372036854775808 AND c7 = 35 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> -9223372036854775809 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> -9223372036854775809 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > -9223372036854775809 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > -9223372036854775809 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -9223372036854775809 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -9223372036854775809 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < -9223372036854775809 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < -9223372036854775809 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= -9223372036854775809 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= -9223372036854775809 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> -9223372036854775809 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> -9223372036854775809 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775809 AND 9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775809 AND 9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775809,9223372036854775808) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775809,9223372036854775808) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -9223372036854775809 AND c2 < 9223372036854775808 AND c7 = 35 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -9223372036854775809 AND c2 < 9223372036854775808 AND c7 = 35 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c1 = 18446744073709551616; + +## Forward index scan, covering ## +--sorted_result +SELECT c2,c7 FROM t3; + +## Backward index scan, covering ## +SELECT c2,c7 FROM t3 ORDER BY c2,c7 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c2,c7 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 = 9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 = 9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <> 9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 > 9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= 9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 < 9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <= 9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 <=> 9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775809 AND 9223372036854775808 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775809 AND 9223372036854775808 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775809,9223372036854775808) ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775809,9223372036854775808) ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -9223372036854775809 AND c2 < 9223372036854775808 AND c7 = 35 ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 >= -9223372036854775809 AND c2 < 9223372036854775808 AND c7 = 35 ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <> 9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 > 9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= 9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 < 9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <= 9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 <=> 9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775809 AND 9223372036854775808 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN -9223372036854775809 AND 9223372036854775808 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775809,9223372036854775808) ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IN (-9223372036854775809,9223372036854775808) ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= -9223372036854775809 AND c2 < 9223372036854775808 AND c7 = 35 ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 >= -9223372036854775809 AND c2 < 9223372036854775808 AND c7 = 35 ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c2,c7 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c2,c7 DESC LIMIT 2; +DROP TABLE t1,t2,t3,t4,t5; + diff --git a/mysql-test/suite/engines/iuds/t/insert_time.test b/mysql-test/suite/engines/iuds/t/insert_time.test new file mode 100644 index 00000000..0e5e2150 --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/insert_time.test @@ -0,0 +1,1065 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3,t4; +--enable_warnings + +######## Running INSERT tests for TIME ######## + +# Create tables +CREATE TABLE t1(c1 TIME NOT NULL, c2 TIME NULL, c3 DATE, PRIMARY KEY(c1), UNIQUE INDEX(c2)); +CREATE TABLE t2(c1 TIME NOT NULL, c2 TIME NULL, c3 DATE, PRIMARY KEY(c1,c2)); +CREATE TABLE t3(c1 TIME NOT NULL, c2 TIME NULL, c3 DATE, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t4(c1 TIME NOT NULL, c2 TIME NULL, c3 DATE); +# Insert some rows with targeted values + +# As a string in 'D HH:MM:SS.fraction' format +INSERT INTO t1 VALUES('12:34:56.78','12:34:56.78','2009-01-01'),('10:22:33','10:22:33','2009-01-02'),('1:23','1:23','2009-01-03'),('20 11:22:33','20 11:22:33','2009-01-04'),('34 9:23','34 9:23','2009-01-05'),('0 10','0 10','2009-01-06'),('45','45','2009-01-07'),('-838:59:59','-838:59:59','2009-01-08'),('0','0','2009-01-09'),('838:59:59','838:59:59','2009-01-10'); +INSERT INTO t2 VALUES('12:34:56.78','12:34:56.78','2009-01-01'),('10:22:33','10:22:33','2009-01-02'),('1:23','1:23','2009-01-03'),('20 11:22:33','20 11:22:33','2009-01-04'),('34 9:23','34 9:23','2009-01-05'),('0 10','0 10','2009-01-06'),('45','45','2009-01-07'),('-838:59:59','-838:59:59','2009-01-08'),('0','0','2009-01-09'),('838:59:59','838:59:59','2009-01-10'); +INSERT INTO t3 VALUES('12:34:56.78','12:34:56.78','2009-01-01'),('10:22:33','10:22:33','2009-01-02'),('1:23','1:23','2009-01-03'),('20 11:22:33','20 11:22:33','2009-01-04'),('34 9:23','34 9:23','2009-01-05'),('0 10','0 10','2009-01-06'),('45','45','2009-01-07'),('-838:59:59','-838:59:59','2009-01-08'),('0','0','2009-01-09'),('838:59:59','838:59:59','2009-01-10'); +INSERT INTO t4 VALUES('12:34:56.78','12:34:56.78','2009-01-01'),('10:22:33','10:22:33','2009-01-02'),('1:23','1:23','2009-01-03'),('20 11:22:33','20 11:22:33','2009-01-04'),('34 9:23','34 9:23','2009-01-05'),('0 10','0 10','2009-01-06'),('45','45','2009-01-07'),('-838:59:59','-838:59:59','2009-01-08'),('0','0','2009-01-09'),('838:59:59','838:59:59','2009-01-10'); + +# As a string with no delimiters in 'HHMMSS' format +INSERT INTO t1 VALUES('101112','101112','2009-01-11'); +INSERT INTO t2 VALUES('101112','101112','2009-01-11'); +INSERT INTO t3 VALUES('101112','101112','2009-01-11'); +INSERT INTO t4 VALUES('101112','101112','2009-01-11'); + +# As a number in HHMMSS format +INSERT INTO t1 VALUES(111112,111112,'2009-01-12'),(12,12,'2009-01-13'),(1234,1234,'2009-01-14'),(123458,123458,'2009-01-15'),(123556.99,123556.99,'2009-01-16'); +INSERT INTO t2 VALUES(111112,111112,'2009-01-12'),(12,12,'2009-01-13'),(1234,1234,'2009-01-14'),(123458,123458,'2009-01-15'),(123556.99,123556.99,'2009-01-16'); +INSERT INTO t3 VALUES(111112,111112,'2009-01-12'),(12,12,'2009-01-13'),(1234,1234,'2009-01-14'),(123458,123458,'2009-01-15'),(123556.99,123556.99,'2009-01-16'); +INSERT INTO t4 VALUES(111112,111112,'2009-01-12'),(12,12,'2009-01-13'),(1234,1234,'2009-01-14'),(123458,123458,'2009-01-15'),(123556.99,123556.99,'2009-01-16'); + +# As the result of a function +SET TIMESTAMP=1233216687; # 2009-01-29 13:41:27 +INSERT INTO t1 VALUES(CURRENT_TIME(),CURRENT_TIME(),'2009-01-17'); +INSERT INTO t2 VALUES(CURRENT_TIME(),CURRENT_TIME(),'2009-01-17'); +INSERT INTO t3 VALUES(CURRENT_TIME(),CURRENT_TIME(),'2009-01-17'); +INSERT INTO t4 VALUES(CURRENT_TIME(),CURRENT_TIME(),'2009-01-17'); + +# Other valid formats (single digit, zero hrs,mins,secs.) +INSERT INTO t1 VALUES('8:3:2','8:3:2','2009-01-18'),('1112','1112','2009-01-19'),(11,11,'2009-01-20'),('00:12:30','00:12:30','2009-01-23'),('9:00:45','9:00:45','2009-01-24'),('9:36:00','9:36:00','2009-01-25'); +INSERT INTO t2 VALUES('8:3:2','8:3:2','2009-01-18'),('1112','1112','2009-01-19'),(11,11,'2009-01-20'),('00:12:30','00:12:30','2009-01-23'),('9:00:45','9:00:45','2009-01-24'),('9:36:00','9:36:00','2009-01-25'); +INSERT INTO t3 VALUES('8:3:2','8:3:2','2009-01-18'),('1112','1112','2009-01-19'),(11,11,'2009-01-20'),('00:12:30','00:12:30','2009-01-23'),('9:00:45','9:00:45','2009-01-24'),('9:36:00','9:36:00','2009-01-25'); +INSERT INTO t4 VALUES('8:3:2','8:3:2','2009-01-18'),('1112','1112','2009-01-19'),(11,11,'2009-01-20'),('00:12:30','00:12:30','2009-01-23'),('9:00:45','9:00:45','2009-01-24'),('9:36:00','9:36:00','2009-01-25'); +# Outside range would be clipped to closest end point +--error ER_DUP_ENTRY +SET STATEMENT sql_mode = '' FOR +INSERT INTO t1 VALUES('-850:00:00','-850:00:00','2009-01-21'); +--error ER_DUP_ENTRY +SET STATEMENT sql_mode = '' FOR +INSERT INTO t1 VALUES('850:00:00','850:00:00','2009-01-21'); +DELETE FROM t1 WHERE c1='-838:59:59' AND c2='-838:59:59'; +DELETE FROM t1 WHERE c1='838:59:59' AND c2='838:59:59'; +INSERT IGNORE INTO t1 VALUES('-850:00:00','-850:00:00','2009-01-21'),('850:00:00','850:00:00','2009-01-21'); + +# Insert invalid values +INSERT IGNORE INTO t4 VALUES('10.22.22','10.22.22','2009-01-26'),(1234567,1234567,'2009-01-27'),(123456789,123456789,'2009-01-28'),(123456789.10,123456789.10,'2009-01-29'),('10 22:22','10 22:22','2009-01-30'),('12.45a','12.45a','2009-01-31'); + +# Insert permissible NULLs +INSERT INTO t1 VALUES('8:29:45',NULL,'2009-02-01'); +INSERT INTO t3 VALUES('8:29:45',NULL,'2009-02-01'); +INSERT INTO t4 VALUES('8:29:45',NULL,'2009-02-01'); + +# Insert duplicate NULLs to unique column +INSERT INTO t1(c1,c2) VALUES('9:30',NULL); +DELETE FROM t1 WHERE c1='9:30' AND c2 IS NULL; + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; + +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2009-01-17'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '838:59:59' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '838:59:59' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '838:59:59' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '838:59:59' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '838:59:59' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '838:59:59' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '838:59:59' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '838:59:59' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '838:59:59' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '838:59:59' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '838:59:59' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '838:59:59' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '838:59:59' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '838:59:59' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '838:59:59' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '838:59:59' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '00:00:00' AND '838:59:59' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '00:00:00' AND '838:59:59' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('00:00:00','838:59:59') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('00:00:00','838:59:59') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '00:00:00' AND c1 < '838:59:59' AND c2 = '11:11:12' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '00:00:00' AND c1 < '838:59:59' AND c2 = '11:11:12' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '838:59:59' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '838:59:59' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '838:59:59' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '838:59:59' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '838:59:59' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '838:59:59' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '838:59:59' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '838:59:59' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '838:59:59' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '838:59:59' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '838:59:59' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '838:59:59' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '00:00:00' AND '838:59:59' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '00:00:00' AND '838:59:59' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('00:00:00','838:59:59') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('00:00:00','838:59:59') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '00:00:00' AND c1 < '838:59:59' AND c2 = '11:11:12' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '00:00:00' AND c1 < '838:59:59' AND c2 = '11:11:12' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2009-01-16'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; + +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c1 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c1 = '00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 = '00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 = '00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 = '00:00:00' ORDER BY c1 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c1 <> '00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <> '00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 > '00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 > '00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 < '00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <= '00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '00:00:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> '00:00:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '00:00:00' AND '09:36:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 BETWEEN '00:00:00' AND '09:36:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('00:00:00','09:36:00') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN ('00:00:00','09:36:00') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '00:00:00' AND c1 < '09:36:00' AND c2 = '01:23:00' ORDER BY c1; +SELECT * FROM t1 WHERE c1 >= '00:00:00' AND c1 < '09:36:00' AND c2 = '01:23:00' ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c1 <> '00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> '00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 > '00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 < '00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 < '00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <= '00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '00:00:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> '00:00:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '00:00:00' AND '09:36:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 BETWEEN '00:00:00' AND '09:36:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN ('00:00:00','09:36:00') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IN ('00:00:00','09:36:00') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '00:00:00' AND c1 < '09:36:00' AND c2 = '01:23:00' ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 >= '00:00:00' AND c1 < '09:36:00' AND c2 = '01:23:00' ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2009-01-15'; + +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t1; + +## Backward index scan, covering ## +SELECT c2 FROM t1 ORDER BY c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = '-838:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 = '-838:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = '-838:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 = '-838:59:59' ORDER BY c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> '-838:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <> '-838:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > '-838:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 > '-838:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-838:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '-838:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < '-838:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 < '-838:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '-838:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <= '-838:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '-838:59:59' ORDER BY c2; +SELECT * FROM t1 WHERE c2 <=> '-838:59:59' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '-838:59:59' AND '10:00:00' ORDER BY c2; +SELECT * FROM t1 WHERE c2 BETWEEN '-838:59:59' AND '10:00:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('-838:59:59','10:00:00') ORDER BY c2; +SELECT * FROM t1 WHERE c2 IN ('-838:59:59','10:00:00') ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-838:59:59' AND c2 < '10:00:00' AND c1 = '00:11:12' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= '-838:59:59' AND c2 < '10:00:00' AND c1 = '00:11:12' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> '-838:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <> '-838:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > '-838:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 > '-838:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-838:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '-838:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < '-838:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 < '-838:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= '-838:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <= '-838:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '-838:59:59' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <=> '-838:59:59' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '-838:59:59' AND '10:00:00' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN '-838:59:59' AND '10:00:00' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN ('-838:59:59','10:00:00') ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IN ('-838:59:59','10:00:00') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '-838:59:59' AND c2 < '10:00:00' AND c1 = '00:11:12' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= '-838:59:59' AND c2 < '10:00:00' AND c1 = '00:11:12' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t1; +--sorted_result +SELECT * FROM t1 WHERE c3 = '2009-01-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t1; + +## Backward index scan, covering ## +SELECT c2 FROM t1 ORDER BY c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t1 ORDER BY c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t1 WHERE c2 = NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 = NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 = NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 = NULL ORDER BY c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t1 WHERE c2 <> NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 <> NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 > NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 > NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 < NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 < NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <= NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 <= NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN NULL AND '10:22:33' ORDER BY c2; +SELECT * FROM t1 WHERE c2 BETWEEN NULL AND '10:22:33' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IN (NULL,'10:22:33') ORDER BY c2; +SELECT * FROM t1 WHERE c2 IN (NULL,'10:22:33') ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 >= NULL AND c2 < '10:22:33' AND c1 = '491:22:33' ORDER BY c2; +SELECT * FROM t1 WHERE c2 >= NULL AND c2 < '10:22:33' AND c1 = '491:22:33' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t1 WHERE c2 <> NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <> NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 > NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 > NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 < NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 < NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <= NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <= NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 <=> NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN NULL AND '10:22:33' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 BETWEEN NULL AND '10:22:33' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN (NULL,'10:22:33') ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IN (NULL,'10:22:33') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= NULL AND c2 < '10:22:33' AND c1 = '491:22:33' ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 >= NULL AND c2 < '10:22:33' AND c1 = '491:22:33' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2 DESC LIMIT 2; + +# Index-merge access +--sorted_result +SELECT * FROM t1 WHERE c1='838:59:59' OR c2='-838:59:59'; + +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2009-01-17'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '00:00:00' AND '838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '00:00:00' AND '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('00:00:00','838:59:59') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('00:00:00','838:59:59') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '00:00:00' AND c1 < '838:59:59' AND c2 = '11:11:12' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '00:00:00' AND c1 < '838:59:59' AND c2 = '11:11:12' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '00:00:00' AND '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '00:00:00' AND '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('00:00:00','838:59:59') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('00:00:00','838:59:59') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '00:00:00' AND c1 < '838:59:59' AND c2 = '11:11:12' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '00:00:00' AND c1 < '838:59:59' AND c2 = '11:11:12' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2009-01-16'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '00:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '00:00:00' AND '09:36:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '00:00:00' AND '09:36:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('00:00:00','09:36:00') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('00:00:00','09:36:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '00:00:00' AND c1 < '09:36:00' AND c2 = '01:23:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '00:00:00' AND c1 < '09:36:00' AND c2 = '01:23:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '00:00:00' AND '09:36:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '00:00:00' AND '09:36:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('00:00:00','09:36:00') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('00:00:00','09:36:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '00:00:00' AND c1 < '09:36:00' AND c2 = '01:23:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '00:00:00' AND c1 < '09:36:00' AND c2 = '01:23:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2009-01-15'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '-838:59:59' AND '10:00:00' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN '-838:59:59' AND '10:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('-838:59:59','10:00:00') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN ('-838:59:59','10:00:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '-838:59:59' AND c2 < '10:00:00' AND c1 = '00:11:12' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '-838:59:59' AND c2 < '10:00:00' AND c1 = '00:11:12' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '-838:59:59' AND '10:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN '-838:59:59' AND '10:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('-838:59:59','10:00:00') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN ('-838:59:59','10:00:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '-838:59:59' AND c2 < '10:00:00' AND c1 = '00:11:12' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '-838:59:59' AND c2 < '10:00:00' AND c1 = '00:11:12' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '2009-01-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = NULL ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN NULL AND '10:22:33' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN NULL AND '10:22:33' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN (NULL,'10:22:33') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN (NULL,'10:22:33') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= NULL AND c2 < '10:22:33' AND c1 = '491:22:33' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= NULL AND c2 < '10:22:33' AND c1 = '491:22:33' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN NULL AND '10:22:33' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN NULL AND '10:22:33' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN (NULL,'10:22:33') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN (NULL,'10:22:33') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= NULL AND c2 < '10:22:33' AND c1 = '491:22:33' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= NULL AND c2 < '10:22:33' AND c1 = '491:22:33' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2009-01-17'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '00:00:00' AND '838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '00:00:00' AND '838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('00:00:00','838:59:59') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('00:00:00','838:59:59') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '00:00:00' AND c1 < '838:59:59' AND c2 = '11:11:12' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '00:00:00' AND c1 < '838:59:59' AND c2 = '11:11:12' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '00:00:00' AND '838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '00:00:00' AND '838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('00:00:00','838:59:59') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('00:00:00','838:59:59') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '00:00:00' AND c1 < '838:59:59' AND c2 = '11:11:12' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '00:00:00' AND c1 < '838:59:59' AND c2 = '11:11:12' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2009-01-16'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '00:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '00:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '00:00:00' AND '09:36:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '00:00:00' AND '09:36:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('00:00:00','09:36:00') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('00:00:00','09:36:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '00:00:00' AND c1 < '09:36:00' AND c2 = '01:23:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '00:00:00' AND c1 < '09:36:00' AND c2 = '01:23:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '00:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '00:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '00:00:00' AND '09:36:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '00:00:00' AND '09:36:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('00:00:00','09:36:00') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('00:00:00','09:36:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '00:00:00' AND c1 < '09:36:00' AND c2 = '01:23:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '00:00:00' AND c1 < '09:36:00' AND c2 = '01:23:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2009-01-15'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '-838:59:59' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> '-838:59:59' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '-838:59:59' AND '10:00:00' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN '-838:59:59' AND '10:00:00' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('-838:59:59','10:00:00') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN ('-838:59:59','10:00:00') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '-838:59:59' AND c2 < '10:00:00' AND c1 = '00:11:12' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '-838:59:59' AND c2 < '10:00:00' AND c1 = '00:11:12' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> '-838:59:59' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> '-838:59:59' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '-838:59:59' AND '10:00:00' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN '-838:59:59' AND '10:00:00' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('-838:59:59','10:00:00') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN ('-838:59:59','10:00:00') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '-838:59:59' AND c2 < '10:00:00' AND c1 = '00:11:12' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '-838:59:59' AND c2 < '10:00:00' AND c1 = '00:11:12' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '2009-01-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND '10:22:33' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND '10:22:33' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,'10:22:33') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN (NULL,'10:22:33') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < '10:22:33' AND c1 = '491:22:33' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < '10:22:33' AND c1 = '491:22:33' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND '10:22:33' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND '10:22:33' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,'10:22:33') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN (NULL,'10:22:33') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < '10:22:33' AND c1 = '491:22:33' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < '10:22:33' AND c1 = '491:22:33' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c1 FROM t3 GROUP BY c1; +--sorted_result +SELECT DISTINCT c1 FROM t3; +--sorted_result +SELECT c1,MIN(c2) FROM t3 GROUP BY c1; + +# Some more testing......... + +# These must return normal result +SELECT CAST(235959.123456 AS TIME); +SELECT CAST(0.235959123456e+6 AS TIME); +SELECT CAST(235959123456e-6 AS TIME); +# These must cut fraction part and produce warning +SELECT CAST(235959.1234567 AS TIME); +SELECT CAST(0.2359591234567e6 AS TIME); +# This must return NULL and produce warning +--replace_result 2.359591234567e+029 2.359591234567e+29 +SELECT CAST(0.2359591234567e+30 AS TIME); + +# Compare time values as strings +select cast('100:55:50' as time) < cast('24:00:00' as time); +select cast('100:55:50' as time) < cast('024:00:00' as time); +select cast('300:55:50' as time) < cast('240:00:00' as time); +select cast('100:55:50' as time) > cast('24:00:00' as time); +select cast('100:55:50' as time) > cast('024:00:00' as time); +select cast('300:55:50' as time) > cast('240:00:00' as time); +create table t5 (f1 time); +insert into t5 values ('24:00:00'); +select cast('24:00:00' as time) = (select f1 from t5); +drop table t5; +# Test Error conditions- PK constraint violation, Unique constraint violation + +# Insert duplicate value to pk column +--error ER_DUP_ENTRY +INSERT INTO t1(c1,c2) VALUES('10:22:33','10:22:34') /* throws error as row exists with c1='10:22:33' */; + +# Insert duplicate value to clustered pk, throws error +--error ER_DUP_ENTRY +INSERT INTO t2(c1,c2) VALUES('12:34:56.78','12:34:56.78') /* throws error as row exists with c1='12:34:56.78',c2='12:34:56.78' */; + +# Insert duplicate value to unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t1(c1,c2) VALUES('10:22:34','34 9:23') /* throws error as row exists with c2='34 9:23' */; + +# Insert duplicate value to clustered unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t3(c1,c2) VALUES('34 9:23','34 9:23') /* throws error as row exists with c1='34 9:23',c2='34 9:23' */; + +# Test 'INSERT IGNORE' with the same rows that reported constraint violation above +# Ignore pk constraint +INSERT IGNORE INTO t1(c1,c2) VALUES('10:22:33','10:22:34') /* doesn't throw error */; +INSERT IGNORE INTO t2(c1,c2) VALUES('12:34:56.78','12:34:56.78') /*doesn't throw error */; +# Ignore unique constraint +INSERT IGNORE INTO t1(c1,c2) VALUES('10:22:34','34 9:23') /*doesn't throw error */; +INSERT IGNORE INTO t3(c1,c2) VALUES('34 9:23','34 9:23') /*doesn't throw error */; +# Select + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with PK one column/multi-column +SELECT * FROM t1 WHERE c1='10:23:33' /* no rows */; +INSERT INTO t1(c1) VALUES('10:22:33') ON DUPLICATE KEY UPDATE c1='10:23:33'; +SELECT * FROM t1 WHERE c1='10:23:33' /* 1 row */; +SELECT * FROM t2 WHERE c1='12:34:56.79' AND c2='12:34:57.78' /* no rows */; +INSERT INTO t2(c1,c2) VALUES('12:34:56.78','12:34:56.78') ON DUPLICATE KEY UPDATE c1='12:34:56.79',c2='12:34:57.78'; +SELECT * FROM t2 WHERE c1='12:34:56.79' AND c2='12:34:57.78' /* 1 row */; +# Test 'INSERT ON DUPLICATE KEY UPDATE' with unique one column/multi-column +SELECT * FROM t1 WHERE c1='10:22:35' AND c2='33 9:23' /* no rows */; +INSERT INTO t1(c1,c2) VALUES('10:22:34','34 9:23') ON DUPLICATE KEY UPDATE c1='10:22:35',c2='33 9:23'; +SELECT * FROM t1 WHERE c1='10:22:35' AND c2='33 9:23' /* 1 row */; +SELECT * FROM t3 WHERE c1='32 9:23' AND c2='33 9:23' /* no rows */; +INSERT INTO t3(c1,c2) VALUES('34 9:23','34 9:23') ON DUPLICATE KEY UPDATE c1='32 9:23',c2='33 9:23'; +SELECT * FROM t3 WHERE c1='32 9:23' AND c2='33 9:23' /* 1 row */; + +# Test 'INSERT SET' +INSERT INTO t1 SET c1='07:23:55',c2='13 06:23:55'; +INSERT INTO t2 SET c1='07:23:55',c2='13 06:23:55'; +INSERT INTO t3 SET c1='07:23:55'; +INSERT IGNORE INTO t4 SET c2='07:23:55'; +SELECT * FROM t1 WHERE c1='07:23:55' AND c2='13 06:23:55' /* Returns 1 row with values for other column as NULL */; +SELECT * FROM t2 WHERE c1='07:23:55' AND c2='13 06:23:55' /* Returns 1 row with values for other column as NULL */; +SELECT * FROM t3 WHERE c1='07:23:55' /* Returns 1 row with values for other column as NULL */; +SELECT * FROM t4 WHERE c2='07:23:55' /* Returns 1 row with values for other column as NULL */; + +# Test 'INSERT INTO SELECT FROM' +CREATE TABLE t5(c1 TIME NOT NULL, c2 TIME NULL, c3 DATE, INDEX idx(c1,c2)); +INSERT INTO t5 SELECT * FROM t4; +SELECT * FROM t5; +TRUNCATE TABLE t5; +INSERT IGNORE INTO t5 SELECT * FROM t4 WHERE c1 >='12colon34colon56'; +SELECT * FROM t5; +TRUNCATE TABLE t5; +DROP TABLE t5; +DROP TABLE t1,t2,t3,t4; + diff --git a/mysql-test/suite/engines/iuds/t/insert_year.test b/mysql-test/suite/engines/iuds/t/insert_year.test new file mode 100644 index 00000000..4d92e36f --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/insert_year.test @@ -0,0 +1,1506 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3,t4; +--enable_warnings + +######## Running INSERT tests for YEAR(4) ######## + +# Create tables +CREATE TABLE t1(c1 YEAR(4) NOT NULL, c2 YEAR(4) NULL, c3 DATE, c4 DATETIME, PRIMARY KEY(c1), UNIQUE INDEX(c2)); +CREATE TABLE t2(c1 YEAR(4) NOT NULL, c2 YEAR(4) NULL, c3 DATE, c4 DATETIME, PRIMARY KEY(c1,c2)); +CREATE TABLE t3(c1 YEAR(4) NOT NULL, c2 YEAR(4) NULL, c3 DATE, c4 DATETIME, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t4(c1 YEAR(4) NOT NULL, c2 YEAR(4) NULL, c3 DATE, c4 DATETIME); +# Insert some rows with targeted values + +# As a four-digit string in the range '1901' to '2155' +INSERT INTO t1 VALUES('1901','1901','98-12-31','98.12.31 11:30:45'),('1999','1999','98-12-30','98.12.30 11:30:45'),('2000','2000','98-12-29','98.12.29 11:30:45'),('2001','2001','98-12-28','98.12.28 11:30:45'),('2099','2099','98-12-27','98.12.27 11:30:45'),('2100','2100','98-12-26','98.12.26 11:30:45'),('2155','2155','98-12-26','98.12.26 11:30:45'); +INSERT INTO t2 VALUES('1901','1901','98-12-31','98.12.31 11:30:45'),('1999','1999','98-12-30','98.12.30 11:30:45'),('2000','2000','98-12-29','98.12.29 11:30:45'),('2001','2001','98-12-28','98.12.28 11:30:45'),('2099','2099','98-12-27','98.12.27 11:30:45'),('2100','2100','98-12-26','98.12.26 11:30:45'),('2155','2155','98-12-26','98.12.26 11:30:45'); +INSERT INTO t3 VALUES('1901','1901','98-12-31','98.12.31 11:30:45'),('1999','1999','98-12-30','98.12.30 11:30:45'),('2000','2000','98-12-29','98.12.29 11:30:45'),('2001','2001','98-12-28','98.12.28 11:30:45'),('2099','2099','98-12-27','98.12.27 11:30:45'),('2100','2100','98-12-26','98.12.26 11:30:45'),('2155','2155','98-12-26','98.12.26 11:30:45'); +INSERT INTO t4 VALUES('1901','1901','98-12-31','98.12.31 11:30:45'),('1999','1999','98-12-30','98.12.30 11:30:45'),('2000','2000','98-12-29','98.12.29 11:30:45'),('2001','2001','98-12-28','98.12.28 11:30:45'),('2099','2099','98-12-27','98.12.27 11:30:45'),('2100','2100','98-12-26','98.12.26 11:30:45'),('2155','2155','98-12-25','98.12.25 11:30:45'); + +# As a four-digit number in the range 1901 to 2155 +INSERT INTO t4 VALUES(1901,1901,'98-12-24','98.12.24 11:30:45'),(1999,1999,'98-12-23','98.12.23 11:30:45'),(2000,2000,'98-12-22','98.12.22 11:30:45'),(2001,2001,'98-12-21','98.12.21 11:30:45'),(2099,2099,'98-12-20','98.12.20 11:30:45'),(2100,2100,'98-12-19','98.12.19 11:30:45'),(2155,2155,'98-12-18','98.12.18 11:30:45'); + +# As a two-digit string in the range '00' to '99' +INSERT INTO t1 VALUES('20','20','98-12-16','98.12.16 11:30:45'),('40','40','98-12-15','98.12.15 11:30:45'),('60','60','98-12-14','98.12.14 11:30:45'),('69','69','98-12-13','98.12.13 11:30:45'),('70','70','98-12-12','98.12.12 11:30:45'),('90','90','98-12-11','98.12.11 11:30:45'); +INSERT INTO t2 VALUES('00','10','98-12-17','98.12.17 11:30:45'),('20','20','98-12-16','98.12.16 11:30:45'),('40','40','98-12-15','98.12.15 11:30:45'),('60','60','98-12-14','98.12.14 11:30:45'),('69','69','98-12-13','98.12.13 11:30:45'),('70','70','98-12-12','98.12.12 11:30:45'),('90','90','98-12-11','98.12.11 11:30:45'),('99','98','98-12-10','98.12.10 11:30:45'); +INSERT INTO t3 VALUES('00','10','98-12-17','98.12.17 11:30:45'),('20','20','98-12-16','98.12.16 11:30:45'),('40','40','98-12-15','98.12.15 11:30:45'),('60','60','98-12-14','98.12.14 11:30:45'),('69','69','98-12-13','98.12.13 11:30:45'),('70','70','98-12-12','98.12.12 11:30:45'),('90','90','98-12-11','98.12.11 11:30:45'),('99','98','98-12-10','98.12.10 11:30:45'); +INSERT INTO t4 VALUES('00','00','98-12-17','98.12.17 11:30:45'),('20','20','98-12-16','98.12.16 11:30:45'),('40','40','98-12-15','98.12.15 11:30:45'),('60','60','98-12-14','98.12.14 11:30:45'),('69','69','98-12-13','98.12.13 11:30:45'),('70','70','98-12-12','98.12.12 11:30:45'),('90','90','98-12-11','98.12.11 11:30:45'),('99','99','98-12-10','98.12.10 11:30:45'); + +# As a two-digit number in the range 1 to 99 +INSERT INTO t4 VALUES(1,1,'98-12-9','98.12.9 11:30:45'),(20,20,'98-12-8','98.12.8 11:30:45'),(40,40,'98-12-7','98.12.7 11:30:45'),(60,60,'98-12-6','98.12.6 11:30:45'),(69,69,'98-12-5','98.12.5 11:30:45'),(70,70,'98-12-4','98.12.4 11:30:45'),(90,90,'98-12-3','98.12.3 11:30:45'),(99,99,'98-12-2','98.12.2 11:30:45'); + +# As the result of a function +SET TIMESTAMP=1233216687; # 2009-01-29 13:41:27 +INSERT IGNORE INTO t1 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT IGNORE INTO t2 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT IGNORE INTO t3 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT IGNORE INTO t4 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); + +# Insert other valid year values one digit strings, '0', '000' +INSERT INTO t1(c1) VALUES('5'); +INSERT IGNORE INTO t2(c1) VALUES('5'); +INSERT INTO t3(c1) VALUES('5'); +INSERT INTO t4(c1,c2) VALUES('0','000'); + +# Insert invalid year values, outside range, would be converted to zero value +INSERT IGNORE INTO t2 VALUES(1900,2156,'08-01-06','08/01/07'); +INSERT IGNORE INTO t3 VALUES('1900','2156','08-01-08','08/1/9'); +INSERT IGNORE INTO t4 VALUES('1900','2156','08-01-08','08/1/9'),(1900,2156,'08-01-08','08/1/9'),(0,00,'08-01-08','08/1/9'),(000,000,'08-01-08','08/1/9'),('-20','100','08-01-08','08/1/9'),(-20,100,'08-01-08','08/1/9'); + +# Insert empty string '', would be converted to zero +INSERT IGNORE INTO t1 VALUES('','','08-01-04','08/01/05') /* Inserts zero dates for '' strings */; + +# Insert non-date value(absurd values), would be converted to zero +INSERT IGNORE INTO t4 VALUES('abcd','abcd','08-01-10','08/01/11'),(1234,1234,'08-01-12','08/01/13') /* Inserts zero dates for absurd dates */; + +# Insert duplicates for parts of the clustered key/unique index +INSERT INTO t2 VALUES('20','30','98-12-16','98.12.16 11:30:45'),('40','20','98-12-15','98.12.15 11:30:45'); +INSERT INTO t3 VALUES('00','20','98-12-17','98.12.17 11:30:45'),('20','40','98-12-10','98.12.10 11:30:45'); + +# Insert permissible NULLs +INSERT INTO t1 VALUES(80,NULL,'08-01-02','08/01/03'); +INSERT INTO t3 VALUES(80,NULL,'08-01-02','08/01/03'); +INSERT INTO t4 VALUES(80,NULL,'08-01-02','08/01/03'); + +# Insert duplicate NULLs to unique column +INSERT INTO t1(c1,c2) VALUES(1992,NULL); + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; + +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '1901' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1901' AND '2020' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '1901' AND '2020' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1901','2020') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('1901','2020') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1901' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1901' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '1901' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '1901' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1901' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '1901' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '1901' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '1901' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1901' AND '2020' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '1901' AND '2020' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1901','2020') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('1901','2020') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1901' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1901' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '10' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '10' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '10' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '10' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '10' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '10' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '10' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '10' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '10' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '10' AND '2020' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '10' AND '2020' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('10','2020') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('10','2020') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '10' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '10' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '10' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '10' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '10' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '10' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '10' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '10' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '10' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '10' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '10' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '10' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '10' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '10' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '10' AND '2020' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '10' AND '2020' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('10','2020') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('10','2020') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '10' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '10' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; + +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = 2155 ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1970' AND 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN '1970' AND 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1970',2155) ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN ('1970',2155) ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1970' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '1970' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1970' AND 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN '1970' AND 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1970',2155) ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN ('1970',2155) ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1970' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '1970' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; + +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = NULL ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '1970' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1970' AND '2020' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '1970' AND '2020' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1970','2020') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('1970','2020') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1970' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1970' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '1970' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '1970' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1970' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '1970' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '1970' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '1970' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1970' AND '2020' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '1970' AND '2020' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1970','2020') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('1970','2020') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1970' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1970' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '69' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN 69 AND '2020' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN 69 AND '2020' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN (69,'2020') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN (69,'2020') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= 69 AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= 69 AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '69' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '69' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '69' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '69' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '69' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '69' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN 69 AND '2020' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN 69 AND '2020' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN (69,'2020') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN (69,'2020') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= 69 AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= 69 AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = 2000 ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '2000' AND 2155 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN '2000' AND 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('2000',2155) ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN ('2000',2155) ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '2000' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '2000' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> 2000 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > 2000 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= 2000 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < 2000 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= 2000 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> 2000 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '2000' AND 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN '2000' AND 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('2000',2155) ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN ('2000',2155) ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '2000' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '2000' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c1 FROM t3 GROUP BY c1; +--sorted_result +SELECT DISTINCT c1 FROM t3; +--sorted_result +SELECT c1,MIN(c2) FROM t3 GROUP BY c1; + +# Using Index-merge +--sorted_result +SELECT * FROM t1 WHERE c1='1901' OR c2='2155'; +# Test Error conditions- PK constraint violation, Unique constraint violation + +# Insert duplicate value to pk column +--error ER_DUP_ENTRY +INSERT INTO t1(c1,c2) VALUES(01,'99'); + +# Insert duplicate value to clustered pk, throws error +--error ER_DUP_ENTRY +INSERT INTO t2(c1,c2) VALUES(99,99); + +# Insert duplicate value to unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t1(c1,c2) VALUES('2098',69); + +# Insert duplicate value to clustered unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t3(c1,c2) VALUES(00,00); + +# Test 'INSERT IGNORE' +# Ignore pk constraint +INSERT IGNORE INTO t1(c1,c2) VALUES(01,'99'); +INSERT IGNORE INTO t2(c1,c2) VALUES('1999','1999'); +# Ignore unique constraint +INSERT IGNORE INTO t1(c1,c2) VALUES('2098','69'); +INSERT IGNORE INTO t3(c1,c2) VALUES(00,00); +SELECT * FROM t1 WHERE c1='01' /* Returns 1 row */; +SELECT * FROM t2 WHERE c1='1999' AND c2='1999' /* Returns 1 row */; +SELECT * FROM t1 WHERE c2='69' /* Returns 1 row */; +SELECT * FROM t3 WHERE c1=0 AND c2=0 /* Returns 1 row */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with PK one column/multi-column +SELECT * FROM t1 WHERE c1='02' /* Returns no rows */; +INSERT INTO t1(c1) VALUES('00') ON DUPLICATE KEY UPDATE c1='02'; +SELECT * FROM t1 WHERE c1='2002' /* Returns 1 row */; +SELECT * FROM t2 WHERE c1=69 AND c2=70 /* Returns no rows */; +INSERT INTO t2 VALUES(99,99,'98-12-20','98.12.20 11:30:45') ON DUPLICATE KEY UPDATE c1=69,c2=70; +SELECT * FROM t2 WHERE c1=2069 AND c2=1970 /* Returns 1 row */; +# Test 'INSERT ON DUPLICATE KEY UPDATE' with unique one column/multi-column +SELECT * FROM t1 WHERE c1=54 AND c2=53 /* Returns no rows */; +INSERT INTO t1 VALUES(69,69,'98-12-18','98.12.18 11:30:45') ON DUPLICATE KEY UPDATE c1=54,c2=53; +SELECT * FROM t1 WHERE c1=54 AND c2=53 /* Returns 1 row */; +SELECT * FROM t3 WHERE c1=6 AND c2=1970 /* Returns no rows */; +INSERT INTO t3(c1,c2) VALUES('69','69') ON DUPLICATE KEY UPDATE c1=06,c2=70; +SELECT * FROM t3 WHERE c1=2006 AND c2=1970 /* Returns 1 row */; + +# Test 'INSERT INTO SELECT FROM' +CREATE TABLE t5(c1 YEAR NOT NULL, c2 YEAR NULL, c3 DATE, c4 DATETIME, INDEX idx(c1,c2)); +INSERT INTO t5 SELECT * FROM t1; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +INSERT INTO t5 SELECT * FROM t2 WHERE c1 >=1970 AND c1 < 1999 AND c2 <> '1990'; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +INSERT INTO t5 SELECT * FROM t3 WHERE c2 BETWEEN '2000' AND '2155'; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +DROP TABLE t5; + +# Test 'INSERT SET' +INSERT INTO t1 SET c1='00'; +INSERT IGNORE INTO t2 SET c1=69; +INSERT INTO t3 SET c1=70; +INSERT IGNORE INTO t4 SET c2=99; +--sorted_result +SELECT * FROM t1 WHERE c1=0; +--sorted_result +SELECT * FROM t2 WHERE c1=69; +--sorted_result +SELECT * FROM t3 WHERE c1=70; +--sorted_result +SELECT * FROM t4 WHERE c2=99; +DROP TABLE t1,t2,t3,t4; + +######## Running INSERT tests for YEAR(2) ######## + +# Create tables +CREATE TABLE t1(c1 YEAR(2) NOT NULL, c2 YEAR(2) NULL, c3 DATE, c4 DATETIME, PRIMARY KEY(c1), UNIQUE INDEX(c2)); +CREATE TABLE t2(c1 YEAR(2) NOT NULL, c2 YEAR(2) NULL, c3 DATE, c4 DATETIME, PRIMARY KEY(c1,c2)); +CREATE TABLE t3(c1 YEAR(2) NOT NULL, c2 YEAR(2) NULL, c3 DATE, c4 DATETIME, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t4(c1 YEAR(2) NOT NULL, c2 YEAR(2) NULL, c3 DATE, c4 DATETIME); +# Insert some rows with targeted values + +# As a four-digit string in the range '1901' to '2155' +INSERT INTO t1 VALUES('1901','1901','98-12-31','98.12.31 11:30:45'),('1999','1999','98-12-30','98.12.30 11:30:45'),('2000','2000','98-12-29','98.12.29 11:30:45'),('2001','2001','98-12-28','98.12.28 11:30:45'),('2099','2099','98-12-27','98.12.27 11:30:45'),('2100','2100','98-12-26','98.12.26 11:30:45'),('2155','2155','98-12-26','98.12.26 11:30:45'); +INSERT INTO t2 VALUES('1901','1901','98-12-31','98.12.31 11:30:45'),('1999','1999','98-12-30','98.12.30 11:30:45'),('2000','2000','98-12-29','98.12.29 11:30:45'),('2001','2001','98-12-28','98.12.28 11:30:45'),('2099','2099','98-12-27','98.12.27 11:30:45'),('2100','2100','98-12-26','98.12.26 11:30:45'),('2155','2155','98-12-26','98.12.26 11:30:45'); +INSERT INTO t3 VALUES('1901','1901','98-12-31','98.12.31 11:30:45'),('1999','1999','98-12-30','98.12.30 11:30:45'),('2000','2000','98-12-29','98.12.29 11:30:45'),('2001','2001','98-12-28','98.12.28 11:30:45'),('2099','2099','98-12-27','98.12.27 11:30:45'),('2100','2100','98-12-26','98.12.26 11:30:45'),('2155','2155','98-12-26','98.12.26 11:30:45'); +INSERT INTO t4 VALUES('1901','1901','98-12-31','98.12.31 11:30:45'),('1999','1999','98-12-30','98.12.30 11:30:45'),('2000','2000','98-12-29','98.12.29 11:30:45'),('2001','2001','98-12-28','98.12.28 11:30:45'),('2099','2099','98-12-27','98.12.27 11:30:45'),('2100','2100','98-12-26','98.12.26 11:30:45'),('2155','2155','98-12-25','98.12.25 11:30:45'); + +# As a four-digit number in the range 1901 to 2155 +INSERT INTO t4 VALUES(1901,1901,'98-12-24','98.12.24 11:30:45'),(1999,1999,'98-12-23','98.12.23 11:30:45'),(2000,2000,'98-12-22','98.12.22 11:30:45'),(2001,2001,'98-12-21','98.12.21 11:30:45'),(2099,2099,'98-12-20','98.12.20 11:30:45'),(2100,2100,'98-12-19','98.12.19 11:30:45'),(2155,2155,'98-12-18','98.12.18 11:30:45'); + +# As a two-digit string in the range '00' to '99' +INSERT INTO t1 VALUES('20','20','98-12-16','98.12.16 11:30:45'),('40','40','98-12-15','98.12.15 11:30:45'),('60','60','98-12-14','98.12.14 11:30:45'),('69','69','98-12-13','98.12.13 11:30:45'),('70','70','98-12-12','98.12.12 11:30:45'),('90','90','98-12-11','98.12.11 11:30:45'); +INSERT INTO t2 VALUES('00','10','98-12-17','98.12.17 11:30:45'),('20','20','98-12-16','98.12.16 11:30:45'),('40','40','98-12-15','98.12.15 11:30:45'),('60','60','98-12-14','98.12.14 11:30:45'),('69','69','98-12-13','98.12.13 11:30:45'),('70','70','98-12-12','98.12.12 11:30:45'),('90','90','98-12-11','98.12.11 11:30:45'),('99','98','98-12-10','98.12.10 11:30:45'); +INSERT INTO t3 VALUES('00','10','98-12-17','98.12.17 11:30:45'),('20','20','98-12-16','98.12.16 11:30:45'),('40','40','98-12-15','98.12.15 11:30:45'),('60','60','98-12-14','98.12.14 11:30:45'),('69','69','98-12-13','98.12.13 11:30:45'),('70','70','98-12-12','98.12.12 11:30:45'),('90','90','98-12-11','98.12.11 11:30:45'),('99','98','98-12-10','98.12.10 11:30:45'); +INSERT INTO t4 VALUES('00','00','98-12-17','98.12.17 11:30:45'),('20','20','98-12-16','98.12.16 11:30:45'),('40','40','98-12-15','98.12.15 11:30:45'),('60','60','98-12-14','98.12.14 11:30:45'),('69','69','98-12-13','98.12.13 11:30:45'),('70','70','98-12-12','98.12.12 11:30:45'),('90','90','98-12-11','98.12.11 11:30:45'),('99','99','98-12-10','98.12.10 11:30:45'); + +# As a two-digit number in the range 1 to 99 +INSERT INTO t4 VALUES(1,1,'98-12-9','98.12.9 11:30:45'),(20,20,'98-12-8','98.12.8 11:30:45'),(40,40,'98-12-7','98.12.7 11:30:45'),(60,60,'98-12-6','98.12.6 11:30:45'),(69,69,'98-12-5','98.12.5 11:30:45'),(70,70,'98-12-4','98.12.4 11:30:45'),(90,90,'98-12-3','98.12.3 11:30:45'),(99,99,'98-12-2','98.12.2 11:30:45'); + +# As the result of a function +SET TIMESTAMP=1233216687; # 2009-01-29 13:41:27 +INSERT IGNORE INTO t1 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT IGNORE INTO t2 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT IGNORE INTO t3 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); +INSERT IGNORE INTO t4 VALUES(NOW(),CURRENT_DATE,NOW(),CURRENT_DATE); + +# Insert other valid year values one digit strings, '0', '000' +INSERT INTO t1(c1) VALUES('5'); +INSERT IGNORE INTO t2(c1) VALUES('5'); +INSERT INTO t3(c1) VALUES('5'); +INSERT INTO t4(c1,c2) VALUES('0','000'); + +# Insert invalid year values, outside range, would be converted to zero value +INSERT IGNORE INTO t2 VALUES(1900,2156,'08-01-06','08/01/07'); +INSERT IGNORE INTO t3 VALUES('1900','2156','08-01-08','08/1/9'); +INSERT IGNORE INTO t4 VALUES('1900','2156','08-01-08','08/1/9'),(1900,2156,'08-01-08','08/1/9'),(0,00,'08-01-08','08/1/9'),(000,000,'08-01-08','08/1/9'),('-20','100','08-01-08','08/1/9'),(-20,100,'08-01-08','08/1/9'); + +# Insert empty string '', would be converted to zero +INSERT IGNORE INTO t1 VALUES('','','08-01-04','08/01/05') /* Inserts zero dates for '' strings */; + +# Insert non-date value(absurd values), would be converted to zero +INSERT IGNORE INTO t4 VALUES('abcd','abcd','08-01-10','08/01/11'),(1234,1234,'08-01-12','08/01/13') /* Inserts zero dates for absurd dates */; + +# Insert duplicates for parts of the clustered key/unique index +INSERT INTO t2 VALUES('20','30','98-12-16','98.12.16 11:30:45'),('40','20','98-12-15','98.12.15 11:30:45'); +INSERT INTO t3 VALUES('00','20','98-12-17','98.12.17 11:30:45'),('20','40','98-12-10','98.12.10 11:30:45'); + +# Insert permissible NULLs +INSERT INTO t1 VALUES(80,NULL,'08-01-02','08/01/03'); +INSERT INTO t3 VALUES(80,NULL,'08-01-02','08/01/03'); +INSERT INTO t4 VALUES(80,NULL,'08-01-02','08/01/03'); + +# Insert duplicate NULLs to unique column +INSERT INTO t1(c1,c2) VALUES(1992,NULL); + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; + +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '1901' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 > '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 < '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1901' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '1901' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1901' AND '2020' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '1901' AND '2020' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1901','2020') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('1901','2020') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1901' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '1901' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '1901' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 > '1901' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1901' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 < '1901' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <= '1901' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '1901' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '1901' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '1901' AND '2020' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '1901' AND '2020' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('1901','2020') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('1901','2020') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '1901' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '1901' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c1 = '10' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 = '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 = '10' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 = '10' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c1 <> '10' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 > '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '10' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <=> '10' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '10' AND '2020' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN '10' AND '2020' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('10','2020') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IN ('10','2020') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '10' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 >= '10' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c1 <> '10' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <> '10' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > '10' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '10' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 < '10' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= '10' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> '10' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> '10' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN '10' AND '2020' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 BETWEEN '10' AND '2020' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN ('10','2020') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN ('10','2020') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= '10' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= '10' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = 2155 ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1970' AND 2155 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN '1970' AND 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1970',2155) ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN ('1970',2155) ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1970' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= '1970' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN '1970' AND 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN '1970' AND 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN ('1970',2155) ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN ('1970',2155) ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= '1970' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= '1970' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t2; +--sorted_result +SELECT * FROM t2 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t2; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t2 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t2 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t2 WHERE c2 = NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 = NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 = NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 = NULL ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t2 WHERE c2 <> NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <> NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 > NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 > NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 < NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 < NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <= NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 <=> NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t2 WHERE c2 <> NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <> NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 > NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 < NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 < NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <= NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <= NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 <=> NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '1970' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1970' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '1970' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1970' AND '2020' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN '1970' AND '2020' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1970','2020') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN ('1970','2020') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1970' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '1970' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '1970' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '1970' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1970' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '1970' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '1970' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '1970' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '1970' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN '1970' AND '2020' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN '1970' AND '2020' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN ('1970','2020') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN ('1970','2020') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '1970' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '1970' AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c1 = '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 = '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 = '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 = '69' ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c1 <> '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <> '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 > '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 > '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 < '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 < '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <= '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '69' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 <=> '69' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN 69 AND '2020' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 BETWEEN 69 AND '2020' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IN (69,'2020') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IN (69,'2020') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 >= 69 AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 >= 69 AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c1 <> '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <> '69' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 > '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 > '69' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= '69' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 < '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 < '69' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <= '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <= '69' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 <=> '69' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 <=> '69' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 BETWEEN 69 AND '2020' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 BETWEEN 69 AND '2020' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IN (69,'2020') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IN (69,'2020') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 >= 69 AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 >= 69 AND c1 < '2020' AND c2 = '2009' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c1 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = 2000 ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 2000 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> 2000 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '2000' AND 2155 ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN '2000' AND 2155 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('2000',2155) ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN ('2000',2155) ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '2000' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= '2000' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> 2000 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > 2000 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= 2000 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < 2000 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= 2000 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> 2000 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> 2000 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN '2000' AND 2155 ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN '2000' AND 2155 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN ('2000',2155) ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN ('2000',2155) ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= '2000' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= '2000' AND c2 < 2155 AND c1 = '1999' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; +## Full table scan ## +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT count(*) as total_rows, min(c2) as min_value, max(c2) FROM t3; +--sorted_result +SELECT * FROM t3 WHERE c3 = '1998-12-11'; + +## Forward index scan, covering ## +--sorted_result +SELECT c1,c2 FROM t3; + +## Backward index scan, covering ## +SELECT c1,c2 FROM t3 ORDER BY c1,c2 DESC; + +## Forward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 LIMIT 2; + +## Backward index scan, non-covering ## +SELECT * FROM t3 ORDER BY c1,c2 DESC LIMIT 2; + +## ref type access +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 = NULL ORDER BY c1,c2 DESC LIMIT 2; + +## Range access, ordered ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 LIMIT 2; + +## Range access, backwards scan ## +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <> NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 > NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 < NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <= NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 <=> NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 BETWEEN NULL AND '2069' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IN (NULL,'2069') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 >= NULL AND c2 < '2069' AND c1 = '2000' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NULL ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC; +SELECT * FROM t3 WHERE c2 IS NOT NULL ORDER BY c1,c2 DESC LIMIT 2; + +# Using index for group-by +--sorted_result +SELECT c1 FROM t3 GROUP BY c1; +--sorted_result +SELECT DISTINCT c1 FROM t3; +--sorted_result +SELECT c1,MIN(c2) FROM t3 GROUP BY c1; + +# Using Index-merge +--sorted_result +SELECT * FROM t1 WHERE c1='1901' OR c2='2155'; +# Test Error conditions- PK constraint violation, Unique constraint violation + +# Insert duplicate value to pk column +--error ER_DUP_ENTRY +INSERT INTO t1(c1,c2) VALUES(01,'99'); + +# Insert duplicate value to clustered pk, throws error +--error ER_DUP_ENTRY +INSERT INTO t2(c1,c2) VALUES(99,99); + +# Insert duplicate value to unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t1(c1,c2) VALUES('2098',69); + +# Insert duplicate value to clustered unique column, throws error +--error ER_DUP_ENTRY +INSERT INTO t3(c1,c2) VALUES(00,00); + +# Test 'INSERT IGNORE' +# Ignore pk constraint +INSERT IGNORE INTO t1(c1,c2) VALUES(01,'99'); +INSERT IGNORE INTO t2(c1,c2) VALUES('1999','1999'); +# Ignore unique constraint +INSERT IGNORE INTO t1(c1,c2) VALUES('2098','69'); +INSERT IGNORE INTO t3(c1,c2) VALUES(00,00); +SELECT * FROM t1 WHERE c1='01' /* Returns 1 row */; +SELECT * FROM t2 WHERE c1='1999' AND c2='1999' /* Returns 1 row */; +SELECT * FROM t1 WHERE c2='69' /* Returns 1 row */; +SELECT * FROM t3 WHERE c1=0 AND c2=0 /* Returns 1 row */; + +# Test 'INSERT ON DUPLICATE KEY UPDATE' with PK one column/multi-column +SELECT * FROM t1 WHERE c1='02' /* Returns no rows */; +INSERT INTO t1(c1) VALUES('00') ON DUPLICATE KEY UPDATE c1='02'; +SELECT * FROM t1 WHERE c1='2002' /* Returns 1 row */; +SELECT * FROM t2 WHERE c1=69 AND c2=70 /* Returns no rows */; +INSERT INTO t2 VALUES(99,99,'98-12-20','98.12.20 11:30:45') ON DUPLICATE KEY UPDATE c1=69,c2=70; +SELECT * FROM t2 WHERE c1=2069 AND c2=1970 /* Returns 1 row */; +# Test 'INSERT ON DUPLICATE KEY UPDATE' with unique one column/multi-column +SELECT * FROM t1 WHERE c1=54 AND c2=53 /* Returns no rows */; +INSERT INTO t1 VALUES(69,69,'98-12-18','98.12.18 11:30:45') ON DUPLICATE KEY UPDATE c1=54,c2=53; +SELECT * FROM t1 WHERE c1=54 AND c2=53 /* Returns 1 row */; +SELECT * FROM t3 WHERE c1=6 AND c2=1970 /* Returns no rows */; +INSERT INTO t3(c1,c2) VALUES('69','69') ON DUPLICATE KEY UPDATE c1=06,c2=70; +SELECT * FROM t3 WHERE c1=2006 AND c2=1970 /* Returns 1 row */; + +# Test 'INSERT INTO SELECT FROM' +CREATE TABLE t5(c1 YEAR NOT NULL, c2 YEAR NULL, c3 DATE, c4 DATETIME, INDEX idx(c1,c2)); +INSERT INTO t5 SELECT * FROM t1; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +INSERT INTO t5 SELECT * FROM t2 WHERE c1 >=1970 AND c1 < 1999 AND c2 <> '1990'; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +INSERT INTO t5 SELECT * FROM t3 WHERE c2 BETWEEN '2000' AND '2155'; +--sorted_result +SELECT * FROM t5; +TRUNCATE TABLE t5; +DROP TABLE t5; + +# Test 'INSERT SET' +INSERT INTO t1 SET c1='00'; +INSERT IGNORE INTO t2 SET c1=69; +INSERT INTO t3 SET c1=70; +INSERT IGNORE INTO t4 SET c2=99; +--sorted_result +SELECT * FROM t1 WHERE c1=0; +--sorted_result +SELECT * FROM t2 WHERE c1=69; +--sorted_result +SELECT * FROM t3 WHERE c1=70; +--sorted_result +SELECT * FROM t4 WHERE c2=99; +DROP TABLE t1,t2,t3,t4; + diff --git a/mysql-test/suite/engines/iuds/t/sample.txt b/mysql-test/suite/engines/iuds/t/sample.txt new file mode 100644 index 00000000..45d36053 --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/sample.txt @@ -0,0 +1,500 @@ +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. +This is a sample text. diff --git a/mysql-test/suite/engines/iuds/t/strings_charsets_update_delete.test b/mysql-test/suite/engines/iuds/t/strings_charsets_update_delete.test new file mode 100644 index 00000000..a648af6d --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/strings_charsets_update_delete.test @@ -0,0 +1,134 @@ +--disable_warnings +--enable_warnings +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18; + +######## Running UPDATE tests ######## + +#Test for latin1 character set +CREATE TABLE t5(c1 CHAR(1) CHARACTER SET latin1); +# Insert some targeted values for latin1 character set; borrowing from ctype_latin.test in the main suite +eval INSERT INTO t5 VALUES (0x00),(0x01),(0x02),(0x03),(0x04),(0x05),(0x06),(0x07); +eval INSERT INTO t5 VALUES (0x08),(0x09),(0x0A),(0x0B),(0x0C),(0x0D),(0x0E),(0x0F); +eval INSERT INTO t5 VALUES (0x10),(0x11),(0x12),(0x13),(0x14),(0x15),(0x16),(0x17); +eval INSERT INTO t5 VALUES (0x18),(0x19),(0x1A),(0x1B),(0x1C),(0x1D),(0x1E),(0x1F); +eval INSERT INTO t5 VALUES (0x20),(0x21),(0x22),(0x23),(0x24),(0x25),(0x26),(0x27); +eval INSERT INTO t5 VALUES (0x28),(0x29),(0x2A),(0x2B),(0x2C),(0x2D),(0x2E),(0x2F); +eval INSERT INTO t5 VALUES (0x30),(0x31),(0x32),(0x33),(0x34),(0x35),(0x36),(0x37); +eval INSERT INTO t5 VALUES (0x38),(0x39),(0x3A),(0x3B),(0x3C),(0x3D),(0x3E),(0x3F); +eval INSERT INTO t5 VALUES (0x40),(0x41),(0x42),(0x43),(0x44),(0x45),(0x46),(0x47); +eval INSERT INTO t5 VALUES (0x48),(0x49),(0x4A),(0x4B),(0x4C),(0x4D),(0x4E),(0x4F); +eval INSERT INTO t5 VALUES (0x50),(0x51),(0x52),(0x53),(0x54),(0x55),(0x56),(0x57); +eval INSERT INTO t5 VALUES (0x58),(0x59),(0x5A),(0x5B),(0x5C),(0x5D),(0x5E),(0x5F); +eval INSERT INTO t5 VALUES (0x60),(0x61),(0x62),(0x63),(0x64),(0x65),(0x66),(0x67); +eval INSERT INTO t5 VALUES (0x68),(0x69),(0x6A),(0x6B),(0x6C),(0x6D),(0x6E),(0x6F); +eval INSERT INTO t5 VALUES (0x70),(0x71),(0x72),(0x73),(0x74),(0x75),(0x76),(0x77); +eval INSERT INTO t5 VALUES (0x78),(0x79),(0x7A),(0x7B),(0x7C),(0x7D),(0x7E),(0x7F); +eval INSERT INTO t5 VALUES (0x80),(0x81),(0x82),(0x83),(0x84),(0x85),(0x86),(0x87); +eval INSERT INTO t5 VALUES (0x88),(0x89),(0x8A),(0x8B),(0x8C),(0x8D),(0x8E),(0x8F); +eval INSERT INTO t5 VALUES (0x90),(0x91),(0x92),(0x93),(0x94),(0x95),(0x96),(0x97); +eval INSERT INTO t5 VALUES (0x98),(0x99),(0x9A),(0x9B),(0x9C),(0x9D),(0x9E),(0x9F); +eval INSERT INTO t5 VALUES (0xA0),(0xA1),(0xA2),(0xA3),(0xA4),(0xA5),(0xA6),(0xA7); +eval INSERT INTO t5 VALUES (0xA8),(0xA9),(0xAA),(0xAB),(0xAC),(0xAD),(0xAE),(0xAF); +eval INSERT INTO t5 VALUES (0xB0),(0xB1),(0xB2),(0xB3),(0xB4),(0xB5),(0xB6),(0xB7); +eval INSERT INTO t5 VALUES (0xB8),(0xB9),(0xBA),(0xBB),(0xBC),(0xBD),(0xBE),(0xBF); +eval INSERT INTO t5 VALUES (0xC0),(0xC1),(0xC2),(0xC3),(0xC4),(0xC5),(0xC6),(0xC7); +eval INSERT INTO t5 VALUES (0xC8),(0xC9),(0xCA),(0xCB),(0xCC),(0xCD),(0xCE),(0xCF); +eval INSERT INTO t5 VALUES (0xD0),(0xD1),(0xD2),(0xD3),(0xD4),(0xD5),(0xD6),(0xD7); +eval INSERT INTO t5 VALUES (0xD8),(0xD9),(0xDA),(0xDB),(0xDC),(0xDD),(0xDE),(0xDF); +eval INSERT INTO t5 VALUES (0xE0),(0xE1),(0xE2),(0xE3),(0xE4),(0xE5),(0xE6),(0xE7); +eval INSERT INTO t5 VALUES (0xE8),(0xE9),(0xEA),(0xEB),(0xEC),(0xED),(0xEE),(0xEF); +eval INSERT INTO t5 VALUES (0xF0),(0xF1),(0xF2),(0xF3),(0xF4),(0xF5),(0xF6),(0xF7); +eval INSERT INTO t5 VALUES (0xF8),(0xF9),(0xFA),(0xFB),(0xFC),(0xFD),(0xFE),(0xFF); +SELECT c1 FROM t5; +CREATE TABLE t6 (a char(1) character set latin2); +INSERT INTO t6 VALUES (0x20),(0x21),(0x22),(0x23),(0x24),(0x25),(0x26),(0x27); +INSERT INTO t6 VALUES (0x28),(0x29),(0x2A),(0x2B),(0x2C),(0x2D),(0x2E),(0x2F); +INSERT INTO t6 VALUES (0x30),(0x31),(0x32),(0x33),(0x34),(0x35),(0x36),(0x37); +INSERT INTO t6 VALUES (0x38),(0x39),(0x3A),(0x3B),(0x3C),(0x3D),(0x3E),(0x3F); +INSERT INTO t6 VALUES (0x40),(0x41),(0x42),(0x43),(0x44),(0x45),(0x46),(0x47); +INSERT INTO t6 VALUES (0x48),(0x49),(0x4A),(0x4B),(0x4C),(0x4D),(0x4E),(0x4F); +INSERT INTO t6 VALUES (0x50),(0x51),(0x52),(0x53),(0x54),(0x55),(0x56),(0x57); +INSERT INTO t6 VALUES (0x58),(0x59),(0x5A),(0x5B),(0x5C),(0x5D),(0x5E),(0x5F); +INSERT INTO t6 VALUES (0x60),(0x61),(0x62),(0x63),(0x64),(0x65),(0x66),(0x67); +INSERT INTO t6 VALUES (0x68),(0x69),(0x6A),(0x6B),(0x6C),(0x6D),(0x6E),(0x6F); +INSERT INTO t6 VALUES (0x70),(0x71),(0x72),(0x73),(0x74),(0x75),(0x76),(0x77); +INSERT INTO t6 VALUES (0x78),(0x79),(0x7A),(0x7B),(0x7C),(0x7D),(0x7E),(0x7F); +INSERT INTO t6 VALUES (0x80),(0x81),(0x82),(0x83),(0x84),(0x85),(0x86),(0x87); +INSERT INTO t6 VALUES (0x88),(0x89),(0x8A),(0x8B),(0x8C),(0x8D),(0x8E),(0x8F); +INSERT INTO t6 VALUES (0x90),(0x91),(0x92),(0x93),(0x94),(0x95),(0x96),(0x97); +INSERT INTO t6 VALUES (0x98),(0x99),(0x9A),(0x9B),(0x9C),(0x9D),(0x9E),(0x9F); +INSERT INTO t6 VALUES (0xA0),(0xA1),(0xA2),(0xA3),(0xA4),(0xA5),(0xA6),(0xA7); +INSERT INTO t6 VALUES (0xA8),(0xA9),(0xAA),(0xAB),(0xAC),(0xAD),(0xAE),(0xAF); +INSERT INTO t6 VALUES (0xB0),(0xB1),(0xB2),(0xB3),(0xB4),(0xB5),(0xB6),(0xB7); +INSERT INTO t6 VALUES (0xB8),(0xB9),(0xBA),(0xBB),(0xBC),(0xBD),(0xBE),(0xBF); +INSERT INTO t6 VALUES (0xC0),(0xC1),(0xC2),(0xC3),(0xC4),(0xC5),(0xC6),(0xC7); +INSERT INTO t6 VALUES (0xC8),(0xC9),(0xCA),(0xCB),(0xCC),(0xCD),(0xCE),(0xCF); +INSERT INTO t6 VALUES (0xD0),(0xD1),(0xD2),(0xD3),(0xD4),(0xD5),(0xD6),(0xD7); +INSERT INTO t6 VALUES (0xD8),(0xD9),(0xDA),(0xDB),(0xDC),(0xDD),(0xDE),(0xDF); +INSERT INTO t6 VALUES (0xE0),(0xE1),(0xE2),(0xE3),(0xE4),(0xE5),(0xE6),(0xE7); +INSERT INTO t6 VALUES (0xE8),(0xE9),(0xEA),(0xEB),(0xEC),(0xED),(0xEE),(0xEF); +INSERT INTO t6 VALUES (0xF0),(0xF1),(0xF2),(0xF3),(0xF4),(0xF5),(0xF6),(0xF7); +INSERT INTO t6 VALUES (0xF8),(0xF9),(0xFA),(0xFB),(0xFC),(0xFD),(0xFE),(0xFF); +SELECT c1 FROM t5; +#Table to test for ascii character set +set names ascii; +select 'e'='`'; +select 'y'='~'; +CREATE TABLE t7(a CHAR(1) CHARACTER SET ascii); +# Insert some targeted values for ascii character set; borrowing from ctype_ascii.test in the main suite + insert into t7 (a) values (' '), ('a'), ('b'), ('c'), ('d'), ('e'), ('f'), ('g'), ('h'), ('i'), ('j'), ('k'), ('l'), ('m'), ('n'), ('o'), ('p'), ('q'), ('r'), ('s'), ('t'), ('u'), ('v'), ('w'), ('x'), ('y'), ('z'), ('A'), ('B'), ('C'), ('D'), ('E'), ('F'), ('G'), ('H'), ('I'), ('J'), ('K'), ('L'), ('M'), ('N'), ('O'), ('P'), ('Q'), ('R'), ('S'), ('T'), ('U'), ('V'), ('W'), ('X'), ('Y'), ('Z'), ('!'), ('@'), ('#'), ('$'), ('%'), ('^'), ('&'), ('*'), ('('), (')'), ('_'), ('+'), ('`'), ('~'), ('1'), ('2'), ('3'), ('4'), ('5'), ('6'), ('7'), ('8'), ('9'), ('0'), ('['), (']'), ('\\'), ('|'), ('}'), ('{'), ('"'), (':'), (''''), (';'), ('/'), ('.'), (','), ('?'), ('>'), ('<'), ('\n'), ('\t'), ('\a'), ('\f'), ('\v'); +SELECT t7a.a, t7b.a FROM t7 as t7a, t7 as t7b WHERE t7a.a=t7b.a ORDER BY BINARY t7a.a, BINARY t7b.a; + UPDATE t7 SET a=CHAR(ASCII(a)+32) WHERE ASCII(a) >= 65 AND ASCII(a) <= 90; + UPDATE t7 SET a=CHAR(ASCII(a)-32) WHERE ASCII(a) >= 97 AND ASCII(a) <= 122; +SELECT a,HEX(a) FROM t7; +#Tests for utf8 character set +CREATE TABLE t8 (a char(10) character set utf8 not null); +INSERT INTO t8 VALUES ('a'),('a\0'),('a\t'),('a '); +SELECT hex(a),STRCMP(a,'a'), STRCMP(a,'a ') FROM t8; +DROP TABLE t8; +CREATE TABLE t8(a VARCHAR(255), KEY(a)) DEFAULT CHARSET=utf8; +eval INSERT INTO t8 VALUES('uUABCDEFGHIGKLMNOPRSTUVWXYZbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'); +INSERT INTO t8 VALUES('uu'); +check table t8; +INSERT INTO t8 VALUES('uU'); +check table t8; +INSERT INTO t8 VALUES('uu'); +check table t8; +INSERT INTO t8 VALUES('uuABC'); +check table t8; +INSERT INTO t8 VALUES('UuABC'); +check table t8; +INSERT INTO t8 VALUES('uuABC'); +check table t8; +alter table t8 add b int; +INSERT INTO t8 VALUES('BCDEFGHIGKLMNOPRSTUVWXYZbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',1); +INSERT INTO t8 VALUES('uuABCDEFGHIGKLMNOPRSTUVWXYZbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',2); +delete from t8 where b=1; +INSERT INTO t8 VALUES('UUABCDEFGHIGKLMNOPRSTUVWXYZbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',1); +check table t8; +INSERT INTO t8 VALUES('uuABCDEFGHIGKLMNOPRSTUVWXYZbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',3); +INSERT INTO t8 VALUES('uuABCDEFGHIGKLMNOPRSTUVWXYZbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',4); +delete from t8 where b=3; +INSERT INTO t8 VALUES('uUABCDEFGHIGKLMNOPRSTUVWXYZbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',3); +check table t8; +UPDATE t8 SET a=REPEAT('Z',255) WHERE a LIKE 'uu%'; +SELECT a,LENGTH(a) FROM t8; +drop table t8; +SET collation_connection = 'utf8_general_ci'; +CREATE TABLE t8 (c1 TEXT character set utf8 collate utf8_general_ci); +insert into t8 values (repeat('बांग्लादे',1200)); +insert into t8 values ('রবীন্দ্রনাথ ঠাকুর'); +insert into t8 values (LOAD_FILE('$MYSQLTEST_VARDIR/hindi.txt')); +ALTER TABLE t8 ADD c2 TEXT CHARACTER SET utf8 collate utf8_general_ci DEFAULT NULL; +INSERT INTO t8 values (repeat('রবীন্দ্রনাথ ঠাকুর',1300),''); +ALTER TABLE t8 ADD INDEX(c1(18)); +UPDATE t8 SET c2='यह हिन्दी में एक अलग वाक्य है. यह एक अलग कॉलम में जोड़ा जा रहा है' WHERE c2=NULL; +SELECT length(c1),c1, length(c2),c2 FROM t8; +SELECT length(c1),c1, length(c2),c2 FROM t8 WHERE c1 LIKE _utf8 'রবীন%' COLLATE utf8_general_ci ; +ALTER TABLE t8 ADD INDEX(c1(18),c2(10)); +SELECT length(c1),c1, length(c2),c2 FROM t8 WHERE c1 LIKE _utf8 'রবীন%' COLLATE utf8_general_ci OR c2 LIKE _utf8 'जग' COLLATE utf8_general_ci; +UPDATE t8 SET c1= REPEAT('৯',12000); +SELECT length(c1),length(c2) FROM t8; +DROP TABLE t8; +SET collation_connection = default; +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18; diff --git a/mysql-test/suite/engines/iuds/t/strings_update_delete.test b/mysql-test/suite/engines/iuds/t/strings_update_delete.test new file mode 100644 index 00000000..736439ca --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/strings_update_delete.test @@ -0,0 +1,146 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18; +--enable_warnings + +######## Running UPDATE tests ######## + +# Generic tables with mixed field types and sizes +CREATE TABLE t1(c1 CHAR(255), c2 TEXT); +eval INSERT INTO t1 VALUES(REPEAT('abcdef',40), REPEAT('1',65535)); +eval INSERT INTO t1 VALUES(REPEAT('abc',80), REPEAT('2',65533)); +eval INSERT INTO t1 VALUES(REPEAT('\t',255), REPEAT('3',65534)); +UPDATE t1 SET c1=REPEAT('\n',255) WHERE c1=REPEAT('\t',255); +--sorted_result +SELECT LENGTH(c1),LENGTH(c2),CHAR_LENGTH(c2) FROM t1; +--sorted_result +SELECT c1, c2 FROM t1 where c1= REPEAT('\n',255); +#--warning 1265 +UPDATE t1 SET c1=REPEAT('xyz',85), c2=REPEAT(c1, 100) ORDER by c1 LIMIT 2; +SHOW WARNINGS; + +--sorted_result +SELECT LENGTH(c2) FROM t1 WHERE c2 LIKE 'xyz%'; +--sorted_result +SELECT LENGTH(c1),LENGTH(c2),CHAR_LENGTH(c2) FROM t1; +--sorted_result +SELECT c1, c2 FROM t1; +--disable_query_log +eval INSERT INTO t1 VALUES(REPEAT('\0',255),LOAD_FILE('$MYSQLTEST_VARDIR/sample.txt')); +--enable_query_log +ALTER TABLE t1 MODIFY c1 TEXT; +UPDATE t1 SET c1=LOAD_FILE('$MYSQLTEST_VARDIR/temp.txt') LIMIT 2; +SHOW WARNINGS; +UPDATE t1 SET c1=NULL WHERE c1 LIKE 'xyz%'; +DELETE FROM t1 LIMIT 1; +DELETE FROM t1 WHERE c1 NOT LIKE 'xyz%' LIMIT 1; +--sorted_result +SELECT length(c1), c1, length(c2), c2 FROM t1; +CREATE TABLE t2(c1 BLOB, c2 TINYBLOB, c3 TEXT); +eval INSERT INTO t2 VALUES(REPEAT('1',65535),REPEAT('a',254),REPEAT('d',65534 )); +eval INSERT INTO t2 VALUES(REPEAT('2',65534),REPEAT('b',253),REPEAT('e',65535 )); +eval INSERT INTO t2 VALUES(REPEAT('3',65533),REPEAT('c',255),REPEAT('f',65533)); +--sorted_result +SELECT c1,c2 FROM t2; +let $i=100; +while($i){ +let $j=100; +while($j){ +eval INSERT INTO t2 VALUES('abcde\t \t fgh \n\n ', ' sdsdsd',NULL); +dec $j; +} +dec $i; +} +--sorted_result +SELECT length(c1),c1, length(c2),c2, length(c3), c3 FROM t2; +UPDATE t2 SET c3='Not NULL' WHERE c3=NULL; +--sorted_result +SELECT length(c1),c1, length(c2),c2, length(c3), c3 FROM t2; + # Multi-table updates/deletes + CREATE TABLE t3 (c1 CHAR(10), c2 CHAR(100)); + INSERT INTO t3 VALUES ('AS','Axel Soa'), ('AK','Axle Kora'), ('HH','Hulk Hogan'); + CREATE TABLE t4 (c1 CHAR(10), c2 CHAR(100)); + INSERT INTO t4 VALUES ('AS','#100, Avenue, UK'), ('AK','#101, Avenue, US'), ('HH','#103, Avenu MT'); + UPDATE t4 SET c2='#102, Avennue MT' WHERE c1='HH'; +--sorted_result +SELECT LENGTH(c1), c1 , LENGTH(c2),c2 FROM t4; +DELETE FROM t3 USING t3,t4 WHERE t3.c1='AS' AND t3.c1=t4.c1 ; +--sorted_result +SELECT length(c1), c1, length(c2), c2 FROM t3; + DROP TABLE t3,t4; + CREATE TABLE t3 (id int(11) NOT NULL default '0',name varchar(10) default NULL,PRIMARY KEY (id)) ; + INSERT INTO t3 VALUES (1, 'aaa'),(2,'aaa'),(3,'aaa'); + CREATE TABLE t4 (id int(11) NOT NULL default '0',name varchar(10) default NULL, PRIMARY KEY (id)) ; + INSERT INTO t4 VALUES (2,'bbb'),(3,'bbb'),(4,'bbb'); + CREATE TABLE t5 (id int(11) NOT NULL default '0', mydate datetime default NULL,PRIMARY KEY (id)); +INSERT INTO t5 VALUES (1,'2002-02-04 00:00:00'),(3,'2002-05-12 00:00:00'),(5,'2002-05-12 00:00:00'),(6,'2002-06-22 00:00:00'),(7,'2002-07-22 00:00:00'); +delete t3,t4,t5 from t3,t4,t5 where to_days(now())-to_days(t5.mydate)>=30 and t5.id=t3.id and t5.id=t4.id; +select * from t5; +DROP TABLE t3,t4,t5; +CREATE TABLE t6 (a char(2) not null primary key, b varchar(20) not null, key (b)); +CREATE TABLE t7 (a char(2) not null primary key, b varchar(20) not null, key (b)); +INSERT INTO t6 values ('AB','MySQLAB'),('JA','Sun Microsystems'),('MS','Microsoft'),('IB','IBM- Inc.'),('GO','Google Inc.'); +INSERT IGNORE INTO t7 values ('AB','Sweden'),('JA','USA'),('MS','United States of Amercica'),('IB','North America'),('GO','South America'); +update t6,t7 set t6.a=LCASE(t6.a); +--sorted_result +select * from t6; +update t6,t7 set t6.a=UCASE(t6.a) where t6.a='AB'; +--sorted_result +select * from t6; +update t6,t7 set t6.b=UPPER(t6.b) where t6.b LIKE 'United%'; +--sorted_result +select * from t7; +update t6,t7 set t6.b=UPPER(t6.b),t7.b=LOWER(t7.b) where LENGTH(t6.b) between 3 and 5 and t7.a=LOWER(t6.a); +--sorted_result +select * from t6; +--sorted_result +select * from t7; +drop table t6,t7; + # Test for some STRING functions on TEXT columns +CREATE TABLE t12(c1 TINYTEXT, c2 TEXT, c3 MEDIUMTEXT, c4 LONGTEXT); +eval INSERT INTO t12 values (" This is a test ","\0 \0 for STRING","functions available \t in", " \t\t MySQL " ); +eval UPDATE t12 SET c1="This is a update test!" WHERE c2 LIKE "\0%"; +--sorted_result +SELECT LENGTH(c1),LENGTH(c2),LENGTH(c3),LENGTH(c4) FROM t12; +--sorted_result +SELECT LEFT(c1,5),LEFT(c2,5),LEFT(c3,5),LEFT(c4,5) FROM t12; +--sorted_result +SELECT RTRIM(c1),RTRIM(c2),RTRIM(c3),RTRIM(c4) FROM t12; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3),HEX(c4) FROM t12; +--sorted_result +SELECT REVERSE(c1),REVERSE(c2),REVERSE(c3),REVERSE(c4) FROM t12; +DELETE FROM t12 WHERE C1 LIKE "%update%"; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3),HEX(c4) FROM t12; +# Test for SET datatype +CREATE TABLE t16 (c1 SET('a', 'b', 'c', 'd', 'e')); +eval INSERT INTO t16 VALUES (('d,a,d,d')); +--sorted_result +SELECT c1 FROM t16; +eval INSERT IGNORE INTO t16 (c1) VALUES ('a,b,d'),('d,A ,b'); +--sorted_result +SELECT c1 FROM t16; +#--warning WARN_DATA_TRUNCATED +eval INSERT IGNORE INTO t16 (c1) VALUES ('f,a,b'); +SHOW WARNINGS; +--sorted_result +SELECT c1 FROM t16; +#--warning ER_DUPLICATED_VALUE_IN_TYPE +SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR +CREATE TABLE t17 (c1 SET('a','b','a','b')); +SHOW WARNINGS; +# Tests for ENUM datatype +# Invalid ENUM value insert behavior +CREATE TABLE t18 (c1 CHAR(4),c2 enum('SMALL','MEDIUM','LARGE','VERY LARGE')); +eval INSERT INTO t18 VALUES('SIZE', 'SMALL'); +eval INSERT IGNORE INTO t18 VALUES('SIZE', 'SMALL1'); +--sorted_result +SELECT * FROM t18 WHERE c2=0; + EXPLAIN SELECT * FROM t18 WHERE c2=0; +eval SET sql_mode= 'STRICT_ALL_TABLES'; +--error 1265 +eval INSERT INTO t18 VALUES('SIZE','SMALL2'); +--sorted_result +SELECT * FROM t18 WHERE c2=0; + DROP TABLE t17,t18; +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18; diff --git a/mysql-test/suite/engines/iuds/t/type_bit_iuds.test b/mysql-test/suite/engines/iuds/t/type_bit_iuds.test new file mode 100644 index 00000000..8f48d50f --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/type_bit_iuds.test @@ -0,0 +1,18324 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; +--enable_warnings + +####Checking the bit values#### +SELECT 0 + b'0'; +SELECT 0 + (0<<0); +######### INSERT/SELECT######### + +#### Insert and select 0 bit data into the table#### +CREATE TABLE t1(c1 BIT(0)); +CREATE TABLE t2(c1 BIT(0), c2 BIT(0), c3 BIT(0)); +let $i=0; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'0'); +INSERT INTO t2 VALUES (b'0', b'0', b'0'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(0) NOT NULL PRIMARY KEY, c2 BIT(0)); +CREATE TABLE t6(c1 BIT(0), c2 BIT(0)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(0)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'0'; +SELECT 0 + (0<<1); +######### INSERT/SELECT######### + +#### Insert and select 1 bit data into the table#### +CREATE TABLE t1(c1 BIT(1)); +CREATE TABLE t2(c1 BIT(1), c2 BIT(1), c3 BIT(1)); +let $i=1; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT IGNORE INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'0'); +INSERT INTO t2 VALUES (b'0', b'0', b'0'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(1) NOT NULL PRIMARY KEY, c2 BIT(1)); +CREATE TABLE t6(c1 BIT(1), c2 BIT(1)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(1)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'0'; +SELECT 0 + (0<<2); +######### INSERT/SELECT######### + +#### Insert and select 2 bit data into the table#### +CREATE TABLE t1(c1 BIT(2)); +CREATE TABLE t2(c1 BIT(2), c2 BIT(2), c3 BIT(2)); +let $i=2; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'0'); +INSERT INTO t2 VALUES (b'0', b'0', b'0'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(2) NOT NULL PRIMARY KEY, c2 BIT(2)); +CREATE TABLE t6(c1 BIT(2), c2 BIT(2)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(2)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'0'; +SELECT 0 + (0<<4); +######### INSERT/SELECT######### + +#### Insert and select 4 bit data into the table#### +CREATE TABLE t1(c1 BIT(4)); +CREATE TABLE t2(c1 BIT(4), c2 BIT(4), c3 BIT(4)); +let $i=4; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'0'); +INSERT INTO t2 VALUES (b'0', b'0', b'0'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(4) NOT NULL PRIMARY KEY, c2 BIT(4)); +CREATE TABLE t6(c1 BIT(4), c2 BIT(4)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(4)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE IGNORE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'0'; +SELECT 0 + (0<<8); +######### INSERT/SELECT######### + +#### Insert and select 8 bit data into the table#### +CREATE TABLE t1(c1 BIT(8)); +CREATE TABLE t2(c1 BIT(8), c2 BIT(8), c3 BIT(8)); +let $i=8; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'0'); +INSERT INTO t2 VALUES (b'0', b'0', b'0'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(8) NOT NULL PRIMARY KEY, c2 BIT(8)); +CREATE TABLE t6(c1 BIT(8), c2 BIT(8)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(8)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE IGNORE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE IGNORE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'0'; +SELECT 0 + (0<<16); +######### INSERT/SELECT######### + +#### Insert and select 16 bit data into the table#### +CREATE TABLE t1(c1 BIT(16)); +CREATE TABLE t2(c1 BIT(16), c2 BIT(16), c3 BIT(16)); +let $i=16; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'0'); +INSERT INTO t2 VALUES (b'0', b'0', b'0'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(16) NOT NULL PRIMARY KEY, c2 BIT(16)); +CREATE TABLE t6(c1 BIT(16), c2 BIT(16)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(16)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'0'; +SELECT 0 + (0<<32); +######### INSERT/SELECT######### + +#### Insert and select 32 bit data into the table#### +CREATE TABLE t1(c1 BIT(32)); +CREATE TABLE t2(c1 BIT(32), c2 BIT(32), c3 BIT(32)); +let $i=32; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'0'); +INSERT INTO t2 VALUES (b'0', b'0', b'0'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(32) NOT NULL PRIMARY KEY, c2 BIT(32)); +CREATE TABLE t6(c1 BIT(32), c2 BIT(32)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(32)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'0'; +SELECT 0 + (0<<64); +######### INSERT/SELECT######### + +#### Insert and select 64 bit data into the table#### +CREATE TABLE t1(c1 BIT(64)); +CREATE TABLE t2(c1 BIT(64), c2 BIT(64), c3 BIT(64)); +let $i=64; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'0'); +INSERT INTO t2 VALUES (b'0', b'0', b'0'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(64) NOT NULL PRIMARY KEY, c2 BIT(64)); +CREATE TABLE t6(c1 BIT(64), c2 BIT(64)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(64)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1'; +SELECT 0 + (1<<0); +######### INSERT/SELECT######### + +#### Insert and select 0 bit data into the table#### +CREATE TABLE t1(c1 BIT(0)); +CREATE TABLE t2(c1 BIT(0), c2 BIT(0), c3 BIT(0)); +let $i=0; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1'); +INSERT INTO t2 VALUES (b'1', b'1', b'1'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(0) NOT NULL PRIMARY KEY, c2 BIT(0)); +CREATE TABLE t6(c1 BIT(0), c2 BIT(0)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(0)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1'; +SELECT 0 + (1<<1); +######### INSERT/SELECT######### + +#### Insert and select 1 bit data into the table#### +CREATE TABLE t1(c1 BIT(1)); +CREATE TABLE t2(c1 BIT(1), c2 BIT(1), c3 BIT(1)); +let $i=1; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT IGNORE INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1'); +INSERT INTO t2 VALUES (b'1', b'1', b'1'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(1) NOT NULL PRIMARY KEY, c2 BIT(1)); +CREATE TABLE t6(c1 BIT(1), c2 BIT(1)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(1)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1'; +SELECT 0 + (1<<2); +######### INSERT/SELECT######### + +#### Insert and select 2 bit data into the table#### +CREATE TABLE t1(c1 BIT(2)); +CREATE TABLE t2(c1 BIT(2), c2 BIT(2), c3 BIT(2)); +let $i=2; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1'); +INSERT INTO t2 VALUES (b'1', b'1', b'1'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(2) NOT NULL PRIMARY KEY, c2 BIT(2)); +CREATE TABLE t6(c1 BIT(2), c2 BIT(2)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(2)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1'; +SELECT 0 + (1<<4); +######### INSERT/SELECT######### + +#### Insert and select 4 bit data into the table#### +CREATE TABLE t1(c1 BIT(4)); +CREATE TABLE t2(c1 BIT(4), c2 BIT(4), c3 BIT(4)); +let $i=4; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1'); +INSERT INTO t2 VALUES (b'1', b'1', b'1'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(4) NOT NULL PRIMARY KEY, c2 BIT(4)); +CREATE TABLE t6(c1 BIT(4), c2 BIT(4)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(4)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE IGNORE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1'; +SELECT 0 + (1<<8); +######### INSERT/SELECT######### + +#### Insert and select 8 bit data into the table#### +CREATE TABLE t1(c1 BIT(8)); +CREATE TABLE t2(c1 BIT(8), c2 BIT(8), c3 BIT(8)); +let $i=8; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1'); +INSERT INTO t2 VALUES (b'1', b'1', b'1'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(8) NOT NULL PRIMARY KEY, c2 BIT(8)); +CREATE TABLE t6(c1 BIT(8), c2 BIT(8)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(8)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE IGNORE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE IGNORE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1'; +SELECT 0 + (1<<16); +######### INSERT/SELECT######### + +#### Insert and select 16 bit data into the table#### +CREATE TABLE t1(c1 BIT(16)); +CREATE TABLE t2(c1 BIT(16), c2 BIT(16), c3 BIT(16)); +let $i=16; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1'); +INSERT INTO t2 VALUES (b'1', b'1', b'1'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(16) NOT NULL PRIMARY KEY, c2 BIT(16)); +CREATE TABLE t6(c1 BIT(16), c2 BIT(16)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(16)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1'; +SELECT 0 + (1<<32); +######### INSERT/SELECT######### + +#### Insert and select 32 bit data into the table#### +CREATE TABLE t1(c1 BIT(32)); +CREATE TABLE t2(c1 BIT(32), c2 BIT(32), c3 BIT(32)); +let $i=32; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1'); +INSERT INTO t2 VALUES (b'1', b'1', b'1'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(32) NOT NULL PRIMARY KEY, c2 BIT(32)); +CREATE TABLE t6(c1 BIT(32), c2 BIT(32)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(32)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1'; +SELECT 0 + (1<<64); +######### INSERT/SELECT######### + +#### Insert and select 64 bit data into the table#### +CREATE TABLE t1(c1 BIT(64)); +CREATE TABLE t2(c1 BIT(64), c2 BIT(64), c3 BIT(64)); +let $i=64; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1'); +INSERT INTO t2 VALUES (b'1', b'1', b'1'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(64) NOT NULL PRIMARY KEY, c2 BIT(64)); +CREATE TABLE t6(c1 BIT(64), c2 BIT(64)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(64)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'10'; +SELECT 0 + (10<<0); +######### INSERT/SELECT######### + +#### Insert and select 0 bit data into the table#### +CREATE TABLE t1(c1 BIT(0)); +CREATE TABLE t2(c1 BIT(0), c2 BIT(0), c3 BIT(0)); +let $i=0; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'10'); +INSERT IGNORE INTO t2 VALUES (b'10', b'10', b'10'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(0) NOT NULL PRIMARY KEY, c2 BIT(0)); +CREATE TABLE t6(c1 BIT(0), c2 BIT(0)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(0)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'10'; +SELECT 0 + (10<<1); +######### INSERT/SELECT######### + +#### Insert and select 1 bit data into the table#### +CREATE TABLE t1(c1 BIT(1)); +CREATE TABLE t2(c1 BIT(1), c2 BIT(1), c3 BIT(1)); +let $i=1; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT IGNORE INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'10'); +INSERT IGNORE INTO t2 VALUES (b'10', b'10', b'10'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(1) NOT NULL PRIMARY KEY, c2 BIT(1)); +CREATE TABLE t6(c1 BIT(1), c2 BIT(1)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(1)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'10'; +SELECT 0 + (10<<2); +######### INSERT/SELECT######### + +#### Insert and select 2 bit data into the table#### +CREATE TABLE t1(c1 BIT(2)); +CREATE TABLE t2(c1 BIT(2), c2 BIT(2), c3 BIT(2)); +let $i=2; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'10'); +INSERT INTO t2 VALUES (b'10', b'10', b'10'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(2) NOT NULL PRIMARY KEY, c2 BIT(2)); +CREATE TABLE t6(c1 BIT(2), c2 BIT(2)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(2)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'10'; +SELECT 0 + (10<<4); +######### INSERT/SELECT######### + +#### Insert and select 4 bit data into the table#### +CREATE TABLE t1(c1 BIT(4)); +CREATE TABLE t2(c1 BIT(4), c2 BIT(4), c3 BIT(4)); +let $i=4; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'10'); +INSERT INTO t2 VALUES (b'10', b'10', b'10'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(4) NOT NULL PRIMARY KEY, c2 BIT(4)); +CREATE TABLE t6(c1 BIT(4), c2 BIT(4)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(4)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE IGNORE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'10'; +SELECT 0 + (10<<8); +######### INSERT/SELECT######### + +#### Insert and select 8 bit data into the table#### +CREATE TABLE t1(c1 BIT(8)); +CREATE TABLE t2(c1 BIT(8), c2 BIT(8), c3 BIT(8)); +let $i=8; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'10'); +INSERT INTO t2 VALUES (b'10', b'10', b'10'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(8) NOT NULL PRIMARY KEY, c2 BIT(8)); +CREATE TABLE t6(c1 BIT(8), c2 BIT(8)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(8)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE IGNORE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE IGNORE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'10'; +SELECT 0 + (10<<16); +######### INSERT/SELECT######### + +#### Insert and select 16 bit data into the table#### +CREATE TABLE t1(c1 BIT(16)); +CREATE TABLE t2(c1 BIT(16), c2 BIT(16), c3 BIT(16)); +let $i=16; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'10'); +INSERT INTO t2 VALUES (b'10', b'10', b'10'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(16) NOT NULL PRIMARY KEY, c2 BIT(16)); +CREATE TABLE t6(c1 BIT(16), c2 BIT(16)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(16)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'10'; +SELECT 0 + (10<<32); +######### INSERT/SELECT######### + +#### Insert and select 32 bit data into the table#### +CREATE TABLE t1(c1 BIT(32)); +CREATE TABLE t2(c1 BIT(32), c2 BIT(32), c3 BIT(32)); +let $i=32; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'10'); +INSERT INTO t2 VALUES (b'10', b'10', b'10'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(32) NOT NULL PRIMARY KEY, c2 BIT(32)); +CREATE TABLE t6(c1 BIT(32), c2 BIT(32)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(32)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'10'; +SELECT 0 + (10<<64); +######### INSERT/SELECT######### + +#### Insert and select 64 bit data into the table#### +CREATE TABLE t1(c1 BIT(64)); +CREATE TABLE t2(c1 BIT(64), c2 BIT(64), c3 BIT(64)); +let $i=64; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'10'); +INSERT INTO t2 VALUES (b'10', b'10', b'10'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(64) NOT NULL PRIMARY KEY, c2 BIT(64)); +CREATE TABLE t6(c1 BIT(64), c2 BIT(64)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(64)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010'; +SELECT 0 + (1010<<0); +######### INSERT/SELECT######### + +#### Insert and select 0 bit data into the table#### +CREATE TABLE t1(c1 BIT(0)); +CREATE TABLE t2(c1 BIT(0), c2 BIT(0), c3 BIT(0)); +let $i=0; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010'); +INSERT IGNORE INTO t2 VALUES (b'1010', b'1010', b'1010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(0) NOT NULL PRIMARY KEY, c2 BIT(0)); +CREATE TABLE t6(c1 BIT(0), c2 BIT(0)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(0)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010'; +SELECT 0 + (1010<<1); +######### INSERT/SELECT######### + +#### Insert and select 1 bit data into the table#### +CREATE TABLE t1(c1 BIT(1)); +CREATE TABLE t2(c1 BIT(1), c2 BIT(1), c3 BIT(1)); +let $i=1; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT IGNORE INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010'); +INSERT IGNORE INTO t2 VALUES (b'1010', b'1010', b'1010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(1) NOT NULL PRIMARY KEY, c2 BIT(1)); +CREATE TABLE t6(c1 BIT(1), c2 BIT(1)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(1)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010'; +SELECT 0 + (1010<<2); +######### INSERT/SELECT######### + +#### Insert and select 2 bit data into the table#### +CREATE TABLE t1(c1 BIT(2)); +CREATE TABLE t2(c1 BIT(2), c2 BIT(2), c3 BIT(2)); +let $i=2; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010'); +INSERT IGNORE INTO t2 VALUES (b'1010', b'1010', b'1010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(2) NOT NULL PRIMARY KEY, c2 BIT(2)); +CREATE TABLE t6(c1 BIT(2), c2 BIT(2)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(2)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010'; +SELECT 0 + (1010<<4); +######### INSERT/SELECT######### + +#### Insert and select 4 bit data into the table#### +CREATE TABLE t1(c1 BIT(4)); +CREATE TABLE t2(c1 BIT(4), c2 BIT(4), c3 BIT(4)); +let $i=4; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1010'); +INSERT INTO t2 VALUES (b'1010', b'1010', b'1010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(4) NOT NULL PRIMARY KEY, c2 BIT(4)); +CREATE TABLE t6(c1 BIT(4), c2 BIT(4)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(4)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE IGNORE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010'; +SELECT 0 + (1010<<8); +######### INSERT/SELECT######### + +#### Insert and select 8 bit data into the table#### +CREATE TABLE t1(c1 BIT(8)); +CREATE TABLE t2(c1 BIT(8), c2 BIT(8), c3 BIT(8)); +let $i=8; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1010'); +INSERT INTO t2 VALUES (b'1010', b'1010', b'1010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(8) NOT NULL PRIMARY KEY, c2 BIT(8)); +CREATE TABLE t6(c1 BIT(8), c2 BIT(8)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(8)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE IGNORE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE IGNORE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010'; +SELECT 0 + (1010<<16); +######### INSERT/SELECT######### + +#### Insert and select 16 bit data into the table#### +CREATE TABLE t1(c1 BIT(16)); +CREATE TABLE t2(c1 BIT(16), c2 BIT(16), c3 BIT(16)); +let $i=16; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1010'); +INSERT INTO t2 VALUES (b'1010', b'1010', b'1010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(16) NOT NULL PRIMARY KEY, c2 BIT(16)); +CREATE TABLE t6(c1 BIT(16), c2 BIT(16)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(16)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010'; +SELECT 0 + (1010<<32); +######### INSERT/SELECT######### + +#### Insert and select 32 bit data into the table#### +CREATE TABLE t1(c1 BIT(32)); +CREATE TABLE t2(c1 BIT(32), c2 BIT(32), c3 BIT(32)); +let $i=32; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1010'); +INSERT INTO t2 VALUES (b'1010', b'1010', b'1010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(32) NOT NULL PRIMARY KEY, c2 BIT(32)); +CREATE TABLE t6(c1 BIT(32), c2 BIT(32)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(32)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010'; +SELECT 0 + (1010<<64); +######### INSERT/SELECT######### + +#### Insert and select 64 bit data into the table#### +CREATE TABLE t1(c1 BIT(64)); +CREATE TABLE t2(c1 BIT(64), c2 BIT(64), c3 BIT(64)); +let $i=64; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1010'); +INSERT INTO t2 VALUES (b'1010', b'1010', b'1010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(64) NOT NULL PRIMARY KEY, c2 BIT(64)); +CREATE TABLE t6(c1 BIT(64), c2 BIT(64)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(64)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010101010101010'; +SELECT 0 + (1010101010101010<<0); +######### INSERT/SELECT######### + +#### Insert and select 0 bit data into the table#### +CREATE TABLE t1(c1 BIT(0)); +CREATE TABLE t2(c1 BIT(0), c2 BIT(0), c3 BIT(0)); +let $i=0; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'1010101010101010', b'1010101010101010', b'1010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(0) NOT NULL PRIMARY KEY, c2 BIT(0)); +CREATE TABLE t6(c1 BIT(0), c2 BIT(0)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(0)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010101010101010'; +SELECT 0 + (1010101010101010<<1); +######### INSERT/SELECT######### + +#### Insert and select 1 bit data into the table#### +CREATE TABLE t1(c1 BIT(1)); +CREATE TABLE t2(c1 BIT(1), c2 BIT(1), c3 BIT(1)); +let $i=1; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT IGNORE INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'1010101010101010', b'1010101010101010', b'1010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(1) NOT NULL PRIMARY KEY, c2 BIT(1)); +CREATE TABLE t6(c1 BIT(1), c2 BIT(1)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(1)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010101010101010'; +SELECT 0 + (1010101010101010<<2); +######### INSERT/SELECT######### + +#### Insert and select 2 bit data into the table#### +CREATE TABLE t1(c1 BIT(2)); +CREATE TABLE t2(c1 BIT(2), c2 BIT(2), c3 BIT(2)); +let $i=2; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'1010101010101010', b'1010101010101010', b'1010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(2) NOT NULL PRIMARY KEY, c2 BIT(2)); +CREATE TABLE t6(c1 BIT(2), c2 BIT(2)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(2)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010101010101010'; +SELECT 0 + (1010101010101010<<4); +######### INSERT/SELECT######### + +#### Insert and select 4 bit data into the table#### +CREATE TABLE t1(c1 BIT(4)); +CREATE TABLE t2(c1 BIT(4), c2 BIT(4), c3 BIT(4)); +let $i=4; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'1010101010101010', b'1010101010101010', b'1010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(4) NOT NULL PRIMARY KEY, c2 BIT(4)); +CREATE TABLE t6(c1 BIT(4), c2 BIT(4)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(4)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE IGNORE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010101010101010'; +SELECT 0 + (1010101010101010<<8); +######### INSERT/SELECT######### + +#### Insert and select 8 bit data into the table#### +CREATE TABLE t1(c1 BIT(8)); +CREATE TABLE t2(c1 BIT(8), c2 BIT(8), c3 BIT(8)); +let $i=8; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'1010101010101010', b'1010101010101010', b'1010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(8) NOT NULL PRIMARY KEY, c2 BIT(8)); +CREATE TABLE t6(c1 BIT(8), c2 BIT(8)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(8)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE IGNORE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE IGNORE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010101010101010'; +SELECT 0 + (1010101010101010<<16); +######### INSERT/SELECT######### + +#### Insert and select 16 bit data into the table#### +CREATE TABLE t1(c1 BIT(16)); +CREATE TABLE t2(c1 BIT(16), c2 BIT(16), c3 BIT(16)); +let $i=16; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1010101010101010'); +INSERT INTO t2 VALUES (b'1010101010101010', b'1010101010101010', b'1010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(16) NOT NULL PRIMARY KEY, c2 BIT(16)); +CREATE TABLE t6(c1 BIT(16), c2 BIT(16)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(16)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010101010101010'; +SELECT 0 + (1010101010101010<<32); +######### INSERT/SELECT######### + +#### Insert and select 32 bit data into the table#### +CREATE TABLE t1(c1 BIT(32)); +CREATE TABLE t2(c1 BIT(32), c2 BIT(32), c3 BIT(32)); +let $i=32; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1010101010101010'); +INSERT INTO t2 VALUES (b'1010101010101010', b'1010101010101010', b'1010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(32) NOT NULL PRIMARY KEY, c2 BIT(32)); +CREATE TABLE t6(c1 BIT(32), c2 BIT(32)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(32)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'1010101010101010'; +SELECT 0 + (1010101010101010<<64); +######### INSERT/SELECT######### + +#### Insert and select 64 bit data into the table#### +CREATE TABLE t1(c1 BIT(64)); +CREATE TABLE t2(c1 BIT(64), c2 BIT(64), c3 BIT(64)); +let $i=64; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1010101010101010'); +INSERT INTO t2 VALUES (b'1010101010101010', b'1010101010101010', b'1010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(64) NOT NULL PRIMARY KEY, c2 BIT(64)); +CREATE TABLE t6(c1 BIT(64), c2 BIT(64)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(64)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'101010101010101010101010101010'; +SELECT 0 + (101010101010101010101010101010<<0); +######### INSERT/SELECT######### + +#### Insert and select 0 bit data into the table#### +CREATE TABLE t1(c1 BIT(0)); +CREATE TABLE t2(c1 BIT(0), c2 BIT(0), c3 BIT(0)); +let $i=0; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'101010101010101010101010101010', b'101010101010101010101010101010', b'101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(0) NOT NULL PRIMARY KEY, c2 BIT(0)); +CREATE TABLE t6(c1 BIT(0), c2 BIT(0)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(0)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'101010101010101010101010101010'; +SELECT 0 + (101010101010101010101010101010<<1); +######### INSERT/SELECT######### + +#### Insert and select 1 bit data into the table#### +CREATE TABLE t1(c1 BIT(1)); +CREATE TABLE t2(c1 BIT(1), c2 BIT(1), c3 BIT(1)); +let $i=1; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT IGNORE INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'101010101010101010101010101010', b'101010101010101010101010101010', b'101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(1) NOT NULL PRIMARY KEY, c2 BIT(1)); +CREATE TABLE t6(c1 BIT(1), c2 BIT(1)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(1)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'101010101010101010101010101010'; +SELECT 0 + (101010101010101010101010101010<<2); +######### INSERT/SELECT######### + +#### Insert and select 2 bit data into the table#### +CREATE TABLE t1(c1 BIT(2)); +CREATE TABLE t2(c1 BIT(2), c2 BIT(2), c3 BIT(2)); +let $i=2; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'101010101010101010101010101010', b'101010101010101010101010101010', b'101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(2) NOT NULL PRIMARY KEY, c2 BIT(2)); +CREATE TABLE t6(c1 BIT(2), c2 BIT(2)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(2)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'101010101010101010101010101010'; +SELECT 0 + (101010101010101010101010101010<<4); +######### INSERT/SELECT######### + +#### Insert and select 4 bit data into the table#### +CREATE TABLE t1(c1 BIT(4)); +CREATE TABLE t2(c1 BIT(4), c2 BIT(4), c3 BIT(4)); +let $i=4; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'101010101010101010101010101010', b'101010101010101010101010101010', b'101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(4) NOT NULL PRIMARY KEY, c2 BIT(4)); +CREATE TABLE t6(c1 BIT(4), c2 BIT(4)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(4)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE IGNORE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'101010101010101010101010101010'; +SELECT 0 + (101010101010101010101010101010<<8); +######### INSERT/SELECT######### + +#### Insert and select 8 bit data into the table#### +CREATE TABLE t1(c1 BIT(8)); +CREATE TABLE t2(c1 BIT(8), c2 BIT(8), c3 BIT(8)); +let $i=8; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'101010101010101010101010101010', b'101010101010101010101010101010', b'101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(8) NOT NULL PRIMARY KEY, c2 BIT(8)); +CREATE TABLE t6(c1 BIT(8), c2 BIT(8)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(8)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE IGNORE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE IGNORE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'101010101010101010101010101010'; +SELECT 0 + (101010101010101010101010101010<<16); +######### INSERT/SELECT######### + +#### Insert and select 16 bit data into the table#### +CREATE TABLE t1(c1 BIT(16)); +CREATE TABLE t2(c1 BIT(16), c2 BIT(16), c3 BIT(16)); +let $i=16; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'101010101010101010101010101010', b'101010101010101010101010101010', b'101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(16) NOT NULL PRIMARY KEY, c2 BIT(16)); +CREATE TABLE t6(c1 BIT(16), c2 BIT(16)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(16)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'101010101010101010101010101010'; +SELECT 0 + (101010101010101010101010101010<<32); +######### INSERT/SELECT######### + +#### Insert and select 32 bit data into the table#### +CREATE TABLE t1(c1 BIT(32)); +CREATE TABLE t2(c1 BIT(32), c2 BIT(32), c3 BIT(32)); +let $i=32; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'101010101010101010101010101010'); +INSERT INTO t2 VALUES (b'101010101010101010101010101010', b'101010101010101010101010101010', b'101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(32) NOT NULL PRIMARY KEY, c2 BIT(32)); +CREATE TABLE t6(c1 BIT(32), c2 BIT(32)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(32)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +SELECT 0 + b'101010101010101010101010101010'; +SELECT 0 + (101010101010101010101010101010<<64); +######### INSERT/SELECT######### + +#### Insert and select 64 bit data into the table#### +CREATE TABLE t1(c1 BIT(64)); +CREATE TABLE t2(c1 BIT(64), c2 BIT(64), c3 BIT(64)); +let $i=64; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'101010101010101010101010101010'); +INSERT INTO t2 VALUES (b'101010101010101010101010101010', b'101010101010101010101010101010', b'101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(64) NOT NULL PRIMARY KEY, c2 BIT(64)); +CREATE TABLE t6(c1 BIT(64), c2 BIT(64)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(64)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output on different platforms +#SELECT 0 + b'1010101010101010101010101010101010101010101010101010101010101010'; +SELECT 0 + (1010101010101010101010101010101010101010101010101010101010101010<<0); +######### INSERT/SELECT######### + +#### Insert and select 0 bit data into the table#### +CREATE TABLE t1(c1 BIT(0)); +CREATE TABLE t2(c1 BIT(0), c2 BIT(0), c3 BIT(0)); +let $i=0; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(0) NOT NULL PRIMARY KEY, c2 BIT(0)); +CREATE TABLE t6(c1 BIT(0), c2 BIT(0)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(0)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output on different platforms +#SELECT 0 + b'1010101010101010101010101010101010101010101010101010101010101010'; +SELECT 0 + (1010101010101010101010101010101010101010101010101010101010101010<<1); +######### INSERT/SELECT######### + +#### Insert and select 1 bit data into the table#### +CREATE TABLE t1(c1 BIT(1)); +CREATE TABLE t2(c1 BIT(1), c2 BIT(1), c3 BIT(1)); +let $i=1; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT IGNORE INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(1) NOT NULL PRIMARY KEY, c2 BIT(1)); +CREATE TABLE t6(c1 BIT(1), c2 BIT(1)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(1)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output on different platforms +#SELECT 0 + b'1010101010101010101010101010101010101010101010101010101010101010'; +SELECT 0 + (1010101010101010101010101010101010101010101010101010101010101010<<2); +######### INSERT/SELECT######### + +#### Insert and select 2 bit data into the table#### +CREATE TABLE t1(c1 BIT(2)); +CREATE TABLE t2(c1 BIT(2), c2 BIT(2), c3 BIT(2)); +let $i=2; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(2) NOT NULL PRIMARY KEY, c2 BIT(2)); +CREATE TABLE t6(c1 BIT(2), c2 BIT(2)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(2)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output on different platforms +#SELECT 0 + b'1010101010101010101010101010101010101010101010101010101010101010'; +SELECT 0 + (1010101010101010101010101010101010101010101010101010101010101010<<4); +######### INSERT/SELECT######### + +#### Insert and select 4 bit data into the table#### +CREATE TABLE t1(c1 BIT(4)); +CREATE TABLE t2(c1 BIT(4), c2 BIT(4), c3 BIT(4)); +let $i=4; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(4) NOT NULL PRIMARY KEY, c2 BIT(4)); +CREATE TABLE t6(c1 BIT(4), c2 BIT(4)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(4)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE IGNORE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output on different platforms +#SELECT 0 + b'1010101010101010101010101010101010101010101010101010101010101010'; +SELECT 0 + (1010101010101010101010101010101010101010101010101010101010101010<<8); +######### INSERT/SELECT######### + +#### Insert and select 8 bit data into the table#### +CREATE TABLE t1(c1 BIT(8)); +CREATE TABLE t2(c1 BIT(8), c2 BIT(8), c3 BIT(8)); +let $i=8; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(8) NOT NULL PRIMARY KEY, c2 BIT(8)); +CREATE TABLE t6(c1 BIT(8), c2 BIT(8)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(8)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE IGNORE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE IGNORE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output on different platforms +#SELECT 0 + b'1010101010101010101010101010101010101010101010101010101010101010'; +SELECT 0 + (1010101010101010101010101010101010101010101010101010101010101010<<16); +######### INSERT/SELECT######### + +#### Insert and select 16 bit data into the table#### +CREATE TABLE t1(c1 BIT(16)); +CREATE TABLE t2(c1 BIT(16), c2 BIT(16), c3 BIT(16)); +let $i=16; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(16) NOT NULL PRIMARY KEY, c2 BIT(16)); +CREATE TABLE t6(c1 BIT(16), c2 BIT(16)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(16)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output on different platforms +#SELECT 0 + b'1010101010101010101010101010101010101010101010101010101010101010'; +SELECT 0 + (1010101010101010101010101010101010101010101010101010101010101010<<32); +######### INSERT/SELECT######### + +#### Insert and select 32 bit data into the table#### +CREATE TABLE t1(c1 BIT(32)); +CREATE TABLE t2(c1 BIT(32), c2 BIT(32), c3 BIT(32)); +let $i=32; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010'); +INSERT IGNORE INTO t2 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(32) NOT NULL PRIMARY KEY, c2 BIT(32)); +CREATE TABLE t6(c1 BIT(32), c2 BIT(32)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(32)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output on different platforms +#SELECT 0 + b'1010101010101010101010101010101010101010101010101010101010101010'; +SELECT 0 + (1010101010101010101010101010101010101010101010101010101010101010<<64); +######### INSERT/SELECT######### + +#### Insert and select 64 bit data into the table#### +CREATE TABLE t1(c1 BIT(64)); +CREATE TABLE t2(c1 BIT(64), c2 BIT(64), c3 BIT(64)); +let $i=64; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT INTO t1 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010'); +INSERT INTO t2 VALUES (b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010', b'1010101010101010101010101010101010101010101010101010101010101010'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(64) NOT NULL PRIMARY KEY, c2 BIT(64)); +CREATE TABLE t6(c1 BIT(64), c2 BIT(64)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(64)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output for different platform +#SELECT 0 + b'10101010101010101010101010101010101010101010101010101010101010101'; +SELECT 0 + (10101010101010101010101010101010101010101010101010101010101010101<<0); +######### INSERT/SELECT######### + +#### Insert and select 0 bit data into the table#### +CREATE TABLE t1(c1 BIT(0)); +CREATE TABLE t2(c1 BIT(0), c2 BIT(0), c3 BIT(0)); +let $i=0; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101'); +INSERT IGNORE INTO t2 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(0) NOT NULL PRIMARY KEY, c2 BIT(0)); +CREATE TABLE t6(c1 BIT(0), c2 BIT(0)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '0' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '0' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '0' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '0' AND c1 < '64' AND c2 = '0' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(0)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output for different platform +#SELECT 0 + b'10101010101010101010101010101010101010101010101010101010101010101'; +SELECT 0 + (10101010101010101010101010101010101010101010101010101010101010101<<1); +######### INSERT/SELECT######### + +#### Insert and select 1 bit data into the table#### +CREATE TABLE t1(c1 BIT(1)); +CREATE TABLE t2(c1 BIT(1), c2 BIT(1), c3 BIT(1)); +let $i=1; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT IGNORE INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101'); +INSERT IGNORE INTO t2 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(1) NOT NULL PRIMARY KEY, c2 BIT(1)); +CREATE TABLE t6(c1 BIT(1), c2 BIT(1)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '1' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '1' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '1' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '1' AND c1 < '64' AND c2 = '1' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(1)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output for different platform +#SELECT 0 + b'10101010101010101010101010101010101010101010101010101010101010101'; +SELECT 0 + (10101010101010101010101010101010101010101010101010101010101010101<<2); +######### INSERT/SELECT######### + +#### Insert and select 2 bit data into the table#### +CREATE TABLE t1(c1 BIT(2)); +CREATE TABLE t2(c1 BIT(2), c2 BIT(2), c3 BIT(2)); +let $i=2; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101'); +INSERT IGNORE INTO t2 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(2) NOT NULL PRIMARY KEY, c2 BIT(2)); +CREATE TABLE t6(c1 BIT(2), c2 BIT(2)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '2' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '2' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '2' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '2' AND c1 < '64' AND c2 = '2' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(2)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT IGNORE INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output for different platform +#SELECT 0 + b'10101010101010101010101010101010101010101010101010101010101010101'; +SELECT 0 + (10101010101010101010101010101010101010101010101010101010101010101<<4); +######### INSERT/SELECT######### + +#### Insert and select 4 bit data into the table#### +CREATE TABLE t1(c1 BIT(4)); +CREATE TABLE t2(c1 BIT(4), c2 BIT(4), c3 BIT(4)); +let $i=4; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101'); +INSERT IGNORE INTO t2 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(4) NOT NULL PRIMARY KEY, c2 BIT(4)); +CREATE TABLE t6(c1 BIT(4), c2 BIT(4)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '4' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '4' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '4' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '4' AND c1 < '64' AND c2 = '4' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(4)); +INSERT IGNORE INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE IGNORE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE IGNORE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE IGNORE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output for different platform +#SELECT 0 + b'10101010101010101010101010101010101010101010101010101010101010101'; +SELECT 0 + (10101010101010101010101010101010101010101010101010101010101010101<<8); +######### INSERT/SELECT######### + +#### Insert and select 8 bit data into the table#### +CREATE TABLE t1(c1 BIT(8)); +CREATE TABLE t2(c1 BIT(8), c2 BIT(8), c3 BIT(8)); +let $i=8; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101'); +INSERT IGNORE INTO t2 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(8) NOT NULL PRIMARY KEY, c2 BIT(8)); +CREATE TABLE t6(c1 BIT(8), c2 BIT(8)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '8' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'8' ORDER BY c1 DESC LIMIT 2 ; + +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '8' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '8' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '8' AND c1 < '64' AND c2 = '8' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(8)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE IGNORE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE IGNORE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE IGNORE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT IGNORE INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output for different platform +#SELECT 0 + b'10101010101010101010101010101010101010101010101010101010101010101'; +SELECT 0 + (10101010101010101010101010101010101010101010101010101010101010101<<16); +######### INSERT/SELECT######### + +#### Insert and select 16 bit data into the table#### +CREATE TABLE t1(c1 BIT(16)); +CREATE TABLE t2(c1 BIT(16), c2 BIT(16), c3 BIT(16)); +let $i=16; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101'); +INSERT IGNORE INTO t2 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(16) NOT NULL PRIMARY KEY, c2 BIT(16)); +CREATE TABLE t6(c1 BIT(16), c2 BIT(16)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '16' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '16' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '16' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '16' AND c1 < '64' AND c2 = '16' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(16)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output for different platform +#SELECT 0 + b'10101010101010101010101010101010101010101010101010101010101010101'; +SELECT 0 + (10101010101010101010101010101010101010101010101010101010101010101<<32); +######### INSERT/SELECT######### + +#### Insert and select 32 bit data into the table#### +CREATE TABLE t1(c1 BIT(32)); +CREATE TABLE t2(c1 BIT(32), c2 BIT(32), c3 BIT(32)); +let $i=32; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101'); +INSERT IGNORE INTO t2 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--sorted_result +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--sorted_result +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(32) NOT NULL PRIMARY KEY, c2 BIT(32)); +CREATE TABLE t6(c1 BIT(32), c2 BIT(32)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '32' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '32' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '32' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '32' AND c1 < '64' AND c2 = '32' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(32)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE IGNORE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + +####Checking the bit values#### +# Produces different output for different platform +#SELECT 0 + b'10101010101010101010101010101010101010101010101010101010101010101'; +SELECT 0 + (10101010101010101010101010101010101010101010101010101010101010101<<64); +######### INSERT/SELECT######### + +#### Insert and select 64 bit data into the table#### +CREATE TABLE t1(c1 BIT(64)); +CREATE TABLE t2(c1 BIT(64), c2 BIT(64), c3 BIT(64)); +let $i=64; +while($i){ +let $j=$i/2; +eval set @v1=$i; +eval set @v2=$j; +set @v3=repeat('1',@v1); +let $STR0= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR0'); +set @v3=repeat('0',@v1); +let $STR1= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR1'); +set @v3=repeat('01',@v2); +let $STR2= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR2'); +set @v3=repeat('10',@v2); +let $STR3= query_get_value(select @v3 as I,I,1); +eval INSERT INTO t1 VALUES (b'$STR3'); +set @v3=repeat('1',@v1); +set @v4=repeat('01',@v2); +set @v5=repeat('10',@v2); +let $STR0= query_get_value(select @v3 as I,I,1); +let $STR2= query_get_value(select @v4 as I,I,1); +let $STR3= query_get_value(select @v5 as I,I,1); +eval INSERT IGNORE INTO t2 VALUES ("b'$STR0'","b'$STR2","b'$STR3'"); +dec $i; +} +INSERT IGNORE INTO t1 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101'); +INSERT IGNORE INTO t2 VALUES (b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101', b'10101010101010101010101010101010101010101010101010101010101010101'); +--sorted_result +SELECT HEX(c1) FROM t1; +--sorted_result +SELECT HEX(c1),HEX(c2),HEX(c3) FROM t2; +--sorted_result +SELECT OCT(c1) FROM t1; +--sorted_result +SELECT OCT(c1),OCT(c2),OCT(c3) FROM t2; +--sorted_result +SELECT BIN(c1) FROM t1; +--sorted_result +SELECT BIN(c1),BIN(c2),BIN(c3) FROM t2; +--sorted_result +SELECT HEX(c1),OCT(c2),BIN(c3) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT HEX(c1+0),HEX(c2+1),HEX(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT OCT(c1+0),OCT(c2+1),OCT(c3+2) FROM t2; +--error ER_DATA_OUT_OF_RANGE +SELECT BIN(c1+0),BIN(c2+1),BIN(c3+2) FROM t2; +--sorted_result +SELECT CONCAT(HEX(c1),HEX(c2),HEX(c3)) FROM t2; +--sorted_result +SELECT CONCAT(OCT(c1),OCT(c2),OCT(c3)) FROM t2; +--sorted_result +SELECT CONCAT(BIN(c1),BIN(c2),BIN(c3)) FROM t2; +--error 1439 +CREATE TABLE t3 (c1 BIT(65)); +# Checking for bug #9571 +CREATE TABLE t4(i INT, b BIT NOT NULL); +ALTER TABLE t4 ADD PRIMARY KEY (i); +CREATE TABLE t5(c1 BIT(64) NOT NULL PRIMARY KEY, c2 BIT(64)); +CREATE TABLE t6(c1 BIT(64), c2 BIT(64)); +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; + +#Insert permissible NULLs +INSERT IGNORE INTO t5 VALUES(96,null); +INSERT INTO t6 VALUES(null,null); +# Now select using various table access methods (full table scan, range scan, index scan etc.) +## Full table scan ## +--sorted_result +SELECT HEX(c1),HEX(c2) FROM t5; +--sorted_result +SELECT count(*) as total_rows, min(c1) as min_value, max(c1) FROM t5; +--sorted_result +SELECT OCT(c2) FROM t5 WHERE c1 = 68; +## Forward index scan, covering ## +--sorted_result +SELECT bin(c1) FROM t5; +## Backward index scan, covering ## +SELECT oct(c1) FROM t5 ORDER BY c1 DESC; +## Forward index scan, non-covering ## +SELECT hex(c1),hex(c2) FROM t5 ORDER BY c1 LIMIT 2 ; +## Backward index scan, non-covering ## +SELECT * FROM t5 ORDER BY c1 DESC LIMIT 2 /* comment7 */; +## ref type access +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 LIMIT 2; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 = '64' ORDER BY c1 DESC LIMIT 2 ; +## Range access, ordered ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 LIMIT 2 ; +## Range access, backwards scan ## +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <> '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 > '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 < '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <= '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 <=>'64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 BETWEEN '64' AND '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IN ( '64' , '64' ) ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 >= '64' AND c1 < '64' AND c2 = '64' ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NULL ORDER BY c1 DESC LIMIT 2 ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC ; +SELECT hex(c1),hex(c2) FROM t5 WHERE c1 IS NOT NULL ORDER BY c1 DESC LIMIT 2 ; +#Inserting different charachers +CREATE TABLE t7(c1 BIT(64)); +INSERT INTO t7 VALUES('a'),('A'),('z'),('Z'),('!'),('`'),('@'),('#'),('~'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('1'),('9'); +--sorted_result +SELECT * FROM t7; +############# UPDATE ########### + +# Update order by limit +UPDATE t6 SET c1='10' WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Update with arithmetic operations +UPDATE t6 SET c1=c2+c1 WHERE c2 < 100; + +UPDATE t6 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; + + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t6 SET c2=NULL WHERE c1=23; + +UPDATE t6 SET c2=10 WHERE c2=NULL; + + +# Update range values +UPDATE t6 SET c1=12 WHERE c1=b'101' AND c2=178; + +UPDATE t6 SET c1=c1+2,c2=c1+c2 WHERE c2=46 OR c2=b'1001'; + +UPDATE t6 SET c2=123 WHERE c1 IN (30,b'101',88); + + +# Update outside range would be clipped to closest endpoints +UPDATE t6 SET c1=b'1111111111111111111111111111111111111111111111111111111111111111111' WHERE c2 < 10; + +UPDATE t6 SET c2=-1 WHERE c1=94; + + +# Update ignore on bad null error +--sorted_result +SELECT hex(c1) FROM t5 WHERE c1<>0; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t5 SET c1=NULL WHERE c1<>0; +UPDATE IGNORE t5 SET c1=NULL WHERE c1>100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +SET SQL_MODE=DEFAULT; + +#Multi table update +--disable_warnings +UPDATE t5,t6 SET t5.c2=t6.c1+t5.c1, t6.c2=t5.c1+t6.c1 WHERE t5.c1 > 100 OR t6.c2 > 100; +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Update using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +UPDATE t5 SET c2='a' WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +UPDATE t5 SET c2=13 where c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--disable_warnings +UPDATE t5 SET c2=c2+10 WHERE c1 IN (b'001',b'101',b'111'); +--enable_warnings +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +UPDATE t5,t6 SET t5.c2=t6.c1+t6.c2 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +############# DELETE ########### + +TRUNCATE t5; +TRUNCATE t6; + +INSERT IGNORE INTO t5 VALUES (95, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (69, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135); +INSERT INTO t6 VALUES (94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),(44, 307), (68, 454), (57, 135),(null,23),(1,null),(null,null); + +# Delete by order by limit +DELETE FROM t6 WHERE c2 > 100 ORDER BY c2 LIMIT 1; + + +# Delete rows with NULL column +DELETE FROM t6 WHERE c2=NULL; + + +# Delete with range values +DELETE FROM t6 WHERE c1=b'101' AND c2=178; + +DELETE FROM t6 WHERE c2=46 OR c2=b'1001'; + +DELETE FROM t6 WHERE c1 IN (30,b'101',88); + + +#Multi table delete +DELETE t5,t6 FROM t5,t6 WHERE t5.c1 > 100 OR t6.c2 > 100; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + + +# Delete using various access methods +TRUNCATE t5; +TRUNCATE t6; +INSERT IGNORE INTO t5 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); +INSERT INTO t6 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10); + +# Update using Const +# EXPLAIN SELECT * FROM t5 WHERE c1=6 AND c2=6; +DELETE FROM t5 WHERE c1=6 AND c2=6; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using range +# EXPLAIN SELECT * FROM t5 WHERE c1 BETWEEN 5 AND 9; +DELETE FROM t5 WHERE c1 BETWEEN 5 AND 9; +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; +# EXPLAIN SELECT * FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +DELETE FROM t5 WHERE c1 IN (b'001',b'101',b'111'); +--sorted_result +SELECT hex(c1),hex(c2) FROM t5; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; +DELETE t5,t6 FROM t5,t6 WHERE t5.c1=t6.c1 AND t5.c2=t6.c2; + +# Droping the tables +DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7; + diff --git a/mysql-test/suite/engines/iuds/t/update_decimal.test b/mysql-test/suite/engines/iuds/t/update_decimal.test new file mode 100644 index 00000000..bf302e6a --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/update_decimal.test @@ -0,0 +1,553 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3,t4; +--enable_warnings + +######## Running UPDATE tests for DECIMAL ######## + +# Create tables +CREATE TABLE t1(c1 DECIMAL(10,5) UNSIGNED NOT NULL, c2 DECIMAL(10,5) SIGNED NULL, c3 DECIMAL, c4 INT, UNIQUE INDEX idx(c1,c4)); + +# Inserting data into table t1 + +# Trailing zeroes are not stripped, D=5 +INSERT INTO t1 VALUES('00100.05000','-00100.05000','00100119',1),('11111.00009','-9999.99999','9999999',2); + +# DECIMAL := DECIMAL(10,0); Decimal values in c3 will be stripped; +INSERT IGNORE INTO t1 VALUES('1000000','10000000','1000000000.0001',3); + +# c1, c2, c3 will be rounded automatically +INSERT INTO t1 values('100.000001','1000.999999','9999.999999',4); + +# Inserting maximum values +INSERT INTO t1 VALUES('99999.99999','-99999.99999','9999999999',5); + +# Test insert leading zero, +/- signs, overflow handling +INSERT INTO t1 VALUES ("0.0","0.0","0.0",6),("01.0","01.0","01.0",7); +INSERT IGNORE INTO t1 VALUES ("-.1","-.1","-.1",8); +INSERT IGNORE INTO t1 VALUES ("+111111111.11","+111111111.11","+111111111.11",9); + +# Inserting in scientific notations +INSERT INTO t1 VALUES('1.0e+4','1.0e-5','1.0e+9',10); +#INSERT INTO t1 VALUES('0.9999999999e+4','-.999999999e+4,'0.9999999999e+10',11); + +--sorted_result +SELECT * FROM t1; + +# UPDATE starts here + +# Update order by limit +UPDATE t1 SET c1='10001.00001' WHERE c2 > 100 ORDER BY c2 LIMIT 1; +--sorted_result +SELECT c1,c2 FROM t1; + +# Update with arithmetic operations +UPDATE IGNORE t1 SET c1=c2+c3 WHERE c3 < 10000; +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; +--sorted_result +SELECT * FROM t1; + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t1 SET c2=NULL WHERE c4=4; +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c2=1.0e+5 WHERE c2=NULL; +--sorted_result +SELECT * FROM t1; + +# Update negative value to unsigned column +UPDATE IGNORE t1 SET c1=-1.0e+2 WHERE c4=2; +SHOW WARNINGS; +--sorted_result +SELECT * FROM t1; +UPDATE IGNORE t1 SET c1=1.0e+20 WHERE c4=2; +SHOW WARNINGS; +--sorted_result +SELECT * FROM t1; + +# Update range values +UPDATE t1 SET c1=0.9999999999e+5 WHERE c3=1 AND c4=7; +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c1=1.2e+2,c2=c4+c2 WHERE c3=9999999999 OR c2=1.0e-5; +--sorted_result +SELECT * FROM t1 WHERE c1=1.2e+2; +UPDATE t1 SET c3=1234567890 WHERE c4 IN (4,5,6); +--sorted_result +SELECT * FROM t1; + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t1 SET c1=99999.999999 WHERE c4=7; +--sorted_result +SELECT c1,c4 FROM t1; +UPDATE t1 SET c2=-9999.0099 WHERE c4=5; +--sorted_result +SELECT c2,c4 FROM t1; + +# Update ignore on bad null error +SELECT c1 FROM t1 WHERE c1>1000; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t1 SET c1=NULL WHERE c1>1000; +UPDATE IGNORE t1 SET c1=NULL WHERE c1>1000; +--sorted_result +SELECT c1 from t1 WHERE c1>1000; +SET SQL_MODE=DEFAULT; + +TRUNCATE t1; +INSERT INTO t1 VALUES ('11111.11111','-11111.11111','1111111111',1),('22222.22222','-22222.22222','2222222222',2),('33333.33333','-33333.33333','3333333333',3),('44444.44444','-44444.44444','4444444444',4),('55555.55555','-55555.55555','5555555555',5),('66666.66666','-66666.66666','6666666666',6),('77777.77777','-77777.77777','7777777777',7),('88888.88888','-88888.88888','8888888888',8),('99999.99999','-99999.99999','9999999999',9); +--sorted_result +SELECT * FROM t1; + +SELECT c1 FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1; +UPDATE t1 SET c1=c1-100, c2=c1+c2 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1; +--sorted_result +SELECT * FROM t1; + +# Multi table update +CREATE TABLE t2(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT, UNIQUE INDEX idx2(c1,c3)); +CREATE TABLE t3(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT, UNIQUE INDEX idx3(c1,c3)); +CREATE TABLE t4(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT, UNIQUE INDEX idx4(c1,c3)); +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6); +INSERT INTO t4 VALUES ('77777.77777','7777777777',7),('88888.88888','8888888888',8),('99999.99999','9999999999',9); +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +UPDATE t1,t2,t3,t4 SET t2.c1=t2.c1+t3.c1, t3.c2=t3.c2-t2.c1, t4.c1=t1.c1*t1.c3 WHERE t1.c2 >'1111111111' AND t4.c2 < '8888888888' ; +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t1; + +# Update using various access methods +TRUNCATE t2; +TRUNCATE t3; +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6); + +# Update using Const +# EXPLAIN SELECT * FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2; +UPDATE t2 SET t2.c1='44444.44444', t2.c3=4 WHERE t2.c1='22222.22222' AND t2.c3=2; +--sorted_result +SELECT * FROM t2; + +# Update using range +# EXPLAIN SELECT * FROM t2 WHERE c1 BETWEEN '11111' AND '44444'; +update t2 set t2.c1='99999.99999' where c1 BETWEEN '11111' AND '44444'; +--sorted_result +SELECT * FROM t2; +# EXPLAIN SELECT * FROM t2 WHERE c1 IN ('44444.44444','99999.99999'); +UPDATE t2 SET c1=c1-1,c2=c2-1 WHERE c1 IN ('44444.44444','99999.99999'); +--sorted_result +SELECT * FROM t2; + +# Update using eq_ref +DROP TABLE t2,t3; +CREATE TABLE t2(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT); +CREATE TABLE t3(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT, UNIQUE INDEX idx3(c1)); +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('11111.11111','4444444444',1),('55555.55555','5555555555',2),('66666.66666','6666666666',3); +# EXPLAIN SELECT * FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; +UPDATE t2,t3 SET t3.c1='22222.22222' WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; + +#Updating with invalid values +UPDATE IGNORE t1 SET c3='asdf' WHERE c1='11111.11111'; +--sorted_result +SELECT c3 FROM t1; +UPDATE IGNORE t1 SET c2="1 e 1" WHERE c4=2; +--sorted_result +SELECT c2 FROM t1; + +#Duplicate keys +--error ER_DUP_ENTRY +UPDATE t4 SET c1=88888.88888,c3=8 WHERE c3=7; + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +# Droping the tables +--disable_warnings +DROP TABLES IF EXISTS t1,t2,t3,t4; +--enable_warnings + +######## Running UPDATE tests for FLOAT ######## + +# Create tables +CREATE TABLE t1(c1 FLOAT(10,5) UNSIGNED NOT NULL, c2 FLOAT(10,5) SIGNED NULL, c3 FLOAT, c4 INT, UNIQUE INDEX idx(c1,c4)); + +# Inserting data into table t1 + +# Trailing zeroes are not stripped, D=5 +INSERT INTO t1 VALUES('00100.05000','-00100.05000','00100119',1),('11111.00009','-9999.99999','9999999',2); + +# DECIMAL := DECIMAL(10,0); Decimal values in c3 will be stripped; +INSERT IGNORE INTO t1 VALUES('1000000','10000000','1000000000.0001',3); + +# c1, c2, c3 will be rounded automatically +INSERT INTO t1 values('100.000001','1000.999999','9999.999999',4); + +# Inserting maximum values +INSERT INTO t1 VALUES('99999.99999','-99999.99999','9999999999',5); + +# Test insert leading zero, +/- signs, overflow handling +INSERT INTO t1 VALUES ("0.0","0.0","0.0",6),("01.0","01.0","01.0",7); +INSERT IGNORE INTO t1 VALUES ("-.1","-.1","-.1",8); +INSERT IGNORE INTO t1 VALUES ("+111111111.11","+111111111.11","+111111111.11",9); + +# Inserting in scientific notations +INSERT INTO t1 VALUES('1.0e+4','1.0e-5','1.0e+9',10); +#INSERT INTO t1 VALUES('0.9999999999e+4','-.999999999e+4,'0.9999999999e+10',11); + +--sorted_result +SELECT * FROM t1; + +# UPDATE starts here + +# Update order by limit +UPDATE t1 SET c1='10001.00001' WHERE c2 > 100 ORDER BY c2 LIMIT 1; +--sorted_result +SELECT c1,c2 FROM t1; + +# Update with arithmetic operations +UPDATE IGNORE t1 SET c1=c2+c3 WHERE c3 < 10000; +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; +--sorted_result +SELECT * FROM t1; + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t1 SET c2=NULL WHERE c4=4; +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c2=1.0e+5 WHERE c2=NULL; +--sorted_result +SELECT * FROM t1; + +# Update negative value to unsigned column +UPDATE IGNORE t1 SET c1=-1.0e+2 WHERE c4=2; +SHOW WARNINGS; +--sorted_result +SELECT * FROM t1; +UPDATE IGNORE t1 SET c1=1.0e+20 WHERE c4=2; +SHOW WARNINGS; +--sorted_result +SELECT * FROM t1; + +# Update range values +UPDATE t1 SET c1=0.9999999999e+5 WHERE c3=1 AND c4=7; +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c1=1.2e+2,c2=c4+c2 WHERE c3=9999999999 OR c2=1.0e-5; +--sorted_result +SELECT * FROM t1 WHERE c1=1.2e+2; +UPDATE t1 SET c3=1234567890 WHERE c4 IN (4,5,6); +--sorted_result +SELECT * FROM t1; + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t1 SET c1=99999.999999 WHERE c4=7; +--sorted_result +SELECT c1,c4 FROM t1; +UPDATE t1 SET c2=-9999.0099 WHERE c4=5; +--sorted_result +SELECT c2,c4 FROM t1; + +# Update ignore on bad null error +SELECT c1 FROM t1 WHERE c1>1000; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t1 SET c1=NULL WHERE c1>1000; +UPDATE IGNORE t1 SET c1=NULL WHERE c1>1000; +--sorted_result +SELECT c1 from t1 WHERE c1>1000; +SET SQL_MODE=DEFAULT; + +TRUNCATE t1; +INSERT INTO t1 VALUES ('11111.11111','-11111.11111','1111111111',1),('22222.22222','-22222.22222','2222222222',2),('33333.33333','-33333.33333','3333333333',3),('44444.44444','-44444.44444','4444444444',4),('55555.55555','-55555.55555','5555555555',5),('66666.66666','-66666.66666','6666666666',6),('77777.77777','-77777.77777','7777777777',7),('88888.88888','-88888.88888','8888888888',8),('99999.99999','-99999.99999','9999999999',9); +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t1; + +SELECT c1 FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1; +UPDATE t1 SET c1=c1-100, c2=c1+c2 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t1; + +# Multi table update +CREATE TABLE t2(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT, UNIQUE INDEX idx2(c1,c3)); +CREATE TABLE t3(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT, UNIQUE INDEX idx3(c1,c3)); +CREATE TABLE t4(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT, UNIQUE INDEX idx4(c1,c3)); +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6); +INSERT INTO t4 VALUES ('77777.77777','7777777777',7),('88888.88888','8888888888',8),('99999.99999','9999999999',9); +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t4; +UPDATE t1,t2,t3,t4 SET t2.c1=t2.c1+t3.c1, t3.c2=t3.c2-t2.c1, t4.c1=t1.c1*t1.c3 WHERE t1.c2 >'1111111111' AND t4.c2 < '8888888888' ; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t1; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t1; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t1; + +# Update using various access methods +TRUNCATE t2; +TRUNCATE t3; +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6); + +# Update using Const +# EXPLAIN SELECT * FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2; +UPDATE t2 SET t2.c1='44444.44444', t2.c3=4 WHERE t2.c1='22222.22222' AND t2.c3=2; +--sorted_result +SELECT * FROM t2; + +# Update using range +# EXPLAIN SELECT * FROM t2 WHERE c1 BETWEEN '11111' AND '44444'; +update t2 set t2.c1='99999.99999' where c1 BETWEEN '11111' AND '44444'; +--sorted_result +SELECT * FROM t2; +# EXPLAIN SELECT * FROM t2 WHERE c1 IN ('44444.44444','99999.99999'); +UPDATE t2 SET c1=c1-1,c2=c2-1 WHERE c1 IN ('44444.44444','99999.99999'); +--sorted_result +SELECT * FROM t2; + +# Update using eq_ref +DROP TABLE t2,t3; +CREATE TABLE t2(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT); +CREATE TABLE t3(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT, UNIQUE INDEX idx3(c1)); +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('11111.11111','4444444444',1),('55555.55555','5555555555',2),('66666.66666','6666666666',3); +# EXPLAIN SELECT * FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; +UPDATE t2,t3 SET t3.c1='22222.22222' WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; + +#Updating with invalid values +UPDATE t1 SET c3='asdf' WHERE c1='11111.11111'; +--sorted_result +SELECT c3 FROM t1; +UPDATE IGNORE t1 SET c2="1 e 1" WHERE c4=2; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT c2 FROM t1; + +#Duplicate keys +--replace_result 88888.89063 88888.89062 +--error ER_DUP_ENTRY +UPDATE t4 SET c1=88888.88888,c3=8 WHERE c3=7; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--replace_result 88888.89063 88888.89062 +--sorted_result +SELECT * FROM t4; +# Droping the tables +--disable_warnings +DROP TABLES IF EXISTS t1,t2,t3,t4; +--enable_warnings + +######## Running UPDATE tests for DOUBLE ######## + +# Create tables +CREATE TABLE t1(c1 DOUBLE(10,5) UNSIGNED NOT NULL, c2 DOUBLE(10,5) SIGNED NULL, c3 DOUBLE, c4 INT, UNIQUE INDEX idx(c1,c4)); + +# Inserting data into table t1 + +# Trailing zeroes are not stripped, D=5 +INSERT INTO t1 VALUES('00100.05000','-00100.05000','00100119',1),('11111.00009','-9999.99999','9999999',2); + +# DECIMAL := DECIMAL(10,0); Decimal values in c3 will be stripped; +INSERT IGNORE INTO t1 VALUES('1000000','10000000','1000000000.0001',3); + +# c1, c2, c3 will be rounded automatically +INSERT INTO t1 values('100.000001','1000.999999','9999.999999',4); + +# Inserting maximum values +INSERT INTO t1 VALUES('99999.99999','-99999.99999','9999999999',5); + +# Test insert leading zero, +/- signs, overflow handling +INSERT INTO t1 VALUES ("0.0","0.0","0.0",6),("01.0","01.0","01.0",7); +INSERT IGNORE INTO t1 VALUES ("-.1","-.1","-.1",8); +INSERT IGNORE INTO t1 VALUES ("+111111111.11","+111111111.11","+111111111.11",9); + +# Inserting in scientific notations +INSERT INTO t1 VALUES('1.0e+4','1.0e-5','1.0e+9',10); +#INSERT INTO t1 VALUES('0.9999999999e+4','-.999999999e+4,'0.9999999999e+10',11); + +--sorted_result +SELECT * FROM t1; + +# UPDATE starts here + +# Update order by limit +UPDATE t1 SET c1='10001.00001' WHERE c2 > 100 ORDER BY c2 LIMIT 1; +--sorted_result +SELECT c1,c2 FROM t1; + +# Update with arithmetic operations +UPDATE IGNORE t1 SET c1=c2+c3 WHERE c3 < 10000; +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4; +--sorted_result +SELECT * FROM t1; + +# Update with NULL ( NULL to number & number to NULL) +UPDATE t1 SET c2=NULL WHERE c4=4; +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c2=1.0e+5 WHERE c2=NULL; +--sorted_result +SELECT * FROM t1; + +# Update negative value to unsigned column +UPDATE IGNORE t1 SET c1=-1.0e+2 WHERE c4=2; +SHOW WARNINGS; +--sorted_result +SELECT * FROM t1; +UPDATE IGNORE t1 SET c1=1.0e+20 WHERE c4=2; +SHOW WARNINGS; +--sorted_result +SELECT * FROM t1; + +# Update range values +UPDATE t1 SET c1=0.9999999999e+5 WHERE c3=1 AND c4=7; +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c1=1.2e+2,c2=c4+c2 WHERE c3=9999999999 OR c2=1.0e-5; +--sorted_result +SELECT * FROM t1 WHERE c1=1.2e+2; +UPDATE t1 SET c3=1234567890 WHERE c4 IN (4,5,6); +--sorted_result +SELECT * FROM t1; + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t1 SET c1=99999.999999 WHERE c4=7; +--sorted_result +SELECT c1,c4 FROM t1; +UPDATE t1 SET c2=-9999.0099 WHERE c4=5; +--sorted_result +SELECT c2,c4 FROM t1; + +# Update ignore on bad null error +SELECT c1 FROM t1 WHERE c1>1000; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t1 SET c1=NULL WHERE c1>1000; +UPDATE IGNORE t1 SET c1=NULL WHERE c1>1000; +--sorted_result +SELECT c1 from t1 WHERE c1>1000; +SET SQL_MODE=DEFAULT; + +TRUNCATE t1; +INSERT INTO t1 VALUES ('11111.11111','-11111.11111','1111111111',1),('22222.22222','-22222.22222','2222222222',2),('33333.33333','-33333.33333','3333333333',3),('44444.44444','-44444.44444','4444444444',4),('55555.55555','-55555.55555','5555555555',5),('66666.66666','-66666.66666','6666666666',6),('77777.77777','-77777.77777','7777777777',7),('88888.88888','-88888.88888','8888888888',8),('99999.99999','-99999.99999','9999999999',9); +--sorted_result +SELECT * FROM t1; + +SELECT c1 FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1; +UPDATE t1 SET c1=c1-100, c2=c1+c2 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1; +--sorted_result +SELECT * FROM t1; + +# Multi table update +CREATE TABLE t2(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT, UNIQUE INDEX idx2(c1,c3)); +CREATE TABLE t3(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT, UNIQUE INDEX idx3(c1,c3)); +CREATE TABLE t4(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT, UNIQUE INDEX idx4(c1,c3)); +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6); +INSERT INTO t4 VALUES ('77777.77777','7777777777',7),('88888.88888','8888888888',8),('99999.99999','9999999999',9); +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +UPDATE t1,t2,t3,t4 SET t2.c1=t2.c1+t3.c1, t3.c2=t3.c2-t2.c1, t4.c1=t1.c1*t1.c3 WHERE t1.c2 >'1111111111' AND t4.c2 < '8888888888' ; +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t1; + +# Update using various access methods +TRUNCATE t2; +TRUNCATE t3; +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6); + +# Update using Const +# EXPLAIN SELECT * FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2; +UPDATE t2 SET t2.c1='44444.44444', t2.c3=4 WHERE t2.c1='22222.22222' AND t2.c3=2; +--sorted_result +SELECT * FROM t2; + +# Update using range +# EXPLAIN SELECT * FROM t2 WHERE c1 BETWEEN '11111' AND '44444'; +update t2 set t2.c1='99999.99999' where c1 BETWEEN '11111' AND '44444'; +--sorted_result +SELECT * FROM t2; +# EXPLAIN SELECT * FROM t2 WHERE c1 IN ('44444.44444','99999.99999'); +UPDATE t2 SET c1=c1-1,c2=c2-1 WHERE c1 IN ('44444.44444','99999.99999'); +--sorted_result +SELECT * FROM t2; + +# Update using eq_ref +DROP TABLE t2,t3; +CREATE TABLE t2(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT); +CREATE TABLE t3(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT, UNIQUE INDEX idx3(c1)); +INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3); +INSERT INTO t3 VALUES ('11111.11111','4444444444',1),('55555.55555','5555555555',2),('66666.66666','6666666666',3); +# EXPLAIN SELECT * FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; +UPDATE t2,t3 SET t3.c1='22222.22222' WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; + +#Updating with invalid values +UPDATE IGNORE t1 SET c3='asdf' WHERE c1='11111.11111'; +--sorted_result +SELECT c3 FROM t1; +UPDATE IGNORE t1 SET c2="1 e 1" WHERE c4=2; +--sorted_result +SELECT c2 FROM t1; + +#Duplicate keys +--error ER_DUP_ENTRY +UPDATE t4 SET c1=88888.88888,c3=8 WHERE c3=7; + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +# Droping the tables +--disable_warnings +DROP TABLES IF EXISTS t1,t2,t3,t4; +--enable_warnings + diff --git a/mysql-test/suite/engines/iuds/t/update_delete_calendar.test b/mysql-test/suite/engines/iuds/t/update_delete_calendar.test new file mode 100644 index 00000000..aa695953 --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/update_delete_calendar.test @@ -0,0 +1,758 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2; +--enable_warnings + +######## Running UPDATE tests for DATE ######## + +# Create tables +CREATE TABLE t1(c1 DATE NOT NULL PRIMARY KEY, c2 DATE NULL, c3 INT, INDEX idx2(c2)); +# Insert into table +INSERT INTO t1 VALUE('1998-01-01','10-01-01',1),('2001-01-01','70-01-01',2),('2001-01-03','2001-01-04 09:34:00',3); +--sorted_result +SELECT * FROM t1; + +# Update year,month,day,4 digit year date type to 2 digit and vice-versa +UPDATE t1 SET c1='69-02-02' WHERE c2='10-01-01'; +SELECT year(c1),month(c1),day(c1),year(c2) FROM t1 WHERE c2='10-01-01'; +UPDATE t1 SET c1='1969-02-02',c2='1910-02-02' WHERE c2='10-01-01'; +SELECT * FROM t1 WHERE c1='1969-02-02' AND c2='1910-02-02'; +UPDATE t1 SET c1='01-02-02',c2='2070-02-02' WHERE c2='70-01-01'; +SELECT year(c1),c2 FROM t1 WHERE c1='01-02-02' AND c2='2070-02-02'; + +# Update with time values +UPDATE t1 SET c1='2001-01-03 08:30:00',c2='2001-01-05' WHERE c2='2001-01-04'; +SELECT c1,hour(c1),minute(c1),second(c1) FROM t1 WHERE c2='2001-01-05'; + +# Update with function +INSERT INTO t1 VALUES('2009-02-25','09-02-27',4); +SET TIMESTAMP=1235553613; #'2009-02-25' +UPDATE t1 SET c2=NOW() WHERE c1 >=CURDATE(); +UPDATE t1 SET c1=DATE_ADD(CURDATE(),INTERVAL '1 1:1:1' DAY_SECOND) WHERE c2=CURDATE(); +--sorted_result +SELECT * FROM t1; + +# Update with Null, null to valid date +INSERT INTO t1 VALUES('2001-01-06','2001-01-07',5),('2001-01-08',NULL,6); +UPDATE t1 SET c2=NULL WHERE c1='2001-01-06'; +--sorted_result +SELECT * FROM t1 WHERE c2 IS NULL; +UPDATE t1 SET c2='2001-01-10' WHERE c2 IS NULL; +--sorted_result +SELECT * FROM t1 WHERE c2='2001-01-10'; + +# Update with invalid dates, converts to zero dates, ALLOW_INVALID_DATES allows +INSERT INTO t1 VALUES('2001-01-11','2001-01-11',7),('2001-01-12','2001-01-12',8),('2001-01-13','2001-01-13',9),('2001-01-14','2001-01-14',10),('2001-01-15','2001-01-15',11),('2001-01-16','2001-01-16',12); +UPDATE t1 SET c1='10:45:15',c2='2009-01-32' WHERE c1='2001-01-11'; +UPDATE t1 SET c2='2009-02-30' WHERE c2='2001-01-12'; +UPDATE t1 SET c2='2009-04-31' WHERE c2='2001-01-13'; +UPDATE t1 SET c2='2009-06-31' WHERE c2='2001-01-14'; +UPDATE t1 SET c2='2009-09-31' WHERE c2='2001-01-15'; +SELECT count(*) FROM t1 WHERE c2='10:45:15' OR c2='2009-01-32' OR c2='2009-02-30' OR c2='2009-04-31' OR c2='2009-06-31' OR c2='2009-09-31' /* returns 0 */; +UPDATE t1 SET c2='2009-11-31' WHERE c2='2001-01-16'; +--sorted_result +SELECT * FROM t1 WHERE c2='0000-00-00'; +SET SQL_MODE=ALLOW_INVALID_DATES; +INSERT INTO t1 VALUES('2001-01-27','2001-01-28',19); +UPDATE t1 SET c1='2009-04-31',c2='2009-02-30' WHERE c3=19; +SELECT c1,c2,day(c1),day(c2) FROM t1 WHERE c3=19; +SET SQL_MODE=DEFAULT; + +# Update with zero dates, zero dates to valid dates +INSERT INTO t1 VALUES('2001-01-17','0000-00-00',13),('2001-01-18','2001-01-18',14); +SET SQL_MODE=TRADITIONAL; +SELECT * FROM t1 WHERE c2='0000-00-00'; +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET c2='0000-00-00' WHERE c2='2001-01-18'; +SET SQL_MODE=DEFAULT; +UPDATE t1 SET c2='0000-00-00' WHERE c2='2001-01-18'; +UPDATE t1 SET c2='2001-01-18' WHERE c2='0000-00-00' AND c1='2001-01-17'; +--sorted_result +SELECT * FROM t1 WHERE c1='0000-00-00' OR c2='0000-00-00'; + +# Update with valid dates with zero in month/day +INSERT INTO t1 VALUES('2001-01-19','2001-01-20',15); +UPDATE t1 SET c1='2010-00-01',c2='2010-10-00' WHERE c3=15; +SELECT *,month(c1),day(c2) from t1 WHERE c3=15; + +# Update with range values +INSERT INTO t1 VALUES('2001-01-21','2001-01-22',16); +UPDATE t1 SET c1='1000-01-01',c2='9999-12-31' WHERE c1='2001-01-21'; +SELECT * FROM t1 WHERE c1='1000-01-01' AND c2='9999-12-31'; + +# Update ignore on bad null/duplicate key +INSERT INTO t1 VALUES('2001-01-23','2001-01-24',17),('2001-01-25','2001-01-26',18); +--error ER_DUP_ENTRY +UPDATE t1 SET c1='2001-01-23' WHERE c1='2001-01-25'; +UPDATE IGNORE t1 SET c1='2001-01-23' WHERE c1='2001-01-25'; +SELECT count(*) FROM t1 WHERE c1='2001-01-23'; +--error ER_DUP_ENTRY +UPDATE t1 SET c1=NULL WHERE c2='2001-01-24' /* updates to 0000-00-00 */; +UPDATE IGNORE t1 SET c1=NULL WHERE c2='2001-01-24'; +--sorted_result +SELECT * FROM t1 WHERE c1='0000-00-00'; + +# Multi table update + +TRUNCATE TABLE t1; +CREATE TABLE t2(c1 DATE NOT NULL PRIMARY KEY, c2 DATE, c3 INT); + +# eq-ref join +INSERT INTO t1 VALUES('2001-01-02','2001-01-01',1),('2001-01-03','2001-01-02',2); +INSERT INTO t2 VALUES('2001-01-02','2001-01-03',1),('2001-01-04','2001-01-05',2); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; +UPDATE t1,t2 SET t2.c1='2005-01-06',t1.c1='2005-01-06' WHERE t2.c1=t1.c1; +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; + +INSERT INTO t1 VALUES('2002-01-01','2002-01-02',3),('2002-01-04','2002-01-02',4); +INSERT INTO t2 VALUES('2002-01-02','2002-01-03',3),('2002-01-03','2002-01-04',4); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +UPDATE t1,t2 SET t2.c1='2002-01-06',t1.c2='2002-01-06' WHERE t2.c1=t1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1='2002-01-06' AND t1.c2='2002-01-06'; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE FROM t1 WHERE c2='2002-01-06' AND c3=3; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DROP TABLE t2; + +# Update with other access methods, ORDER BY LIMIT +TRUNCATE TABLE t1; +ALTER TABLE t1 CHANGE c1 c1 DATE NOT NULL, DROP PRIMARY KEY; +ALTER TABLE t1 CHANGE c1 c1 DATE NOT NULL, ADD KEY(c1); + +# ref access +UPDATE t1 SET c1='2002-01-07' WHERE c2='2002-01-05'; +SELECT * FROM t1 WHERE c1='2002-01-07'; + +# range access +INSERT INTO t1 VALUES('2002-01-08','2002-01-09',4),('2002-01-10','2002-01-11',5),('2002-01-12','2002-01-13',6),('2002-01-14','2002-01-15',7),('2002-01-16','2002-01-17',8),('2002-01-18','2002-01-19',9),('2002-01-20','2002-01-21',10),('2002-01-22','2002-01-23',11),('2002-01-24','2002-01-25',12),('2002-01-26','2002-01-27',13),('2002-01-28','2002-01-29',14),('2002-01-30','2002-01-31',15),('2002-02-01','2002-02-02',16),('2002-02-03','2002-02-04',17),('2002-02-05','2002-02-06',18),('2002-02-07','2002-02-08',19),('2002-02-09','2002-02-10',20); +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c1='2003-01-01' WHERE c2 <> '2002-01-09' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <> '2002-01-09' ORDER BY c2; +UPDATE t1 SET c1='2003-01-01' WHERE c2 >= '2002-01-13' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '2002-01-13' ORDER BY c2 DESC; +UPDATE t1 SET c1='2003-01-01' WHERE c2 <='2002-01-21' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <='2002-01-21' ORDER BY c2; +UPDATE t1 SET c1='2003-01-01' WHERE c2 <=> '2002-01-23' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '2002-01-23' ORDER BY c2 DESC; +UPDATE t1 SET c1='2003-01-01' WHERE c2 BETWEEN '2002-01-25' AND '2002-01-29' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '2002-01-25' AND '2002-01-29' ORDER BY c2; +UPDATE t1 SET c1='2003-01-01' WHERE c2 IN('2002-01-29','2002-01-31') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN('2002-01-29','2002-01-31') ORDER BY c2 DESC; +UPDATE t1 SET c1='2003-01-01' WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +UPDATE t1 SET c1='2003-01-01' WHERE c2>= '2002-02-06' AND c1 < '2002-02-09' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2>= '2002-02-06' AND c1 < '2002-02-09' ORDER BY c2; +INSERT INTO t1 VALUES('2002-03-01','2002-03-01',1),('2002-03-03','2002-03-04',2),('2002-03-05','2002-03-06',3),('2005-01-01','2005-01-02',4),('2005-01-03','2005-01-04',5),('2005-01-05','2005-01-06',6),('2005-01-07','2005-01-08',7),('2005-01-09',NULL,8); +# Select using various access methods +## Full table scan +--sorted_result +SELECT * FROM t1; +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; +# ref access +--sorted_result +SELECT * FROM t1 WHERE c1='2003-01-01'; +## Range access ## +SELECT * FROM t1 WHERE c1 <> '2003-01-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <> '2003-01-01' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 > '2003-01-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 >= '2003-01-01' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 < '2003-01-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <= '2003-01-01' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <=> '2003-01-01' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '2003-01-01' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 BETWEEN '2002-03-01' AND '2003-01-01' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '2002-03-01' AND '2003-01-01' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IN('2003-01-01','2005-01-07') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN('2003-01-01','2005-01-07') ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2,c1 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1; +SELECT * FROM t1 WHERE c1>='2003-01-01' AND c1 <= '2005-01-07' ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1>='2003-01-01' AND c1 <= '2005-01-07' ORDER BY c2,c1; + +# Index-merge access +SELECT * FROM t1 WHERE c1='2003-01-03' OR c2='2002-03-06'; +UPDATE t1 SET c1='2006-01-01' WHERE c1='2003-01-03' OR c2='2002-03-06'; +--sorted_result +SELECT * FROM t1 WHERE c1='2006-01-01' OR c2='2002-03-04'; + +# Testing delete using various access methods +TRUNCATE TABLE t1; +ALTER TABLE t1 CHANGE c1 c1 DATE NOT NULL, ADD PRIMARY KEY(c1); +INSERT INTO t1 VALUES(NOW(),NOW(),3),(ADDTIME(NOW(),'1 01:01:01'),ADDTIME(NOW(),'1 01:01:01'),4),(ADDTIME(NOW(),'2 01:01:01'),ADDTIME(NOW(),'2 01:01:01'),5),(ADDTIME(NOW(),'3 01:01:01'),ADDTIME(NOW(),'3 01:01:01'),6); +INSERT INTO t1 VALUES('1000-01-01','1000-01-01',1),('9999-12-31','9999-12-31',2); +SELECT * FROM t1 WHERE c1 <='1000-01-01'; +DELETE FROM t1 WHERE c1 <='1000-01-01'; +SELECT * FROM t1 WHERE c1 <='1000-01-01'; +SELECT * FROM t1 WHERE c1 >='9999-12-31'; +DELETE FROM t1 WHERE c1 >='9999-12-31'; +SELECT * FROM t1 WHERE c1 >='9999-12-31'; +SELECT * FROM t1 WHERE c1 > ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +DELETE FROM t1 WHERE c1 > ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> CURDATE() ORDER BY c1; +DELETE FROM t1 WHERE c1 <> CURDATE() ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <> CURDATE() ORDER BY c1; +INSERT INTO t1 VALUES('2001-01-01',NOW(),7),(ADDTIME(NOW(),'1 01:01:01'),ADDTIME(NOW(),'1 01:01:01'),8),(ADDTIME(NOW(),'2 01:01:01'),ADDTIME(NOW(),'2 01:01:01'),9),(ADDTIME(NOW(),'3 01:01:01'),ADDTIME(NOW(),'3 01:01:01'),10); +SELECT * FROM t1 WHERE c1 < ADDTIME(NOW(),'2 01:01:01') ORDER BY c1; +DELETE FROM t1 WHERE c1 < ADDTIME(NOW(),'2 01:01:01') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < ADDTIME(NOW(),'2 01:01:01') ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +DELETE FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> ADDDATE(CURDATE(),'1 01:01:01') ORDER BY c1 DESC; +DELETE FROM t1 WHERE c1 <=> ADDDATE(CURDATE(),'1 01:01:01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> ADDDATE(CURDATE(),'1 01:01:01') ORDER BY c1 DESC; +INSERT INTO t1 VALUES('2001-01-01',NOW(),11),(ADDTIME(NOW(),'1 01:01:01'),ADDTIME(NOW(),'1 01:01:01'),12),(ADDTIME(NOW(),'4 01:01:01'),NULL,13),(ADDTIME(NOW(),'5 01:01:01'),NULL,14); +SELECT * FROM t1 WHERE c1 BETWEEN CURDATE() AND ADDTIME(NOW(),'2 01:01:01') ORDER BY c1; +DELETE FROM t1 WHERE c1 BETWEEN CURDATE() AND ADDTIME(NOW(),'2 01:01:01') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN CURDATE() AND ADDTIME(NOW(),'2 01:01:01') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN(CURDATE(),ADDDATE(CURDATE(),'3 01:01:01')) ORDER BY c1 DESC; +DELETE FROM t1 WHERE c1 IN(CURDATE(),ADDDATE(CURDATE(),'3 01:01:01')) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN(CURDATE(),ADDDATE(CURDATE(),'3 01:01:01')) ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2,c1; +DELETE FROM t1 WHERE c2 IS NULL ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2,c1; +INSERT INTO t1 VALUES(ADDTIME(NOW(),'6 01:01:01'),ADDTIME(NOW(),'6 01:01:01'),15),(ADDTIME(NOW(),'7 01:01:01'),NULL,16),(ADDTIME(NOW(),'8 01:01:01'),ADDTIME(NOW(),'8 01:01:01'),17),(ADDTIME(NOW(),'9 01:01:01'),ADDTIME(NOW(),'9 01:01:01'),18),(ADDTIME(NOW(),'10 01:01:01'),ADDTIME(NOW(),'10 01:01:01'),19); +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC; +DELETE FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC; +SELECT * FROM t1 WHERE c1>=ADDTIME(NOW(),'5 01:01:01') AND c2 < ADDTIME(NOW(),'8 01:01:01') ORDER BY c1; +DELETE FROM t1 WHERE c1>=ADDTIME(NOW(),'5 01:01:01') AND c2 < ADDTIME(NOW(),'8 01:01:01') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1>=ADDTIME(NOW(),'5 01:01:01') AND c2 < ADDTIME(NOW(),'8 01:01:01') ORDER BY c1; +--sorted_result +SELECT * FROM t1 WHERE c1=ADDDATE(CURDATE(),'9 01:01:01') OR c2=ADDDATE(CURDATE(),'10 01:01:01'); +DELETE FROM t1 WHERE c1=ADDDATE(CURDATE(),'9 01:01:01') OR c2=ADDDATE(CURDATE(),'10 01:01:01'); +# Disable warnings due to #43763 +--disable_warnings +--sorted_result +SELECT * FROM t1 WHERE c1=ADDDATE(CURDATE(),'9 01:01:01') OR c2=ADDDATE(CURDATE(),'10 01:01:01'); +--enable_warnings +SELECT count(*) FROM t1; +TRUNCATE TABLE t1; +SELECT count(*) FROM t1; + +# Multi-table delete +# eq-ref join +CREATE TABLE t2(c1 DATE NOT NULL PRIMARY KEY, c2 DATE, c3 INT); +INSERT INTO t1 VALUES('2001-01-02','2001-01-01',1),('2001-01-03','2001-01-02',2); +INSERT INTO t2 VALUES('2001-01-02','2001-01-03',1),('2001-01-04','2001-01-05',2); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; +DELETE t1,t2 FROM t1,t2 WHERE t2.c1=t1.c1; +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES('2001-01-01','2001-01-02',1),('2001-01-03','2001-01-02',2); +INSERT INTO t2 VALUES('2001-01-02','2001-01-03',1),('2001-01-04','2001-01-05',2); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE FROM a1, a2 USING t1 AS a1 INNER JOIN t2 AS a2 WHERE a2.c1=a1.c2; +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DROP TABLE t1,t2; + +######## Running UPDATE tests for DATETIME ######## + +# Create tables +CREATE TABLE t1(c1 DATETIME NOT NULL PRIMARY KEY, c2 DATETIME NULL, c3 INT, INDEX idx2(c2)); + +# Update date values to datetime field +INSERT INTO t1 VALUE('1998-01-01 09:23:45','10-01-01 14:12:33',1); +UPDATE t1 SET c1='2001-01-01' WHERE c2='10-01-01 14:12:33'; +SELECT c1,hour(c1),minute(c1),second(c1) FROM t1 WHERE c2='10-01-01 14:12:33'; + +# Update with single digit hour, minute, second,fraction part to time +INSERT INTO t1 VALUES('2009-01-01 08:42:42','2009-01-02 23:59:59',2); +UPDATE t1 SET c1='2009-01-01 1:2:3',c2='2009-01-02 23:59:59.999999' WHERE c2='2009-01-02 23:59:59'; +SELECT c1,ADDTIME(c2,'1 1:1:1.000002') FROM t1 WHERE c3=2; + +# Update with function +INSERT INTO t1 VALUES('2009-02-25 15:45','09-02-27 15:46',3); +SET TIMESTAMP=1235553613; #'2009-02-25' +UPDATE t1 SET c2=NOW() WHERE c1 >=CURDATE(); +UPDATE t1 SET c1=DATE_ADD(CURDATE(),INTERVAL '1 1:1:1' DAY_SECOND) WHERE c2=CURRENT_TIMESTAMP(); +--sorted_result +SELECT * FROM t1; + +# Update with Null, null to valid date +INSERT INTO t1 VALUES('2001-01-06','2001-01-07 09:30:00',4),('2001-01-08',NULL,5); +--sorted_result +SELECT * FROM t1 WHERE c2 IS NULL; +UPDATE t1 SET c2=NULL WHERE c1='2001-01-06 00:00:00'; +--sorted_result +SELECT * FROM t1 WHERE c2 IS NULL; +UPDATE t1 SET c2='2001-01-10 00:00:00' WHERE c2 IS NULL; +--sorted_result +SELECT * FROM t1 WHERE c2='2001-01-10'; + +# Update with invalid datetimes, converts to zero datetime +INSERT INTO t1 VALUES('2001-01-09','2001-01-10',6),('2001-01-11','2001-01-12',7); +UPDATE t1 SET c1='2001-01-09 24:59:59',c2='2009-01-10 23:60:59' WHERE c1='2001-01-09'; +UPDATE t1 SET c2='2001-01-11 23:59:60' WHERE c1='2001-01-11'; +SELECT count(*) FROM t1 WHERE c1='2001-01-09 24:59:59' AND c2='2009-01-10 23:60:59'; +SELECT count(*) FROM t1 WHERE c2='2001-01-11 23:59:60' /* returns 0 */; +--sorted_result +SELECT * FROM t1 WHERE c1='0000-00-00 00:00:00' OR c2='0000-00-00 00:00:00'; + +# Update with zero datetimes, zero datetimes to valid datetimes +INSERT INTO t1 VALUES('2001-01-17','0000-00-00 00:00:00',8),('2001-01-18','2001-01-18 07:35',9); +SET SQL_MODE=TRADITIONAL; +SELECT * FROM t1 WHERE c2='0000-00-00 00:00:00'; +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET c2='0000-00-00 00:00:00' WHERE c2='2001-01-18 07:35'; +SET SQL_MODE=DEFAULT; +UPDATE t1 SET c2='0000-00-00 00:00:00' WHERE c2='2001-01-18 07:35'; +UPDATE t1 SET c2='2001-01-17 12:34:00' WHERE c2='0000-00-00 00:00:00' AND c1='2001-01-17'; +--sorted_result +SELECT * FROM t1 WHERE c1='0000-00-00 00:00:00' OR c2='0000-00-00 00:00:00'; +--sorted_result +SELECT * FROM t1 WHERE c2='2001-01-17 12:34:00'; + +# Update with range values +INSERT INTO t1 VALUES('2001-01-21 05:43:43','2001-01-22 06:53:53',10); +UPDATE t1 SET c1='1000-01-01 00:00:00',c2='9999-12-31 23:59:59' WHERE c1='2001-01-21 05:43:43'; +SELECT * FROM t1 WHERE c1='1000-01-01 00:00:00' AND c2='9999-12-31 23:59:59'; + +# Update ignore on bad null/duplicate key +INSERT INTO t1 VALUES('2001-01-23 02:33','2001-01-24 03:33',11),('2001-01-25 04:33','2001-01-26 05:33',12); +--error ER_DUP_ENTRY +UPDATE t1 SET c1='2001-01-23 02:33' WHERE c1='2001-01-25 04:33'; +UPDATE IGNORE t1 SET c1='2001-01-23 02:33' WHERE c1='2001-01-25 04:33'; +SELECT count(*) FROM t1 WHERE c1='2001-01-23 02:33'; +--error ER_DUP_ENTRY +UPDATE t1 SET c1=NULL WHERE c2='2001-01-24 03:33' /* updates to 0000-00-00 00:00:00 */; +UPDATE IGNORE t1 SET c1=NULL WHERE c2='2001-01-24 03:33'; +--sorted_result +SELECT * FROM t1 WHERE c1='0000-00-00 00:00:00'; + +# Multi table update + +TRUNCATE TABLE t1; +CREATE TABLE t2(c1 DATETIME NOT NULL PRIMARY KEY, c2 DATETIME, c3 INT); + +# eq-ref join +INSERT INTO t1 VALUES('2001-01-02 2:30:45','2001-01-01 1:30',1),('2001-01-03 3:30','2001-01-02 2:30:45',2); +INSERT INTO t2 VALUES('2001-01-02 2:30:45','2001-01-03 3:30',1),('2001-01-04 4:30','2001-01-05 5:30',2); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; +UPDATE t1,t2 SET t2.c1='2005-01-06 2:30:50',t1.c1='2005-01-06 2:30:50' WHERE t2.c1=t1.c1; +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; + +INSERT INTO t1 VALUES('2002-01-01 3:30','2002-01-02 2:30:45',3),('2002-01-04 4:30','2002-01-02 2:30:45',4); +INSERT INTO t2 VALUES('2002-01-02 2:30:45','2002-01-03 3:30',3),('2002-01-03 3:30','2002-01-04 4:30',4); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +UPDATE t1,t2 SET t2.c1='2002-01-06 2:30:50',t1.c2='2002-01-06 2:30:50' WHERE t2.c1=t1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1='2002-01-06 2:30:50' AND t1.c2='2002-01-06 2:30:50'; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE FROM t1 WHERE c2='2002-01-06 2:30:50' AND c3=3; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DROP TABLE t2; + +# Update with other access methods, ORDER BY LIMIT +TRUNCATE TABLE t1; +ALTER TABLE t1 CHANGE c1 c1 DATETIME NOT NULL, DROP PRIMARY KEY; +ALTER TABLE t1 CHANGE c1 c1 DATETIME NOT NULL, ADD KEY(c1); + +# ref access +UPDATE t1 SET c1='2002-01-07 7:30' WHERE c2='2002-01-05 5:30'; +SELECT * FROM t1 WHERE c1='2002-01-07 7:30'; + +# range access, MRR +INSERT INTO t1 VALUES('2002-01-08 1:30','2002-01-09 1:30',4),('2002-01-08 1:30:5','2002-01-09 1:30:5',5),('2002-01-08 1:30:10','2002-01-09 1:30:10',6),('2002-01-08 1:30:15','2002-01-09 1:30:15',7),('2002-01-08 1:30:20','2002-01-09 1:30:20',8),('2002-01-08 1:30:25','2002-01-09 1:30:25',9),('2002-01-08 1:30:30','2002-01-09 1:30:30',10),('2002-01-08 1:30:35','2002-01-09 1:30:35',11),('2002-01-08 1:30:40','2002-01-09 1:30:40',12),('2002-01-08 1:30:45','2002-01-09 1:30:45',13),('2002-01-08 1:30:50','2002-01-09 1:30:50',14),('2002-01-08 1:30:55','2002-01-09 1:30:55',15),('2002-01-08 1:30:59','2002-01-09 1:30:59',16),('2002-01-08 2:00','2002-01-09 2:00',17),('2002-01-08 2:00:05','2002-01-09 2:00:05',18),('2002-01-08 2:00:10','2002-01-09 2:00:10',19),('2002-01-08 2:00:15','2002-01-09 2:00:15',20); +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 <> '2002-01-09 01:30:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <> '2002-01-09 01:30:00' ORDER BY c2; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 >= '20020109013010' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '20020109013010' ORDER BY c2 DESC; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 <='02-01-09 1:30:20' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <='02-01-09 1:30:20' ORDER BY c2; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 <=> '020109013030' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '020109013030' ORDER BY c2 DESC; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 BETWEEN '20020109 01:30:40' AND '20020109 01:30:50' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '20020109 01:30:40' AND '20020109 01:30:50' ORDER BY c2; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 IN('2002-01-09 1:30:55','2002-01-09 2:00') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN('2002-01-09 1:30:55','2002-01-09 2:00') ORDER BY c2 DESC; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2>= '2002-02-09 2:00:5' AND c1 < '2002-02-09 2:00:15' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2>= '2002-02-09 2:00:5' AND c1 < '2002-02-09 2:00:15' ORDER BY c2; +INSERT INTO t1 VALUES('20020301000001','20020302000001',1),('020303010030','020304010030',2),('050103000001','050104000001',3),('5-10-10 1:2:3','5-10-10 1:2:3',4),('0000-00-00 00:00:01',NULL,5); +# Select using various access methods +## Full table scan +--sorted_result +SELECT * FROM t1; +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; +# ref access +--sorted_result +SELECT * FROM t1 WHERE c1='2003-01-01 1:2:3'; +## Range access ## +SELECT * FROM t1 WHERE c1 <> '2003-01-01 1:2:3' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <> '2003-01-01 1:2:3' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 > '20030101010203' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '20030101010203' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 < '03-01-01 1:2:3' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '03-01-01 1:2:3' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <=> '2003-01-01 1:2:3' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '2003-01-01 1:2:3' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 BETWEEN '20020301' AND '2003-01-01 1:2:3' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '20020301' AND '2003-01-01 1:2:3' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IN('2003-01-01 1:2:3','2005-01-03 00:00:01') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN('2003-01-01 1:2:3','2005-01-03 00:00:01') ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2,c1 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1; +SELECT * FROM t1 WHERE c1>='2003-01-01 01:02:03' AND c1 <= '20050104000001' ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1>='2003-01-01 01:02:03' AND c1 <= '20050104000001' ORDER BY c2,c1; + +# Index-merge access +SELECT * FROM t1 WHERE c1='2003-01-03 1:2:3' OR c2='2002-03-02 00:00:01'; +UPDATE t1 SET c1='20060101000001' WHERE c1='2003-01-03 1:2:3' OR c2='2002-03-02 00:00:01'; +--sorted_result +SELECT * FROM t1 WHERE c1='20060101000001' OR c2='020304010030'; + +# Testing delete using various access methods +TRUNCATE TABLE t1; +ALTER TABLE t1 CHANGE c1 c1 DATETIME NOT NULL, ADD PRIMARY KEY(c1); +INSERT INTO t1 VALUES(NOW(),NOW(),3),(ADDTIME(NOW(),'1 01:01:01'),ADDTIME(NOW(),'1 01:01:01'),4),(ADDTIME(NOW(),'2 01:01:01'),ADDTIME(NOW(),'2 01:01:01'),5),(ADDTIME(NOW(),'3 01:01:01'),ADDTIME(NOW(),'3 01:01:01'),6); +INSERT INTO t1 VALUES('1000-01-01 00:00:00','1000-01-01 00:00:00',1),('9999-12-31 23:59:59','9999-12-31 23:59:59',2); +SELECT * FROM t1 WHERE c1 <='1000-01-01 00:00:00'; +DELETE FROM t1 WHERE c1 <='1000-01-01 00:00:00'; +SELECT * FROM t1 WHERE c1 <='1000-01-01 00:00:00'; +SELECT * FROM t1 WHERE c1 >='9999-12-31 23:59:59'; +DELETE FROM t1 WHERE c1 >='9999-12-31 23:59:59'; +SELECT * FROM t1 WHERE c1 >='9999-12-31 23:59:59'; +SELECT * FROM t1 WHERE c1 > ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +DELETE FROM t1 WHERE c1 > ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> CURRENT_TIMESTAMP() ORDER BY c1; +DELETE FROM t1 WHERE c1 <> CURRENT_TIMESTAMP() ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <> CURRENT_TIMESTAMP() ORDER BY c1; +INSERT INTO t1 VALUES('2001-01-01',NOW(),7),(ADDTIME(NOW(),'1 01:01:01'),ADDTIME(NOW(),'1 01:01:01'),8),(ADDTIME(NOW(),'2 01:01:01'),ADDTIME(NOW(),'2 01:01:01'),9),(ADDTIME(NOW(),'3 01:01:01'),ADDTIME(NOW(),'3 01:01:01'),10); +SELECT * FROM t1 WHERE c1 < ADDTIME(NOW(),'2 01:01:01') ORDER BY c1; +DELETE FROM t1 WHERE c1 < ADDTIME(NOW(),'2 01:01:01') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < ADDTIME(NOW(),'2 01:01:01') ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +DELETE FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +DELETE FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +INSERT INTO t1 VALUES('2001-01-01',NOW(),11),(ADDTIME(NOW(),'1 01:01:01'),ADDTIME(NOW(),'1 01:01:01'),12),(ADDTIME(NOW(),'4 01:01:01'),NULL,13),(ADDTIME(NOW(),'5 01:01:01'),NULL,14); +SELECT * FROM t1 WHERE c1 BETWEEN NOW() AND ADDTIME(NOW(),'2 01:01:01') ORDER BY c1; +DELETE FROM t1 WHERE c1 BETWEEN NOW() AND ADDTIME(NOW(),'2 01:01:01') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN NOW() AND ADDTIME(NOW(),'2 01:01:01') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN(NOW(),ADDTIME(NOW(),'3 01:01:01')) ORDER BY c1 DESC; +DELETE FROM t1 WHERE c1 IN(NOW(),ADDTIME(NOW(),'3 01:01:01')) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN(NOW(),ADDTIME(NOW(),'3 01:01:01')) ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2,c1; +DELETE FROM t1 WHERE c2 IS NULL ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2,c1; +INSERT INTO t1 VALUES(ADDTIME(NOW(),'6 01:01:01'),ADDTIME(NOW(),'6 01:01:01'),15),(ADDTIME(NOW(),'7 01:01:01'),NULL,16),(ADDTIME(NOW(),'8 01:01:01'),ADDTIME(NOW(),'8 01:01:01'),17),(ADDTIME(NOW(),'9 01:01:01'),ADDTIME(NOW(),'9 01:01:01'),18),(ADDTIME(NOW(),'10 01:01:01'),ADDTIME(NOW(),'10 01:01:01'),19); +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC; +DELETE FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC; +SELECT * FROM t1 WHERE c1>=ADDTIME(NOW(),'5 01:01:01') AND c2 < ADDTIME(NOW(),'8 13:25') ORDER BY c1; +DELETE FROM t1 WHERE c1>=ADDTIME(NOW(),'5 01:01:01') AND c2 < ADDTIME(NOW(),'8 13:25') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1>=ADDTIME(NOW(),'5 01:01:01') AND c2 < ADDTIME(NOW(),'8 13:25') ORDER BY c1; + +--sorted_result +SELECT * FROM t1 WHERE c1=ADDTIME(NOW(),'9 01:01:01') OR c2=ADDTIME(NOW(),'10 01:01:01'); +DELETE FROM t1 WHERE c1=ADDTIME(NOW(),'9 01:01:01') OR c2=ADDTIME(NOW(),'10 01:01:01'); +--sorted_result +SELECT * FROM t1 WHERE c1=ADDTIME(NOW(),'9 01:01:01') OR c2=ADDTIME(NOW(),'10 01:01:01'); +SELECT count(*) FROM t1; +TRUNCATE TABLE t1; +SELECT count(*) FROM t1; + +# Multi-table delete +# eq-ref join +CREATE TABLE t2(c1 DATETIME NOT NULL PRIMARY KEY, c2 DATETIME, c3 INT); +INSERT INTO t1 VALUES('2001-01-01 1:30','2001-01-02 2:30',1),('2001-01-03 3:30','2001-01-02 2:30',2); +INSERT INTO t2 VALUES('2001-01-02 2:30','2001-01-03 3:30',1),('2001-01-04 4:30','2001-01-05 5:30',2); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE t1,t2 FROM t1,t2 WHERE t2.c1=t1.c2; +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES('2001-01-01 1:30','2001-01-02 2:30',1),('2001-01-03 3:30','2001-01-02 2:30',2); +INSERT INTO t2 VALUES('2001-01-02 2:30','2001-01-03 3:30',1),('2001-01-04 4:30','2001-01-05 5:30',2); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE FROM a1, a2 USING t1 AS a1 INNER JOIN t2 AS a2 WHERE a2.c1=a1.c2; +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DROP TABLE t1,t2; + +# More tests for update/delete........ +CREATE TABLE mt1(id int(11) NOT NULL default '0', name varchar(10) default NULL, PRIMARY KEY (id)); +INSERT INTO mt1 VALUES (1,'aaa'),(2,'aaa'),(3,'aaa'); +CREATE TABLE mt2 (id int(11) NOT NULL default '0', name varchar(10) default NULL, PRIMARY KEY (id)); +INSERT INTO mt2 VALUES (2,'bbb'),(3,'bbb'),(4,'bbb'); +CREATE TABLE mt3 (id int(11) NOT NULL default '0', mydate datetime default NULL, PRIMARY KEY (id)); +INSERT INTO mt3 VALUES (1,'2002-02-04 00:00:00'),(3,'2002-05-12 00:00:00'),(5,'2002-05-12 00:00:00'),(6,'2002-06-22 00:00:00'),(7,'2002-07-22 00:00:00'); +delete mt1,mt2,mt3 from mt1,mt2,mt3 where to_days(now())-to_days(mt3.mydate)>=30 and mt3.id=mt1.id and mt3.id=mt2.id; +--sorted_result +select * from mt3; +DROP TABLE mt1,mt2,mt3; + +######## Running UPDATE tests for TIMESTAMP ######## + +# Create tables +CREATE TABLE t1(c1 TIMESTAMP NOT NULL PRIMARY KEY, c2 TIMESTAMP NULL, c3 INT, INDEX idx2(c2)); + +# Update date values to timestamp field +INSERT INTO t1 VALUE('1998-01-01 09:23:45','10-01-01 14:12:33',1); +UPDATE t1 SET c1='2001-01-01' WHERE c2='10-01-01 14:12:33'; +SELECT c1,hour(c1),minute(c1),second(c1) FROM t1 WHERE c2='10-01-01 14:12:33'; + +# Update with single digit hour, minute, second,fraction part to time +INSERT INTO t1 VALUES('2009-01-01 08:42:42','2009-01-02 23:59:59',2); +UPDATE t1 SET c1='2009-01-01 1:2:3',c2='2009-01-02 23:59:59.999999' WHERE c2='2009-01-02 23:59:59'; +SELECT c1,ADDTIME(c2,'1 1:1:1.000002') FROM t1 WHERE c3=2; + +# Update with function +INSERT INTO t1 VALUES('2009-02-25 15:45','09-02-27 15:46',3); +SET TIMESTAMP=1235553613; #'2009-02-25' +UPDATE t1 SET c2=NOW() WHERE c1 >=CURDATE() /* updates c1 with current timestamp */; +UPDATE t1 SET c1=DATE_ADD(CURDATE(),INTERVAL '1 1:1:1' DAY_SECOND) WHERE c2=CURRENT_TIMESTAMP(); +--sorted_result +SELECT * FROM t1; + +# Update with Null, null to valid date +INSERT INTO t1 VALUES('2001-01-06','2001-01-07 09:30:00',4),('2001-01-08',NULL,5); +UPDATE t1 SET c1='20010106010030',c2=NULL WHERE c1='2001-01-06 00:00:00'; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c2 IS NULL; +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c1=c1,c2='2001-01-10 00:00:00' WHERE c2 IS NULL; +--sorted_result +SELECT * FROM t1 WHERE c2='2001-01-10'; + +# Update with invalid datetimes, converts to zero datetime +INSERT INTO t1 VALUES('2001-01-09','2001-01-10',6),('2001-01-11','2001-01-12',7); +UPDATE t1 SET c1='2001-01-09 24:59:59',c2='2009-01-10 23:60:59' WHERE c1='2001-01-09'; +UPDATE t1 SET c1='2001-01-11 23:59:59',c2='2001-01-11 23:59:60' WHERE c1='2001-01-11'; +SELECT count(*) FROM t1 WHERE c1='2001-01-09 24:59:59' AND c2='2009-01-10 23:60:59'; +SELECT count(*) FROM t1 WHERE c1='2001-01-11 23:59:59' AND c2='2001-01-11 23:59:60'; +--sorted_result +SELECT * FROM t1 WHERE c1='0000-00-00 00:00:00' OR c2='0000-00-00 00:00:00'; + +# Update with zero datetimes, zero datetimes to valid datetimes +INSERT INTO t1 VALUES('2001-01-17','0000-00-00 00:00:00',8),('2001-01-18','2001-01-18 07:35',9); +SET SQL_MODE=TRADITIONAL; +SELECT * FROM t1 WHERE c2='0000-00-00 00:00:00'; +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET c1='1972-01-01 07:35',c2='0000-00-00 00:00:00' WHERE c2='2001-01-18 07:35'; +SET SQL_MODE=DEFAULT; +UPDATE t1 SET c1='1972-01-01 07:35',c2='0000-00-00 00:00:00' WHERE c2='2001-01-18 07:35'; +UPDATE t1 SET c1='2001-01-17 12:34:00',c2='2001-01-17 12:34:00' WHERE c2='0000-00-00 00:00:00' AND c1='2001-01-17'; +--sorted_result +SELECT * FROM t1 WHERE c1='0000-00-00 00:00:00' OR c2='0000-00-00 00:00:00'; +--sorted_result +SELECT * FROM t1 WHERE c1='2001-01-17 12:34:00' AND c2='2001-01-17 12:34:00'; + +# Update with range values +INSERT INTO t1 VALUES('2001-01-21 05:43:43','2001-01-22 06:53:53',10); +UPDATE t1 SET c1='1971-01-01 00:00:01',c2='2038-01-09 03:14:07' WHERE c1='2001-01-21 05:43:43'; +SELECT * FROM t1 WHERE c1='1971-01-01 00:00:01' AND c2='2038-01-09 03:14:07'; + +# Update ignore on duplicate key +INSERT INTO t1 VALUES('2001-01-23 02:33','2001-01-24 03:33',11),('2001-01-25 04:33','2001-01-26 05:33',12); +--error ER_DUP_ENTRY +UPDATE t1 SET c1='2001-01-23 02:33' WHERE c1='2001-01-25 04:33'; +UPDATE IGNORE t1 SET c1='2001-01-23 02:33' WHERE c1='2001-01-25 04:33'; +SELECT count(*) FROM t1 WHERE c1='2001-01-23 02:33'; +UPDATE t1 SET c1=NULL WHERE c2='2001-01-24 03:33' /* updates to current timestamp */; +UPDATE IGNORE t1 SET c1=NULL WHERE c2='2001-01-26 05:33'; +--sorted_result +SELECT * FROM t1 WHERE c1=CURRENT_TIMESTAMP(); + +# Multi table update + +TRUNCATE TABLE t1; +CREATE TABLE t2(c1 TIMESTAMP NOT NULL PRIMARY KEY, c2 TIMESTAMP, c3 INT); + +# eq-ref join +INSERT INTO t1 VALUES('2001-01-02 2:30:45','2001-01-01 1:30',1),('2001-01-03 3:30','2001-01-02 2:30:45',2); +INSERT INTO t2 VALUES('2001-01-02 2:30:45','2001-01-03 3:30',1),('2001-01-04 4:30','2001-01-05 5:30',2); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; +UPDATE t1,t2 SET t2.c1='2005-01-06 2:30:50',t1.c1='2005-01-06 2:30:50' WHERE t2.c1=t1.c1; +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; + +INSERT INTO t1 VALUES('2002-01-01 3:30','2002-01-02 2:30:45',3),('2002-01-04 4:30','2002-01-02 2:30:45',4); +INSERT INTO t2 VALUES('2002-01-02 2:30:45','2002-01-03 3:30',3),('2002-01-03 3:30','2002-01-04 4:30',4); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +UPDATE t1,t2 SET t2.c1='2002-01-06 2:30:50',t1.c1=t1.c1,t1.c2='2002-01-06 2:30:50' WHERE t2.c1=t1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1='2002-01-06 2:30:50' AND t1.c2='2002-01-06 2:30:50'; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE FROM t1 WHERE c2='2002-01-06 2:30:50' AND c3=3; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DROP TABLE t2; + +# Update with other access methods, ORDER BY LIMIT +TRUNCATE TABLE t1; +ALTER TABLE t1 CHANGE c1 c1 TIMESTAMP NOT NULL, DROP PRIMARY KEY; +ALTER TABLE t1 CHANGE c1 c1 TIMESTAMP NOT NULL, ADD KEY(c1); + +# ref access +UPDATE t1 SET c1='2002-01-07 7:30' WHERE c2='2002-01-05 5:30'; +SELECT * FROM t1 WHERE c1='2002-01-07 7:30'; + +# range access, MRR +INSERT INTO t1 VALUES('2002-01-08 1:30','2002-01-09 1:30',4),('2002-01-08 1:30:5','2002-01-09 1:30:5',5),('2002-01-08 1:30:10','2002-01-09 1:30:10',6),('2002-01-08 1:30:15','2002-01-09 1:30:15',7),('2002-01-08 1:30:20','2002-01-09 1:30:20',8),('2002-01-08 1:30:25','2002-01-09 1:30:25',9),('2002-01-08 1:30:30','2002-01-09 1:30:30',10),('2002-01-08 1:30:35','2002-01-09 1:30:35',11),('2002-01-08 1:30:40','2002-01-09 1:30:40',12),('2002-01-08 1:30:45','2002-01-09 1:30:45',13),('2002-01-08 1:30:50','2002-01-09 1:30:50',14),('2002-01-08 1:30:55','2002-01-09 1:30:55',15),('2002-01-08 1:30:59','2002-01-09 1:30:59',16),('2002-01-08 2:00','2002-01-09 2:00',17),('2002-01-08 2:00:05','2002-01-09 2:00:05',18),('2002-01-08 2:00:10','2002-01-09 2:00:10',19),('2002-01-08 2:00:15','2002-01-09 2:00:15',20); +--sorted_result +SELECT * FROM t1; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 <> '2002-01-09 01:30:00' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <> '2002-01-09 01:30:00' ORDER BY c2; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 >= '20020109013010' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 >= '20020109013010' ORDER BY c2 DESC; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 <='02-01-09 1:30:20' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 <='02-01-09 1:30:20' ORDER BY c2; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 <=> '020109013030' ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 <=> '020109013030' ORDER BY c2 DESC; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 BETWEEN '20020109 01:30:40' AND '20020109 01:30:50' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 BETWEEN '20020109 01:30:40' AND '20020109 01:30:50' ORDER BY c2; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 IN('2002-01-09 1:30:55','2002-01-09 2:00') ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IN('2002-01-09 1:30:55','2002-01-09 2:00') ORDER BY c2 DESC; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2; +UPDATE t1 SET c1='2003-01-01 1:2:3' WHERE c2>= '2002-02-09 2:00:5' AND c1 < '2002-02-09 2:00:15' ORDER BY c2 LIMIT 2; +SELECT * FROM t1 WHERE c2>= '2002-02-09 2:00:5' AND c1 < '2002-02-09 2:00:15' ORDER BY c2; +INSERT INTO t1 VALUES('20020301000001','20020302000001',1),('020303010030','020304010030',2),('050103000001','050104000001',3),('5-10-10 1:2:3','5-10-10 1:2:3',4),('0000-00-00 00:00:01',NULL,5); +# Select using various access methods +## Full table scan +--sorted_result +SELECT * FROM t1; +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t1; +## Backward index scan, covering ## +SELECT c1 FROM t1 ORDER BY c1 DESC; +# ref access +--sorted_result +SELECT * FROM t1 WHERE c1='2003-01-01 1:2:3'; +## Range access ## +SELECT * FROM t1 WHERE c1 <> '2003-01-01 1:2:3' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 <> '2003-01-01 1:2:3' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 > '20030101010203' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > '20030101010203' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 < '03-01-01 1:2:3' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 < '03-01-01 1:2:3' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 <=> '2003-01-01 1:2:3' ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 <=> '2003-01-01 1:2:3' ORDER BY c1,c2; +SELECT * FROM t1 WHERE c1 BETWEEN '20020301' AND '2003-01-01 1:2:3' ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN '20020301' AND '2003-01-01 1:2:3' ORDER BY c1,c2 DESC; +SELECT * FROM t1 WHERE c1 IN('2003-01-01 1:2:3','2005-01-03 00:00:01') ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN('2003-01-01 1:2:3','2005-01-03 00:00:01') ORDER BY c1,c2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2,c1 DESC; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1; +SELECT * FROM t1 WHERE c1>='2003-01-01 01:02:03' AND c1 <= '20050104000001' ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1>='2003-01-01 01:02:03' AND c1 <= '20050104000001' ORDER BY c2,c1; + +# Index-merge access +SELECT * FROM t1 WHERE c1='2003-01-03 1:2:3' OR c2='2002-03-02 00:00:01'; +UPDATE t1 SET c1='20060101000001' WHERE c1='2003-01-03 1:2:3' OR c2='2002-03-02 00:00:01'; +--sorted_result +SELECT * FROM t1 WHERE c1='20060101000001' OR c2='020304010030'; + +# Testing delete using various access methods +TRUNCATE TABLE t1; +ALTER TABLE t1 CHANGE c1 c1 TIMESTAMP NOT NULL, ADD PRIMARY KEY(c1); +INSERT INTO t1 VALUES(NOW(),NOW(),3),(ADDTIME(NOW(),'1 01:01:01'),ADDTIME(NOW(),'1 01:01:01'),4),(ADDTIME(NOW(),'2 01:01:01'),ADDTIME(NOW(),'2 01:01:01'),5),(ADDTIME(NOW(),'3 01:01:01'),ADDTIME(NOW(),'3 01:01:01'),6); +INSERT INTO t1 VALUES('1971-01-01 00:00:01','1971-01-01 00:00:01',1),('2038-01-09 03:14:07','2038-01-09 03:14:07',2); +SELECT * FROM t1 WHERE c1 <='1971-01-01 00:00:01'; +DELETE FROM t1 WHERE c1 <='1971-01-01 00:00:01'; +SELECT * FROM t1 WHERE c1 <='1971-01-01 00:00:01'; +SELECT * FROM t1 WHERE c1 >='2038-01-09 03:14:07'; +DELETE FROM t1 WHERE c1 >='2038-01-09 03:14:07'; +SELECT * FROM t1 WHERE c1 >='2038-01-09 03:14:07'; +SELECT * FROM t1 WHERE c1 > ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +DELETE FROM t1 WHERE c1 > ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 > ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <> CURRENT_TIMESTAMP() ORDER BY c1; +DELETE FROM t1 WHERE c1 <> CURRENT_TIMESTAMP() ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 <> CURRENT_TIMESTAMP() ORDER BY c1; +INSERT INTO t1 VALUES('2001-01-01',NOW(),7),(ADDTIME(NOW(),'1 01:01:01'),ADDTIME(NOW(),'1 01:01:01'),8),(ADDTIME(NOW(),'2 01:01:01'),ADDTIME(NOW(),'2 01:01:01'),9),(ADDTIME(NOW(),'3 01:01:01'),ADDTIME(NOW(),'3 01:01:01'),10); +SELECT * FROM t1 WHERE c1 < ADDTIME(NOW(),'2 01:01:01') ORDER BY c1; +DELETE FROM t1 WHERE c1 < ADDTIME(NOW(),'2 01:01:01') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 < ADDTIME(NOW(),'2 01:01:01') ORDER BY c1; +SELECT * FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +DELETE FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +DELETE FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c1 <=> ADDTIME(NOW(),'1 01:01:01') ORDER BY c1 DESC; +INSERT INTO t1 VALUES('2001-01-01',NOW(),11),(ADDTIME(NOW(),'1 01:01:01'),ADDTIME(NOW(),'1 01:01:01'),12),(ADDTIME(NOW(),'4 01:01:01'),NULL,13),(ADDTIME(NOW(),'5 01:01:01'),NULL,14); +SELECT * FROM t1 WHERE c1 BETWEEN NOW() AND ADDTIME(NOW(),'2 01:01:01') ORDER BY c1; +DELETE FROM t1 WHERE c1 BETWEEN NOW() AND ADDTIME(NOW(),'2 01:01:01') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1 BETWEEN NOW() AND ADDTIME(NOW(),'2 01:01:01') ORDER BY c1; +SELECT * FROM t1 WHERE c1 IN(NOW(),ADDTIME(NOW(),'3 01:01:01')) ORDER BY c1 DESC; +DELETE FROM t1 WHERE c1 IN(NOW(),ADDTIME(NOW(),'3 01:01:01')) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c1 IN(NOW(),ADDTIME(NOW(),'3 01:01:01')) ORDER BY c1 DESC; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2,c1; +DELETE FROM t1 WHERE c2 IS NULL ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NULL ORDER BY c2,c1; +INSERT INTO t1 VALUES(ADDTIME(NOW(),'6 01:01:01'),ADDTIME(NOW(),'6 01:01:01'),15),(ADDTIME(NOW(),'7 01:01:01'),NULL,16),(ADDTIME(NOW(),'8 01:01:01'),ADDTIME(NOW(),'8 01:01:01'),17),(ADDTIME(NOW(),'9 01:01:01'),ADDTIME(NOW(),'9 01:01:01'),18),(ADDTIME(NOW(),'10 01:01:01'),ADDTIME(NOW(),'10 01:01:01'),19); +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC; +DELETE FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t1 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC; +SELECT * FROM t1 WHERE c1>=ADDTIME(NOW(),'5 01:01:01') AND c2 < ADDTIME(NOW(),'8 13:25') ORDER BY c1; +DELETE FROM t1 WHERE c1>=ADDTIME(NOW(),'5 01:01:01') AND c2 < ADDTIME(NOW(),'8 13:25') ORDER BY c1 LIMIT 2; +SELECT * FROM t1 WHERE c1>=ADDTIME(NOW(),'5 01:01:01') AND c2 < ADDTIME(NOW(),'8 13:25') ORDER BY c1; + +--sorted_result +SELECT * FROM t1 WHERE c1=ADDTIME(NOW(),'9 01:01:01') OR c2=ADDTIME(NOW(),'10 01:01:01'); +DELETE FROM t1 WHERE c1=ADDTIME(NOW(),'9 01:01:01') OR c2=ADDTIME(NOW(),'10 01:01:01'); +--sorted_result +SELECT * FROM t1 WHERE c1=ADDTIME(NOW(),'9 01:01:01') OR c2=ADDTIME(NOW(),'10 01:01:01'); +SELECT count(*) FROM t1; +TRUNCATE TABLE t1; +SELECT count(*) FROM t1; + +# Multi-table delete +# eq-ref join +CREATE TABLE t2(c1 TIMESTAMP NOT NULL PRIMARY KEY, c2 TIMESTAMP, c3 INT); +INSERT INTO t1 VALUES('2001-01-01 1:30','2001-01-02 2:30',1),('2001-01-03 3:30','2001-01-02 2:30',2); +INSERT INTO t2 VALUES('2001-01-02 2:30','2001-01-03 3:30',1),('2001-01-04 4:30','2001-01-05 5:30',2); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE t1,t2 FROM t1,t2 WHERE t2.c1=t1.c2; +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES('2001-01-01 1:30','2001-01-02 2:30',1),('2001-01-03 3:30','2001-01-02 2:30',2); +INSERT INTO t2 VALUES('2001-01-02 2:30','2001-01-03 3:30',1),('2001-01-04 4:30','2001-01-05 5:30',2); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE FROM a1, a2 USING t1 AS a1 INNER JOIN t2 AS a2 WHERE a2.c1=a1.c2; +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DROP TABLE t1,t2; + diff --git a/mysql-test/suite/engines/iuds/t/update_delete_number.test b/mysql-test/suite/engines/iuds/t/update_delete_number.test new file mode 100644 index 00000000..ce3f9014 --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/update_delete_number.test @@ -0,0 +1,1784 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2; +--enable_warnings + +######## Running UPDATE tests for INT ######## + +# Create table +CREATE TABLE t1(c1 INT UNSIGNED NOT NULL, c2 INT SIGNED NULL, c3 INT, INDEX idx2(c2)); + +# Insert into tables +INSERT INTO t1 VALUES(0,-128,0),(1,1,1),(2,2,2),(0,\N,3),(101,-101,4),(102,-102,5),(103,-103,6),(104,-104,7),(105,-105,8); +--sorted_result +SELECT * FROM t1; + +# Update order by limit +UPDATE t1 SET c1=110 WHERE c2 >-128 ORDER BY c2 LIMIT 2; +--sorted_result +SELECT * FROM t1 WHERE c1=110; + +# Update with NULL(null to numbers, numbers to null) +UPDATE t1 SET c1=c1+1,c2=NULL WHERE c1=101; +--sorted_result +SELECT * FROM t1 WHERE c1=102 AND c2 IS NULL; +UPDATE t1 SET c1=120 WHERE c2 IS NULL; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c1=120; + +# Update negative value to unsigned col +UPDATE IGNORE t1 SET c1=-120 WHERE c2=-102; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c2=-102; + +# Update range values +UPDATE t1 SET c1=0,c2=-2147483648 WHERE c1=103 AND c2=-103; +--sorted_result +SELECT * FROM t1 WHERE c1=0 AND c2=-2147483648; +UPDATE t1 SET c1=4294967295,c2=2147483647 WHERE c1=104 OR c2=105; +--sorted_result +SELECT * FROM t1 WHERE c1=4294967295 AND c2=2147483647; +UPDATE t1 SET c2=0 WHERE c1 IN (1,2); +--sorted_result +SELECT * FROM t1 WHERE c2=0; + +# Update outside range, would be clipped to closest endpoint +INSERT INTO t1 VALUES(106,-106,9),(107,-107,10),(108,-108,11),(109,-109,12),(255,127,13); +UPDATE IGNORE t1 SET c1=4294967296,c2=2147483648 WHERE c2 BETWEEN -108 AND -106; +SELECT COUNT(*) FROM t1 WHERE c1=4294967296 AND c2=2147483648 /* no rows */; +--sorted_result +SELECT * FROM t1 WHERE c1=4294967295 AND c2=2147483647; +UPDATE IGNORE t1 SET c2=-2147483649 WHERE c1=109 ORDER BY c1; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c1=109; + +# Update ignore on bad null error +INSERT INTO t1 VALUES(110,-110,14),(111,-111,15); +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t1 SET c1=NULL WHERE c2=-110; +UPDATE IGNORE t1 SET c1=NULL WHERE c2=-110 /* updates to default value 0 */; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c2=-110; +SET SQL_MODE=DEFAULT; +UPDATE IGNORE t1 SET c1=NULL WHERE c2=-111 /* updates to default value 0 */; +--sorted_result +SELECT * FROM t1 WHERE c1=0; + +# Update with multi-range +SELECT * FROM t1 WHERE c2>=-101 AND c1<=101 ORDER BY c2; +UPDATE t1 SET c1=c1+1,c2=c2+1 WHERE c2>=-101 AND c1<=101 ORDER BY c2 LIMIT 2; +--sorted_result +SELECT * FROM t1; + +# Create table with AUTO_INCREMENT Primary Key +CREATE TABLE t2(c1 INT SIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 INT UNSIGNED NULL, c3 INT); + +# Update ignore on duplicate key error +INSERT INTO t2(c1) VALUES(1),(2),(3),(4),(5); +--error ER_DUP_ENTRY +UPDATE t2 SET c1=1 WHERE c1=3; +UPDATE IGNORE t2 SET c1=1 WHERE c1>=3; +--sorted_result +SELECT c1 FROM t2; + +# Update the auto_incremented value with boundary values to unsigned/signed field +TRUNCATE TABLE t1; +ALTER TABLE t1 CHANGE c1 c1 INT UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY(c1); +INSERT INTO t1 VALUES(1,2,3),(4,5,6),(7,8,9),(10,11,12); +TRUNCATE TABLE t2; +INSERT INTO t2 VALUES(1,2,3),(4,5,6),(7,8,9),(10,11,12); +INSERT INTO t1(c2,c3) VALUES(13,14); +SELECT c1 FROM t1 WHERE c2=13; +INSERT INTO t2(c2,c3) VALUES(13,14); +SELECT c1 FROM t2 WHERE c2=13; +# Update the unsigned auto_increment field +UPDATE t1 SET c1=4294967295,c2=2147483647 WHERE c2=13; +SELECT c1,c2 FROM t1 ORDER BY c1; +UPDATE IGNORE t2 SET c1=0,c2=-2147483648 WHERE c2=2; +SELECT c1,c2 FROM t1 ORDER BY c1; +UPDATE t2 SET c2=0 WHERE c2=5; +SELECT c1,c2 FROM t1 ORDER BY c1; +# Update the signed auto_increment field +UPDATE t2 SET c1=2147483647,c2=4294967295 WHERE c2=13; +SELECT c1,c2 FROM t2 ORDER BY c1; +UPDATE t2 SET c1=-2147483648,c2=0 WHERE c2=2; +SELECT c1,c2 FROM t2 ORDER BY c1; +UPDATE t2 SET c1=0,c2=0 WHERE c2=5; +SELECT c1,c2 FROM t2 ORDER BY c1; + +# Multi table update +CREATE TABLE mt1 (c1 INT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +CREATE TABLE mt2 (c1 INT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +CREATE TABLE mt3 (c1 INT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +INSERT INTO mt1 VALUES(1,1),(2,2),(3,3),(4,4),(5,5); +INSERT INTO mt2 VALUES(11,1),(12,1),(13,1),(14,2),(15,6); +INSERT INTO mt3 VALUES(21,11),(22,11),(23,13),(24,14),(25,15); +UPDATE IGNORE mt1, mt2 ,mt3 SET mt1.c2 = 30, mt2.c2 = 40, mt3.c2=50 WHERE mt1.c1=mt2.c2 AND mt2.c1=mt3.c2; +--sorted_result +SELECT * FROM mt1; +--sorted_result +SELECT * FROM mt2; +--sorted_result +SELECT * FROM mt3; +DROP TABLE mt1,mt2,mt3; + +# Update,Select,Delete,Select using various access methods +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +ALTER TABLE t2 CHANGE c2 c2 INT UNSIGNED NULL, ADD KEY(c2); +INSERT INTO t1 VALUES(1,-1,1),(2,-2,2),(3,-3,3),(4,-4,4),(5,-5,5),(6,-6,6),(7,-7,7),(8,-8,8),(9,-9,9),(10,-10,10),(11,NULL,11); +INSERT INTO t2 VALUES(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(-7,7,7),(-8,8,8),(-9,9,9),(10,10,10),(-11,NULL,11),(-12,12,12); + +# Update using various methods + +# Using eq-ref +UPDATE t1,t2 SET t1.c1=50,t1.c2=50,t2.c1=50,t2.c2=50 WHERE t2.c1=t1.c1; +--sorted_result +SELECT * FROM t1,t2 WHERE t1.c1=50 AND t1.c2=50 AND t2.c1=50 AND t2.c2=50; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; + +ALTER TABLE t2 CHANGE c1 c1 INT SIGNED NOT NULL, DROP PRIMARY KEY; +ALTER TABLE t2 CHANGE c1 c1 INT SIGNED NOT NULL, ADD KEY(c1); +INSERT INTO t2 VALUES(-2147483648,0,13),(2147483647,4294967295,14),(0,2147483648,15),(2147483647,2147483647,16); + +# range access +UPDATE t2 SET c1=-2147483648 WHERE c2 <> 0 ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <> 0 ORDER BY c2; +UPDATE t2 SET c1=-2147483648 WHERE c2 >= 0 ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= 0 ORDER BY c2 DESC; +UPDATE t2 SET c1=-2147483648 WHERE c2 <= 3 ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= 3 ORDER BY c2; +UPDATE t2 SET c1=-2147483648 WHERE c2 <=> 4 ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> 4 ORDER BY c2; +UPDATE t2 SET c1=-2147483648 WHERE c2 BETWEEN 4 AND 7 ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN 4 AND 7 ORDER BY c2; +UPDATE t2 SET c1=-2147483648 WHERE c2 IN(8,9) ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN(8,9) ORDER BY c2 DESC; +UPDATE t2 SET c1=-2147483648 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2; +UPDATE t2 SET c1=-2147483648 WHERE c2>= 6 AND c2 < 9 ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2>= 6 AND c2 < 9 ORDER BY c2; + +# Using index-merge +UPDATE t2 SET c1=-2147483648 WHERE c1=-12 OR c2=1; +--sorted_result +SELECT * FROM t2 WHERE c1=-2147483648; + +# Select using various access methods +## Full table scan +--sorted_result +SELECT * FROM t2; +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t2; +## Backward index scan, covering ## +SELECT c1 FROM t2 ORDER BY c1 DESC; +# ref access +--sorted_result +SELECT * FROM t2 WHERE c1=-2147483648; +## Range access ## +SELECT * FROM t2 WHERE c1 <> -2147483648 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> -2147483648 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -2147483648 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= -2147483648 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < -2147483648 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= -2147483648 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -2147483648 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> -2147483648 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -2147483648 AND 2147483647 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN -2147483648 AND 2147483647 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN(-2147483648,2147483647) ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN(-2147483648,2147483647) ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1>=-2147483648 AND c1 <= 2147483647 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1>=-2147483648 AND c1 <= 2147483647 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c2,c1 LIMIT 2; + +# Test multi update with different join methods +CREATE TABLE mt1 (a int not null primary key, b int not null, key (b)); +CREATE TABLE mt2 (a int not null primary key, b int not null, key (b)); +INSERT INTO mt1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO mt2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +# Full join, without key +update mt1,mt2 set mt1.a=mt1.a+100; +--sorted_result +select * from mt1; +# unique key +update mt1,mt2 set mt1.a=mt1.a+100 where mt1.a=101; +--sorted_result +select * from mt1; +# ref key +update mt1,mt2 set mt1.b=mt1.b+10 where mt1.b=2; +--sorted_result +select * from mt1; +# Range key (in mt1) +update mt1,mt2 set mt1.b=mt1.b+2,mt2.b=mt1.b+10 where mt1.b between 3 and 5 and mt2.a=mt1.a-100; +--sorted_result +select * from mt1; +--sorted_result +select * from mt2; +# test for non-updating table which is also used in sub-select +update mt1,mt2 set mt1.b=mt2.b, mt1.a=mt2.a where mt1.a=mt2.a and not exists (select * from mt2 where mt2.a > 10); +drop table mt1,mt2; + +# Testing delete using various access methods +TRUNCATE TABLE t2; +INSERT INTO t2 VALUES(-128,0,1),(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(0,0,7),(1,1,8),(127,255,9); + +# Using Index-merge +SELECT * FROM t2 WHERE c1=127 OR c2=3; +DELETE FROM t2 WHERE c1=127 OR c2=3; +SELECT * FROM t2 WHERE c1=127 OR c2=3; + +# Range access +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1; +DELETE FROM t2 WHERE c1 >= -128 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1; +SELECT * FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1; +DELETE FROM t2 WHERE c1 < 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1; +SELECT * FROM t2 WHERE c1 > -3 ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 > -3 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -3 ORDER BY c1 DESC; +INSERT INTO t2 VALUES(-128,0,1),(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(0,0,7),(1,1,8),(2,NULL,9),(3,NULL,10),(127,255,11); +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1; +DELETE FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1; +SELECT * FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1; +DELETE FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1; +DELETE FROM t2 WHERE c2 IS NOT NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC; +DELETE FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC; + +# Muti-table delete + +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES(254,127,1),(0,-128,2),(1,127,3),(2,-128,4),(3,NULL,5); +INSERT INTO t2 VALUES(127,255,1),(127,1,2),(-128,0,3),(-128,2,4),(-1,NULL,5); + +# join (Range checked for each record) +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +DELETE t1,t2 FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES(254,127,1),(0,-128,2),(1,127,3),(2,-128,4),(3,NULL,5); +INSERT INTO t2 VALUES(127,255,1),(127,1,2),(-128,0,3),(-128,2,4),(-1,NULL,5); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE FROM a1, a2 USING t1 AS a1 INNER JOIN t2 AS a2 WHERE a2.c1=a1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +--error ER_UPDATE_TABLE_USED +DELETE FROM t1,t2 using t1,t2 where t1.c1=(select c1 from t1); + +# eq-ref join +CREATE TABLE t3(c1 INT UNSIGNED NOT NULL PRIMARY KEY, c2 INT SIGNED NULL, c3 INT); +CREATE TABLE t4(c1 INT UNSIGNED, c2 INT); +INSERT INTO t3 VALUES(200,126,1),(250,-127,2); +INSERT INTO t4 VALUES(200,1),(150,3); +--sorted_result +SELECT * FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +DELETE t3.*,t4.* FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +SELECT * FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; + +DROP TABLE t1,t2,t3,t4; + +# More tests for updates............. +# Update with ORDER BY +create table mt1 (a int not null, b int not null, key (a)); +insert into mt1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3); +SET @tmp=0; +update mt1 set b=(@tmp:=@tmp+1) order by a; +update mt1 set b=99 where a=1 order by b asc limit 1; +select * from mt1 order by a,b; +update mt1 set b=100 where a=1 order by b desc limit 2; +update mt1 set a=a+10+b where a=1 order by b; +select * from mt1 order by a,b; +create table mt2 (a int not null, b int not null); +insert into mt2 values (1,1),(1,2),(1,3); +update mt1 set b=(select distinct 1 from (select * from mt2) a); +drop table mt1,mt2; + +# Multi table update +create table mt1 (f1 int); +create table mt2 (f2 int); +insert into mt1 values(1),(2); +insert into mt2 values(1),(1); +--enable_info +update mt1,mt2 set f1=3,f2=3 where f1=f2 and f1=1; +--disable_info +update mt2 set f2=1; +update mt1 set f1=1 where f1=3; +--enable_info +update mt2,mt1 set f1=3,f2=3 where f1=f2 and f1=1; +--disable_info +--sorted_result +SELECT * FROM mt1; +--sorted_result +SELECT * FROM mt2; +drop table mt1,mt2; + +# Update with subquery +create table mt1(f1 int, f2 int); +create table mt2(f3 int, f4 int); +create index idx on mt2(f3); +insert into mt1 values(1,0),(2,0); +insert into mt2 values(1,1),(2,2); +UPDATE mt1 SET mt1.f2=(SELECT MAX(mt2.f4) FROM mt2 WHERE mt2.f3=mt1.f1); +select * from mt1; +drop table mt1,mt2; + +# Update and partial key part +create table mt1 (a int, b char(255), key(a, b(20))); +insert into mt1 values (0, '1'); +update mt1 set b = b + 1 where a = 0; +--sorted_result +select * from mt1; +drop table mt1; + +# Update with subquery with ref built with a key from the updated table +create table mt1(f1 int, f2 int); +create table mt2(f3 int, f4 int); +create index idx on mt2(f3); +insert into mt1 values(1,0),(2,0); +insert into mt2 values(1,1),(2,2); +UPDATE mt1 SET mt1.f2=(SELECT MAX(mt2.f4) FROM mt2 WHERE mt2.f3=mt1.f1); +--sorted_result +select * from mt1; +drop table mt1,mt2; + +# Update on last_insert_id() +create table mt1 (id int not null auto_increment primary key, id_str varchar(32)); +insert into mt1 (id_str) values ("test"); +update mt1 set id_str = concat(id_str, id) where id = last_insert_id(); +--sorted_result +select * from mt1; +drop table mt1; + +# More updates +create table mt1 (n int(10) not null primary key, d int(10)); +create table mt2 (n int(10) not null primary key, d int(10)); +insert into mt1 values(1,1), (3,3); +insert into mt2 values(1,10),(2,20); +UPDATE mt2 left outer join mt1 on mt1.n=mt2.n SET mt1.d=mt2.d; +--sorted_result +select * from mt1; +--sorted_result +select * from mt2; +drop table mt1,mt2; +create table mt1 (n int(10), d int(10)); +create table mt2 (n int(10), d int(10)); +insert into mt1 values(1,1),(1,2); +insert into mt2 values(1,10),(2,20); +UPDATE mt1,mt2 SET mt1.d=mt2.d,mt2.d=30 WHERE mt1.n=mt2.n; +--sorted_result +select * from mt1; +--sorted_result +select * from mt2; +drop table mt1,mt2; +create table mt1 (n int(10), d int(10)); +create table mt2 (n int(10), d int(10)); +insert into mt1 values(1,1),(3,2); +insert into mt2 values(1,10),(1,20); +UPDATE mt1,mt2 SET mt1.d=mt2.d,mt2.d=30 WHERE mt1.n=mt2.n; +--sorted_result +select * from mt1; +--sorted_result +select * from mt2; +UPDATE mt1 a ,mt2 b SET a.d=b.d,b.d=30 WHERE a.n=b.n; +--sorted_result +select * from mt1; +--sorted_result +select * from mt2; +DELETE a, b FROM mt1 a,mt2 b where a.n=b.n; +--sorted_result +select * from mt1; +--sorted_result +select * from mt2; +drop table mt1,mt2; + +# Multi table UPDATE IGNORE on duplicate keys +CREATE TABLE mt1 (`colA` int(10) unsigned NOT NULL auto_increment, `colB` int(11) NOT NULL default '0', PRIMARY KEY (`colA`)); +INSERT INTO mt1 VALUES (4433,5424); +CREATE TABLE mt2 (`colC` int(10) unsigned NOT NULL default '0', `colA` int(10) unsigned NOT NULL default '0', `colD` int(10) unsigned NOT NULL default '0', `colE` int(10) unsigned NOT NULL default '0', `colF` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`colC`,`colA`,`colD`,`colE`)); +INSERT INTO mt2 VALUES (3,4433,10005,495,500); +INSERT INTO mt2 VALUES (3,4433,10005,496,500); +INSERT INTO mt2 VALUES (3,4433,10009,494,500); +INSERT INTO mt2 VALUES (3,4433,10011,494,500); +INSERT INTO mt2 VALUES (3,4433,10005,497,500); +INSERT INTO mt2 VALUES (3,4433,10013,489,500); +INSERT INTO mt2 VALUES (3,4433,10005,494,500); +INSERT INTO mt2 VALUES (3,4433,10005,493,500); +INSERT INTO mt2 VALUES (3,4433,10005,492,500); +UPDATE IGNORE mt2,mt1 set mt2.colE = mt2.colE + 1,colF=0 WHERE mt1.colA = mt2.colA AND (mt1.colB & 4096) > 0 AND (colE + 1) < colF; +--sorted_result +SELECT * FROM mt2; +DROP TABLE mt1,mt2; + +# Test multi-update and multi-delete with impossible where +create table mt1(id1 smallint(5), field char(5)); +create table mt2(id2 smallint(5), field char(5)); +insert into mt1 values (1, 'a'), (2, 'aa'); +insert into mt2 values (1, 'b'), (2, 'bb'); +--sorted_result +select * from mt1; +--sorted_result +select * from mt2; +update mt2 inner join mt1 on mt1.id1=mt2.id2 set mt2.field=mt1.field where 0=1; +update mt2, mt1 set mt2.field=mt1.field where mt1.id1=mt2.id2 and 0=1; +delete mt1, mt2 from mt2 inner join mt1 on mt1.id1=mt2.id2 where 0=1; +delete mt1, mt2 from mt2,mt1 where mt1.id1=mt2.id2 and 0=1; +drop table mt1,mt2; + +create table mt1 (n numeric(10)); +create table mt2 (n numeric(10)); +insert into mt2 values (1),(2),(4),(8),(16),(32); +--sorted_result +select * from mt2 left outer join mt1 using (n); +delete mt1,mt2 from mt2 left outer join mt1 using (n); +--sorted_result +select * from mt2 left outer join mt1 using (n); +drop table mt1,mt2 ; + +create table mt1(id1 int not null primary key, t varchar(100)) pack_keys = 1; +create table mt2(id2 int not null, t varchar(100), index(id2)) pack_keys = 1; +disable_query_log; +let $1 = 1000; +while ($1) +{ +let $2 = 5; +eval insert into mt1 values ($1,'aaaaaaaaaaaaaaaaaaaa'); +while ($2) +{ +eval insert into mt2(id2,t) values ($1,'bbbbbbbbbbbbbbbbb'); +dec $2; +} +dec $1; +} +enable_query_log; +delete mt1 from mt1,mt2 where mt1.id1 = mt2.id2 and mt1.id1 > 500; +drop table mt1,mt2; + +# Test delete with outer join and const tables +--disable_warnings +create table mt1 (aclid bigint not null primary key, status tinyint(1) not null); +create table mt2 (refid bigint not null primary key, aclid bigint, index idx_acl(aclid)); +--enable_warnings +insert into mt2 values(1,null); +delete mt2, mt1 from mt2 left join mt1 on (mt2.aclid=mt1.aclid) where mt2.refid='1'; +drop table mt1, mt2; + +# multi delete wrong table check +create table mt1 (a int, primary key (a)); +create table mt2 (a int, primary key (a)); +create table mt3 (a int, primary key (a)); +-- error ER_UNKNOWN_TABLE +delete mt1,mt3 from mt1,mt2 where mt1.a=mt2.a and mt2.a=(select mt3.a from mt3 where mt1.a=mt3.a); +drop table mt1, mt2, mt3; +# multi* unique updating table check +create table mt1 (col1 int); +create table mt2 (col1 int); +update mt1,mt2 set mt1.col1 = (select max(col1) from mt1) where mt1.col1 = mt2.col1; +-- error ER_UPDATE_TABLE_USED +delete mt1 from mt1,mt2 where mt1.col1 < (select max(col1) from mt1) and mt1.col1 = mt2.col1; +drop table mt1,mt2; + +# With Foreign Key +CREATE TABLE IF NOT EXISTS `mt1` (`id` int(11) NOT NULL auto_increment, `tst` text, `tsmt1` text, PRIMARY KEY (`id`)); +CREATE TABLE IF NOT EXISTS `mt2` (`ID` int(11) NOT NULL auto_increment, `ParId` int(11) default NULL, `tst` text, `tsmt1` text, PRIMARY KEY (`ID`), KEY `IX_ParId_mt2` (`ParId`), FOREIGN KEY (`ParId`) REFERENCES `mt1` (`id`)); +INSERT INTO mt1(tst,tsmt1) VALUES("MySQL","MySQL AB"), ("MSSQL","Microsoft"), ("ORACLE","ORACLE"); +INSERT INTO mt2(ParId) VALUES(1), (2), (3); +--sorted_result +select * from mt2; +UPDATE mt2, mt1 SET mt2.tst = mt1.tst, mt2.tsmt1 = mt1.tsmt1 WHERE mt2.ParId = mt1.Id; +--sorted_result +select * from mt2; +drop table mt2,mt1; + +# Test alias +CREATE TABLE mt1 ( a int ); +CREATE TABLE mt2 ( a int ); +DELETE mt1 FROM mt1, mt2 AS t3; +DELETE t4 FROM mt1, mt1 AS t4; +DELETE t3 FROM mt1 AS t3, mt1 AS t4; +--error ER_UNKNOWN_TABLE +DELETE mt1 FROM mt1 AS t3, mt2 AS t4; +INSERT INTO mt1 values (1),(2); +INSERT INTO mt2 values (1),(2); +DELETE mt1 FROM mt1 AS mt2, mt2 AS mt1 where mt1.a=mt2.a and mt1.a=1; +SELECT * from mt1; +SELECT * from mt2; +DELETE mt2 FROM mt1 AS mt2, mt2 AS mt1 where mt1.a=mt2.a and mt1.a=2; +SELECT * from mt1; +SELECT * from mt2; +DROP TABLE mt1,mt2; + +create table mt1(id1 int not null auto_increment primary key, t char(12)); +create table mt2(id2 int not null, t char(12)); +create table mt3(id3 int not null, t char(12), index(id3)); +disable_query_log; +let $1 = 100; +while ($1) +{ +let $2 = 5; +eval insert into mt1(t) values ('$1'); +while ($2) +{ +eval insert into mt2(id2,t) values ($1,'$2'); +let $3 = 10; +while ($3) +{ +eval insert into mt3(id3,t) values ($1,'$2'); +dec $3; +} +dec $2; +} +dec $1; +} +enable_query_log; +select count(*) from mt1 where id1 > 95; +select count(*) from mt2 where id2 > 95; +select count(*) from mt3 where id3 > 95; +update mt1,mt2,mt3 set mt1.t="aaa", mt2.t="bbb", mt3.t="cc" where mt1.id1 = mt2.id2 and mt2.id2 = mt3.id3 and mt1.id1 > 90; +select count(*) from mt1 where t = "aaa"; +select count(*) from mt1 where id1 > 90; +select count(*) from mt2 where t = "bbb"; +select count(*) from mt2 where id2 > 90; +select count(*) from mt3 where t = "cc"; +select count(*) from mt3 where id3 > 90; +delete mt1.*, mt2.*, mt3.* from mt1,mt2,mt3 where mt1.id1 = mt2.id2 and mt2.id2 = mt3.id3 and mt1.id1 > 95; +check table mt1, mt2, mt3; +select count(*) from mt1 where id1 > 95; +select count(*) from mt2 where id2 > 95; +select count(*) from mt3 where id3 > 95; +delete mt1, mt2, mt3 from mt1,mt2,mt3 where mt1.id1 = mt2.id2 and mt2.id2 = mt3.id3 and mt1.id1 > 5; +select count(*) from mt1 where id1 > 5; +select count(*) from mt2 where id2 > 5; +select count(*) from mt3 where id3 > 5; +delete from mt1, mt2, mt3 using mt1,mt2,mt3 where mt1.id1 = mt2.id2 and mt2.id2 = mt3.id3 and mt1.id1 > 0; +# These queries will force a scan of the table +select count(*) from mt1 where id1; +select count(*) from mt2 where id2; +select count(*) from mt3 where id3; +drop table mt1,mt2,mt3; + +######## Running UPDATE tests for TINYINT ######## + +# Create table +CREATE TABLE t1(c1 TINYINT UNSIGNED NOT NULL, c2 TINYINT SIGNED NULL, c3 INT, INDEX idx2(c2)); + +# Insert into tables +INSERT INTO t1 VALUES(0,-128,0),(1,1,1),(2,2,2),(0,\N,3),(101,-101,4),(102,-102,5),(103,-103,6),(104,-104,7),(105,-105,8); +--sorted_result +SELECT * FROM t1; + +# Update order by limit +UPDATE t1 SET c1=110 WHERE c2 >-128 ORDER BY c2 LIMIT 2; +--sorted_result +SELECT * FROM t1 WHERE c1=110; + +# Update with NULL(null to numbers, numbers to null) +UPDATE t1 SET c1=c1+1,c2=NULL WHERE c1=101; +--sorted_result +SELECT * FROM t1 WHERE c1=102 AND c2 IS NULL; +UPDATE t1 SET c1=120 WHERE c2 IS NULL; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c1=120; + +# Update negative value to unsigned col +UPDATE IGNORE t1 SET c1=-120 WHERE c2=-102; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c2=-102; + +# Update range values +UPDATE t1 SET c1=0,c2=-128 WHERE c1=103 AND c2=-103; +--sorted_result +SELECT * FROM t1 WHERE c1=0 AND c2=-128; +UPDATE t1 SET c1=255,c2=127 WHERE c1=104 OR c2=105; +--sorted_result +SELECT * FROM t1 WHERE c1=255 AND c2=127; +UPDATE t1 SET c2=0 WHERE c1 IN (1,2); +--sorted_result +SELECT * FROM t1 WHERE c2=0; + +# Update outside range, would be clipped to closest endpoint +INSERT INTO t1 VALUES(106,-106,9),(107,-107,10),(108,-108,11),(109,-109,12),(255,127,13); +UPDATE IGNORE t1 SET c1=256,c2=128 WHERE c2 BETWEEN -108 AND -106; +SELECT COUNT(*) FROM t1 WHERE c1=256 AND c2=128 /* no rows */; +--sorted_result +SELECT * FROM t1 WHERE c1=255 AND c2=127; +UPDATE IGNORE t1 SET c2=-129 WHERE c1=109 ORDER BY c1; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c1=109; + +# Update ignore on bad null error +INSERT INTO t1 VALUES(110,-110,14),(111,-111,15); +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t1 SET c1=NULL WHERE c2=-110; +UPDATE IGNORE t1 SET c1=NULL WHERE c2=-110 /* updates to default value 0 */; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c2=-110; +SET SQL_MODE=DEFAULT; +UPDATE IGNORE t1 SET c1=NULL WHERE c2=-111 /* updates to default value 0 */; +--sorted_result +SELECT * FROM t1 WHERE c1=0; + +# Update with multi-range +SELECT * FROM t1 WHERE c2>=-101 AND c1<=101 ORDER BY c2; +UPDATE t1 SET c1=c1+1,c2=c2+1 WHERE c2>=-101 AND c1<=101 ORDER BY c2 LIMIT 2; +--sorted_result +SELECT * FROM t1; + +# Create table with AUTO_INCREMENT Primary Key +CREATE TABLE t2(c1 TINYINT SIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 TINYINT UNSIGNED NULL, c3 INT); + +# Update ignore on duplicate key error +INSERT INTO t2(c1) VALUES(1),(2),(3),(4),(5); +--error ER_DUP_ENTRY +UPDATE t2 SET c1=1 WHERE c1=3; +UPDATE IGNORE t2 SET c1=1 WHERE c1>=3; +--sorted_result +SELECT c1 FROM t2; + +# Update the auto_increment value +TRUNCATE TABLE t1; +ALTER TABLE t1 CHANGE c1 c1 TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY(c1); +INSERT INTO t1 VALUES(1,2,3),(4,5,6),(7,8,9),(10,11,12); +TRUNCATE TABLE t2; +INSERT INTO t2 VALUES(1,2,3),(4,5,6),(7,8,9),(10,11,12); +INSERT INTO t1(c2,c3) VALUES(13,14); +SELECT c1 FROM t1 WHERE c2=13; +INSERT INTO t2(c2,c3) VALUES(13,14); +SELECT c1 FROM t2 WHERE c2=13; +# Update the unsigned auto_increment field +UPDATE t1 SET c1=255,c2=127 WHERE c2=13; +SELECT c1,c2 FROM t1 ORDER BY c1; +UPDATE IGNORE t2 SET c1=0,c2=-128 WHERE c2=2; +SELECT c1,c2 FROM t1 ORDER BY c1; +UPDATE t2 SET c2=0 WHERE c2=5; +SELECT c1,c2 FROM t1 ORDER BY c1; +# Update the signed auto_increment field +UPDATE t2 SET c1=127,c2=255 WHERE c2=13; +SELECT c1,c2 FROM t2 ORDER BY c1; +UPDATE t2 SET c1=-128,c2=0 WHERE c2=2; +SELECT c1,c2 FROM t2 ORDER BY c1; +UPDATE t2 SET c1=0,c2=0 WHERE c2=5; +SELECT c1,c2 FROM t2 ORDER BY c1; + +# Multi table update +CREATE TABLE mt1 (c1 TINYINT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +CREATE TABLE mt2 (c1 TINYINT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +CREATE TABLE mt3 (c1 TINYINT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +INSERT INTO mt1 VALUES(1,1),(2,2),(3,3),(4,4),(5,5); +INSERT INTO mt2 VALUES(11,1),(12,1),(13,1),(14,2),(15,6); +INSERT INTO mt3 VALUES(21,11),(22,11),(23,13),(24,14),(25,15); +UPDATE IGNORE mt1, mt2 ,mt3 SET mt1.c2 = 30, mt2.c2 = 40, mt3.c2=50 WHERE mt1.c1=mt2.c2 AND mt2.c1=mt3.c2; +--sorted_result +SELECT * FROM mt1; +--sorted_result +SELECT * FROM mt2; +--sorted_result +SELECT * FROM mt3; +DROP TABLE mt1,mt2,mt3; + +# Update,Select,Delete,Select using various access methods +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +ALTER TABLE t2 CHANGE c2 c2 TINYINT UNSIGNED NULL, ADD KEY(c2); +INSERT INTO t1 VALUES(1,-1,1),(2,-2,2),(3,-3,3),(4,-4,4),(5,-5,5),(6,-6,6),(7,-7,7),(8,-8,8),(9,-9,9),(10,-10,10),(11,NULL,11); +INSERT INTO t2 VALUES(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(-7,7,7),(-8,8,8),(-9,9,9),(10,10,10),(-11,NULL,11),(-12,12,12); + +# Update using various methods +# eq-ref join +UPDATE t1,t2 SET t1.c1=50,t1.c2=50,t2.c1=50,t2.c2=50 WHERE t2.c1=t1.c1; +--sorted_result +SELECT * FROM t1,t2 WHERE t1.c1=50 AND t1.c2=50 AND t2.c1=50 AND t2.c2=50; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; + +ALTER TABLE t2 CHANGE c1 c1 TINYINT SIGNED NOT NULL, DROP PRIMARY KEY; +ALTER TABLE t2 CHANGE c1 c1 TINYINT SIGNED NOT NULL, ADD KEY(c1); +INSERT INTO t2 VALUES(-128,0,13),(127,255,14),(0,128,15),(127,127,16); + +# range access +UPDATE t2 SET c1=-128 WHERE c2 <> 0 ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <> 0 ORDER BY c2; +UPDATE t2 SET c1=-128 WHERE c2 >= 0 ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 >= 0 ORDER BY c2 DESC; +UPDATE t2 SET c1=-128 WHERE c2 <= 3 ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 <= 3 ORDER BY c2; +UPDATE t2 SET c1=-128 WHERE c2 <=> 4 ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> 4 ORDER BY c2; +UPDATE t2 SET c1=-128 WHERE c2 BETWEEN 4 AND 7 ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN 4 AND 7 ORDER BY c2; +UPDATE t2 SET c1=-128 WHERE c2 IN(8,9) ORDER BY c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN(8,9) ORDER BY c2 DESC; +UPDATE t2 SET c1=-128 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2; +UPDATE t2 SET c1=-128 WHERE c2>= 6 AND c2 < 9 ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2>= 6 AND c2 < 9 ORDER BY c2; + +# Using index-merge +UPDATE t2 SET c1=-128 WHERE c1=-12 OR c2=1; +--sorted_result +SELECT * FROM t2 WHERE c1=-128; + +# Select using various access methods +## Full table scan +--sorted_result +SELECT * FROM t2; +## Forward index scan, covering ## +--sorted_result +SELECT c1 FROM t2; +## Backward index scan, covering ## +SELECT c1 FROM t2 ORDER BY c1 DESC; +# ref access +--sorted_result +SELECT * FROM t2 WHERE c1=-128; +## Range access ## +SELECT * FROM t2 WHERE c1 <> -128 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <> -128 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -128 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 < -128 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 <= -128 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -128 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 <=> -128 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1,c2; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1,c2 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN(-128,127) ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1 IN(-128,127) ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c1>=-128 AND c1 <= 127 ORDER BY c1,c2 DESC; +SELECT * FROM t2 WHERE c1>=-128 AND c1 <= 127 ORDER BY c1,c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c2,c1 LIMIT 2; + +--sorted_result +SELECT * FROM t2 WHERE c1=-128 OR c2=3; + +# Test multi update with different join methods +CREATE TABLE mt1 (a tinyint not null primary key, b tinyint not null, key (b)); +CREATE TABLE mt2 (a tinyint not null primary key, b tinyint not null, key (b)); +INSERT INTO mt1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO mt2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +# Full join, without key +update mt1,mt2 set mt1.a=mt1.a+100; +--sorted_result +select * from mt1; +# unique key +update ignore mt1,mt2 set mt1.a=mt1.a+100 where mt1.a=101; +--sorted_result +select * from mt1; +# ref key +update mt1,mt2 set mt1.b=mt1.b+10 where mt1.b=2; +--sorted_result +select * from mt1; +# Range key (in mt1) +update mt1,mt2 set mt1.b=mt1.b+2,mt2.b=mt1.b+10 where mt1.b between 3 and 5 and mt2.a=mt1.a-100; +--sorted_result +select * from mt1; +--sorted_result +select * from mt2; +# test for non-updating table which is also used in sub-select +update mt1,mt2 set mt1.b=mt2.b, mt1.a=mt2.a where mt1.a=mt2.a and not exists (select * from mt2 where mt2.a > 10); +drop table mt1,mt2; + +# Testing delete using various access methods +TRUNCATE TABLE t2; +INSERT INTO t2 VALUES(-128,0,1),(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(0,0,7),(1,1,8),(127,255,9); + +# Using Index-merge +# explain SELECT * FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1; +SELECT * FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1; +DELETE FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1; + +# Range access +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1; +DELETE FROM t2 WHERE c1 >= -128 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1; +SELECT * FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1; +DELETE FROM t2 WHERE c1 < 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1; +SELECT * FROM t2 WHERE c1 > -3 ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 > -3 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -3 ORDER BY c1 DESC; +INSERT INTO t2 VALUES(-128,0,1),(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(0,0,7),(1,1,8),(2,NULL,9),(3,NULL,10),(127,255,11); +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1; +DELETE FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1; +SELECT * FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1; +DELETE FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1; +DELETE FROM t2 WHERE c2 IS NOT NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC; +DELETE FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC; + +# Muti-table delete + +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES(254,127,1),(0,-128,2),(1,127,3),(2,-128,4),(3,NULL,5); +INSERT INTO t2 VALUES(127,255,1),(127,1,2),(-128,0,3),(-128,2,4),(-1,NULL,5); + +# join(Range checked for each record) +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +DELETE t1,t2 FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES(254,127,1),(0,-128,2),(1,127,3),(2,-128,4),(3,NULL,5); +INSERT INTO t2 VALUES(127,255,1),(127,1,2),(-128,0,3),(-128,2,4),(-1,NULL,5); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE FROM a1, a2 USING t1 AS a1 INNER JOIN t2 AS a2 WHERE a2.c1=a1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +--error ER_UPDATE_TABLE_USED +DELETE FROM t1,t2 using t1,t2 where t1.c1=(select c1 from t1); + +# eq-ref join +CREATE TABLE t3(c1 TINYINT UNSIGNED NOT NULL PRIMARY KEY, c2 TINYINT SIGNED NULL, c3 INT); +CREATE TABLE t4(c1 TINYINT UNSIGNED, c2 INT); +INSERT INTO t3 VALUES(200,126,1),(250,-127,2); +INSERT INTO t4 VALUES(200,1),(150,3); +--sorted_result +SELECT * FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +DELETE t3.*,t4.* FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +SELECT * FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +DROP TABLE t1,t2,t3,t4; + +######## Running UPDATE tests for SMALLINT ######## + +# Create table +CREATE TABLE t1(c1 SMALLINT UNSIGNED NOT NULL, c2 SMALLINT SIGNED NULL, c3 INT, INDEX idx2(c2)); + +# Insert into tables +INSERT INTO t1 VALUES(0,-128,0),(1,1,1),(2,2,2),(0,\N,3),(101,-101,4),(102,-102,5),(103,-103,6),(104,-104,7),(105,-105,8); +--sorted_result +SELECT * FROM t1; + +# Update order by limit +UPDATE t1 SET c1=110 WHERE c2 >-128 ORDER BY c2 LIMIT 2; +--sorted_result +SELECT * FROM t1 WHERE c1=110; + +# Update with NULL(null to numbers, numbers to null) +UPDATE t1 SET c1=c1+1,c2=NULL WHERE c1=101; +--sorted_result +SELECT * FROM t1 WHERE c1=102 AND c2 IS NULL; +UPDATE t1 SET c1=120 WHERE c2 IS NULL; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c1=120; + +# Update negative value to unsigned col +UPDATE IGNORE t1 SET c1=-120 WHERE c2=-102; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c2=-102; + +# Update range values +UPDATE t1 SET c1=0,c2=-32768 WHERE c1=103 AND c2=-103; +--sorted_result +SELECT * FROM t1 WHERE c1=0 AND c2=-32768; +UPDATE t1 SET c1=65535,c2=32767 WHERE c1=104 OR c2=105; +--sorted_result +SELECT * FROM t1 WHERE c1=65535 AND c2=32767; +UPDATE t1 SET c2=0 WHERE c1 IN (1,2); +--sorted_result +SELECT * FROM t1 WHERE c2=0; + +# Update outside range, would be clipped to closest endpoint +INSERT INTO t1 VALUES(106,-106,9),(107,-107,10),(108,-108,11),(109,-109,12),(255,127,13); +UPDATE IGNORE t1 SET c1=65536,c2=32768 WHERE c2 BETWEEN -108 AND -106; +SELECT COUNT(*) FROM t1 WHERE c1=65536 AND c2=32768 /* no rows */; +--sorted_result +SELECT * FROM t1 WHERE c1=65535 AND c2=32767; +UPDATE IGNORE t1 SET c2=-32769 WHERE c1=109 ORDER BY c1; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c1=109; + +# Update ignore on bad null error +INSERT INTO t1 VALUES(110,-110,14),(111,-111,15); +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t1 SET c1=NULL WHERE c2=-110; +UPDATE IGNORE t1 SET c1=NULL WHERE c2=-110 /* updates to default value 0 */; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c2=-110; +SET SQL_MODE=DEFAULT; +UPDATE IGNORE t1 SET c1=NULL WHERE c2=-111 /* updates to default value 0 */; +--sorted_result +SELECT * FROM t1 WHERE c1=0; + +# Update with multi-range +SELECT * FROM t1 WHERE c2>=-101 AND c1<=101 ORDER BY c2; +UPDATE t1 SET c1=c1+1,c2=c2+1 WHERE c2>=-101 AND c1<=101 ORDER BY c2 LIMIT 2; +--sorted_result +SELECT * FROM t1; + +# Create table with AUTO_INCREMENT Primary Key +CREATE TABLE t2(c1 SMALLINT SIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 SMALLINT UNSIGNED NULL, c3 INT); + +# Update ignore on duplicate key error +INSERT INTO t2(c1) VALUES(1),(2),(3),(4),(5); +--error ER_DUP_ENTRY +UPDATE t2 SET c1=1 WHERE c1=3; +UPDATE IGNORE t2 SET c1=1 WHERE c1>=3; +--sorted_result +SELECT c1 FROM t2; + +# Update the auto_incremented value with boundary values to unsigned/signed field +TRUNCATE TABLE t1; +ALTER TABLE t1 CHANGE c1 c1 SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY(c1); +INSERT INTO t1 VALUES(1,2,3),(4,5,6),(7,8,9),(10,11,12); +TRUNCATE TABLE t2; +INSERT INTO t2 VALUES(1,2,3),(4,5,6),(7,8,9),(10,11,12); +INSERT INTO t1(c2,c3) VALUES(13,14); +SELECT c1 FROM t1 WHERE c2=13; +INSERT INTO t2(c2,c3) VALUES(13,14); +SELECT c1 FROM t2 WHERE c2=13; +# Update the unsigned auto_increment field +UPDATE t1 SET c1=65535,c2=32767 WHERE c2=13; +SELECT c1,c2 FROM t1 ORDER BY c1; +UPDATE IGNORE t2 SET c1=0,c2=-32768 WHERE c2=2; +SELECT c1,c2 FROM t1 ORDER BY c1; +UPDATE t2 SET c2=0 WHERE c2=5; +SELECT c1,c2 FROM t1 ORDER BY c1; +# Update the signed auto_increment field +UPDATE t2 SET c1=32767,c2=65535 WHERE c2=13; +SELECT c1,c2 FROM t2 ORDER BY c1; +UPDATE t2 SET c1=-32768,c2=0 WHERE c2=2; +SELECT c1,c2 FROM t2 ORDER BY c1; +UPDATE t2 SET c1=0,c2=0 WHERE c2=5; +SELECT c1,c2 FROM t2 ORDER BY c1; + +# Multi table update +CREATE TABLE mt1 (c1 SMALLINT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +CREATE TABLE mt2 (c1 SMALLINT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +CREATE TABLE mt3 (c1 SMALLINT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +INSERT INTO mt1 VALUES(1,1),(2,2),(3,3),(4,4),(5,5); +INSERT INTO mt2 VALUES(11,1),(12,1),(13,1),(14,2),(15,6); +INSERT INTO mt3 VALUES(21,11),(22,11),(23,13),(24,14),(25,15); +UPDATE IGNORE mt1, mt2 ,mt3 SET mt1.c2 = 30, mt2.c2 = 40, mt3.c2=50 WHERE mt1.c1=mt2.c2 AND mt2.c1=mt3.c2; +--sorted_result +SELECT * FROM mt1; +--sorted_result +SELECT * FROM mt2; +--sorted_result +SELECT * FROM mt3; +DROP TABLE mt1,mt2,mt3; + +# Update,Select,Delete,Select using various access methods +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +ALTER TABLE t2 CHANGE c2 c2 SMALLINT UNSIGNED NULL, ADD KEY(c2); +INSERT INTO t1 VALUES(1,-1,1),(2,-2,2),(3,-3,3),(4,-4,4),(5,-5,5),(6,-6,6),(7,-7,7),(8,-8,8),(9,-9,9),(10,-10,10),(11,NULL,11); +INSERT INTO t2 VALUES(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(-7,7,7),(-8,8,8),(-9,9,9),(10,10,10),(-11,NULL,11),(-12,12,12); + +# Update using various methods +# eq-ref join +UPDATE t1,t2 SET t1.c1=50,t1.c2=50,t2.c1=50,t2.c2=50 WHERE t2.c1=t1.c1; +--sorted_result +SELECT * FROM t1,t2 WHERE t1.c1=50 AND t1.c2=50 AND t2.c1=50 AND t2.c2=50; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; +ALTER TABLE t2 CHANGE c1 c1 SMALLINT SIGNED NOT NULL, DROP PRIMARY KEY; +ALTER TABLE t2 CHANGE c1 c1 SMALLINT SIGNED NOT NULL, ADD KEY(c1); +INSERT INTO t2 VALUES(-32768,0,12),(0,255,13),(32767,65535,14); + +# range access +UPDATE t2 SET c2=65535 WHERE c1 <> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 <> 0 ORDER BY c1; +UPDATE t2 SET c2=65535 WHERE c1 >= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1 DESC; +UPDATE t2 SET c2=65535 WHERE c1 <= -9 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -9 ORDER BY c1; +UPDATE t2 SET c2=65535 WHERE c1 <=> -3 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -3 ORDER BY c1; +UPDATE t2 SET c2=65535 WHERE c1 BETWEEN -6 AND -4 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -6 AND -4 ORDER BY c1; +UPDATE t2 SET c2=65535 WHERE c1 IN(-7,-8) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN(-7,-8) ORDER BY c1 DESC; +UPDATE t2 SET c2=65535 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2; +UPDATE t2 SET c2=65535 WHERE c1>= -32768 AND c1 < -9 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1>= -32768 AND c1 < -9 ORDER BY c1; + +# Using index-merge +UPDATE t2 SET c2=65535 WHERE c1=-2 OR c2=1; +--sorted_result +SELECT * FROM t2 WHERE c2=65535; + +# Select using various access methods +## Full table scan +--sorted_result +SELECT * FROM t2; +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t2; +## Backward index scan, covering ## +SELECT c2 FROM t2 ORDER BY c2 DESC; +# ref access +--sorted_result +SELECT * FROM t2 WHERE c2=65535; +## Range access ## +SELECT * FROM t2 WHERE c2 <> 65535 ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 <> 65535 ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > 65535 ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 >= 65535 ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 < 65535 ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 <= 65535 ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> 65535 ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 <=> 65535 ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN 0 AND 65535 ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 BETWEEN 0 AND 65535 ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN(0,65535) ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 IN(0,65535) ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 >=0 AND c2 <= 65535 ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 >=0 AND c2 <= 65535 ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c2,c1 LIMIT 2; + +--sorted_result +SELECT * FROM t2 WHERE c2=65535 OR c1=-4; + +# Test multi update with different join methods +CREATE TABLE mt1 (a smallint not null primary key, b smallint not null, key (b)); +CREATE TABLE mt2 (a smallint not null primary key, b smallint not null, key (b)); +INSERT INTO mt1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO mt2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +# Full join, without key +update mt1,mt2 set mt1.a=mt1.a+100; +--sorted_result +select * from mt1; +# unique key +update mt1,mt2 set mt1.a=mt1.a+100 where mt1.a=101; +--sorted_result +select * from mt1; +# ref key +update mt1,mt2 set mt1.b=mt1.b+10 where mt1.b=2; +--sorted_result +select * from mt1; +# Range key (in mt1) +update mt1,mt2 set mt1.b=mt1.b+2,mt2.b=mt1.b+10 where mt1.b between 3 and 5 and mt2.a=mt1.a-100; +--sorted_result +select * from mt1; +--sorted_result +select * from mt2; +# test for non-updating table which is also used in sub-select +update mt1,mt2 set mt1.b=mt2.b, mt1.a=mt2.a where mt1.a=mt2.a and not exists (select * from mt2 where mt2.a > 10); +drop table mt1,mt2; + +# Testing delete using various access methods +TRUNCATE TABLE t2; +INSERT INTO t2 VALUES(-128,0,1),(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(0,0,7),(1,1,8),(127,255,9); + +# Using Index-merge +SELECT * FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1; +DELETE FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1; + +# Range access +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1; +DELETE FROM t2 WHERE c1 >= -128 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1; +SELECT * FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1; +DELETE FROM t2 WHERE c1 < 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1; +SELECT * FROM t2 WHERE c1 > -3 ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 > -3 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -3 ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1=-3 OR c2=2; +DELETE FROM t2 WHERE c1=-3 OR c2=2; +SELECT * FROM t2 WHERE c1=-3 OR c2=2; +INSERT INTO t2 VALUES(-128,0,1),(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(0,0,7),(1,1,8),(2,NULL,9),(3,NULL,10),(127,255,11); +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1; +DELETE FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1; +SELECT * FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1; +DELETE FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1; +DELETE FROM t2 WHERE c2 IS NOT NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC; +DELETE FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC; + +# Muti-table delete + +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES(254,127,1),(0,-128,2),(1,127,3),(2,-128,4),(3,NULL,5); +INSERT INTO t2 VALUES(127,255,1),(127,1,2),(-128,0,3),(-128,2,4),(-1,NULL,5); + +# join(Range checked for each record) +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +DELETE t1,t2 FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES(254,127,1),(0,-128,2),(1,127,3),(2,-128,4),(3,NULL,5); +INSERT INTO t2 VALUES(127,255,1),(127,1,2),(-128,0,3),(-128,2,4),(-1,NULL,5); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE FROM a1, a2 USING t1 AS a1 INNER JOIN t2 AS a2 WHERE a2.c1=a1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +--error ER_UPDATE_TABLE_USED +DELETE FROM t1,t2 using t1,t2 where t1.c1=(select c1 from t1); + +# eq-ref join +CREATE TABLE t3(c1 SMALLINT UNSIGNED NOT NULL PRIMARY KEY, c2 SMALLINT SIGNED NULL, c3 INT); +CREATE TABLE t4(c1 SMALLINT UNSIGNED, c2 INT); +INSERT INTO t3 VALUES(200,126,1),(250,-127,2); +INSERT INTO t4 VALUES(200,1),(150,3); +--sorted_result +SELECT * FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +DELETE t3.*,t4.* FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +SELECT * FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +DROP TABLE t1,t2,t3,t4; + +######## Running UPDATE tests for MEDIUMINT ######## + +# Create table +CREATE TABLE t1(c1 MEDIUMINT UNSIGNED NOT NULL, c2 MEDIUMINT SIGNED NULL, c3 INT, INDEX idx2(c2)); + +# Insert into tables +INSERT INTO t1 VALUES(0,-128,0),(1,1,1),(2,2,2),(0,\N,3),(101,-101,4),(102,-102,5),(103,-103,6),(104,-104,7),(105,-105,8); +--sorted_result +SELECT * FROM t1; + +# Update order by limit +UPDATE t1 SET c1=110 WHERE c2 >-128 ORDER BY c2 LIMIT 2; +--sorted_result +SELECT * FROM t1 WHERE c1=110; + +# Update with NULL(null to numbers, numbers to null) +UPDATE t1 SET c1=c1+1,c2=NULL WHERE c1=101; +--sorted_result +SELECT * FROM t1 WHERE c1=102 AND c2 IS NULL; +UPDATE t1 SET c1=120 WHERE c2 IS NULL; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c1=120; + +# Update negative value to unsigned col +UPDATE IGNORE t1 SET c1=-120 WHERE c2=-102; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c2=-102; + +# Update range values +UPDATE t1 SET c1=0,c2=-8388608 WHERE c1=103 AND c2=-103; +--sorted_result +SELECT * FROM t1 WHERE c1=0 AND c2=-8388608; +UPDATE t1 SET c1=16777215,c2=8388607 WHERE c1=104 OR c2=105; +--sorted_result +SELECT * FROM t1 WHERE c1=16777215 AND c2=8388607; +UPDATE t1 SET c2=0 WHERE c1 IN (1,2); +--sorted_result +SELECT * FROM t1 WHERE c2=0; + +# Update outside range, would be clipped to closest endpoint +INSERT INTO t1 VALUES(106,-106,9),(107,-107,10),(108,-108,11),(109,-109,12),(255,127,13); +UPDATE IGNORE t1 SET c1=16777216,c2=8388608 WHERE c2 BETWEEN -108 AND -106; +SELECT COUNT(*) FROM t1 WHERE c1=16777216 AND c2=8388608 /* no rows */; +--sorted_result +SELECT * FROM t1 WHERE c1=16777215 AND c2=8388607; +UPDATE IGNORE t1 SET c2=-8388609 WHERE c1=109 ORDER BY c1; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c1=109; + +# Update ignore on bad null error +INSERT INTO t1 VALUES(110,-110,14),(111,-111,15); +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t1 SET c1=NULL WHERE c2=-110; +UPDATE IGNORE t1 SET c1=NULL WHERE c2=-110 /* updates to default value 0 */; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c2=-110; +SET SQL_MODE=DEFAULT; +UPDATE IGNORE t1 SET c1=NULL WHERE c2=-111 /* updates to default value 0 */; +--sorted_result +SELECT * FROM t1 WHERE c1=0; + +# Update with multi-range +SELECT * FROM t1 WHERE c2>=-101 AND c1<=101 ORDER BY c2; +UPDATE t1 SET c1=c1+1,c2=c2+1 WHERE c2>=-101 AND c1<=101 ORDER BY c2 LIMIT 2; +--sorted_result +SELECT * FROM t1; + +# Create table with AUTO_INCREMENT Primary Key +CREATE TABLE t2(c1 MEDIUMINT SIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 MEDIUMINT UNSIGNED NULL, c3 INT); + +# Update ignore on duplicate key error +INSERT INTO t2(c1) VALUES(1),(2),(3),(4),(5); +--error ER_DUP_ENTRY +UPDATE t2 SET c1=1 WHERE c1=3; +UPDATE IGNORE t2 SET c1=1 WHERE c1>=3; +--sorted_result +SELECT c1 FROM t2; + +# Update the auto_incremented value with boundary values to unsigned/signed field +TRUNCATE TABLE t1; +ALTER TABLE t1 CHANGE c1 c1 MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY(c1); +INSERT INTO t1 VALUES(1,2,3),(4,5,6),(7,8,9),(10,11,12); +TRUNCATE TABLE t2; +INSERT INTO t2 VALUES(1,2,3),(4,5,6),(7,8,9),(10,11,12); +INSERT INTO t1(c2,c3) VALUES(13,14); +SELECT c1 FROM t1 WHERE c2=13; +INSERT INTO t2(c2,c3) VALUES(13,14); +SELECT c1 FROM t2 WHERE c2=13; +# Update the unsigned auto_increment field +UPDATE t1 SET c1=16777215,c2=8388607 WHERE c2=13; +SELECT c1,c2 FROM t1 ORDER BY c1; +UPDATE IGNORE t2 SET c1=0,c2=-8388608 WHERE c2=2; +SELECT c1,c2 FROM t1 ORDER BY c1; +UPDATE t2 SET c2=0 WHERE c2=5; +SELECT c1,c2 FROM t1 ORDER BY c1; +# Update the signed auto_increment field +UPDATE t2 SET c1=8388607,c2=16777215 WHERE c2=13; +SELECT c1,c2 FROM t2 ORDER BY c1; +UPDATE t2 SET c1=-8388608,c2=0 WHERE c2=2; +SELECT c1,c2 FROM t2 ORDER BY c1; +UPDATE t2 SET c1=0,c2=0 WHERE c2=5; +SELECT c1,c2 FROM t2 ORDER BY c1; + +# Multi table update +CREATE TABLE mt1 (c1 MEDIUMINT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +CREATE TABLE mt2 (c1 MEDIUMINT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +CREATE TABLE mt3 (c1 MEDIUMINT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +INSERT INTO mt1 VALUES(1,1),(2,2),(3,3),(4,4),(5,5); +INSERT INTO mt2 VALUES(11,1),(12,1),(13,1),(14,2),(15,6); +INSERT INTO mt3 VALUES(21,11),(22,11),(23,13),(24,14),(25,15); +UPDATE IGNORE mt1, mt2 ,mt3 SET mt1.c2 = 30, mt2.c2 = 40, mt3.c2=50 WHERE mt1.c1=mt2.c2 AND mt2.c1=mt3.c2; +--sorted_result +SELECT * FROM mt1; +--sorted_result +SELECT * FROM mt2; +--sorted_result +SELECT * FROM mt3; +DROP TABLE mt1,mt2,mt3; + +# Update,Select,Delete,Select using various access methods +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +ALTER TABLE t2 CHANGE c2 c2 MEDIUMINT UNSIGNED NULL, ADD KEY(c2); +INSERT INTO t1 VALUES(1,-1,1),(2,-2,2),(3,-3,3),(4,-4,4),(5,-5,5),(6,-6,6),(7,-7,7),(8,-8,8),(9,-9,9),(10,-10,10),(11,NULL,11); +INSERT INTO t2 VALUES(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(-7,7,7),(-8,8,8),(-9,9,9),(10,10,10),(-11,NULL,11),(-12,12,12); + +# Update using various methods +# eq-ref join +UPDATE t1,t2 SET t1.c1=50,t1.c2=50,t2.c1=50,t2.c2=50 WHERE t2.c1=t1.c1; +--sorted_result +SELECT * FROM t1,t2 WHERE t1.c1=50 AND t1.c2=50 AND t2.c1=50 AND t2.c2=50; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; +ALTER TABLE t2 CHANGE c1 c1 MEDIUMINT SIGNED NOT NULL, DROP PRIMARY KEY; +ALTER TABLE t2 CHANGE c1 c1 MEDIUMINT SIGNED NOT NULL, ADD KEY(c1); +INSERT INTO t2 VALUES(-8388608,0,12),(0,255,13),(8388607,16777215,14); + +# range access +UPDATE t2 SET c2=16777215 WHERE c1 <> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 <> 0 ORDER BY c1; +UPDATE t2 SET c2=16777215 WHERE c1 >= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1 DESC; +UPDATE t2 SET c2=16777215 WHERE c1 <= -9 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -9 ORDER BY c1; +UPDATE t2 SET c2=16777215 WHERE c1 <=> -3 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -3 ORDER BY c1; +UPDATE t2 SET c2=16777215 WHERE c1 BETWEEN -6 AND -4 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -6 AND -4 ORDER BY c1; +UPDATE t2 SET c2=16777215 WHERE c1 IN(-7,-8) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN(-7,-8) ORDER BY c1 DESC; +UPDATE t2 SET c2=16777215 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2; +UPDATE t2 SET c2=16777215 WHERE c1>= -8388608 AND c1 < -9 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1>= -8388608 AND c1 < -9 ORDER BY c1; + +# Using index-merge +UPDATE t2 SET c2=16777215 WHERE c1=-2 OR c2=1; +--sorted_result +SELECT * FROM t2 WHERE c2=16777215; + +# Select using various access methods +## Full table scan +--sorted_result +SELECT * FROM t2; +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t2; +## Backward index scan, covering ## +SELECT c2 FROM t2 ORDER BY c2 DESC; +# ref access +--sorted_result +SELECT * FROM t2 WHERE c2=16777215; +## Range access ## +SELECT * FROM t2 WHERE c2 <> 16777215 ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 <> 16777215 ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > 16777215 ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 >= 16777215 ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 < 16777215 ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 <= 16777215 ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> 16777215 ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 <=> 16777215 ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN 0 AND 16777215 ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 BETWEEN 0 AND 16777215 ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN(0,16777215) ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 IN(0,16777215) ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 >=0 AND c2 <= 16777215 ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 >=0 AND c2 <= 16777215 ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c2,c1 LIMIT 2; + +--sorted_result +SELECT * FROM t2 WHERE c2=16777215 OR c1=-4; + +# Test multi update with different join methods +CREATE TABLE mt1 (a mediumint not null primary key, b mediumint not null, key (b)); +CREATE TABLE mt2 (a mediumint not null primary key, b mediumint not null, key (b)); +INSERT INTO mt1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO mt2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +# Full join, without key +update mt1,mt2 set mt1.a=mt1.a+100; +--sorted_result +select * from mt1; +# unique key +update mt1,mt2 set mt1.a=mt1.a+100 where mt1.a=101; +--sorted_result +select * from mt1; +# ref key +update mt1,mt2 set mt1.b=mt1.b+10 where mt1.b=2; +--sorted_result +select * from mt1; +# Range key (in mt1) +update mt1,mt2 set mt1.b=mt1.b+2,mt2.b=mt1.b+10 where mt1.b between 3 and 5 and mt2.a=mt1.a-100; +--sorted_result +select * from mt1; +--sorted_result +select * from mt2; +# test for non-updating table which is also used in sub-select +update mt1,mt2 set mt1.b=mt2.b, mt1.a=mt2.a where mt1.a=mt2.a and not exists (select * from mt2 where mt2.a > 10); +drop table mt1,mt2; + +# Testing delete using various access methods +TRUNCATE TABLE t2; +INSERT INTO t2 VALUES(-128,0,1),(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(0,0,7),(1,1,8),(127,255,9); + +# Using Index-merge +SELECT * FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1; +DELETE FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1; + +# Range access +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1; +DELETE FROM t2 WHERE c1 >= -128 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1; +SELECT * FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1; +DELETE FROM t2 WHERE c1 < 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1; +SELECT * FROM t2 WHERE c1 > -3 ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 > -3 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -3 ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1=-3 OR c2=2; +DELETE FROM t2 WHERE c1=-3 OR c2=2; +SELECT * FROM t2 WHERE c1=-3 OR c2=2; +INSERT INTO t2 VALUES(-128,0,1),(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(0,0,7),(1,1,8),(2,NULL,9),(3,NULL,10),(127,255,11); +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1; +DELETE FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1; +SELECT * FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1; +DELETE FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1; +DELETE FROM t2 WHERE c2 IS NOT NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC; +DELETE FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC; + +# Muti-table delete + +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES(254,127,1),(0,-128,2),(1,127,3),(2,-128,4),(3,NULL,5); +INSERT INTO t2 VALUES(127,255,1),(127,1,2),(-128,0,3),(-128,2,4),(-1,NULL,5); + +# join(Range checked for each record) +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +DELETE t1,t2 FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES(254,127,1),(0,-128,2),(1,127,3),(2,-128,4),(3,NULL,5); +INSERT INTO t2 VALUES(127,255,1),(127,1,2),(-128,0,3),(-128,2,4),(-1,NULL,5); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE FROM a1, a2 USING t1 AS a1 INNER JOIN t2 AS a2 WHERE a2.c1=a1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +--error ER_UPDATE_TABLE_USED +DELETE FROM t1,t2 using t1,t2 where t1.c1=(select c1 from t1); + +# eq-ref join +CREATE TABLE t3(c1 MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY, c2 MEDIUMINT SIGNED NULL, c3 INT); +CREATE TABLE t4(c1 MEDIUMINT UNSIGNED, c2 INT); +INSERT INTO t3 VALUES(200,126,1),(250,-127,2); +INSERT INTO t4 VALUES(200,1),(150,3); +--sorted_result +SELECT * FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +DELETE t3.*,t4.* FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +SELECT * FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +DROP TABLE t1,t2,t3,t4; + +######## Running UPDATE tests for BIGINT ######## + +# Create table +CREATE TABLE t1(c1 BIGINT UNSIGNED NOT NULL, c2 BIGINT SIGNED NULL, c3 INT, INDEX idx2(c2)); + +# Insert into tables +INSERT INTO t1 VALUES(0,-128,0),(1,1,1),(2,2,2),(0,\N,3),(101,-101,4),(102,-102,5),(103,-103,6),(104,-104,7),(105,-105,8); +--sorted_result +SELECT * FROM t1; + +# Update order by limit +UPDATE t1 SET c1=110 WHERE c2 >-128 ORDER BY c2 LIMIT 2; +--sorted_result +SELECT * FROM t1 WHERE c1=110; + +# Update with NULL(null to numbers, numbers to null) +UPDATE t1 SET c1=c1+1,c2=NULL WHERE c1=101; +--sorted_result +SELECT * FROM t1 WHERE c1=102 AND c2 IS NULL; +UPDATE t1 SET c1=120 WHERE c2 IS NULL; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c1=120; + +# Update negative value to unsigned col +UPDATE IGNORE t1 SET c1=-120 WHERE c2=-102; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c2=-102; + +# Update range values +UPDATE t1 SET c1=0,c2=-9223372036854775808 WHERE c1=103 AND c2=-103; +--sorted_result +SELECT * FROM t1 WHERE c1=0 AND c2=-9223372036854775808; +UPDATE t1 SET c1=18446744073709551615,c2=9223372036854775807 WHERE c1=104 OR c2=105; +--sorted_result +SELECT * FROM t1 WHERE c1=18446744073709551615 AND c2=9223372036854775807; +UPDATE t1 SET c2=0 WHERE c1 IN (1,2); +--sorted_result +SELECT * FROM t1 WHERE c2=0; + +# Update outside range, would be clipped to closest endpoint +INSERT INTO t1 VALUES(106,-106,9),(107,-107,10),(108,-108,11),(109,-109,12),(255,127,13); +UPDATE IGNORE t1 SET c1=18446744073709551616,c2=9223372036854775808 WHERE c2 BETWEEN -108 AND -106; +SELECT COUNT(*) FROM t1 WHERE c1=18446744073709551616 AND c2=9223372036854775808 /* no rows */; +--sorted_result +SELECT * FROM t1 WHERE c1=18446744073709551615 AND c2=9223372036854775807; +UPDATE IGNORE t1 SET c2=-9223372036854775809 WHERE c1=109 ORDER BY c1; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c1=109; + +# Update ignore on bad null error +INSERT INTO t1 VALUES(110,-110,14),(111,-111,15); +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t1 SET c1=NULL WHERE c2=-110; +UPDATE IGNORE t1 SET c1=NULL WHERE c2=-110 /* updates to default value 0 */; +--sorted_result +SELECT c1,c2 FROM t1 WHERE c2=-110; +SET SQL_MODE=DEFAULT; +UPDATE IGNORE t1 SET c1=NULL WHERE c2=-111 /* updates to default value 0 */; +--sorted_result +SELECT * FROM t1 WHERE c1=0; + +# Update with multi-range +SELECT * FROM t1 WHERE c2>=-101 AND c1<=101 ORDER BY c2; +UPDATE t1 SET c1=c1+1,c2=c2+1 WHERE c2>=-101 AND c1<=101 ORDER BY c2 LIMIT 2; +--sorted_result +SELECT * FROM t1; + +# Create table with AUTO_INCREMENT Primary Key +CREATE TABLE t2(c1 BIGINT SIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, c2 BIGINT UNSIGNED NULL, c3 INT); + +# Update ignore on duplicate key error +INSERT INTO t2(c1) VALUES(1),(2),(3),(4),(5); +--error ER_DUP_ENTRY +UPDATE t2 SET c1=1 WHERE c1=3; +UPDATE IGNORE t2 SET c1=1 WHERE c1>=3; +--sorted_result +SELECT c1 FROM t2; + +# Update the auto_incremented value with boundary values to unsigned/signed field +TRUNCATE TABLE t1; +ALTER TABLE t1 CHANGE c1 c1 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY(c1); +INSERT INTO t1 VALUES(1,2,3),(4,5,6),(7,8,9),(10,11,12); +TRUNCATE TABLE t2; +INSERT INTO t2 VALUES(1,2,3),(4,5,6),(7,8,9),(10,11,12); +INSERT INTO t1(c2,c3) VALUES(13,14); +SELECT c1 FROM t1 WHERE c2=13; +INSERT INTO t2(c2,c3) VALUES(13,14); +SELECT c1 FROM t2 WHERE c2=13; +# Update the unsigned auto_increment field +UPDATE t1 SET c1=18446744073709551615,c2=9223372036854775807 WHERE c2=13; +SELECT c1,c2 FROM t1 ORDER BY c1; +UPDATE IGNORE t2 SET c1=0,c2=-9223372036854775808 WHERE c2=2; +SELECT c1,c2 FROM t1 ORDER BY c1; +UPDATE t2 SET c2=0 WHERE c2=5; +SELECT c1,c2 FROM t1 ORDER BY c1; +# Update the signed auto_increment field +UPDATE t2 SET c1=9223372036854775807,c2=18446744073709551615 WHERE c2=13; +SELECT c1,c2 FROM t2 ORDER BY c1; +UPDATE t2 SET c1=-9223372036854775808,c2=0 WHERE c2=2; +SELECT c1,c2 FROM t2 ORDER BY c1; +UPDATE t2 SET c1=0,c2=0 WHERE c2=5; +SELECT c1,c2 FROM t2 ORDER BY c1; + +# Multi table update +CREATE TABLE mt1 (c1 BIGINT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +CREATE TABLE mt2 (c1 BIGINT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +CREATE TABLE mt3 (c1 BIGINT NOT NULL PRIMARY KEY, c2 INTEGER, KEY(c2)); +INSERT INTO mt1 VALUES(1,1),(2,2),(3,3),(4,4),(5,5); +INSERT INTO mt2 VALUES(11,1),(12,1),(13,1),(14,2),(15,6); +INSERT INTO mt3 VALUES(21,11),(22,11),(23,13),(24,14),(25,15); +UPDATE IGNORE mt1, mt2 ,mt3 SET mt1.c2 = 30, mt2.c2 = 40, mt3.c2=50 WHERE mt1.c1=mt2.c2 AND mt2.c1=mt3.c2; +--sorted_result +SELECT * FROM mt1; +--sorted_result +SELECT * FROM mt2; +--sorted_result +SELECT * FROM mt3; +DROP TABLE mt1,mt2,mt3; + +# Update,Select,Delete,Select using various access methods +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +ALTER TABLE t2 CHANGE c2 c2 BIGINT UNSIGNED NULL, ADD KEY(c2); +INSERT INTO t1 VALUES(1,-1,1),(2,-2,2),(3,-3,3),(4,-4,4),(5,-5,5),(6,-6,6),(7,-7,7),(8,-8,8),(9,-9,9),(10,-10,10),(11,NULL,11); +INSERT INTO t2 VALUES(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(-7,7,7),(-8,8,8),(-9,9,9),(10,10,10),(-11,NULL,11),(-12,12,12); + +# Update using various methods +# eq-ref join +UPDATE t1,t2 SET t1.c1=50,t1.c2=50,t2.c1=50,t2.c2=50 WHERE t2.c1=t1.c1; +--sorted_result +SELECT * FROM t1,t2 WHERE t1.c1=50 AND t1.c2=50 AND t2.c1=50 AND t2.c2=50; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c1; +ALTER TABLE t2 CHANGE c1 c1 BIGINT SIGNED NOT NULL, DROP PRIMARY KEY; +ALTER TABLE t2 CHANGE c1 c1 BIGINT SIGNED NOT NULL, ADD KEY(c1); +INSERT INTO t2 VALUES(-9223372036854775808,0,12),(0,255,13),(9223372036854775807,18446744073709551615,14); + +# range access +UPDATE t2 SET c2=18446744073709551615 WHERE c1 <> 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 <> 0 ORDER BY c1; +UPDATE t2 SET c2=18446744073709551615 WHERE c1 >= 0 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 >= 0 ORDER BY c1 DESC; +UPDATE t2 SET c2=18446744073709551615 WHERE c1 <= -9 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 <= -9 ORDER BY c1; +UPDATE t2 SET c2=18446744073709551615 WHERE c1 <=> -3 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <=> -3 ORDER BY c1; +UPDATE t2 SET c2=18446744073709551615 WHERE c1 BETWEEN -6 AND -4 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -6 AND -4 ORDER BY c1; +UPDATE t2 SET c2=18446744073709551615 WHERE c1 IN(-7,-8) ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 IN(-7,-8) ORDER BY c1 DESC; +UPDATE t2 SET c2=18446744073709551615 WHERE c2 IS NULL ORDER BY c2 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2; +UPDATE t2 SET c2=18446744073709551615 WHERE c1>= -9223372036854775808 AND c1 < -9 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1>= -9223372036854775808 AND c1 < -9 ORDER BY c1; + +# Using index-merge +UPDATE t2 SET c2=18446744073709551615 WHERE c1=-2 OR c2=1; +--sorted_result +SELECT * FROM t2 WHERE c2=18446744073709551615; + +# Select using various access methods +## Full table scan +--sorted_result +SELECT * FROM t2; +## Forward index scan, covering ## +--sorted_result +SELECT c2 FROM t2; +## Backward index scan, covering ## +SELECT c2 FROM t2 ORDER BY c2 DESC; +# ref access +--sorted_result +SELECT * FROM t2 WHERE c2=18446744073709551615; +## Range access ## +SELECT * FROM t2 WHERE c2 <> 18446744073709551615 ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 <> 18446744073709551615 ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 > 18446744073709551615 ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 >= 18446744073709551615 ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 < 18446744073709551615 ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 <= 18446744073709551615 ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 <=> 18446744073709551615 ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 <=> 18446744073709551615 ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 BETWEEN 0 AND 18446744073709551615 ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 BETWEEN 0 AND 18446744073709551615 ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IN(0,18446744073709551615) ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 IN(0,18446744073709551615) ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 >=0 AND c2 <= 18446744073709551615 ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 >=0 AND c2 <= 18446744073709551615 ORDER BY c2,c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c2,c1 DESC; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c2,c1 LIMIT 2; + +--sorted_result +SELECT * FROM t2 WHERE c2=18446744073709551615 OR c1=-4; + +# Test multi update with different join methods +CREATE TABLE mt1 (a bigint not null primary key, b bigint not null, key (b)); +CREATE TABLE mt2 (a bigint not null primary key, b bigint not null, key (b)); +INSERT INTO mt1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +INSERT INTO mt2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9); +# Full join, without key +update mt1,mt2 set mt1.a=mt1.a+100; +--sorted_result +select * from mt1; +# unique key +update mt1,mt2 set mt1.a=mt1.a+100 where mt1.a=101; +--sorted_result +select * from mt1; +# ref key +update mt1,mt2 set mt1.b=mt1.b+10 where mt1.b=2; +--sorted_result +select * from mt1; +# Range key (in mt1) +update mt1,mt2 set mt1.b=mt1.b+2,mt2.b=mt1.b+10 where mt1.b between 3 and 5 and mt2.a=mt1.a-100; +--sorted_result +select * from mt1; +--sorted_result +select * from mt2; +# test for non-updating table which is also used in sub-select +update mt1,mt2 set mt1.b=mt2.b, mt1.a=mt2.a where mt1.a=mt2.a and not exists (select * from mt2 where mt2.a > 10); +drop table mt1,mt2; + +# Testing delete using various access methods +TRUNCATE TABLE t2; +INSERT INTO t2 VALUES(-128,0,1),(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(0,0,7),(1,1,8),(127,255,9); + +# Using Index-merge +SELECT * FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1; +DELETE FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1=127 OR c2=3 ORDER BY c1; + +# Range access +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1; +DELETE FROM t2 WHERE c1 >= -128 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -128 ORDER BY c1; +SELECT * FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 <= 127 ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1; +DELETE FROM t2 WHERE c1 < 0 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 < 0 ORDER BY c1; +SELECT * FROM t2 WHERE c1 > -3 ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 > -3 ORDER BY c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c1 > -3 ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1=-3 OR c2=2; +DELETE FROM t2 WHERE c1=-3 OR c2=2; +SELECT * FROM t2 WHERE c1=-3 OR c2=2; +INSERT INTO t2 VALUES(-128,0,1),(-1,1,1),(-2,2,2),(-3,3,3),(-4,4,4),(-5,5,5),(-6,6,6),(0,0,7),(1,1,8),(2,NULL,9),(3,NULL,10),(127,255,11); +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1; +DELETE FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 BETWEEN -128 AND 127 ORDER BY c1; +SELECT * FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +DELETE FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 IN(-2,0) ORDER BY c1 DESC; +SELECT * FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1; +DELETE FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c1 >= -6 AND c2 < 3 ORDER BY c1; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1; +DELETE FROM t2 WHERE c2 IS NOT NULL ORDER BY c1 LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NOT NULL ORDER BY c1; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC; +DELETE FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC LIMIT 2; +SELECT * FROM t2 WHERE c2 IS NULL ORDER BY c2,c1 DESC; + +# Muti-table delete +# +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES(254,127,1),(0,-128,2),(1,127,3),(2,-128,4),(3,NULL,5); +INSERT INTO t2 VALUES(127,255,1),(127,1,2),(-128,0,3),(-128,2,4),(-1,NULL,5); + +# join(Range checked for each record) +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +DELETE t1,t2 FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2 OR t2.c2=t1.c1 OR t2.c2<=>t1.c2; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +INSERT INTO t1 VALUES(254,127,1),(0,-128,2),(1,127,3),(2,-128,4),(3,NULL,5); +INSERT INTO t2 VALUES(127,255,1),(127,1,2),(-128,0,3),(-128,2,4),(-1,NULL,5); +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +DELETE FROM a1, a2 USING t1 AS a1 INNER JOIN t2 AS a2 WHERE a2.c1=a1.c2; +--sorted_result +SELECT * FROM t1,t2 WHERE t2.c1=t1.c2; +--error ER_UPDATE_TABLE_USED +DELETE FROM t1,t2 using t1,t2 where t1.c1=(select c1 from t1); + +# eq-ref join +CREATE TABLE t3(c1 BIGINT UNSIGNED NOT NULL PRIMARY KEY, c2 BIGINT SIGNED NULL, c3 INT); +CREATE TABLE t4(c1 BIGINT UNSIGNED, c2 INT); +INSERT INTO t3 VALUES(200,126,1),(250,-127,2); +INSERT INTO t4 VALUES(200,1),(150,3); +--sorted_result +SELECT * FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +DELETE t3.*,t4.* FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +SELECT * FROM t3,t4 WHERE t3.c1=t4.c1 AND t3.c3=t4.c2; +DROP TABLE t1,t2,t3,t4; + diff --git a/mysql-test/suite/engines/iuds/t/update_time.test b/mysql-test/suite/engines/iuds/t/update_time.test new file mode 100644 index 00000000..bdfe81d3 --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/update_time.test @@ -0,0 +1,198 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3,t4; +--enable_warnings +# Create tables +CREATE TABLE t1(c1 TIME NOT NULL, c2 TIME NULL, PRIMARY KEY(c1)); +CREATE TABLE t2(c1 TIME NOT NULL, c2 TIME NULL, PRIMARY KEY(c1,c2)); +CREATE TABLE t3(c1 TIME NOT NULL, c2 TIME NULL, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t4(c1 TIME NOT NULL, c2 TIME NULL); + +# As a string in 'D HH:MM:SS.fraction' format + +INSERT INTO t1 VALUES ('00:00:00.00','00:00:00.00'),('01:01:01.01','01:01:01.00'),('838:59:59.00','838:59:59.00'),('00:00:01','00:00:01'),('02:02:02','02:02:02'),('838:59:58','838:59:58'),('-838:59:59','-838:59:59'),('00:03','00:03'),('03:03','03:03'),('838:58','838:58'),('00 00:00:04','00 00:00:04'),('04 04:04:04','04 04:04:04'),('34 22:59:57','34 22:59:57'),('00 00:04','00 00:04'),('05 05:05','05 05:05'),('34 22:56','34 22:56'),('05 05','05 05'),('06 06','06 06'),('34 22','34 22'),('07','07'),('59','59'); +INSERT INTO t2 VALUES ('00:00:00.00','00:00:00.00'),('01:01:01.01','01:01:01.00'),('838:59:59.00','838:59:59.00'),('00:00:01','00:00:01'),('02:02:02','02:02:02'),('838:59:58','838:59:58'),('-838:59:59','-838:59:59'),('00:03','00:03'),('03:03','03:03'),('838:58','838:58'),('00 00:00:04','00 00:00:04'),('04 04:04:04','04 04:04:04'),('34 22:59:57','34 22:59:57'),('00 00:04','00 00:04'),('05 05:05','05 05:05'),('34 22:56','34 22:56'),('05 05','05 05'),('06 06','06 06'),('34 22','34 22'),('07','07'),('59','59'); +INSERT INTO t3 VALUES ('00:00:00.00','00:00:00.00'),('01:01:01.01','01:01:01.00'),('838:59:59.00','838:59:59.00'),('00:00:01','00:00:01'),('02:02:02','02:02:02'),('838:59:58','838:59:58'),('-838:59:59','-838:59:59'),('00:03','00:03'),('03:03','03:03'),('838:58','838:58'),('00 00:00:04','00 00:00:04'),('04 04:04:04','04 04:04:04'),('34 22:59:57','34 22:59:57'),('00 00:04','00 00:04'),('05 05:05','05 05:05'),('34 22:56','34 22:56'),('05 05','05 05'),('06 06','06 06'),('34 22','34 22'),('07','07'),('59','59'); +INSERT INTO t4 VALUES ('00:00:00.00','00:00:00.00'),('01:01:01.01','01:01:01.00'),('838:59:59.00','838:59:59.00'),('00:00:01','00:00:01'),('02:02:02','02:02:02'),('838:59:58','838:59:58'),('-838:59:59','-838:59:59'),('00:03','00:03'),('03:03','03:03'),('838:58','838:58'),('00 00:00:04','00 00:00:04'),('04 04:04:04','04 04:04:04'),('34 22:59:57','34 22:59:57'),('00 00:04','00 00:04'),('05 05:05','05 05:05'),('34 22:56','34 22:56'),('05 05','05 05'),('06 06','06 06'),('34 22','34 22'),('07','07'),('59','59'); + +#As a string with no delimiters in 'HHMMSS' format + +INSERT INTO t1 VALUES('000008','000008'),('080808','080808'),('8385955','8385955'),('-8385955','-8385955'),('0009','0009'),('0909','0909'),('5454','5454'),('10','10'),('53','53'); +INSERT INTO t2 VALUES('000008','000008'),('080808','080808'),('8385955','8385955'),('-8385955','-8385955'),('0009','0009'),('0909','0909'),('5454','5454'),('10','10'),('53','53'); +INSERT INTO t3 VALUES('000008','000008'),('080808','080808'),('8385955','8385955'),('-8385955','-8385955'),('0009','0009'),('0909','0909'),('5454','5454'),('10','10'),('53','53'); +INSERT INTO t4 VALUES('000008','000008'),('080808','080808'),('8385955','8385955'),('-8385955','-8385955'),('0009','0009'),('0909','0909'),('5454','5454'),('10','10'),('53','53'); + +#As a number in HHMMSS format + +INSERT INTO t1 VALUES (000011.00,000011.00),(111111.11,111111.11),(8385952.00,8385952.00),(000012,000012),(121212,121212),(8385951,8385951),(1313,1313),(5151,5151),(14,14),(50,50); +INSERT INTO t2 VALUES (000011.00,000011.00),(111111.11,111111.11),(8385952.00,8385952.00),(000012,000012),(121212,121212),(8385951,8385951),(1313,1313),(5151,5151),(14,14),(50,50); +INSERT INTO t3 VALUES (000011.00,000011.00),(111111.11,111111.11),(8385952.00,8385952.00),(000012,000012),(121212,121212),(8385951,8385951),(1313,1313),(5151,5151),(14,14),(50,50); +INSERT INTO t4 VALUES (000011.00,000011.00),(111111.11,111111.11),(8385952.00,8385952.00),(000012,000012),(121212,121212),(8385951,8385951),(1313,1313),(5151,5151),(14,14),(50,50); + +#As the result of a function that returns a value that is acceptable in a TIME context +SET TIMESTAMP=1233216687; # 2009-01-29 13:41:27 +INSERT INTO t1 VALUES(CURRENT_TIME(),CURRENT_TIME()); +INSERT INTO t2 VALUES(CURRENT_TIME(),CURRENT_TIME()); +INSERT INTO t3 VALUES(CURRENT_TIME(),CURRENT_TIME()); +INSERT INTO t4 VALUES(CURRENT_TIME(),CURRENT_TIME()); +#Insert permissible NULLs +INSERT INTO t1 VALUES('123456',null); +#INSERT INTO t2 VALUES('123456',null); +INSERT INTO t3 VALUES('123456',null); +INSERT INTO t4 VALUES('123456',null); +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +#Updating the tables +--sorted_result +SELECT c1 FROM t1 WHERE c1='00:00:07'; +UPDATE t1 SET c1='22:22:22' WHERE c1='00:00:07'; +--sorted_result +SELECT c1 FROM t1; +--sorted_result +SELECT c1 FROM t2 WHERE c1='-838:59:59' AND c2='-838:59:59'; +UPDATE t2 SET c1='22:22:22' WHERE c1='-838:59:59' AND c2='-838:59:59'; +--sorted_result +SELECT c1 FROM t2; + +# Update with NULL ( NULL to number & number to NULL) +--sorted_result +SELECT c2 FROM t3 WHERE c2=null; +UPDATE t3 SET c2='34 22:59:59' WHERE c2=null; +--sorted_result +SELECT c2 FROM t3; +--sorted_result +SELECT c2 FROM t4 WHERE c1='00:00:00'; +UPDATE t4 SET c2=null WHERE c1='00:00:00'; +--sorted_result +SELECT c2 FROM t4; + +#Update order by limit +--sorted_result +SELECT c1 FROM t4 WHERE c1 < '000009'; +UPDATE t4 SET c1='0101' WHERE c1 < '000009' ORDER BY c1 LIMIT 3; +--sorted_result +SELECT c1 FROM t4; + +#Update negative value to unsigned column +--sorted_result +SELECT c1 FROM t1 WHERE c1='12:12:12'; +UPDATE t1 SET c1='-12:12:12' WHERE c1='12:12:12'; +--sorted_result +SELECT c1 FROM t1; + +#Update with Arithmetic operations +--sorted_result +SELECT c1 FROM t1 WHERE c1=111127; +UPDATE t1 SET c1=c1+c2 WHERE c1=111127; +--sorted_result +SELECT c1 FROM t1; +--sorted_result +SELECT c1 FROM t2 WHERE c2='100:04:04'; +UPDATE t2 SET c1=c1 - '010101' WHERE c2=1000404; +--sorted_result +SELECT c1 FROM t2; +--sorted_result +SELECT c2 FROM t3 WHERE c2=020202; +UPDATE t3 SET c2=c1 * 2 WHERE c2='020202'; +--sorted_result +SELECT c1 FROM t3; +--sorted_result +SELECT c1 FROM t4 WHERE c1=121212; +UPDATE t4 SET c1=c1 / 2 WHERE c1='12:12:12'; +--sorted_result +SELECT c1 FROM t4; + +#Update range values +UPDATE t1 SET c2=1250000 WHERE c1='00:00:09' AND c1='01:01:01'; +--sorted_result +SELECT c2 FROM t1; +UPDATE t2 SET c1=125959 WHERE c2=000400 OR c2= 000900; +--sorted_result +SELECT c1 FROM t2; +UPDATE t2 SET c2='1111' WHERE c1 IN ('100:04:04',005454,'2:2:2',111111); +--sorted_result +SELECT c2 FROM t2; + +#Update outside range would be clipped to closest endpoints +UPDATE IGNORE t4 SET c2='-838:59:60' WHERE c1='100:04:04'; +--sorted_result +SELECT c2 FROM t4; +UPDATE IGNORE t4 SET c2='838:59:60' WHERE c1='100:04:04'; +--sorted_result +SELECT c2 FROM t4; +UPDATE t4 SET c2='00:00:00' WHERE c1='100:04:04'; +--sorted_result +SELECT c2 FROM t4; +UPDATE IGNORE t4 SET c2='11:11:60' WHERE c1='100:04:04'; +--sorted_result +SELECT c2 FROM t4; +UPDATE IGNORE t4 SET c2='11:60:11' WHERE c1='100:04:04'; +--sorted_result +SELECT c2 FROM t4; + +# Update ignore on bad null error +--sorted_result +SELECT c1 FROM t3 WHERE c2 < '000007'; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t3 SET c1=NULL WHERE c2 < '000007'; +UPDATE IGNORE t3 SET c1=NULL WHERE c2 < '000007'; +--sorted_result +SELECT c1 from t3 WHERE c2 < '000007'; +SET SQL_MODE=DEFAULT; + +#Duplicate keys +--error ER_DUP_ENTRY +UPDATE t1 SET c1=8385958 WHERE c2='34 22:59:59'; + +#Update with invalid values +UPDATE IGNORE t1 SET c2='def' WHERE c1=59; +--sorted_result +SELECT c2 FROM t1; +--error ER_PARSE_ERROR +UPDATE t4 SET c1=11:11:11 WHERE c2=NULL; +--sorted_result +SELECT c1 FROM t4; + +#Multi table update +UPDATE t1,t2,t3,t4 SET t1.c2=t2.c1+t2.c2,t3.c2=t4.c1*2 WHERE t1.c1='00:13:13' AND t2.c1=080808 AND t4.c1='00:04:00' AND t3.c2=020202; + +# Update using various access methods + +# Update using Const +# EXPLAIN SELECT * FROM t1 WHERE c1='00:09:09' AND c2='00:09:09'; +UPDATE t1 SET t1.c1='00:12:12' WHERE c1='00:09:09' AND c2='00:09:09'; +--sorted_result +SELECT * FROM t1; + +# Update using range +# EXPLAIN SELECT * FROM t1 WHERE c1 BETWEEN 080000 AND 100000; +--replace_regex /(Data truncated for column 'c2' at row) [1-9][0-9]*/\1 N/ +UPDATE IGNORE t1 SET t1.c2='99999.99999' WHERE c1 BETWEEN 080000 AND 100000; +--sorted_result +SELECT * FROM t1; +# EXPLAIN SELECT * FROM t1 WHERE c1 IN (222222,8385955,1500000); +UPDATE IGNORE t1 SET c1=c1+1,c2=c2-1 WHERE c1 IN (222222,8385955,1500000) ORDER BY c1; +--sorted_result +SELECT * FROM t1; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3; +UPDATE t1,t2 SET t1.c2='22222.22222' WHERE t1.c1=t2.c1 AND t1.c2=t2.c2; + +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +#Drop tables; +DROP TABLE IF EXISTS t1,t2,t3,t4; + diff --git a/mysql-test/suite/engines/iuds/t/update_year.test b/mysql-test/suite/engines/iuds/t/update_year.test new file mode 100644 index 00000000..599c637e --- /dev/null +++ b/mysql-test/suite/engines/iuds/t/update_year.test @@ -0,0 +1,212 @@ +--disable_warnings +DROP TABLE IF EXISTS t1,t2,t3,t4; +--enable_warnings +# Create tables +CREATE TABLE t1(c1 YEAR NOT NULL,c2 YEAR, PRIMARY KEY(c1)); +CREATE TABLE t2(c1 YEAR NOT NULL, c2 YEAR, UNIQUE INDEX idx(c1,c2)); +CREATE TABLE t3(c1 YEAR(2) NOT NULL,c2 YEAR(2), PRIMARY KEY(c1)); +CREATE TABLE t4(c1 YEAR(2), c2 YEAR(2), UNIQUE INDEX idx(c1,c2)); +#Insert as 4-digit number format in the range '1901' to '2155' +INSERT INTO t1 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); +INSERT INTO t2 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); +INSERT INTO t3 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); +INSERT INTO t4 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); +#Insert as 4-digit string format in the range '1901' to '2155' +INSERT INTO t1 VALUES ('1902','1902'),('1971','1971'),('1998','1998'),('2001','2001'),('2154','2154'); +INSERT INTO t2 VALUES ('1902','1902'),('1971','1971'),('1998','1998'),('2001','2001'),('2154','2154'); +INSERT INTO t3 VALUES ('1902','1902'),('1971','1971'),('1998','1998'),('2001','2001'),('2154','2154'); +INSERT INTO t4 VALUES ('1902','1902'),('1971','1971'),('1998','1998'),('2001','2001'),('2154','2154'); +#Insert as 2-digit number format +INSERT INTO t1 VALUES (04,04),(64,64),(69,69),(97,97); +INSERT INTO t2 VALUES (04,04),(64,64),(69,69),(97,97); +INSERT INTO t3 VALUES (04,04),(64,64),(69,69),(97,97); +INSERT INTO t4 VALUES (04,04),(64,64),(69,69),(97,97); +#Insert as 2-digit string format +INSERT INTO t1 VALUES ('05','05'),('65','65'),('75','75'),('95','95'); +INSERT INTO t2 VALUES ('05','05'),('65','65'),('75','75'),('95','95'); +INSERT INTO t3 VALUES ('05','05'),('65','65'),('75','75'),('95','95'); +INSERT INTO t4 VALUES ('05','05'),('65','65'),('75','75'),('95','95'); +#Insert permissible NULLs +INSERT INTO t1 VALUES ('09',null),('61',null),('79',null),('96',null); +INSERT INTO t2 VALUES ('09',null),('61',null),('79',null),('96',null); +INSERT INTO t3 VALUES ('09',null),('61',null),('79',null),('96',null); +INSERT INTO t4 VALUES ('09',null),('61',null),('79',null),('96',null); +--sorted_result +SELECT * FROM t1; +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; +#Updating the tables +--sorted_result +SELECT c1 FROM t1 WHERE c1='2005'; +UPDATE t1 SET c1='2003' WHERE c1='2005'; +--sorted_result +SELECT c1 FROM t1; + +# Update with NULL ( NULL to number & number to NULL) +--sorted_result +SELECT c2 FROM t2 WHERE c2=null; +UPDATE t2 SET c2='2070' WHERE c2=null AND c1='1996'; +--sorted_result +SELECT c2 FROM t2; +--sorted_result +SELECT c2 FROM t3 WHERE c2 < '64'; +UPDATE t3 SET c2=null WHERE c2 < '64' ORDER BY c2 LIMIT 3; +--sorted_result +SELECT c2 FROM t3; + +#Update order by limit +--sorted_result +SELECT c1 FROM t4 WHERE c1 < '55'; +UPDATE t4 SET c1='00' WHERE c1 < '65' ORDER BY c1 LIMIT 5; +--sorted_result +SELECT c1 FROM t4; + +#Update with Arithmetic operations +# +#Updating 'YY' values +--sorted_result +SELECT c1 FROM t3 WHERE c1='05'; +UPDATE t3 SET c1=c1+c2 WHERE c1='05'; +--sorted_result +SELECT c1 FROM t3; +--sorted_result +SELECT c1 FROM t4 WHERE c2=4; +UPDATE t4 SET c1=c1 + 04 WHERE c2=04; +--sorted_result +SELECT c1 FROM t4; +--sorted_result +SELECT c2 FROM t3 WHERE c2=75; +UPDATE t3 SET c2=c2 + 1902 WHERE c2='75'; +--sorted_result +SELECT c2 FROM t3; +--sorted_result +SELECT c1 FROM t4 WHERE c1=09; +UPDATE t4 SET c1=c1 - c2 WHERE c1='09'; +--sorted_result +SELECT c1 FROM t4; +--sorted_result +SELECT c1 FROM t3 WHERE c1=75; +UPDATE t3 SET c1=c1 - 01 WHERE c1='75'; +--sorted_result +SELECT c1 FROM t3; +--sorted_result +SELECT c1 FROM t4 WHERE c1=98; +UPDATE t4 SET c1=c1 / 2 WHERE c1='98'; +--sorted_result +SELECT c1 FROM t4; +--sorted_result +SELECT c2 FROM t3 WHERE c2=03; +UPDATE t3 SET c2=c2 * 03 WHERE c2='03'; +--sorted_result +SELECT c2 FROM t3; +# +#Updating 'YYYY' values +--sorted_result +SELECT c1 FROM t1 WHERE c1 > 2060 AND c1 < 2070; +UPDATE t1 SET c1=c1 + 10 WHERE c1 > 2060 AND c1 < 2070; +--sorted_result +SELECT c1 FROM t1; +--sorted_result +SELECT c1 FROM t2 WHERE c1 > 1969 AND c1 < 1980; +UPDATE t2 SET c1=c1 - 10 WHERE c1 > 1969 AND c1 < 1980 ORDER BY c1 LIMIT 2; +--sorted_result +SELECT c1 FROM t2; + +#Update range values +UPDATE t2 SET c2=2009 WHERE c1=2009 AND c2=null; +--sorted_result +SELECT c2 FROM t2; +UPDATE t1 SET c2=2155 WHERE c1=1979 OR c1=2154; +--sorted_result +SELECT c2 FROM t1; +UPDATE t4 SET c1=99 WHERE c2 IN (01,54,65,69,null); +--sorted_result +SELECT c1 FROM t4; + +# Update outside range would be clipped to closest endpoints +UPDATE IGNORE t1 SET c2=-1 WHERE c1=2071; +--sorted_result +SELECT c2 FROM t1; +UPDATE t1 SET c2=0 WHERE c1=2003; +--sorted_result +SELECT c2 FROM t1; +UPDATE IGNORE t1 SET c2=2156 WHERE c1=2001; +--sorted_result +SELECT c2 FROM t1; +UPDATE IGNORE t4 SET c2=-1 WHERE c1=71; +--sorted_result +SELECT c2 FROM t4; +UPDATE t4 SET c2=0 WHERE c1=70; +--sorted_result +SELECT c2 FROM t4; +UPDATE IGNORE t4 SET c2=100 WHERE c1=79; +--sorted_result +SELECT c2 FROM t4; + +# Update ignore on bad null error +--sorted_result +SELECT c1 FROM t1 WHERE c2 < 1975; +SET SQL_MODE=STRICT_ALL_TABLES; +--error ER_BAD_NULL_ERROR +UPDATE t1 SET c1=NULL WHERE c2 < 1975; +UPDATE IGNORE t1 SET c1=NULL WHERE c2 < 1975; +--sorted_result +SELECT c1 from t1 WHERE c2 < 1975; +SET SQL_MODE=DEFAULT + +#Update with invalid values +#UPDATE t2 SET c1='def' WHERE c2=2064; +#--sorted_result +#SELECT c1 FROM t2; +UPDATE IGNORE t4 SET c1=-70 WHERE c2=75; +--sorted_result +SELECT c1 FROM t4; + +#Update duplicate key +--error ER_DUP_ENTRY +UPDATE t1 SET c1=1971 WHERE c2=1995; + +#Multi table update +UPDATE t1,t2,t3,t4 SET t3.c1=t4.c1+t4.c2 WHERE t3.c1=61 AND t4.c2=4; + +# Update using various access methods + +# Update using Const +# EXPLAIN SELECT * FROM t1 WHERE c1=2074 AND c2=2064; +UPDATE t1 SET t1.c1=2073 WHERE c1=2074 AND c2=2064; +--sorted_result +SELECT * FROM t1; + +# Update using range +# EXPLAIN SELECT * FROM t1 WHERE c1 BETWEEN 2000 AND 2010; +UPDATE t1 SET t1.c2=0000 WHERE c1 BETWEEN 2000 AND 2010; +--sorted_result +SELECT * FROM t1; +# EXPLAIN SELECT * FROM t1 WHERE c1 IN (2154,2009,1979); +UPDATE IGNORE t1 SET c1=c1-1,c2=c2+1 WHERE c1 IN (2154,2009,1979); +--sorted_result +SELECT * FROM t1; + +# Update using eq_ref +# EXPLAIN SELECT * FROM t1,t2 WHERE t1.c1=t2.c1 AND t1.c2=t2.c2; +UPDATE t1,t2 SET t1.c2='2155' WHERE t1.c1=t2.c1 AND t1.c2=t2.c2; + +#BUG49910 +--disable_result_log +--sorted_result +SELECT * FROM t1; +--enable_result_log +--sorted_result +SELECT * FROM t2; +--sorted_result +SELECT * FROM t3; +--sorted_result +SELECT * FROM t4; + +#Drop tables +DROP TABLE IF EXISTS t1,t2,t3,t4; + |