summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRex <rex.johnston@mariadb.com>2023-02-02 06:29:05 +1200
committerRex <rex.johnston@mariadb.com>2023-02-14 14:46:21 +1200
commitd9395d42273a4ec4742fac528d8ecece1baaa151 (patch)
tree9d15538184d337a1c6b175fbadc3321ae31e9668
parentb05218e08f45a17f46d1b73cbb9dcb2969dc04cd (diff)
downloadmariadb-git-bb-10.4-MDEV-30334.tar.gz
MDEV-30334 Optimizer trace produces invalid JSON with WHERE subquerybb-10.4-MDEV-30334
Simple code rearrangement to stop it displaying an unsigned int in a String.
-rw-r--r--mysql-test/main/opt_trace.result17
-rw-r--r--mysql-test/main/opt_trace.test17
-rw-r--r--sql/sql_select.cc7
3 files changed, 39 insertions, 2 deletions
diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result
index 2eef0da62bb..a8277070438 100644
--- a/mysql-test/main/opt_trace.result
+++ b/mysql-test/main/opt_trace.result
@@ -8522,5 +8522,22 @@ SELECT a FROM t1 WHERE (a,b) in (SELECT @c,@d);
a
DROP TABLE t1;
#
+# MDEV-30334 Optimizer trace produces invalid JSON with WHERE subquery
+# Simple code rearrangement to stop it displaying an unsigned int in a String.
+#
+SET optimizer_trace= 'enabled=on';
+CREATE TABLE t1 (id INT PRIMARY KEY);
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (3),(4);
+SELECT * FROM t1 WHERE id < ( SELECT SUM(a) FROM t2 );
+id
+1
+2
+SELECT JSON_VALID(trace) FROM information_schema.optimizer_trace;
+JSON_VALID(trace)
+1
+DROP TABLE t1, t2;
+#
# End of 10.4 tests
#
diff --git a/mysql-test/main/opt_trace.test b/mysql-test/main/opt_trace.test
index 0785d828a07..1bc48b6f75a 100644
--- a/mysql-test/main/opt_trace.test
+++ b/mysql-test/main/opt_trace.test
@@ -678,5 +678,22 @@ SELECT a FROM t1 WHERE (a,b) in (SELECT @c,@d);
DROP TABLE t1;
--echo #
+--echo # MDEV-30334 Optimizer trace produces invalid JSON with WHERE subquery
+--echo # Simple code rearrangement to stop it displaying an unsigned int in a String.
+--echo #
+
+SET optimizer_trace= 'enabled=on';
+
+CREATE TABLE t1 (id INT PRIMARY KEY);
+INSERT INTO t1 VALUES (1),(2);
+CREATE TABLE t2 (a INT);
+INSERT INTO t2 VALUES (3),(4);
+
+SELECT * FROM t1 WHERE id < ( SELECT SUM(a) FROM t2 );
+SELECT JSON_VALID(trace) FROM information_schema.optimizer_trace;
+
+DROP TABLE t1, t2;
+
+--echo #
--echo # End of 10.4 tests
--echo #
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index eb54484fa51..228ce799457 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -27865,6 +27865,8 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
}
}
str->append(" */ ");
+ if (join && join->cleaned) // if this join has been cleaned
+ return; // the select_number printed above is all we have
}
str->append(STRING_WITH_LEN("select "));
@@ -27875,11 +27877,12 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type)
JOIN already cleaned up so it is dangerous to print items
because temporary tables they pointed on could be freed.
*/
- str->append('#');
- str->append(select_number);
+ str->append("#");
+ str->append_ulonglong(select_number);
return;
}
+
/* First add options */
if (options & SELECT_STRAIGHT_JOIN)
str->append(STRING_WITH_LEN("straight_join "));