--source ../include/partition_join_pushdown_for_single_partition_init.inc

--echo
--echo drop and create databases
--connection master_1
--disable_warnings
DROP DATABASE IF EXISTS auto_test_local;
CREATE DATABASE auto_test_local;
USE auto_test_local;
  --connection child2_1
    SET @old_log_output = @@global.log_output;
    SET GLOBAL log_output = 'TABLE,FILE';
  DROP DATABASE IF EXISTS auto_test_remote;
  CREATE DATABASE auto_test_remote;
  USE auto_test_remote;
  --connection child2_2
    SET @old_log_output = @@global.log_output;
    SET GLOBAL log_output = 'TABLE,FILE';
  DROP DATABASE IF EXISTS auto_test_remote2;
  CREATE DATABASE auto_test_remote2;
  USE auto_test_remote2;
  --connection child2_3
    SET @old_log_output = @@global.log_output;
    SET GLOBAL log_output = 'TABLE,FILE';
  DROP DATABASE IF EXISTS auto_test_remote3;
  CREATE DATABASE auto_test_remote3;
  USE auto_test_remote3;
--enable_warnings

--echo
--echo create table and insert
  --connection child2_1
    --disable_query_log
    echo CHILD2_1_DROP_TABLES;
    echo CHILD2_1_DROP_TABLES2;
    echo CHILD2_1_CREATE_TABLES;
    echo CHILD2_1_CREATE_TABLES2;
  --disable_warnings
DROP TABLE IF EXISTS tbl_a;
DROP TABLE IF EXISTS tbl_b;
  --enable_warnings
CREATE TABLE tbl_a (
value int NOT NULL,
PRIMARY KEY(value)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE tbl_b (
value2 int NOT NULL,
PRIMARY KEY(value2)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    --enable_query_log
    TRUNCATE TABLE mysql.general_log;
  --connection child2_2
    --disable_query_log
    echo CHILD2_2_DROP_TABLES;
    echo CHILD2_2_DROP_TABLES2;
    echo CHILD2_2_CREATE_TABLES;
    echo CHILD2_2_CREATE_TABLES2;
  --disable_warnings
DROP TABLE IF EXISTS tbl_a;
DROP TABLE IF EXISTS tbl_b;
  --enable_warnings
CREATE TABLE tbl_a (
value int NOT NULL,
PRIMARY KEY(value)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE tbl_b (
value2 int NOT NULL,
PRIMARY KEY(value2)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    --enable_query_log
    TRUNCATE TABLE mysql.general_log;
  --connection child2_3
    --disable_query_log
    echo CHILD2_3_DROP_TABLES;
    echo CHILD2_3_DROP_TABLES2;
    echo CHILD2_3_CREATE_TABLES;
    echo CHILD2_3_CREATE_TABLES2;
  --disable_warnings
DROP TABLE IF EXISTS tbl_a;
DROP TABLE IF EXISTS tbl_b;
  --enable_warnings
CREATE TABLE tbl_a (
value int NOT NULL,
PRIMARY KEY(value)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE tbl_b (
value2 int NOT NULL,
PRIMARY KEY(value2)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    --enable_query_log
    TRUNCATE TABLE mysql.general_log;
--connection master_1
--disable_warnings
DROP TABLE IF EXISTS tbl_a;
DROP TABLE IF EXISTS tbl_b;
--enable_warnings
--disable_query_log
echo CREATE TABLE tbl_a (
    value int NOT NULL,
    PRIMARY KEY(value)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1;
CREATE TABLE tbl_a (
    value int NOT NULL,
    PRIMARY KEY(value)
) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a"'
  PARTITION BY RANGE(value) (
PARTITION pt1 VALUES LESS THAN (5) COMMENT='srv "s_2_1"',
PARTITION pt2 VALUES LESS THAN (10) COMMENT='srv "s_2_2"',
PARTITION pt3 VALUES LESS THAN (15) COMMENT='srv "s_2_3"'
  );
echo CREATE TABLE tbl_b (
    value2 int NOT NULL,
    PRIMARY KEY(value2)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_2;
CREATE TABLE tbl_b (
    value2 int NOT NULL,
    PRIMARY KEY(value2)
) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_b"'
  PARTITION BY RANGE(value2) (
PARTITION pt1 VALUES LESS THAN (5) COMMENT='srv "s_2_1"',
PARTITION pt2 VALUES LESS THAN (10) COMMENT='srv "s_2_2"',
PARTITION pt3 VALUES LESS THAN (15) COMMENT='srv "s_2_3"'
  );
--enable_query_log

--disable_ps_protocol
insert into tbl_a values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into tbl_b values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
--enable_ps_protocol

--connection master_1
--disable_ps2_protocol
SELECT sum(a.value), count(b.value2) FROM tbl_a a, tbl_b b WHERE a.value = b.value2 AND a.value = 5;
SELECT sum(a.value), count(b.value2) FROM tbl_a a, tbl_b b WHERE a.value = 5 and b.value2 = 5;
  --connection child2_1
    --disable_view_protocol
SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %';
    --enable_view_protocol
SELECT value FROM tbl_a ORDER BY value;
  --connection child2_2
    --disable_view_protocol
SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %';
    --enable_view_protocol
SELECT value FROM tbl_a ORDER BY value;
  --connection child2_3
    --disable_view_protocol
SELECT argument FROM mysql.general_log WHERE command_type != 'Execute' AND argument LIKE '%select %';
    --enable_view_protocol
SELECT value FROM tbl_a ORDER BY value;
--enable_ps2_protocol

--echo
--echo deinit
--disable_warnings
--connection master_1
DROP DATABASE IF EXISTS auto_test_local;
  --connection child2_1
  DROP DATABASE IF EXISTS auto_test_remote;
    SET GLOBAL log_output = @old_log_output;
  --connection child2_2
  DROP DATABASE IF EXISTS auto_test_remote2;
    SET GLOBAL log_output = @old_log_output;
  --connection child2_3
  DROP DATABASE IF EXISTS auto_test_remote3;
    SET GLOBAL log_output = @old_log_output;
--enable_warnings
--source ../include/partition_join_pushdown_for_single_partition_deinit.inc
--echo
--echo end of test
