Skip to content

Commit afbe3f7

Browse files
committed
Bug#21448719: WRONG RESULT FOR JSON VALUE IN OUTER JOIN WITH VIEW
Item_direct_view_ref overrides all the val_*() functions in order to ensure that they return NULL for the null-extended values of the inner table of an outer join. It does not override val_json(), so JSON values could in some cases come out as not NULL when NULL is expected. This patch provides an override for val_json() in Item_direct_view_ref, so that JSON gets the same handling of NULL as the other data types.
1 parent b6959fe commit afbe3f7

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

mysql-test/r/json.result

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12855,3 +12855,19 @@ null
1285512855
null
1285612856
null
1285712857
DROP TABLE t;
12858+
#
12859+
# Bug#21448719: WRONG RESULT FOR JSON VALUE IN OUTER JOIN WITH VIEW
12860+
#
12861+
CREATE TABLE t1(j1 JSON);
12862+
CREATE TABLE t2(j2 JSON);
12863+
CREATE VIEW v AS SELECT CAST('1' AS JSON) AS jv, j2 FROM t2;
12864+
INSERT INTO t1 VALUES ('1');
12865+
SELECT j1, jv, j2, JSON_ARRAY(j1, jv, j2) FROM t1 LEFT JOIN v ON j1 = jv;
12866+
j1 jv j2 JSON_ARRAY(j1, jv, j2)
12867+
1 NULL NULL [1, null, null]
12868+
INSERT INTO t2 VALUES ('1');
12869+
SELECT j1, jv, j2, JSON_ARRAY(j1, jv, j2) FROM t1 LEFT JOIN v ON j1 = jv;
12870+
j1 jv j2 JSON_ARRAY(j1, jv, j2)
12871+
1 1 1 [1, 1, 1]
12872+
DROP TABLE t1, t2;
12873+
DROP VIEW v;

mysql-test/t/json.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5783,6 +5783,19 @@ REPLACE INTO t SELECT j FROM t;
57835783
SELECT * FROM t;
57845784
DROP TABLE t;
57855785

5786+
--echo #
5787+
--echo # Bug#21448719: WRONG RESULT FOR JSON VALUE IN OUTER JOIN WITH VIEW
5788+
--echo #
5789+
CREATE TABLE t1(j1 JSON);
5790+
CREATE TABLE t2(j2 JSON);
5791+
CREATE VIEW v AS SELECT CAST('1' AS JSON) AS jv, j2 FROM t2;
5792+
INSERT INTO t1 VALUES ('1');
5793+
SELECT j1, jv, j2, JSON_ARRAY(j1, jv, j2) FROM t1 LEFT JOIN v ON j1 = jv;
5794+
INSERT INTO t2 VALUES ('1');
5795+
SELECT j1, jv, j2, JSON_ARRAY(j1, jv, j2) FROM t1 LEFT JOIN v ON j1 = jv;
5796+
DROP TABLE t1, t2;
5797+
DROP VIEW v;
5798+
57865799
# Local Variables:
57875800
# mode: sql
57885801
# sql-product: mysql

sql/item.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8772,6 +8772,17 @@ bool Item_direct_view_ref::val_bool()
87728772
}
87738773

87748774

8775+
bool Item_direct_view_ref::val_json(Json_wrapper *wr)
8776+
{
8777+
if (has_null_row())
8778+
{
8779+
null_value= TRUE;
8780+
return false;
8781+
}
8782+
return super::val_json(wr);
8783+
}
8784+
8785+
87758786
bool Item_direct_view_ref::is_null()
87768787
{
87778788
if (has_null_row())

sql/item.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4150,6 +4150,7 @@ class Item_direct_view_ref :public Item_direct_ref
41504150
virtual my_decimal *val_decimal(my_decimal *dec);
41514151
virtual String *val_str(String *str);
41524152
virtual bool val_bool();
4153+
virtual bool val_json(Json_wrapper *wr);
41534154
virtual bool is_null();
41544155
virtual bool send(Protocol *prot, String *tmp);
41554156
virtual type_conversion_status save_in_field(Field *field,

0 commit comments

Comments
 (0)