Skip to content

Commit

Permalink
MDEV-28649 json_array(false) in the definition of view return 0 inste…
Browse files Browse the repository at this point in the history
…ad of "true"

Using any boolean argument to a function in a view resulted in a view
definition like:

  select json_array(0) AS `json_array(false)`

This was imply the Item::print function used was from Item_int::print
rather than a specific Item_bool::print function.

Simplification to STRING_WITH_LEN noted from Alexey Botchkov's
patch after almost equivalent implementation.

Rather than EXPLAIN=JSON display "true", because its
json, it doesn't need quotes. Adjust the json_write to identify
boolean Items and then just print directly using add_bool.
  • Loading branch information
grooverdan committed Dec 13, 2024
1 parent 6dcd9de commit 4aaffae
Show file tree
Hide file tree
Showing 50 changed files with 237 additions and 208 deletions.
8 changes: 4 additions & 4 deletions mysql-test/main/derived_cond_pushdown.result
Original file line number Diff line number Diff line change
Expand Up @@ -15558,7 +15558,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ref key0 key0 5 test.t1.a 9 100.00 Using where
2 DERIVED t2 ALL idx_a NULL NULL NULL 90 100.00 Using temporary; Using filesort
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t1` left join (/* select#2 */ select `test`.`t2`.`a` AS `a`,max(`test`.`t2`.`b`) AS `max`,min(`test`.`t2`.`b`) AS `min` from `test`.`t2` group by `test`.`t2`.`a`) `t` on(`t`.`a` = `test`.`t1`.`a` and `test`.`t1`.`a` is not null) where 1
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`t`.`max` AS `max`,`t`.`min` AS `min` from `test`.`t1` left join (/* select#2 */ select `test`.`t2`.`a` AS `a`,max(`test`.`t2`.`b`) AS `max`,min(`test`.`t2`.`b`) AS `min` from `test`.`t2` group by `test`.`t2`.`a`) `t` on(`t`.`a` = `test`.`t1`.`a` and `test`.`t1`.`a` is not null) where true
explain format=json select t1.a,t.max,t.min
from t1 left join
(select a, max(t2.b) max, min(t2.b) min from t2 group by t2.a) t
Expand All @@ -15567,7 +15567,7 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
"const_condition": "1",
"const_condition": true,
"table": {
"table_name": "t1",
"access_type": "ALL",
Expand Down Expand Up @@ -16751,7 +16751,7 @@ EXPLAIN
"lateral": 1,
"query_block": {
"select_id": 3,
"const_condition": "1",
"const_condition": true,
"outer_ref_condition": "t4.c is not null",
"table": {
"table_name": "t3",
Expand Down Expand Up @@ -16942,7 +16942,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings:
Note 1003 /* select#1 */ select NULL AS `f`,`v2`.`f` AS `f` from `test`.`t1` `a` straight_join `test`.`t1` `b` join `test`.`v2` where 0
Note 1003 /* select#1 */ select NULL AS `f`,`v2`.`f` AS `f` from `test`.`t1` `a` straight_join `test`.`t1` `b` join `test`.`v2` where false
DROP VIEW v1,v2;
DROP TABLE t1;
#
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/derived_split_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ ANALYZE
"select_id": 1,
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"const_condition": "1",
"const_condition": true,
"table": {
"table_name": "t1",
"access_type": "ALL",
Expand Down
22 changes: 11 additions & 11 deletions mysql-test/main/derived_view.result
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t ALL NULL NULL NULL NULL 2 100.00 Using where
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t`.`a` AS `a` from `test`.`t1` left join (`test`.`t2` `t` join `test`.`t3`) on(`test`.`t`.`a` >= 1 and `test`.`t3`.`b` > 5) where 1 group by `test`.`t`.`a`
Note 1003 select `test`.`t`.`a` AS `a` from `test`.`t1` left join (`test`.`t2` `t` join `test`.`t3`) on(`test`.`t`.`a` >= 1 and `test`.`t3`.`b` > 5) where true group by `test`.`t`.`a`
SELECT t.a FROM t1 LEFT JOIN
(t2 t JOIN t3 ON t3.b > 5) ON t.a >= 1
GROUP BY t.a;
Expand All @@ -1066,7 +1066,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t2`.`a` >= 1 and `test`.`t3`.`b` > 5) where 1 group by `test`.`t2`.`a`
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t2`.`a` >= 1 and `test`.`t3`.`b` > 5) where true group by `test`.`t2`.`a`
SELECT t.a FROM t1 LEFT JOIN
(( SELECT * FROM t2 ) t JOIN t3 ON t3.b > 5) ON t.a >= 1
GROUP BY t.a;
Expand All @@ -1082,7 +1082,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where
1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t2`.`a` >= 1 and `test`.`t3`.`b` > 5) where 1 group by `test`.`t2`.`a`
Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t2`.`a` >= 1 and `test`.`t3`.`b` > 5) where true group by `test`.`t2`.`a`
SELECT t.a FROM t1 LEFT JOIN
(v1 t JOIN t3 ON t3.b > 5) ON t.a >= 1
GROUP BY t.a;
Expand Down Expand Up @@ -1351,7 +1351,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a`,0 AS `a`,0 AS `b` from `test`.`t2` semi join (dual) where 1
Note 1003 select `test`.`t2`.`a` AS `a`,0 AS `a`,0 AS `b` from `test`.`t2` semi join (dual) where true
SELECT * FROM t2 RIGHT JOIN v1 AS t ON t.a != 0
WHERE t.a IN (SELECT b FROM t1);
a a b
Expand All @@ -1364,7 +1364,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1003 select `test`.`t2`.`a` AS `a`,0 AS `a`,0 AS `b` from `test`.`t2` semi join (dual) where 1
Note 1003 select `test`.`t2`.`a` AS `a`,0 AS `a`,0 AS `b` from `test`.`t2` semi join (dual) where true
DROP VIEW v1;
DROP TABLE t1,t2;
#
Expand Down Expand Up @@ -1438,7 +1438,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 system NULL NULL NULL NULL 1 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select 6 AS `a`,5 AS `b` from `test`.`t3` where 1
Note 1003 /* select#1 */ select 6 AS `a`,5 AS `b` from `test`.`t3` where true
SELECT t.a,t.b FROM t3 RIGHT JOIN ((SELECT * FROM t1) AS t, t2) ON t2.b != 0
WHERE (t.a,t.b) NOT IN (SELECT 7, 5);
a b
Expand All @@ -1452,7 +1452,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 system NULL NULL NULL NULL 1 100.00
3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select 6 AS `a`,5 AS `b` from `test`.`t3` where 1
Note 1003 /* select#1 */ select 6 AS `a`,5 AS `b` from `test`.`t3` where true
SELECT t.a,t.b FROM t3 RIGHT JOIN (v1 AS t, t2) ON t2.b != 0
WHERE (t.a,t.b) NOT IN (SELECT 7, 5);
a b
Expand All @@ -1466,7 +1466,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t3 system NULL NULL NULL NULL 1 100.00
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 /* select#1 */ select 6 AS `a`,5 AS `b` from `test`.`t3` where 1
Note 1003 /* select#1 */ select 6 AS `a`,5 AS `b` from `test`.`t3` where true
DROP VIEW v1;
DROP TABLE t1,t2,t3;
#
Expand Down Expand Up @@ -2595,7 +2595,7 @@ EXPLAIN EXTENDED SELECT a FROM v1 WHERE a > 100 ORDER BY b;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings:
Note 1003 select 4 AS `a` from dual where 0 order by 1
Note 1003 select 4 AS `a` from dual where false order by 1
DROP VIEW v1;
DROP TABLE t1;
CREATE TABLE IF NOT EXISTS `galleries` (
Expand Down Expand Up @@ -3001,7 +3001,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ref key0 key0 5 test.t1.id 2 100.00
2 DERIVED t1 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index; Using filesort
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`v2`.`order_pk` AS `order_pk` from `test`.`t1` left join `test`.`v2` on(`v2`.`order_pk` = `test`.`t1`.`id`) where 1
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`v2`.`order_pk` AS `order_pk` from `test`.`t1` left join `test`.`v2` on(`v2`.`order_pk` = `test`.`t1`.`id`) where true
SELECT * FROM t1 LEFT JOIN v3 ON t1.id=v3.order_pk;
id order_pk
1 1
Expand All @@ -3015,7 +3015,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> ref key0 key0 5 test.t1.id 2 100.00
2 DERIVED t1 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index; Using filesort
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`v3`.`order_pk` AS `order_pk` from `test`.`t1` left join `test`.`v3` on(`v3`.`order_pk` = `test`.`t1`.`id`) where 1
Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`v3`.`order_pk` AS `order_pk` from `test`.`t1` left join `test`.`v3` on(`v3`.`order_pk` = `test`.`t1`.`id`) where true
DROP VIEW v1,v2,v3;
DROP TABLE t1;
set optimizer_switch=@exit_optimizer_switch;
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/main/explain.result
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
2 SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 Const row not found
2 SUBQUERY t system NULL NULL NULL NULL 0 0.00 Const row not found
Warnings:
Note 1003 /* select#1 */ select 1 AS `1` from `test`.`t1` where 0
Note 1003 /* select#1 */ select 1 AS `1` from `test`.`t1` where false
SET SESSION sql_mode=@old_sql_mode;
DROP TABLE t1;
End of 5.0 tests.
Expand Down Expand Up @@ -396,7 +396,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 0 0.00 Const row not found
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
Warnings:
Note 1003 /* select#1 */ select NULL AS `a` from (/* select#2 */ select NULL AS `a` from `test`.`t1` where 0) `t`
Note 1003 /* select#1 */ select NULL AS `a` from (/* select#2 */ select NULL AS `a` from `test`.`t1` where false) `t`
set optimizer_switch=@tmp_optimizer_switch;
DROP TABLE t1,t2;
#
Expand Down
6 changes: 3 additions & 3 deletions mysql-test/main/explain_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
"const_condition": "1",
"const_condition": true,
"table": {
"table_name": "t1",
"access_type": "ALL",
Expand Down Expand Up @@ -1252,7 +1252,7 @@ EXPLAIN
{
"query_block": {
"select_id": 1,
"const_condition": "1",
"const_condition": true,
"table": {
"table_name": "t2",
"access_type": "const",
Expand All @@ -1277,7 +1277,7 @@ ANALYZE
"select_id": 1,
"r_loops": 1,
"r_total_time_ms": "REPLACED",
"const_condition": "1",
"const_condition": true,
"table": {
"table_name": "t2",
"access_type": "const",
Expand Down
8 changes: 4 additions & 4 deletions mysql-test/main/func_isnull.result
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE d1 IS NULL;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`d1` AS `d1` from `test`.`t1` where `test`.`t1`.`d1` = 0
Note 1003 select `test`.`t1`.`d1` AS `d1` from `test`.`t1` where `test`.`t1`.`d1` = false
SELECT count(*) FROM t1 WHERE d1 IS NULL;
count(*)
2
Expand All @@ -62,7 +62,7 @@ EXPLAIN EXTENDED SELECT * FROM v1 WHERE d1 IS NULL;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
Warnings:
Note 1003 select `test`.`t1`.`d1` AS `d1` from `test`.`t1` where `test`.`t1`.`d1` = 0
Note 1003 select `test`.`t1`.`d1` AS `d1` from `test`.`t1` where `test`.`t1`.`d1` = false
SELECT count(*) FROM v1 WHERE d1 IS NULL;
count(*)
2
Expand Down Expand Up @@ -90,7 +90,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t2`.`d1` AS `d1`,`test`.`t1`.`d1` AS `d1` from `test`.`t2` left join `test`.`t1` on(`test`.`t1`.`d1` = `test`.`t2`.`d1`) where `test`.`t1`.`d1` = 0 or `test`.`t1`.`d1` is null
Note 1003 select `test`.`t2`.`d1` AS `d1`,`test`.`t1`.`d1` AS `d1` from `test`.`t2` left join `test`.`t1` on(`test`.`t1`.`d1` = `test`.`t2`.`d1`) where `test`.`t1`.`d1` = false or `test`.`t1`.`d1` is null
SELECT * FROM t2 LEFT JOIN v1 ON t2.d1=v1.d1 WHERE v1.d1 IS NULL;
d1 d1
0000-00-00 00:00:00 0000-00-00 00:00:00
Expand All @@ -102,7 +102,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t2`.`d1` AS `d1`,`test`.`t1`.`d1` AS `d1` from `test`.`t2` left join (`test`.`t1`) on(`test`.`t1`.`d1` = `test`.`t2`.`d1`) where `test`.`t1`.`d1` = 0 or `test`.`t1`.`d1` is null
Note 1003 select `test`.`t2`.`d1` AS `d1`,`test`.`t1`.`d1` AS `d1` from `test`.`t2` left join (`test`.`t1`) on(`test`.`t1`.`d1` = `test`.`t2`.`d1`) where `test`.`t1`.`d1` = false or `test`.`t1`.`d1` is null
DROP VIEW v1;
DROP TABLE t1,t2;
#
Expand Down
8 changes: 8 additions & 0 deletions mysql-test/main/func_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -1728,5 +1728,13 @@ Warnings:
Warning 4036 Character disallowed in JSON in argument 1 to function 'json_extract' at position 2
SET @@collation_connection= @save_collation_connection;
#
# MDEV-28649 json_array(false) in the definition of view return 0 instead of "true"
#
create view v1 as select json_array(false) as ja_false, json_array(true) as ja_true;
select * from v1;
ja_false ja_true
[false] [true]
drop view v1;
#
# End of 10.5 tests
#
9 changes: 9 additions & 0 deletions mysql-test/main/func_json.test
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,15 @@ SELECT JSON_EXTRACT('{"a": 1,"b": 2}','$.a');

SET @@collation_connection= @save_collation_connection;


--echo #
--echo # MDEV-28649 json_array(false) in the definition of view return 0 instead of "true"
--echo #

create view v1 as select json_array(false) as ja_false, json_array(true) as ja_true;
select * from v1;
drop view v1;

--echo #
--echo # End of 10.5 tests
--echo #
6 changes: 3 additions & 3 deletions mysql-test/main/having.result
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ explain extended select count(a) as b from t1 where a=0 having b >=0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings:
Note 1003 select count(NULL) AS `b` from dual where 0 having `b` >= 0
Note 1003 select count(NULL) AS `b` from dual where false having `b` >= 0
drop table t1;
CREATE TABLE t1 (
raw_id int(10) NOT NULL default '0',
Expand Down Expand Up @@ -467,7 +467,7 @@ HAVING (table2.f2 = 8 AND table1.f1 >= 6);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings:
Note 1003 select 0 AS `f1`,7 AS `f2` from `test`.`t1` `table1` join `test`.`t1` `table2` where 0 group by 0,7 having 1
Note 1003 select 0 AS `f1`,7 AS `f2` from `test`.`t1` `table1` join `test`.`t1` `table2` where false group by 0,7 having 1
EXPLAIN EXTENDED
SELECT table1.f1, table2.f2
FROM t1 AS table1
Expand All @@ -478,7 +478,7 @@ HAVING (table2.f2 = 8);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings:
Note 1003 select `test`.`table1`.`f1` AS `f1`,7 AS `f2` from `test`.`t1` `table1` join `test`.`t1` `table2` where 0 group by `test`.`table1`.`f1`,7 having 1
Note 1003 select `test`.`table1`.`f1` AS `f1`,7 AS `f2` from `test`.`t1` `table1` join `test`.`t1` `table2` where false group by `test`.`table1`.`f1`,7 having 1
DROP TABLE t1;
#
# Bug#52336 Segfault / crash in 5.1 copy_fields (param=0x9872980) at sql_select.cc:15355
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/having_cond_pushdown.result
Original file line number Diff line number Diff line change
Expand Up @@ -5046,7 +5046,7 @@ EXPLAIN
"access_type": "ALL",
"rows": 2,
"filtered": 100,
"attached_condition": "t1.a = (subquery#2) and (1 or (subquery#2) > t1.b)"
"attached_condition": "t1.a = (subquery#2) and (true or (subquery#2) > t1.b)"
},
"subqueries": [
{
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/insert_returning.result
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ EXPLAIN EXTENDED INSERT INTO t1 SELECT * FROM t1 WHERE id1=9 RETURNING val1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings:
Note 1003 insert into `test`.`t1` select sql_buffer_result NULL AS `id1`,NULL AS `val1` from `test`.`t1` where 0
Note 1003 insert into `test`.`t1` select sql_buffer_result NULL AS `id1`,NULL AS `val1` from `test`.`t1` where false
EXPLAIN FORMAT="json" INSERT INTO t1 SELECT * FROM t1 WHERE id1=10 RETURNING val1;
EXPLAIN
{
Expand Down
Loading

0 comments on commit 4aaffae

Please sign in to comment.