-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
f534557
commit 7f96549
Showing
6 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
USE test; | ||
set global tianmu_index_search=on; | ||
DROP TABLE IF EXISTS tt1,tt2; | ||
CREATE TABLE tt1(id INT PRIMARY KEY,name VARCHAR(5),copy_id INT) ENGINE=TIANMU; | ||
CREATE TABLE tt2(id INT PRIMARY KEY,name VARCHAR(5),copy_id INT) ENGINE=TIANMU; | ||
INSERT INTO tt1 VALUES(1,'AAA',1),(2,'AAA',2),(3,'BBB',3),(4,'BBB',4),(5,'CCC',5); | ||
INSERT INTO tt2 VALUES(1,'BBB',1),(2,'BBB',2),(3,'CCC',3),(4,'CCC',4),(5,'DDD',5); | ||
SELECT * FROM tt1 WHERE EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND name = 'BBB'); | ||
id name copy_id | ||
1 AAA 1 | ||
2 AAA 2 | ||
SELECT * FROM tt1 WHERE EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND tt2.id = 2); | ||
id name copy_id | ||
2 AAA 2 | ||
SELECT * FROM tt1 WHERE EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND tt2.id > 2); | ||
id name copy_id | ||
3 BBB 3 | ||
4 BBB 4 | ||
5 CCC 5 | ||
SELECT * FROM tt1 WHERE EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND tt2.id < 2); | ||
id name copy_id | ||
1 AAA 1 | ||
SELECT * FROM tt1 WHERE NOT EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND name = 'BBB'); | ||
id name copy_id | ||
3 BBB 3 | ||
4 BBB 4 | ||
5 CCC 5 | ||
SELECT * FROM tt1 WHERE NOT EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND tt2.id = 2); | ||
id name copy_id | ||
1 AAA 1 | ||
3 BBB 3 | ||
4 BBB 4 | ||
5 CCC 5 | ||
SELECT * FROM tt1 WHERE NOT EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND tt2.id > 2); | ||
id name copy_id | ||
1 AAA 1 | ||
2 AAA 2 | ||
SELECT * FROM tt1 WHERE NOT EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND tt2.id < 2); | ||
id name copy_id | ||
2 AAA 2 | ||
3 BBB 3 | ||
4 BBB 4 | ||
5 CCC 5 | ||
set global tianmu_index_search=off; | ||
DROP TABLE tt1,tt2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--source include/have_tianmu.inc | ||
|
||
USE test; | ||
|
||
--disable_warnings | ||
|
||
## enable the tianmu primary key index | ||
|
||
set global tianmu_index_search=on; | ||
|
||
## DDL | ||
|
||
DROP TABLE IF EXISTS tt1,tt2; | ||
|
||
CREATE TABLE tt1(id INT PRIMARY KEY,name VARCHAR(5),copy_id INT) ENGINE=TIANMU; | ||
CREATE TABLE tt2(id INT PRIMARY KEY,name VARCHAR(5),copy_id INT) ENGINE=TIANMU; | ||
|
||
## insert data | ||
|
||
INSERT INTO tt1 VALUES(1,'AAA',1),(2,'AAA',2),(3,'BBB',3),(4,'BBB',4),(5,'CCC',5); | ||
INSERT INTO tt2 VALUES(1,'BBB',1),(2,'BBB',2),(3,'CCC',3),(4,'CCC',4),(5,'DDD',5); | ||
|
||
## subquery EXISTS | ||
|
||
SELECT * FROM tt1 WHERE EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND name = 'BBB'); | ||
|
||
SELECT * FROM tt1 WHERE EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND tt2.id = 2); | ||
|
||
SELECT * FROM tt1 WHERE EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND tt2.id > 2); | ||
|
||
SELECT * FROM tt1 WHERE EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND tt2.id < 2); | ||
|
||
## subquery NOT EXISTS | ||
|
||
SELECT * FROM tt1 WHERE NOT EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND name = 'BBB'); | ||
|
||
SELECT * FROM tt1 WHERE NOT EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND tt2.id = 2); | ||
|
||
SELECT * FROM tt1 WHERE NOT EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND tt2.id > 2); | ||
|
||
SELECT * FROM tt1 WHERE NOT EXISTS (SELECT 1 FROM tt2 WHERE tt1.id = tt2.id AND tt2.id < 2); | ||
|
||
## disable the tianmu primary key index | ||
|
||
set global tianmu_index_search=off; | ||
|
||
## clean test table | ||
|
||
DROP TABLE tt1,tt2; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters