Commit 17839657 authored by Yuchen Pei's avatar Yuchen Pei

MDEV-26247 Re-implement spider gbh query rewrite of tables

Spider GBH's query rewrite of table joins is overly complex and
error-prone. We replace it with something closer to what
dbug_print() (more specifically, print_join()) does, but catered to
spider.

More specifically, we replace the body of
spider_db_mbase_util::append_from_and_tables() with a call to
spider_db_mbase_util::append_join(), and remove downstream append_X
functions.

We make it handle const tables by rewriting them as (select 1). This
fixes the main issue in MDEV-26247.

We also ban semijoin from spider gbh, which fixes MDEV-31645 and
MDEV-30392, as semi-join is an "internal" join, and "semi join" does
not parse, and it is different from "join" in that it deduplicates the
right hand side

Not all queries passed to a group by handler are valid (MDEV-32273),
for example, a join on expr may refer outer fields not in the current
context. We detect this during the handler creation when walking the
join. See also gbh_outer_fields_in_join.test.

It also skips eliminated tables, which fixes MDEV-26193.
parent 0bacef76
#
# MDEV-26247 Spider: Valid LEFT JOIN results in ERROR 1064
#
for master_1
for child2
child2_1
child2_2
child2_3
for child3
connection child2_1;
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
CREATE TABLE t1 (a int) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE t2 (a int) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE t3 (a int) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (1), (2);
INSERT INTO t3 VALUES (1), (2), (3);
connection master_1;
CREATE DATABASE auto_test_local;
USE auto_test_local;
CREATE TABLE t1 (a int) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='srv "s_2_1", table "t1"';
CREATE TABLE t2 (a int) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='srv "s_2_1", table "t2"';
CREATE TABLE t3 (a int) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='srv "s_2_1", table "t3"';
select * from t3 left join t1 on t3.a = t1.a left join t2 on t3.a = t2.a;
a a a
1 1 1
2 NULL 2
3 NULL NULL
select * from t1 left join t2 on t1.a = t2.a right join t3 on t3.a = t1.a;
a a a
1 1 1
NULL NULL 2
NULL NULL 3
select * from t3 left join (t1 left join t2 on t1.a = t2.a) on t3.a = t1.a;
a a a
1 1 1
2 NULL NULL
3 NULL NULL
drop table t1, t2, t3;
connection master_1;
DROP DATABASE IF EXISTS auto_test_local;
connection child2_1;
DROP DATABASE IF EXISTS auto_test_remote;
for master_1
for child2
child2_1
child2_2
child2_3
for child3
......@@ -72,6 +72,7 @@ SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select `pkey`,`val` from `auto_test_remote`.`tbl_a`
select `pkey`,`val` from `auto_test_remote`.`tbl_a` where `pkey` = 1
select 1 from (select 1) t0
select `pkey`,`val` from `auto_test_remote`.`tbl_a`
select `pkey`,`val` from `auto_test_remote`.`tbl_a`
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
......@@ -85,6 +86,7 @@ argument
select `pkey`,`val` from `auto_test_remote2`.`tbl_a`
select `pkey`,`val` from `auto_test_remote2`.`tbl_a`
select `pkey`,`val` from `auto_test_remote2`.`tbl_a` where `pkey` = 2
select 1 from (select 1) t0
select `pkey`,`val` from `auto_test_remote2`.`tbl_a`
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT pkey, val FROM tbl_a ORDER BY pkey;
......
#
# MDEV-26247 Spider: Valid LEFT JOIN results in ERROR 1064
#
for master_1
for child2
child2_1
child2_2
child2_3
for child3
connection child2_1;
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
CREATE TABLE t1 (
a11 int,
primary key (a11)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE t2 (
a21 int,
a22 int,
primary key (a21, a22)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE t3 (
a31 int,
a32 int,
primary key (a31, a32)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (1, 11), (2, 22), (3, 33);
INSERT INTO t3 VALUES (1, 111), (2, 222), (3, 333);
connection master_1;
CREATE DATABASE auto_test_local;
USE auto_test_local;
CREATE TABLE t1 (
a11 int,
primary key (a11)
) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='srv "s_2_1", table "t1"';
CREATE TABLE t2 (
a21 int,
a22 int,
primary key (a21, a22)
) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='srv "s_2_1", table "t2"';
CREATE TABLE t3 (
a31 int,
a32 int,
primary key (a31, a32)
) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='srv "s_2_1", table "t3"';
SELECT a22 FROM t1 LEFT JOIN t2 ON a11 = a21 WHERE a11 IN (1);
a22
11
SELECT a22 FROM t1 LEFT JOIN t2 ON a11 = a21 - a21 WHERE a11 IN (1);
a22
NULL
SELECT a22 FROM t2 RIGHT JOIN t1 ON a21 = a11 WHERE a11 IN (1);
a22
11
SELECT a22 FROM t2 RIGHT JOIN t1 ON a21 = a11 WHERE a11 IN (1,2);
a22
11
22
SELECT a22, a32 FROM t1 LEFT JOIN t2 ON a11 = a21 RIGHT JOIN t3 on a21 = a31 WHERE a11 IN (1);
a22 a32
11 111
SELECT a22, a32 FROM t1 LEFT JOIN t2 ON a11 = a21 - a21 RIGHT JOIN t3 on a21 = a31 - a31 WHERE a11 IN (1);
a22 a32
SELECT a22, a32 FROM t1 LEFT JOIN t2 ON a11 = a21 RIGHT JOIN t3 on a21 = a31 WHERE a11 IN (1,2);
a22 a32
11 111
22 222
SELECT a22 FROM t2 LEFT JOIN t1 ON a11 = a21 WHERE a11 IN (1);
a22
11
SELECT a22 FROM t2 LEFT JOIN t1 ON a11 = a21 - a21 WHERE a11 IN (1);
a22
SELECT a22 FROM t1 RIGHT JOIN t2 ON a21 = a11 WHERE a11 IN (1);
a22
11
SELECT a22 FROM t1 RIGHT JOIN t2 ON a21 = a11 WHERE a11 IN (1,2);
a22
11
22
connection master_1;
DROP DATABASE IF EXISTS auto_test_local;
connection child2_1;
DROP DATABASE IF EXISTS auto_test_remote;
for master_1
for child2
child2_1
child2_2
child2_3
for child3
#
# MDEV-29163 Server crash with SIGSEGV or dynamic-stack-buffer-overflow in spider_db_mbase_util::append_table
#
for master_1
for child2
for child3
CREATE SERVER s FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (b INT);
CREATE TABLE t3 (c INT, PRIMARY KEY(c));
CREATE TABLE t1_spider (a INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't1'";
CREATE TABLE t2_spider (b INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't2'";
CREATE TABLE t3_spider (c INT, PRIMARY KEY(c)) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't3'";
SELECT t1_spider.* FROM t1_spider LEFT JOIN t2_spider LEFT JOIN t3_spider ON b = c ON a = b;
a
DROP TABLE t1_spider, t2_spider, t3_spider, t1, t2, t3;
drop server s;
for master_1
for child2
for child3
#
# end of test mdev_29163
#
#
# MDEV-30392 Syntax error upon query with subquery from Spider table
#
for master_1
for child2
for child3
CREATE SERVER srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (a INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 'srv', table 't1'";
SELECT a FROM t2 WHERE a IN ( SELECT a FROM t2 );
a
1
2
DROP TABLE t1, t2;
DROP SERVER srv;
for master_1
for child2
for child3
#
# end of test mdev_30392
#
#
# MDEV-31645 Spider doesn't recognize semi JOIN
#
for master_1
for child2
for child3
CREATE SERVER srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
CREATE TABLE t1 ( a bigint(20) NOT NULL, b bigint(20) DEFAULT 0, PRIMARY KEY (a));
CREATE TABLE t2 ( a bigint(20) NOT NULL, b bigint(20) DEFAULT 0, PRIMARY KEY (a)) ENGINE=SPIDER COMMENT='srv "srv", WRAPPER "mysql", TABLE "t1"';
SELECT * FROM t2 WHERE b IN (SELECT b FROM t2 WHERE a > 10);
a b
SELECT * FROM t2
WHERE A BETWEEN 0 AND 10 AND B IN(SELECT B FROM t2 WHERE A BETWEEN 11 AND 20);
a b
drop table t1, t2;
drop server srv;
for master_1
for child2
for child3
#
# end of test mdev_31645
#
#
# Test joining a spider table with a non-spider table
#
for master_1
for child2
for child3
CREATE SERVER srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
create table t1 (c int);
create table t2 (d int);
insert into t2 values (1), (2);
create table t3 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t1"';
insert into t3 values (2), (3);
select c from t3 join t2 on c = d;
c
2
drop table t1, t2, t3;
drop server srv;
for master_1
for child2
for child3
#
# end of test spider_join_with_non_spider
#
#
# Test spider select with subqueries
#
for master_1
for child2
for child3
CREATE SERVER srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
create table t1 (c1 int);
create table t2 (c2 int);
insert into t1 values (1), (2);
insert into t2 values (0), (1), (2);
create table t1s (c1 int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t1"';
create table t2s (c2 int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
select c1 from t1s, (select c2 from t2s where c2 > 0) t where c1 + 1 = c2;
c1
1
drop table t1, t2, t1s, t2s;
drop server srv;
for master_1
for child2
for child3
#
# end of test subquery
#
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
!include ../my_2_1.cnf
--echo #
--echo # MDEV-26247 Spider: Valid LEFT JOIN results in ERROR 1064
--echo #
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
--connection child2_1
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
eval CREATE TABLE t1 (a int) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
eval CREATE TABLE t2 (a int) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
eval CREATE TABLE t3 (a int) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (1), (2);
INSERT INTO t3 VALUES (1), (2), (3);
--connection master_1
CREATE DATABASE auto_test_local;
USE auto_test_local;
eval CREATE TABLE t1 (a int) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='srv "s_2_1", table "t1"';
eval CREATE TABLE t2 (a int) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='srv "s_2_1", table "t2"';
eval CREATE TABLE t3 (a int) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='srv "s_2_1", table "t3"';
select * from t3 left join t1 on t3.a = t1.a left join t2 on t3.a = t2.a;
select * from t1 left join t2 on t1.a = t2.a right join t3 on t3.a = t1.a;
select * from t3 left join (t1 left join t2 on t1.a = t2.a) on t3.a = t1.a;
drop table t1, t2, t3;
--connection master_1
DROP DATABASE IF EXISTS auto_test_local;
--connection child2_1
DROP DATABASE IF EXISTS auto_test_remote;
--disable_query_log
--disable_result_log
--source ../t/test_deinit.inc
--enable_query_log
--enable_result_log
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
!include ../my_2_1.cnf
--echo #
--echo # MDEV-26247 Spider: Valid LEFT JOIN results in ERROR 1064
--echo #
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
--connection child2_1
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
eval CREATE TABLE t1 (
a11 int,
primary key (a11)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
eval CREATE TABLE t2 (
a21 int,
a22 int,
primary key (a21, a22)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
eval CREATE TABLE t3 (
a31 int,
a32 int,
primary key (a31, a32)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
INSERT INTO t1 VALUES (1), (2), (3);
INSERT INTO t2 VALUES (1, 11), (2, 22), (3, 33);
INSERT INTO t3 VALUES (1, 111), (2, 222), (3, 333);
--connection master_1
CREATE DATABASE auto_test_local;
USE auto_test_local;
eval CREATE TABLE t1 (
a11 int,
primary key (a11)
) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='srv "s_2_1", table "t1"';
eval CREATE TABLE t2 (
a21 int,
a22 int,
primary key (a21, a22)
) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='srv "s_2_1", table "t2"';
eval CREATE TABLE t3 (
a31 int,
a32 int,
primary key (a31, a32)
) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='srv "s_2_1", table "t3"';
SELECT a22 FROM t1 LEFT JOIN t2 ON a11 = a21 WHERE a11 IN (1);
SELECT a22 FROM t1 LEFT JOIN t2 ON a11 = a21 - a21 WHERE a11 IN (1);
SELECT a22 FROM t2 RIGHT JOIN t1 ON a21 = a11 WHERE a11 IN (1);
SELECT a22 FROM t2 RIGHT JOIN t1 ON a21 = a11 WHERE a11 IN (1,2);
SELECT a22, a32 FROM t1 LEFT JOIN t2 ON a11 = a21 RIGHT JOIN t3 on a21 = a31 WHERE a11 IN (1);
SELECT a22, a32 FROM t1 LEFT JOIN t2 ON a11 = a21 - a21 RIGHT JOIN t3 on a21 = a31 - a31 WHERE a11 IN (1);
SELECT a22, a32 FROM t1 LEFT JOIN t2 ON a11 = a21 RIGHT JOIN t3 on a21 = a31 WHERE a11 IN (1,2);
SELECT a22 FROM t2 LEFT JOIN t1 ON a11 = a21 WHERE a11 IN (1);
SELECT a22 FROM t2 LEFT JOIN t1 ON a11 = a21 - a21 WHERE a11 IN (1);
SELECT a22 FROM t1 RIGHT JOIN t2 ON a21 = a11 WHERE a11 IN (1);
SELECT a22 FROM t1 RIGHT JOIN t2 ON a21 = a11 WHERE a11 IN (1,2);
--connection master_1
DROP DATABASE IF EXISTS auto_test_local;
--connection child2_1
DROP DATABASE IF EXISTS auto_test_remote;
--disable_query_log
--disable_result_log
--source ../t/test_deinit.inc
--enable_query_log
--enable_result_log
--echo #
--echo # MDEV-29163 Server crash with SIGSEGV or dynamic-stack-buffer-overflow in spider_db_mbase_util::append_table
--echo #
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
evalp CREATE SERVER s FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (b INT);
CREATE TABLE t3 (c INT, PRIMARY KEY(c));
CREATE TABLE t1_spider (a INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't1'";
CREATE TABLE t2_spider (b INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't2'";
CREATE TABLE t3_spider (c INT, PRIMARY KEY(c)) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't3'";
SELECT t1_spider.* FROM t1_spider LEFT JOIN t2_spider LEFT JOIN t3_spider ON b = c ON a = b;
# Cleanup
DROP TABLE t1_spider, t2_spider, t3_spider, t1, t2, t3;
drop server s;
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
--echo #
--echo # end of test mdev_29163
--echo #
--echo #
--echo # MDEV-30392 Syntax error upon query with subquery from Spider table
--echo #
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
evalp CREATE SERVER srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (a INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 'srv', table 't1'";
SELECT a FROM t2 WHERE a IN ( SELECT a FROM t2 );
# Cleanup
DROP TABLE t1, t2;
DROP SERVER srv;
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
--echo #
--echo # end of test mdev_30392
--echo #
--echo #
--echo # MDEV-31645 Spider doesn't recognize semi JOIN
--echo #
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
evalp CREATE SERVER srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
CREATE TABLE t1 ( a bigint(20) NOT NULL, b bigint(20) DEFAULT 0, PRIMARY KEY (a));
CREATE TABLE t2 ( a bigint(20) NOT NULL, b bigint(20) DEFAULT 0, PRIMARY KEY (a)) ENGINE=SPIDER COMMENT='srv "srv", WRAPPER "mysql", TABLE "t1"';
SELECT * FROM t2 WHERE b IN (SELECT b FROM t2 WHERE a > 10);
SELECT * FROM t2
WHERE A BETWEEN 0 AND 10 AND B IN(SELECT B FROM t2 WHERE A BETWEEN 11 AND 20);
drop table t1, t2;
drop server srv;
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
--echo #
--echo # end of test mdev_31645
--echo #
--echo #
--echo # Test joining a spider table with a non-spider table
--echo #
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
evalp CREATE SERVER srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
create table t1 (c int);
create table t2 (d int);
insert into t2 values (1), (2);
create table t3 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t1"';
insert into t3 values (2), (3);
select c from t3 join t2 on c = d;
drop table t1, t2, t3;
drop server srv;
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
--echo #
--echo # end of test spider_join_with_non_spider
--echo #
--echo #
--echo # Test spider select with subqueries
--echo #
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
evalp CREATE SERVER srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
create table t1 (c1 int);
create table t2 (c2 int);
insert into t1 values (1), (2);
insert into t2 values (0), (1), (2);
create table t1s (c1 int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t1"';
create table t2s (c2 int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
select c1 from t1s, (select c2 from t2s where c2 > 0) t where c1 + 1 = c2;
drop table t1, t2, t1s, t2s;
drop server srv;
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
--echo #
--echo # end of test subquery
--echo #
......@@ -167,7 +167,7 @@ connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select `id`,`hr_status`,`region_code`,`region` from `auto_test_remote`.`tbl_person` where `id` = '24FC3F0A5119432BAE13DD65AABAA39C' and `region` = 510411
select count(0) `count(0)` from `auto_test_remote`.`tbl_ncd_cm_person` t0 where ((t0.`person_id` = '24FC3F0A5119432BAE13DD65AABAA39C') and (t0.`diseaseKind_id` = '52A0328740914BCE86ED10A4D2521816'))
select count(0) `count(0)` from (select 1) t0 join `auto_test_remote`.`tbl_ncd_cm_person` t1 where ((t1.`person_id` = '24FC3F0A5119432BAE13DD65AABAA39C') and (t1.`diseaseKind_id` = '52A0328740914BCE86ED10A4D2521816'))
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT * FROM tbl_person;
id hr_status region_code region
......
......@@ -87,7 +87,7 @@ NULL NULL NULL 3
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_no_idx` t3 left join (`auto_test_remote`.`ta_r_auto_inc` t2 join `auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r` t0) on ((t2.`b` = t3.`b`) and (t2.`c` = t1.`c`) and (t0.`a` = t1.`a`) and (t1.`a` is not null) and (t3.`b` is not null)) where 1 order by t3.`a` desc
select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_no_idx` t3 left join (`auto_test_remote`.`ta_r` t0 join `auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r_auto_inc` t2) on ((t2.`b` = t3.`b`) and (t2.`c` = t1.`c`) and (t0.`a` = t1.`a`) and (t1.`a` is not null) and (t3.`b` is not null)) where 1 order by t3.`a` desc
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a;
a b date_format(c, '%Y-%m-%d %H:%i:%s')
......
......@@ -86,7 +86,7 @@ NULL c 2000-01-03 00:00:00 3
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_auto_inc` t2 left join (`auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r` t0) on ((t1.`c` = t2.`c`) and (t0.`a` = t1.`a`) and (t1.`a` is not null)) left join `auto_test_remote`.`ta_r_no_idx` t3 on (t3.`b` = t2.`b`) where 1 order by t3.`a` desc
select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_auto_inc` t2 left join (`auto_test_remote`.`ta_r` t0 join `auto_test_remote`.`ta_r_3` t1) on ((t1.`c` = t2.`c`) and (t0.`a` = t1.`a`) and (t1.`a` is not null)) left join `auto_test_remote`.`ta_r_no_idx` t3 on (t3.`b` = t2.`b`) where 1 order by t3.`a` desc
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a;
a b date_format(c, '%Y-%m-%d %H:%i:%s')
......
......@@ -79,7 +79,7 @@ a b c
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select t0.`b` `b`,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r_int` t2 left join (`auto_test_remote`.`ta_r` t0 join `auto_test_remote`.`ta_r_3` t1) on ((t0.`a` = t2.`a`) and (t1.`a` = t2.`a`)) where 1 order by t0.`b` desc
select t0.`b` `b`,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r_int` t2 left join (`auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r` t0) on ((t0.`a` = t2.`a`) and (t1.`a` = t2.`a`)) where 1 order by t0.`b` desc
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a;
a b date_format(c, '%Y-%m-%d %H:%i:%s')
......
......@@ -87,7 +87,7 @@ NULL c 2000-01-03 00:00:00 3
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_no_idx` t3 left join `auto_test_remote`.`ta_r_auto_inc` t2 on ((t2.`b` = t3.`b`) and (t3.`b` is not null)) left join `auto_test_remote`.`ta_r_3` t1 on (t1.`c` = t2.`c`) left join `auto_test_remote`.`ta_r` t0 on ((t0.`a` = t1.`a`) and (t1.`a` is not null)) where 1 order by t3.`a` desc
select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_no_idx` t3 left join (`auto_test_remote`.`ta_r_auto_inc` t2 left join (`auto_test_remote`.`ta_r_3` t1 left join `auto_test_remote`.`ta_r` t0 on ((t0.`a` = t1.`a`) and (t1.`a` is not null))) on (t1.`c` = t2.`c`)) on ((t2.`b` = t3.`b`) and (t3.`b` is not null)) where 1 order by t3.`a` desc
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a;
a b date_format(c, '%Y-%m-%d %H:%i:%s')
......
......@@ -86,7 +86,7 @@ NULL c 2000-01-03 00:00:00 3
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_auto_inc` t2 left join `auto_test_remote`.`ta_r_3` t1 on (t1.`c` = t2.`c`) left join `auto_test_remote`.`ta_r` t0 on ((t0.`a` = t1.`a`) and (t1.`a` is not null)) left join `auto_test_remote`.`ta_r_no_idx` t3 on (t3.`b` = t2.`b`) where 1 order by t3.`a` desc
select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_auto_inc` t2 left join (`auto_test_remote`.`ta_r_3` t1 left join `auto_test_remote`.`ta_r` t0 on ((t0.`a` = t1.`a`) and (t1.`a` is not null))) on (t1.`c` = t2.`c`) left join `auto_test_remote`.`ta_r_no_idx` t3 on (t3.`b` = t2.`b`) where 1 order by t3.`a` desc
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a;
a b date_format(c, '%Y-%m-%d %H:%i:%s')
......
......@@ -87,7 +87,7 @@ NULL c 2000-01-03 00:00:00 3
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_no_idx` t3 left join (`auto_test_remote`.`ta_r_auto_inc` t2 join `auto_test_remote`.`ta_r_3` t1 left join `auto_test_remote`.`ta_r` t0 on ((t0.`a` = t1.`a`) and (t1.`a` is not null))) on ((t2.`b` = t3.`b`) and (t2.`c` = t1.`c`) and (t3.`b` is not null)) where 1 order by t3.`a` desc
select t0.`a` `a`,t2.`b` `b`,t2.`c` `c`,t3.`a` `a` from `auto_test_remote`.`ta_r_no_idx` t3 left join (`auto_test_remote`.`ta_r_3` t1 left join `auto_test_remote`.`ta_r` t0 on ((t0.`a` = t1.`a`) and (t1.`a` is not null)) join `auto_test_remote`.`ta_r_auto_inc` t2) on ((t2.`b` = t3.`b`) and (t2.`c` = t1.`c`) and (t3.`b` is not null)) where 1 order by t3.`a` desc
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a;
a b date_format(c, '%Y-%m-%d %H:%i:%s')
......
......@@ -86,8 +86,10 @@ SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select `value` from `auto_test_remote2`.`tbl_a` where `value` = 5
select `value2` from `auto_test_remote2`.`tbl_b` where `value2` = 5
select sum('5') `sum(a.value)`,count('5') `count(b.value2)` from (select 1) t0 join (select 1) t1
select `value` from `auto_test_remote2`.`tbl_a` where `value` = 5
select `value2` from `auto_test_remote2`.`tbl_b` where `value2` = 5
select sum('5') `sum(a.value)`,count('5') `count(b.value2)` from (select 1) t0 join (select 1) t1
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT value FROM tbl_a ORDER BY value;
value
......
......@@ -46,7 +46,7 @@ connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%`tbl_a`%' ;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%`tbl_b`%';
argument
select t0.`val` `val`,t0.`akey` `akey` from `auto_test_remote`.`tbl_a` t0 where (t0.`akey` = '4')
select t0.`val` `val`,t0.`akey` `akey` from `auto_test_remote`.`tbl_a` t0 join (select 1) t1 where (t0.`akey` = '4')
SELECT argument FROM mysql.general_log WHERE argument LIKE '%`tbl_a`%' ;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%`tbl_b`%'
argument
......
This diff is collapsed.
......@@ -157,40 +157,22 @@ class spider_db_mbase_util: public spider_db_util
String *from
) override;
#ifdef SPIDER_HAS_GROUP_BY_HANDLER
int append_table(
ha_spider *spider,
spider_fields *fields,
spider_string *str,
TABLE_LIST *table_list,
TABLE_LIST **used_table_list,
uint *current_pos,
TABLE_LIST **cond_table_list_ptr,
bool top_down,
bool first
);
int append_tables_top_down(
ha_spider *spider,
spider_fields *fields,
spider_string *str,
TABLE_LIST *table_list,
TABLE_LIST **used_table_list,
uint *current_pos,
TABLE_LIST **cond_table_list_ptr
);
int append_tables_top_down_check(
TABLE_LIST *table_list,
TABLE_LIST **used_table_list,
uint *current_pos
);
int append_embedding_tables(
ha_spider *spider,
spider_fields *fields,
spider_string *str,
TABLE_LIST *table_list,
TABLE_LIST **used_table_list,
uint *current_pos,
TABLE_LIST **cond_table_list_ptr
);
int append_table_list(spider_fields *fields,
spider_string *str, TABLE_LIST *table,
table_map *upper_usable_tables,
table_map eliminated_tables);
int append_table_array(spider_fields *fields,
spider_string *str, TABLE_LIST **table,
TABLE_LIST **end, table_map *upper_usable_tables,
table_map eliminated_tables);
int append_join(spider_fields *fields, spider_string *str,
List<TABLE_LIST> *tables, table_map *upper_usable_tables,
table_map eliminated_tables);
int append_from_and_tables(
ha_spider *spider,
spider_fields *fields,
......
......@@ -25,6 +25,7 @@
#include "probes_mysql.h"
#include "sql_class.h"
#include "sql_partition.h"
#include "sql_select.h"
#include "ha_partition.h"
#endif
#include "sql_common.h"
......@@ -1282,14 +1283,16 @@ static int spider_send_query(
DBUG_RETURN(0);
}
/*
Prepare and send query to data nodes and store the query results.
*/
int spider_group_by_handler::init_scan()
{
int error_num;
DBUG_ENTER("spider_group_by_handler::init_scan");
store_error = 0;
#ifndef DBUG_OFF
Field **field;
for (field = table->field; *field; field++)
for (Field **field = table->field; *field; field++)
DBUG_PRINT("info",("spider field_name=%s", SPIDER_field_name_str(*field)));
#endif
......@@ -1439,8 +1442,6 @@ group_by_handler *spider_create_group_by_handler(
from = query->from;
do {
DBUG_PRINT("info",("spider from=%p", from));
if (from->table->const_table)
continue;
++table_count;
if (from->table->part_info)
{
......@@ -1468,15 +1469,6 @@ group_by_handler *spider_create_group_by_handler(
table_idx = 0;
from = query->from;
while (from && from->table->const_table)
{
from = from->next_local;
}
if (!from)
{
/* all tables are const_table */
goto skip_free_table_holder;
}
#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
if (from->table->part_info)
{
......@@ -1512,8 +1504,6 @@ group_by_handler *spider_create_group_by_handler(
}
while ((from = from->next_local))
{
if (from->table->const_table)
continue;
#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
if (from->table->part_info)
{
......@@ -1556,8 +1546,6 @@ group_by_handler *spider_create_group_by_handler(
from = query->from;
do {
if (from->table->const_table)
continue;
#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
if (from->table->part_info)
{
......@@ -1701,10 +1689,6 @@ group_by_handler *spider_create_group_by_handler(
goto skip_free_table_holder;
from = query->from;
while (from->table->const_table)
{
from = from->next_local;
}
#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
if (from->table->part_info)
{
......@@ -1777,8 +1761,6 @@ group_by_handler *spider_create_group_by_handler(
while ((from = from->next_local))
{
if (from->table->const_table)
continue;
fields->clear_conn_holder_from_conn();
#if defined(PARTITION_HAS_GET_CHILD_HANDLERS)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment