Skip to content

Commit 67745e4

Browse files
mariadb-RexJohnstonvuvova
authored andcommitted
MDEV-30334 Optimizer trace produces invalid JSON with WHERE subquery
Simple code rearrangement to stop it displaying an unsigned int in a String.
1 parent 552c477 commit 67745e4

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

mysql-test/main/opt_trace.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10374,6 +10374,23 @@ exp1 exp2
1037410374
] 1
1037510375
DROP TABLE t1;
1037610376
#
10377+
# MDEV-30334 Optimizer trace produces invalid JSON with WHERE subquery
10378+
# Simple code rearrangement to stop it displaying an unsigned int in a String.
10379+
#
10380+
SET optimizer_trace= 'enabled=on';
10381+
CREATE TABLE t1 (id INT PRIMARY KEY);
10382+
INSERT INTO t1 VALUES (1),(2);
10383+
CREATE TABLE t2 (a INT);
10384+
INSERT INTO t2 VALUES (3),(4);
10385+
SELECT * FROM t1 WHERE id < ( SELECT SUM(a) FROM t2 );
10386+
id
10387+
1
10388+
2
10389+
SELECT JSON_VALID(trace) FROM information_schema.optimizer_trace;
10390+
JSON_VALID(trace)
10391+
1
10392+
DROP TABLE t1, t2;
10393+
#
1037710394
# End of 10.4 tests
1037810395
#
1037910396
set optimizer_trace='enabled=on';

mysql-test/main/opt_trace.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,23 @@ SELECT b, a FROM t1 WHERE b <> 'p' OR a = 4 GROUP BY b, a HAVING a <= 7; SELECT
883883
DROP TABLE t1;
884884
--enable_view_protocol
885885

886+
--echo #
887+
--echo # MDEV-30334 Optimizer trace produces invalid JSON with WHERE subquery
888+
--echo # Simple code rearrangement to stop it displaying an unsigned int in a String.
889+
--echo #
890+
891+
SET optimizer_trace= 'enabled=on';
892+
893+
CREATE TABLE t1 (id INT PRIMARY KEY);
894+
INSERT INTO t1 VALUES (1),(2);
895+
CREATE TABLE t2 (a INT);
896+
INSERT INTO t2 VALUES (3),(4);
897+
898+
SELECT * FROM t1 WHERE id < ( SELECT SUM(a) FROM t2 );
899+
SELECT JSON_VALID(trace) FROM information_schema.optimizer_trace;
900+
901+
DROP TABLE t1, t2;
902+
886903
--echo #
887904
--echo # End of 10.4 tests
888905
--echo #

sql/sql_select.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30812,6 +30812,8 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
3081230812
}
3081330813
}
3081430814
str->append(STRING_WITH_LEN(" */ "));
30815+
if (join && join->cleaned) // if this join has been cleaned
30816+
return; // the select_number printed above is all we have
3081530817
}
3081630818

3081730819
if (sel_type == SELECT_CMD ||
@@ -30826,10 +30828,11 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
3082630828
because temporary tables they pointed on could be freed.
3082730829
*/
3082830830
str->append('#');
30829-
str->append(select_number);
30831+
str->append_ulonglong(select_number);
3083030832
return;
3083130833
}
3083230834

30835+
3083330836
/* First add options */
3083430837
if (options & SELECT_STRAIGHT_JOIN)
3083530838
str->append(STRING_WITH_LEN("straight_join "));

0 commit comments

Comments
 (0)