summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2020-06-30 18:11:35 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2020-06-30 18:29:02 +0530
commitcc0dca366357651ddb549e31a12b1ecd39c7380e (patch)
tree863f06ec7ba49576f70079b475c1e9ae1a6e73aa
parent8e8f9671cbef43ef347e2c942de074278847241f (diff)
downloadmariadb-git-cc0dca366357651ddb549e31a12b1ecd39c7380e.tar.gz
MDEV-22910: SIGSEGV in Opt_trace_context::is_started & SIGSEGV in Json_writer::add_table_name (on optimized builds)
Make sure to initialize members of TABLE::reginfo when TABLE::init is called. In this case the problem was that table->reginfo.join_tab was set for the SELECT query and then was reused by the UPDATE query. This case occurred only when the SELECT query had a degenerate join.
-rw-r--r--mysql-test/main/opt_trace.result31
-rw-r--r--mysql-test/main/opt_trace.test11
-rw-r--r--sql/opt_range.cc6
-rw-r--r--sql/table.cc2
4 files changed, 46 insertions, 4 deletions
diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result
index 6da22802cca..ee1273decf6 100644
--- a/mysql-test/main/opt_trace.result
+++ b/mysql-test/main/opt_trace.result
@@ -8559,5 +8559,36 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_columns'))
]
]
drop table t1;
+#
+# MDEV-22910:SIGSEGV in Opt_trace_context::is_started & SIGSEGV in Json_writer::add_table_name
+# (on optimized builds)
+#
+CREATE TABLE t1( a INT, b INT, PRIMARY KEY( a ) );
+SELECT sum(b), row_number() OVER (order by b) FROM t1 WHERE a = 101;
+sum(b) row_number() OVER (order by b)
+NULL 1
+UPDATE t1 SET b=10 WHERE a=1;
+SELECT JSON_DETAILED(JSON_EXTRACT(trace, '$**.range_scan_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+JSON_DETAILED(JSON_EXTRACT(trace, '$**.range_scan_alternatives'))
+[
+
+ [
+
+ {
+ "index": "PRIMARY",
+ "ranges":
+ [
+ "(1) <= (a) <= (1)"
+ ],
+ "rowid_ordered": true,
+ "using_mrr": false,
+ "index_only": false,
+ "rows": 0,
+ "cost": 1.125,
+ "chosen": true
+ }
+ ]
+]
+DROP TABLE t1;
set optimizer_trace='enabled=off';
# End of 10.4 tests
diff --git a/mysql-test/main/opt_trace.test b/mysql-test/main/opt_trace.test
index 8633ed5b020..9040b5a54d0 100644
--- a/mysql-test/main/opt_trace.test
+++ b/mysql-test/main/opt_trace.test
@@ -611,5 +611,16 @@ EXPLAIN EXTENDED SELECT * from t1 WHERE b >= 10 and b < 25;
select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_columns')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
drop table t1;
+--echo #
+--echo # MDEV-22910:SIGSEGV in Opt_trace_context::is_started & SIGSEGV in Json_writer::add_table_name
+--echo # (on optimized builds)
+--echo #
+
+CREATE TABLE t1( a INT, b INT, PRIMARY KEY( a ) );
+SELECT sum(b), row_number() OVER (order by b) FROM t1 WHERE a = 101;
+UPDATE t1 SET b=10 WHERE a=1;
+SELECT JSON_DETAILED(JSON_EXTRACT(trace, '$**.range_scan_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE;
+DROP TABLE t1;
+
set optimizer_trace='enabled=off';
--echo # End of 10.4 tests
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index ecbf5d6afcb..86935f3ef27 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -2690,10 +2690,8 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
DBUG_PRINT("info",("Time to scan table: %g", read_time));
Json_writer_object table_records(thd);
- if (head->reginfo.join_tab)
- table_records.add_table_name(head->reginfo.join_tab);
- else
- table_records.add_table_name(head);
+ table_records.add_table_name(head);
+
Json_writer_object trace_range(thd, "range_analysis");
{
Json_writer_object table_rec(thd, "table_scan");
diff --git a/sql/table.cc b/sql/table.cc
index 648b1794582..7f2f008cba0 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -5160,6 +5160,8 @@ void TABLE::init(THD *thd, TABLE_LIST *tl)
fulltext_searched= 0;
file->ft_handler= 0;
reginfo.impossible_range= 0;
+ reginfo.join_tab= NULL;
+ reginfo.not_exists_optimize= FALSE;
created= TRUE;
cond_selectivity= 1.0;
cond_selectivity_sampling_explain= NULL;