Skip to content

Commit

Permalink
test(mtr):add alter_column.test/having.test/update_join.test/where_co…
Browse files Browse the repository at this point in the history
…nditions.test(#497)
  • Loading branch information
shangyanwen authored and mergify[bot] committed Oct 27, 2022
1 parent 8705db6 commit 87c8638
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 0 deletions.
42 changes: 42 additions & 0 deletions mysql-test/suite/tianmu/r/alter_column.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# Test add, modify, rename, drop column
# Author: syw
#
DROP DATABASE IF EXISTS alter_colunm;
CREATE DATABASE alter_colunm;
USE alter_colunm;
CREATE TABLE t1 (c1 INT, c2 CHAR(1)) ENGINE=tianmu;
INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e');
ALTER TABLE t1 ADD COLUMN c11 INT NOT NULL;
ALTER TABLE t1 ADD COLUMN c11 INT(1);
ERROR 42S21: Duplicate column name 'c11'
ALTER TABLE t1 ADD COLUMN c21 CHAR(2);
ALTER TABLE t1 ADD COLUMN c11 INT(2);
ERROR 42S21: Duplicate column name 'c11'
ALTER TABLE t1 ADD COLUMN c12 CHAR(1) AFTER c11;
ALTER TABLE t1 ADD COLUMN c0 INT FIRST;
ALTER TABLE t1 MODIFY COLUMN c11 TINYINT;
ALTER TABLE t1 CHANGE COLUMN c2 c2new CHAR(2);
ALTER TABLE t1 CHANGE COLUMN c2 c2new CHAR(1);
ERROR 42S22: Unknown column 'c2' in 't1'
ALTER TABLE t1 CHANGE COLUMN c2new c2 CHAR(1);
ALTER TABLE t1 DROP COLUMN IF EXISTS c11;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS c11' at line 1
ALTER TABLE t1 DROP COLUMN c11;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c0` int(11) DEFAULT NULL,
`c1` int(11) DEFAULT NULL,
`c2` char(1) DEFAULT NULL,
`c12` char(1) DEFAULT NULL,
`c21` char(2) DEFAULT NULL
) ENGINE=TIANMU DEFAULT CHARSET=latin1
SELECT * FROM t1 ORDER BY c1;
c0 c1 c2 c12 c21
NULL 1 a NULL NULL
NULL 2 b NULL NULL
NULL 3 c NULL NULL
NULL 4 d NULL NULL
NULL 5 e NULL NULL
DROP DATABASE alter_colunm;
43 changes: 43 additions & 0 deletions mysql-test/suite/tianmu/r/having.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Test HAVING clause
# Author: syw
#
DROP DATABASE IF EXISTS having_test;
CREATE DATABASE having_test;
USE having_test;
CREATE TABLE t1(col1 INT, col2 TEXT)ENGINE=tianmu;
INSERT INTO t1 VALUES(1, repeat('s',20)),(2, repeat('o',20)),(3, 'sss'),(4, 'ooo');
INSERT INTO t1 SELECT * FROM t1;
SELECT col2 FROM t1 GROUP BY col2 HAVING col2 LIKE '%o%' ORDER BY col2;
col2
ooo
oooooooooooooooooooo
SELECT col1 FROM t1 GROUP BY col1 HAVING col1 > 1 ORDER BY col1;
col1
2
3
4
SELECT col1, col2 FROM t1 GROUP BY col1, col2 HAVING col1 > 1 AND col2 LIKE '%o%' ORDER BY col1;
col1 col2
2 oooooooooooooooooooo
4 ooo
SELECT col1, col2 FROM t1 GROUP BY col1, col2 HAVING col1 > 1 OR col2 LIKE '%o%' ORDER BY col1;
col1 col2
2 oooooooooooooooooooo
3 sss
4 ooo
CREATE TABLE t2(col1 INT, col2 DATETIME)ENGINE=tianmu;
INSERT INTO t2 VALUES(1, '2020-2-2'),(2, '2020-3-3'),(5,'2020-6-6'),(6, '2020-7-7');
SELECT t1.col1, SUM(t1.col1*t2.col1) AS a FROM t1 JOIN t2 ON t1.col1 = t2.col1 GROUP BY t1.col1 HAVING a>1 ORDER BY t1.col1;
col1 a
1 2
2 8
SELECT t1.col1, SUM(t1.col1*t2.col1) AS a FROM t1 LEFT JOIN t2 ON t1.col1 = t2.col1 GROUP BY t1.col1 HAVING a>1 ORDER BY t1.col1;
col1 a
1 2
2 8
SELECT t1.col1, SUM(t1.col1*t2.col1) AS a FROM t1 RIGHT JOIN t2 ON t1.col1 = t2.col1 GROUP BY t1.col1 HAVING a>1 ORDER BY t1.col1;
col1 a
1 2
2 8
DROP DATABASE having_test;
55 changes: 55 additions & 0 deletions mysql-test/suite/tianmu/r/update_join.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Test Update JOIN
# Author: syw
#
DROP DATABASE IF EXISTS mcs82_db;
CREATE DATABASE mcs82_db;
USE mcs82_db;
CREATE TABLE t1 (t1_int INT, t1_char CHAR(5))ENGINE=tianmu;
CREATE TABLE t2 (t2_int INT, t2_char CHAR(5))ENGINE=tianmu;
INSERT INTO t1 VALUES (NULL, ''),(1, 'aaa'),(2, 'bbb'),(3, 'ccc'),(4, 'ddd'),(5, 'aa'),(6, ''),(7, 'aaaaa');
INSERT INTO t2 VALUES (NULL, ''),(1, 'hhhh'),(3, 'iii'),(5, 'jjj'),(6, ''),(7, 'lll'),(9, 'm'),(11, 'nnn');
SELECT * FROM t1 ORDER BY t1_int;
t1_int t1_char
NULL
1 aaa
2 bbb
3 ccc
4 ddd
5 aa
6
7 aaaaa
UPDATE t1 JOIN t2 on t1.t1_int=t2.t2_int SET t1.t1_char='sssss';
SELECT * FROM t1 ORDER BY t1_int;
t1_int t1_char
NULL
1 sssss
2 bbb
3 sssss
4 ddd
5 sssss
6 sssss
7 sssss
UPDATE t1 INNER JOIN t2 on t1.t1_int=t2.t2_int SET t1.t1_char='pqrs' WHERE t1_char LIKE '%a%';
SELECT * FROM t1 ORDER BY t1_int;
t1_int t1_char
NULL
1 sssss
2 bbb
3 sssss
4 ddd
5 sssss
6 sssss
7 sssss
UPDATE t2 LEFT JOIN t1 on t1.t1_int=t2.t2_int SET t1.t1_char='xyz' WHERE t1_char is NULL;
SELECT * FROM t2 ORDER BY t2_int;
t2_int t2_char
NULL
1 hhhh
3 iii
5 jjj
6
7 lll
9 m
11 nnn
DROP DATABASE mcs82_db;
79 changes: 79 additions & 0 deletions mysql-test/suite/tianmu/r/where_conditions.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#
# Test WHERE conditions
# Author: syw
#
DROP DATABASE IF EXISTS where_conditions_test;
CREATE DATABASE where_conditions_test;
USE where_conditions_test;
CREATE TABLE t1
(
t1_tinyint TINYINT DEFAULT 0,
t1_int INT DEFAULT NULL,
t1_bigint BIGINT,
t1_decimal DECIMAL(5,2),
t1_text TEXT,
t1_char CHAR(5),
t1_varchar VARCHAR(255) DEFAULT 'hello world!',
t1_datetime DATETIME
)ENGINE=tianmu;
INSERT INTO t1 VALUES();
INSERT INTO t1 VALUES(NULL, NULL, NULL, NULL, '', '', '', NULL);
INSERT INTO t1 VALUES(1, 123456, 987654321, 122.32, repeat('z', 20), 'aaa', repeat('a', 20), '1111-11-11 11:11:11');
INSERT INTO t1 VALUES(0, 1023456, 887654321, 222.32, repeat('y', 20), 'aaa', repeat('b', 20), '1111-11-11 11:11:11');
INSERT INTO t1 VALUES(1, -123456, -987654321, -122.32, repeat('z', 20), 'bbb', repeat('a', 20), '1111-11-11 11:11:11');
INSERT INTO t1 VALUES(0, -1023456, -887654321, -222.32, repeat('x', 20), 'bbb', repeat('b', 20), '1111-11-11 11:11:11');
SELECT * FROM t1;
t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime
0 NULL NULL NULL NULL NULL hello world! NULL
NULL NULL NULL NULL NULL
1 123456 987654321 122.32 zzzzzzzzzzzzzzzzzzzz aaa aaaaaaaaaaaaaaaaaaaa 1111-11-11 11:11:11
0 1023456 887654321 222.32 yyyyyyyyyyyyyyyyyyyy aaa bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
1 -123456 -987654321 -122.32 zzzzzzzzzzzzzzzzzzzz bbb aaaaaaaaaaaaaaaaaaaa 1111-11-11 11:11:11
0 -1023456 -887654321 -222.32 xxxxxxxxxxxxxxxxxxxx bbb bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
SELECT * FROM t1 WHERE t1_int IS NULL;
t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime
0 NULL NULL NULL NULL NULL hello world! NULL
NULL NULL NULL NULL NULL
SELECT * FROM t1 WHERE t1_tinyint = 0;
t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime
0 NULL NULL NULL NULL NULL hello world! NULL
0 1023456 887654321 222.32 yyyyyyyyyyyyyyyyyyyy aaa bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
0 -1023456 -887654321 -222.32 xxxxxxxxxxxxxxxxxxxx bbb bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
SELECT * FROM t1 WHERE t1_tinyint != 0;
t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime
1 123456 987654321 122.32 zzzzzzzzzzzzzzzzzzzz aaa aaaaaaaaaaaaaaaaaaaa 1111-11-11 11:11:11
1 -123456 -987654321 -122.32 zzzzzzzzzzzzzzzzzzzz bbb aaaaaaaaaaaaaaaaaaaa 1111-11-11 11:11:11
SELECT * FROM t1 WHERE t1_bigint > 0;
t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime
1 123456 987654321 122.32 zzzzzzzzzzzzzzzzzzzz aaa aaaaaaaaaaaaaaaaaaaa 1111-11-11 11:11:11
0 1023456 887654321 222.32 yyyyyyyyyyyyyyyyyyyy aaa bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
SELECT * FROM t1 WHERE t1_bigint < 0;
t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime
1 -123456 -987654321 -122.32 zzzzzzzzzzzzzzzzzzzz bbb aaaaaaaaaaaaaaaaaaaa 1111-11-11 11:11:11
0 -1023456 -887654321 -222.32 xxxxxxxxxxxxxxxxxxxx bbb bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
SELECT * FROM t1 WHERE t1_decimal >= -122.22;
t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime
1 123456 987654321 122.32 zzzzzzzzzzzzzzzzzzzz aaa aaaaaaaaaaaaaaaaaaaa 1111-11-11 11:11:11
0 1023456 887654321 222.32 yyyyyyyyyyyyyyyyyyyy aaa bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
SELECT * FROM t1 WHERE t1_decimal <= -122.22;
t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime
1 -123456 -987654321 -122.32 zzzzzzzzzzzzzzzzzzzz bbb aaaaaaaaaaaaaaaaaaaa 1111-11-11 11:11:11
0 -1023456 -887654321 -222.32 xxxxxxxxxxxxxxxxxxxx bbb bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
SELECT * FROM t1 WHERE t1_text LIKE '%x%';
t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime
0 -1023456 -887654321 -222.32 xxxxxxxxxxxxxxxxxxxx bbb bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
SELECT * FROM t1 WHERE t1_datetime BETWEEN '111-11-10' AND '1111-11-12';
t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime
1 123456 987654321 122.32 zzzzzzzzzzzzzzzzzzzz aaa aaaaaaaaaaaaaaaaaaaa 1111-11-11 11:11:11
0 1023456 887654321 222.32 yyyyyyyyyyyyyyyyyyyy aaa bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
1 -123456 -987654321 -122.32 zzzzzzzzzzzzzzzzzzzz bbb aaaaaaaaaaaaaaaaaaaa 1111-11-11 11:11:11
0 -1023456 -887654321 -222.32 xxxxxxxxxxxxxxxxxxxx bbb bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
SELECT * FROM t1 WHERE t1_text LIKE '%x%' OR t1_varchar LIKE '%a%';
t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime
1 123456 987654321 122.32 zzzzzzzzzzzzzzzzzzzz aaa aaaaaaaaaaaaaaaaaaaa 1111-11-11 11:11:11
1 -123456 -987654321 -122.32 zzzzzzzzzzzzzzzzzzzz bbb aaaaaaaaaaaaaaaaaaaa 1111-11-11 11:11:11
0 -1023456 -887654321 -222.32 xxxxxxxxxxxxxxxxxxxx bbb bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
SELECT * FROM t1 WHERE t1_text LIKE '%x%' AND t1_varchar LIKE '%b%';
t1_tinyint t1_int t1_bigint t1_decimal t1_text t1_char t1_varchar t1_datetime
0 -1023456 -887654321 -222.32 xxxxxxxxxxxxxxxxxxxx bbb bbbbbbbbbbbbbbbbbbbb 1111-11-11 11:11:11
DROP DATABASE where_conditions_test;
60 changes: 60 additions & 0 deletions mysql-test/suite/tianmu/t/alter_column.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
--echo #
--echo # Test add, modify, rename, drop column
--echo # Author: syw
--echo #

--source include/have_tianmu.inc

--disable_warnings
DROP DATABASE IF EXISTS alter_colunm;
--enable_warnings

CREATE DATABASE alter_colunm;
USE alter_colunm;

CREATE TABLE t1 (c1 INT, c2 CHAR(1)) ENGINE=tianmu;
INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e');

#################
# Add New Column
#################

ALTER TABLE t1 ADD COLUMN c11 INT NOT NULL;
--error 1060
ALTER TABLE t1 ADD COLUMN c11 INT(1);
ALTER TABLE t1 ADD COLUMN c21 CHAR(2);

#Duplicate column name
--error 1060
ALTER TABLE t1 ADD COLUMN c11 INT(2);
ALTER TABLE t1 ADD COLUMN c12 CHAR(1) AFTER c11;
ALTER TABLE t1 ADD COLUMN c0 INT FIRST;

#################
# Modify Column
#################

ALTER TABLE t1 MODIFY COLUMN c11 TINYINT;

#################
# Rename Column
#################

ALTER TABLE t1 CHANGE COLUMN c2 c2new CHAR(2);
--error 1054
ALTER TABLE t1 CHANGE COLUMN c2 c2new CHAR(1);
ALTER TABLE t1 CHANGE COLUMN c2new c2 CHAR(1);

#################
# DROP Column
#################

--error 1064
ALTER TABLE t1 DROP COLUMN IF EXISTS c11;
ALTER TABLE t1 DROP COLUMN c11;

SHOW CREATE TABLE t1;
SELECT * FROM t1 ORDER BY c1;

# Clean UP
DROP DATABASE alter_colunm;
32 changes: 32 additions & 0 deletions mysql-test/suite/tianmu/t/having.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--echo #
--echo # Test HAVING clause
--echo # Author: syw
--echo #

--source include/have_tianmu.inc

--disable_warnings
DROP DATABASE IF EXISTS having_test;
--enable_warnings

CREATE DATABASE having_test;
USE having_test;

CREATE TABLE t1(col1 INT, col2 TEXT)ENGINE=tianmu;
INSERT INTO t1 VALUES(1, repeat('s',20)),(2, repeat('o',20)),(3, 'sss'),(4, 'ooo');
INSERT INTO t1 SELECT * FROM t1;
SELECT col2 FROM t1 GROUP BY col2 HAVING col2 LIKE '%o%' ORDER BY col2;
SELECT col1 FROM t1 GROUP BY col1 HAVING col1 > 1 ORDER BY col1;
SELECT col1, col2 FROM t1 GROUP BY col1, col2 HAVING col1 > 1 AND col2 LIKE '%o%' ORDER BY col1;
SELECT col1, col2 FROM t1 GROUP BY col1, col2 HAVING col1 > 1 OR col2 LIKE '%o%' ORDER BY col1;
#--error ER_INTERNAL_ERROR
#SELECT col1, col2, SUM(LENGTH(col2)) FROM t1 GROUP BY col1 HAVING col1 > 1 AND col2 LIKE '%o%' ORDER BY col1;

CREATE TABLE t2(col1 INT, col2 DATETIME)ENGINE=tianmu;
INSERT INTO t2 VALUES(1, '2020-2-2'),(2, '2020-3-3'),(5,'2020-6-6'),(6, '2020-7-7');
SELECT t1.col1, SUM(t1.col1*t2.col1) AS a FROM t1 JOIN t2 ON t1.col1 = t2.col1 GROUP BY t1.col1 HAVING a>1 ORDER BY t1.col1;
SELECT t1.col1, SUM(t1.col1*t2.col1) AS a FROM t1 LEFT JOIN t2 ON t1.col1 = t2.col1 GROUP BY t1.col1 HAVING a>1 ORDER BY t1.col1;
SELECT t1.col1, SUM(t1.col1*t2.col1) AS a FROM t1 RIGHT JOIN t2 ON t1.col1 = t2.col1 GROUP BY t1.col1 HAVING a>1 ORDER BY t1.col1;

# Clean UP
DROP DATABASE having_test;
33 changes: 33 additions & 0 deletions mysql-test/suite/tianmu/t/update_join.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--echo #
--echo # Test Update JOIN
--echo # Author: syw
--echo #

--source include/have_tianmu.inc

--disable_warnings
DROP DATABASE IF EXISTS mcs82_db;
--enable_warnings

CREATE DATABASE mcs82_db;
USE mcs82_db;

CREATE TABLE t1 (t1_int INT, t1_char CHAR(5))ENGINE=tianmu;
CREATE TABLE t2 (t2_int INT, t2_char CHAR(5))ENGINE=tianmu;

INSERT INTO t1 VALUES (NULL, ''),(1, 'aaa'),(2, 'bbb'),(3, 'ccc'),(4, 'ddd'),(5, 'aa'),(6, ''),(7, 'aaaaa');
INSERT INTO t2 VALUES (NULL, ''),(1, 'hhhh'),(3, 'iii'),(5, 'jjj'),(6, ''),(7, 'lll'),(9, 'm'),(11, 'nnn');

SELECT * FROM t1 ORDER BY t1_int;
UPDATE t1 JOIN t2 on t1.t1_int=t2.t2_int SET t1.t1_char='sssss';

SELECT * FROM t1 ORDER BY t1_int;
UPDATE t1 INNER JOIN t2 on t1.t1_int=t2.t2_int SET t1.t1_char='pqrs' WHERE t1_char LIKE '%a%';

SELECT * FROM t1 ORDER BY t1_int;
UPDATE t2 LEFT JOIN t1 on t1.t1_int=t2.t2_int SET t1.t1_char='xyz' WHERE t1_char is NULL;

SELECT * FROM t2 ORDER BY t2_int;

# Clean UP
DROP DATABASE mcs82_db;
Loading

0 comments on commit 87c8638

Please sign in to comment.