Skip to content

Commit fa6eaea

Browse files
authored
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.
1 parent 7f26499 commit fa6eaea

File tree

6 files changed

+168
-1
lines changed

6 files changed

+168
-1
lines changed

sql/item_jsonfunc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ class Item_func_json_insert: public Item_json_str_multipath
375375
const char *func_name() const
376376
{
377377
return mode_insert ?
378-
(mode_replace ? "json_set" : "json_insert") : "json_update";
378+
(mode_replace ? "json_set" : "json_insert") : "json_replace";
379379
}
380380
Item *get_copy(THD *thd)
381381
{ return get_item_copy<Item_func_json_insert>(thd, this); }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--let $MASTER_1_COMMENT_P_2_1= $MASTER_1_COMMENT_P_2_1_BACKUP
2+
--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP
3+
--disable_warnings
4+
--disable_query_log
5+
--disable_result_log
6+
--source ../t/test_deinit.inc
7+
--enable_result_log
8+
--enable_query_log
9+
--enable_warnings
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--disable_warnings
2+
--disable_query_log
3+
--disable_result_log
4+
--source ../t/test_init.inc
5+
--enable_result_log
6+
--enable_query_log
7+
--enable_warnings
8+
--let $MASTER_1_COMMENT_P_2_1_BACKUP= $MASTER_1_COMMENT_P_2_1
9+
let $MASTER_1_COMMENT_P_2_1=
10+
PARTITION BY RANGE(i) (
11+
PARTITION pt1 VALUES LESS THAN (5) COMMENT='srv "s_2_1", table "ta_r2"',
12+
PARTITION pt2 VALUES LESS THAN (10) COMMENT='srv "s_2_1", table "ta_r3"',
13+
PARTITION pt3 VALUES LESS THAN MAXVALUE COMMENT='srv "s_2_1", table "ta_r4"'
14+
);
15+
--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES
16+
let $CHILD2_1_CREATE_TABLES=
17+
CREATE TABLE ta_r2 (
18+
i INT,
19+
j JSON,
20+
PRIMARY KEY(i)
21+
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON
22+
CREATE TABLE ta_r3 (
23+
i INT,
24+
j JSON,
25+
PRIMARY KEY(i)
26+
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET $STR_SEMICOLON
27+
CREATE TABLE ta_r4 (
28+
i INT,
29+
j JSON,
30+
PRIMARY KEY(i)
31+
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
for master_1
2+
for child2
3+
child2_1
4+
child2_2
5+
child2_3
6+
for child3
7+
8+
this test is for MDEV-24523
9+
10+
drop and create databases
11+
connection master_1;
12+
CREATE DATABASE auto_test_local;
13+
USE auto_test_local;
14+
connection child2_1;
15+
CREATE DATABASE auto_test_remote;
16+
USE auto_test_remote;
17+
18+
create table and insert
19+
connection child2_1;
20+
CHILD2_1_CREATE_TABLES
21+
connection master_1;
22+
CREATE TABLE tbl_a (
23+
i INT,
24+
j JSON,
25+
PRIMARY KEY(i)
26+
) ENGINE=Spider PARTITION BY RANGE(i) (
27+
PARTITION pt1 VALUES LESS THAN (5) COMMENT='srv "s_2_1", table "ta_r2"',
28+
PARTITION pt2 VALUES LESS THAN (10) COMMENT='srv "s_2_1", table "ta_r3"',
29+
PARTITION pt3 VALUES LESS THAN MAXVALUE COMMENT='srv "s_2_1", table "ta_r4"'
30+
)
31+
INSERT INTO tbl_a VALUES (1, '{ "a": 1, "b": [2, 3]}');
32+
33+
test 1
34+
connection master_1;
35+
UPDATE tbl_a SET j = JSON_REPLACE(j, '$.a', 10, '$.c', '[1, 2]');
36+
SELECT * FROM tbl_a;
37+
i j
38+
1 {"a": 10, "b": [2, 3]}
39+
TRUNCATE TABLE tbl_a;
40+
INSERT INTO tbl_a VALUES (1, '{ "a": 1, "b": [2, 3]}');
41+
UPDATE tbl_a SET j = JSON_REPLACE(j, '$.a', 10, '$.b', '[1, 2]');
42+
SELECT * FROM tbl_a;
43+
i j
44+
1 {"a": 10, "b": "[1, 2]"}
45+
46+
deinit
47+
connection master_1;
48+
DROP DATABASE IF EXISTS auto_test_local;
49+
connection child2_1;
50+
DROP DATABASE IF EXISTS auto_test_remote;
51+
for master_1
52+
for child2
53+
child2_1
54+
child2_2
55+
child2_3
56+
for child3
57+
58+
end of test
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
!include include/default_mysqld.cnf
2+
!include ../my_1_1.cnf
3+
!include ../my_2_1.cnf
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
--source ../include/mdev_24523_init.inc
2+
--echo
3+
--echo this test is for MDEV-24523
4+
--echo
5+
--echo drop and create databases
6+
7+
--connection master_1
8+
--disable_warnings
9+
CREATE DATABASE auto_test_local;
10+
USE auto_test_local;
11+
12+
--connection child2_1
13+
CREATE DATABASE auto_test_remote;
14+
USE auto_test_remote;
15+
--enable_warnings
16+
17+
--echo
18+
--echo create table and insert
19+
20+
--connection child2_1
21+
--disable_query_log
22+
--disable_ps_protocol
23+
echo CHILD2_1_CREATE_TABLES;
24+
eval $CHILD2_1_CREATE_TABLES;
25+
--enable_ps_protocol
26+
--enable_query_log
27+
28+
--connection master_1
29+
--disable_query_log
30+
echo CREATE TABLE tbl_a (
31+
i INT,
32+
j JSON,
33+
PRIMARY KEY(i)
34+
) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1;
35+
eval CREATE TABLE tbl_a (
36+
i INT,
37+
j JSON,
38+
PRIMARY KEY(i)
39+
) $MASTER_1_ENGINE $MASTER_1_COMMENT_P_2_1;
40+
--enable_query_log
41+
INSERT INTO tbl_a VALUES (1, '{ "a": 1, "b": [2, 3]}');
42+
43+
--echo
44+
--echo test 1
45+
46+
--connection master_1
47+
UPDATE tbl_a SET j = JSON_REPLACE(j, '$.a', 10, '$.c', '[1, 2]');
48+
SELECT * FROM tbl_a;
49+
TRUNCATE TABLE tbl_a;
50+
INSERT INTO tbl_a VALUES (1, '{ "a": 1, "b": [2, 3]}');
51+
UPDATE tbl_a SET j = JSON_REPLACE(j, '$.a', 10, '$.b', '[1, 2]');
52+
SELECT * FROM tbl_a;
53+
--echo
54+
--echo deinit
55+
--disable_warnings
56+
57+
--connection master_1
58+
DROP DATABASE IF EXISTS auto_test_local;
59+
60+
--connection child2_1
61+
DROP DATABASE IF EXISTS auto_test_remote;
62+
63+
--enable_warnings
64+
--source ../include/mdev_24523_deinit.inc
65+
--echo
66+
--echo end of test

0 commit comments

Comments
 (0)