Commit 50784c88 authored by Yuchen Pei's avatar Yuchen Pei

MDEV-32238 Adding a switch to disable the spider group by handler

The system variable spider_disable_group_by_handler, if on, will
disable the spider group by handler (gbh), and such disablement serves
as workaround to bugs caused by gbh, labelled with spider-gbh on jira,
including MDEV-26247, MDEV-28998, MDEV-29163, MDEV-30392, MDEV-31645.
Tests for these tickets are added accordingly with the workaround in
place.
parent 05c99435
#
# 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;
set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler;
set spider_disable_group_by_handler=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;
set spider_disable_group_by_handler=@old_spider_disable_group_by_handler;
connection child2_1;
DROP DATABASE IF EXISTS auto_test_remote;
for master_1
for child2
child2_1
child2_2
child2_3
for child3
#
# end of test mdev_26247
#
#
# MDEV-28998 ASAN errors in spider_fields::free_conn_holder or spider_create_group_by_handler
#
for master_1
for child2
for child3
set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler;
set spider_disable_group_by_handler=1;
CREATE SERVER s 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 t1_SPIDER (a INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't1'";
CREATE TABLE t2 AS SELECT a FROM t1_SPIDER;
SELECT * FROM t2;
a
1
2
DROP TABLE t2, t1_SPIDER, t1;
drop server s;
set spider_disable_group_by_handler=@old_spider_disable_group_by_handler;
for master_1
for child2
for child3
#
# end of test mdev_28998
#
#
# 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
set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler;
set spider_disable_group_by_handler=1;
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;
set spider_disable_group_by_handler=@old_spider_disable_group_by_handler;
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
set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler;
set spider_disable_group_by_handler=1;
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;
set spider_disable_group_by_handler=@old_spider_disable_group_by_handler;
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
set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler;
set spider_disable_group_by_handler=1;
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"';
SET SESSION optimizer_switch='semijoin=off';
SELECT * FROM t2
WHERE A BETWEEN 0 AND 10 AND B IN(SELECT B FROM t2 WHERE A BETWEEN 11 AND 20);
a b
SET SESSION optimizer_switch='semijoin=on';
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;
set spider_disable_group_by_handler=@old_spider_disable_group_by_handler;
for master_1
for child2
for child3
#
# end of test mdev_31645
#
!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
#FIXME: this is a workaround.
set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler;
set spider_disable_group_by_handler=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;
set spider_disable_group_by_handler=@old_spider_disable_group_by_handler;
--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 # end of test mdev_26247
--echo #
--echo #
--echo # MDEV-28998 ASAN errors in spider_fields::free_conn_holder or spider_create_group_by_handler
--echo #
if (`select not(count(*)) from information_schema.system_variables where variable_name='have_sanitizer' and global_value like "%ASAN%"`)
{
--skip test needs to be run with ASAN
}
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
# FIXME: this is a workaround.
set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler;
set spider_disable_group_by_handler=1;
evalp CREATE SERVER s 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 t1_SPIDER (a INT) ENGINE=SPIDER COMMENT = "wrapper 'mysql', srv 's', table 't1'";
CREATE TABLE t2 AS SELECT a FROM t1_SPIDER;
SELECT * FROM t2;
# Cleanup
DROP TABLE t2, t1_SPIDER, t1;
drop server s;
set spider_disable_group_by_handler=@old_spider_disable_group_by_handler;
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
--echo #
--echo # end of test mdev_28998
--echo #
--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
#FIXME: this is a workaround.
set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler;
set spider_disable_group_by_handler=1;
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;
set spider_disable_group_by_handler=@old_spider_disable_group_by_handler;
--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
set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler;
set spider_disable_group_by_handler=1;
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;
set spider_disable_group_by_handler=@old_spider_disable_group_by_handler;
--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
set @old_spider_disable_group_by_handler=@@spider_disable_group_by_handler;
set spider_disable_group_by_handler=1;
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"';
SET SESSION optimizer_switch='semijoin=off';
SELECT * FROM t2
WHERE A BETWEEN 0 AND 10 AND B IN(SELECT B FROM t2 WHERE A BETWEEN 11 AND 20);
SET SESSION optimizer_switch='semijoin=on';
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;
set spider_disable_group_by_handler=@old_spider_disable_group_by_handler;
--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 #
......@@ -1612,6 +1612,9 @@ group_by_handler *spider_create_group_by_handler(
long tgt_link_status;
DBUG_ENTER("spider_create_group_by_handler");
if (spider_param_disable_group_by_handler(thd))
DBUG_RETURN(NULL);
switch (thd_sql_command(thd))
{
case SQLCOM_UPDATE:
......
......@@ -2351,6 +2351,17 @@ static MYSQL_THDVAR_INT(
SPIDER_THDVAR_OVERRIDE_VALUE_FUNC(int, strict_group_by)
static MYSQL_THDVAR_BOOL(
disable_group_by_handler, /* name */
PLUGIN_VAR_OPCMDARG, /* opt */
"Disables the group by handler", /* comment */
NULL, /* check */
NULL, /* update */
FALSE /* def */
);
SPIDER_THDVAR_VALUE_FUNC(bool, disable_group_by_handler)
static struct st_mysql_storage_engine spider_storage_engine =
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
......@@ -2465,6 +2476,7 @@ static struct st_mysql_sys_var* spider_system_variables[] = {
MYSQL_SYSVAR(wait_timeout),
MYSQL_SYSVAR(sync_sql_mode),
MYSQL_SYSVAR(strict_group_by),
MYSQL_SYSVAR(disable_group_by_handler),
NULL
};
......
......@@ -366,3 +366,4 @@ int spider_param_strict_group_by(
THD *thd,
int strict_group_by
);
bool spider_param_disable_group_by_handler(THD *thd);
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