Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tianmu): fix subquery of exists when use primary key (#971 #944) #1050

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions mysql-test/suite/tianmu/r/issue971.result
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;
13 changes: 13 additions & 0 deletions mysql-test/suite/tianmu/r/trigger.result
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,25 @@ END|
UPDATE IGNORE t1 SET a=2 WHERE a=1;
Warnings:
Warning 1062 Duplicate entry '2' for key 'PRIMARY'
SHOW WARNINGS;
Level Code Message
Warning 1062 Duplicate entry '2' for key 'PRIMARY'
SELECT * FROM t2;
after_update
UPDATE IGNORE t1,t3 SET t1.a=2 WHERE t1.a=1;
Warnings:
Warning 1062 Duplicate entry '2' for key 'PRIMARY'
SHOW WARNINGS;
Level Code Message
Warning 1062 Duplicate entry '2' for key 'PRIMARY'
SELECT * FROM t2;
after_update
UPDATE IGNORE t3,t1 SET t1.a=2 WHERE t1.a=1;
Warnings:
Warning 1062 Duplicate entry '2' for key 'PRIMARY'
SHOW WARNINGS;
Level Code Message
Warning 1062 Duplicate entry '2' for key 'PRIMARY'
SELECT * FROM t1;
a
1
Expand Down
50 changes: 50 additions & 0 deletions mysql-test/suite/tianmu/t/issue971.test
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;

3 changes: 3 additions & 0 deletions mysql-test/suite/tianmu/t/trigger.test
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,13 @@ END|
DELIMITER ;|

UPDATE IGNORE t1 SET a=2 WHERE a=1;
SHOW WARNINGS;
SELECT * FROM t2;
UPDATE IGNORE t1,t3 SET t1.a=2 WHERE t1.a=1;
SHOW WARNINGS;
SELECT * FROM t2;
UPDATE IGNORE t3,t1 SET t1.a=2 WHERE t1.a=1;
SHOW WARNINGS;
SELECT * FROM t1;
SELECT * FROM t2;
DROP TRIGGER post_update_t1;
Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/core/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ bool Descriptor::ExsitTmpTable() const {
}

bool Descriptor::IsleftIndexSearch() const {
if (!tianmu_sysvar_index_search || IsType_OrTree())
if (!tianmu_sysvar_index_search || IsType_OrTree() || IsType_Between())
return false;
if (IsType_AttrValOrAttrValVal() && encoded) {
auto col = static_cast<vcolumn::SingleColumn *>(attr.vc);
Expand Down
1 change: 1 addition & 0 deletions storage/tianmu/core/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class Descriptor {
bool IsType_Subquery();
bool IsType_Exists() const { return op == common::Operator::O_EXISTS || op == common::Operator::O_NOT_EXISTS; }
bool IsType_In() const { return op == common::Operator::O_IN || op == common::Operator::O_NOT_IN; }
bool IsType_Between() const { return op == common::Operator::O_BETWEEN || op == common::Operator::O_NOT_BETWEEN; }

bool IsType_TIANMUExpression() const; // only columns, constants and TIANMUExpressions
bool IsType_JoinComplex() const;
Expand Down