diff --git a/mysql-test/r/range_estimator.result b/mysql-test/r/range_estimator.result index bd5c8bb4aba..8a0da0484f6 100644 --- a/mysql-test/r/range_estimator.result +++ b/mysql-test/r/range_estimator.result @@ -838,3 +838,8 @@ Warnings: Note 1003 /* select#1 */ select `test`.`tbl_int`.`col1` AS `col1`,`test`.`tbl_int`.`col2` AS `col2` from `test`.`tbl_int` where ((`test`.`tbl_int`.`col2` = 2) and (`test`.`tbl_int`.`col1` >= 1)) DROP TABLE tbl_int; SET SESSION range_estimation = @savmode; +# postfix: Uninitialized range estimator for internal temporary tables +WITH v0 ( c1 ) AS ( SELECT -128 UNION SELECT NULL ) SELECT * FROM v0 AS v1, v0 AS v2 JOIN v0 AS v3 USING (c1); +c1 c1 +NULL -128 +-128 -128 diff --git a/mysql-test/t/range_estimator.test b/mysql-test/t/range_estimator.test index 4a4647ee6f0..a908a3b967a 100644 --- a/mysql-test/t/range_estimator.test +++ b/mysql-test/t/range_estimator.test @@ -348,3 +348,7 @@ EXPLAIN SELECT * FROM tbl_int WHERE col1 >= 1 and col2 = 2; DROP TABLE tbl_int; SET SESSION range_estimation = @savmode; + +--echo # postfix: Uninitialized range estimator for internal temporary tables + +WITH v0 ( c1 ) AS ( SELECT -128 UNION SELECT NULL ) SELECT * FROM v0 AS v1, v0 AS v2 JOIN v0 AS v3 USING (c1); diff --git a/sql/range_optimizer/range_estimator.cc b/sql/range_optimizer/range_estimator.cc index 455415b40cf..76b80bc37a3 100644 --- a/sql/range_optimizer/range_estimator.cc +++ b/sql/range_optimizer/range_estimator.cc @@ -59,10 +59,6 @@ void init_range_settings(Range_settings &settings, const RANGE_OPT_PARAM ¶m, } } -void Range_estimator::init(TABLE *tbl) { - table = tbl; -} - void Range_estimator::use_index(uint kr) { keyno = kr; diff --git a/sql/range_optimizer/range_estimator.h b/sql/range_optimizer/range_estimator.h index a986929342e..fd81746cc30 100644 --- a/sql/range_optimizer/range_estimator.h +++ b/sql/range_optimizer/range_estimator.h @@ -73,7 +73,7 @@ struct Range_settings { */ class Range_estimator { public: - void init(TABLE *_table); + Range_estimator(TABLE *_table) : table(_table) {} /// Set the index to evaluate key ranges. void use_index(uint keyno); diff --git a/sql/table.cc b/sql/table.cc index 748fd2c27ff..7a6a33c04e9 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4164,8 +4164,6 @@ void TABLE::init(THD *thd, Table_ref *tl) { pos_in_table_list = tl; tl->table = this; - range_estimator.init(this); - clear_column_bitmaps(); /* Tables may be reused in a sub statement. */ diff --git a/sql/table.h b/sql/table.h index 0f9adf2fe0a..029374cbe00 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1962,7 +1962,7 @@ struct TABLE { bool all_partitions_pruned_away{false}; MDL_ticket *mdl_ticket{nullptr}; - Range_estimator range_estimator; + Range_estimator range_estimator{this}; private: /// Cost model object for operations on this table