Commit fa6eaead authored by Yongxin Xu's avatar Yongxin Xu Committed by GitHub

MDEV-24523 Execution of JSON_REPLACE failed on Spider

JSON_REPLACE() function executed with an error on Spider SE.
This patch fixes the problem, and it also fixes the MDEV-24541.

The problem is that Item_func_json_insert::func_name() returns
the wrong function name "json_update". 
The Spider SE reconstructs a query based on the return value
in some cases. Thus, if the return value is wrong, the Spider SE
may generate a wrong query.
parent 7f264997
...@@ -375,7 +375,7 @@ class Item_func_json_insert: public Item_json_str_multipath ...@@ -375,7 +375,7 @@ class Item_func_json_insert: public Item_json_str_multipath
const char *func_name() const const char *func_name() const
{ {
return mode_insert ? return mode_insert ?
(mode_replace ? "json_set" : "json_insert") : "json_update"; (mode_replace ? "json_set" : "json_insert") : "json_replace";
} }
Item *get_copy(THD *thd) Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_json_insert>(thd, this); } { return get_item_copy<Item_func_json_insert>(thd, this); }
......
--let $MASTER_1_COMMENT_P_2_1= $MASTER_1_COMMENT_P_2_1_BACKUP
--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP
--disable_warnings
--disable_query_log
--disable_result_log
--source ../t/test_deinit.inc
--enable_result_log
--enable_query_log
--enable_warnings
--disable_warnings
--disable_query_log
--disable_result_log
--source ../t/test_init.inc
--enable_result_log
--enable_query_log
--enable_warnings
--let $MASTER_1_COMMENT_P_2_1_BACKUP= $MASTER_1_COMMENT_P_2_1
let $MASTER_1_COMMENT_P_2_1=
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"'
);
--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES
let $CHILD2_1_CREATE_TABLES=
CREATE TABLE ta_r2 (
i INT,
j JSON,
PRIMARY KEY(i)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON
CREATE TABLE ta_r3 (
i INT,
j JSON,
PRIMARY KEY(i)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON
CREATE TABLE ta_r4 (
i INT,
j JSON,
PRIMARY KEY(i)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
for master_1
for child2
child2_1
child2_2
child2_3
for child3
this test is for MDEV-24523
drop and create databases
connection master_1;
CREATE DATABASE auto_test_local;
USE auto_test_local;
connection child2_1;
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
create table and insert
connection child2_1;
CHILD2_1_CREATE_TABLES
connection master_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"'
)
INSERT INTO tbl_a VALUES (1, '{ "a": 1, "b": [2, 3]}');
test 1
connection master_1;
UPDATE tbl_a SET j = JSON_REPLACE(j, '$.a', 10, '$.c', '[1, 2]');
SELECT * FROM tbl_a;
i j
1 {"a": 10, "b": [2, 3]}
TRUNCATE TABLE tbl_a;
INSERT INTO tbl_a VALUES (1, '{ "a": 1, "b": [2, 3]}');
UPDATE tbl_a SET j = JSON_REPLACE(j, '$.a', 10, '$.b', '[1, 2]');
SELECT * FROM tbl_a;
i j
1 {"a": 10, "b": "[1, 2]"}
deinit
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
end of test
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
!include ../my_2_1.cnf
--source ../include/mdev_24523_init.inc
--echo
--echo this test is for MDEV-24523
--echo
--echo drop and create databases
--connection master_1
--disable_warnings
CREATE DATABASE auto_test_local;
USE auto_test_local;
--connection child2_1
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;
eval $CHILD2_1_CREATE_TABLES;
--enable_ps_protocol
--enable_query_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;
eval CREATE TABLE tbl_a (
i INT,
j JSON,
PRIMARY KEY(i)
) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1;
--enable_query_log
INSERT INTO tbl_a VALUES (1, '{ "a": 1, "b": [2, 3]}');
--echo
--echo test 1
--connection master_1
UPDATE tbl_a SET j = JSON_REPLACE(j, '$.a', 10, '$.c', '[1, 2]');
SELECT * FROM tbl_a;
TRUNCATE TABLE tbl_a;
INSERT INTO tbl_a VALUES (1, '{ "a": 1, "b": [2, 3]}');
UPDATE tbl_a SET j = JSON_REPLACE(j, '$.a', 10, '$.b', '[1, 2]');
SELECT * FROM tbl_a;
--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;
--enable_warnings
--source ../include/mdev_24523_deinit.inc
--echo
--echo end of test
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