--source ../include/mdev_24517_init.inc
--echo
--echo this test is for MDEV-24517
--echo
--echo drop and create databases

--connection master_1
--disable_warnings
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';
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
--enable_warnings

--echo
--echo create table and insert

--connection child2_1
--disable_query_log
--disable_ps_protocol
echo CHILD2_1_CREATE_TABLES;
CREATE TABLE ta_r2 (
i INT,
j JSON,
PRIMARY KEY(i)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
CREATE TABLE ta_r3 (
i INT,
j JSON,
PRIMARY KEY(i)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
CREATE TABLE ta_r4 (
i INT,
j JSON,
PRIMARY KEY(i)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--enable_ps_protocol
--enable_query_log
TRUNCATE TABLE mysql.general_log;

--connection master_1
--disable_query_log
echo CREATE TABLE tbl_a (
  i INT,
  j JSON,
  PRIMARY KEY(i)
) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1;
CREATE TABLE tbl_a (
  i INT,
  j JSON,
  PRIMARY KEY(i)
) ENGINE=Spider PARTITION BY RANGE(i) (
PARTITION pt1 VALUES LESS THAN (5) COMMENT='srv "s_2_1", table "ta_r2"',
PARTITION pt2 VALUES LESS THAN (10) COMMENT='srv "s_2_1", table "ta_r3"',
PARTITION pt3 VALUES LESS THAN MAXVALUE COMMENT='srv "s_2_1", table "ta_r4"'
  );
--enable_query_log
--disable_ps_protocol
INSERT INTO tbl_a (i, j) VALUES
  (1, '{"ID": "3", "Name": "Barney", "Age": 18}'),
  (2, '{"ID": "4", "Name": "Betty", "Age": 19}'),
  (3, '{"ID": "2", "Name": "Wilma", "Age": 20}'),
  (4, '[10, 20, [30, 40]]');
--enable_ps_protocol

--echo
--echo test 1

--connection child2_1
TRUNCATE TABLE mysql.general_log;

--connection master_1
SELECT * FROM tbl_a WHERE JSON_EXTRACT(j, '$.Age')=19;
SELECT * FROM tbl_a WHERE JSON_EXTRACT(j, '$.Name')="Betty";
SELECT i, JSON_EXTRACT(j, "$.ID")
  FROM tbl_a
  WHERE JSON_EXTRACT(j, "$.ID") > 1 AND i < 4
  ORDER BY JSON_EXTRACT(j, "$.Name");
SELECT * FROM tbl_a WHERE JSON_EXTRACT(j, '$[1]') = 20;
SELECT * FROM tbl_a WHERE JSON_EXTRACT(j, '$[2][0]') = 30;

--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;

--enable_warnings
--source ../include/mdev_24517_deinit.inc
--echo
--echo end of test
