From: Sergey Glukhov Date: May 12 2012 8:32am Subject: bzr push into mysql-trunk branch (sergey.glukhov:3824 to 3825) Bug#13948247 List-Archive: http://lists.mysql.com/commits/143861 X-Bug: 13948247 Message-Id: <201205120840.q4C8e0aE031328@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3825 Sergey Glukhov 2012-05-12 Bug#13948247 DIVISION BY 0 IN GET_BEST_DISJUNCT_QUICK WITH FORCE INDEX GROUP BY An attempt to create QUICK_SELECT object for empty table (BLACKHOLE is always empty) leads to 'DIVISION BY 0' crash. The fix is to skip QUICK_SELECT creation for empty table as it's meaningless. @ mysql-test/r/blackhole.result test case @ mysql-test/t/blackhole.test test case @ sql/opt_range.cc skip QUICK_SELECT creation for empty table modified: mysql-test/r/blackhole.result mysql-test/t/blackhole.test sql/opt_range.cc 3824 Gleb Shchepa 2012-05-11 Bug #13906945: EXPLAIN JSON DISPLAYS ATTACHED CONDITION WRONGLY IF INDEX_SUBQUERY The value of the "attached_condition" string in JSON EXPLAIN may display an outdated (unoptimized) expression text. For top query, shallow_explain() writes attached_condition, then explain_subqueries() runs JOIN::optimize() on subquery which *transforms* subquery, so the subquery text printed in top query's attached_condition becomes out-of-date. The abstract "Lazy" class has been introduced to emulate a lazy computation to evaluate expressions on demand. The Lazy_condition successor for this class has been introduced to defer Item tree pretty-printer call. @ mysql-test/r/explain_json_all.result New test. Updates for old tests. @ mysql-test/r/explain_json_none.result New test. Updates for old tests. @ mysql-test/r/innodb_explain_json_non_select_all.result Updates for old tests. @ mysql-test/r/innodb_explain_json_non_select_none.result Updates for old tests. @ mysql-test/r/myisam_explain_json_non_select_all.result Updates for old tests. @ mysql-test/r/myisam_explain_json_non_select_none.result Updates for old tests. @ mysql-test/r/subquery_sj_mat_nosj.result Updates for old tests. @ mysql-test/r/subquery_sj_none.result Updates for old tests. @ mysql-test/r/subquery_sj_none_bka.result Updates for old tests. @ mysql-test/r/subquery_sj_none_bka_nixbnl.result Updates for old tests. @ mysql-test/r/subquery_sj_none_bkaunique.result Updates for old tests. @ sql/opt_explain.cc * The Lazy_condition successor for the Lazy class has been introduced to defer Item tree pretty-printer call. * col_attached_condition string value has been replaced with a deferred calculation object to compute it later. @ sql/opt_explain_format.h * The abstract "Lazy" class has been introduced to emulate a lazy computation to evaluate procedures on demand. * The mem_root_str class has been modified to accept Lazy class object for further evaluation. @ sql/opt_explain_traditional.cc Minor update. modified: mysql-test/r/explain_json_all.result mysql-test/r/explain_json_none.result mysql-test/r/innodb_explain_json_non_select_all.result mysql-test/r/innodb_explain_json_non_select_none.result mysql-test/r/myisam_explain_json_non_select_all.result mysql-test/r/myisam_explain_json_non_select_none.result mysql-test/r/subquery_sj_mat_nosj.result mysql-test/r/subquery_sj_none.result mysql-test/r/subquery_sj_none_bka.result mysql-test/r/subquery_sj_none_bka_nixbnl.result mysql-test/r/subquery_sj_none_bkaunique.result sql/opt_explain.cc sql/opt_explain_format.h sql/opt_explain_traditional.cc === modified file 'mysql-test/r/blackhole.result' --- a/mysql-test/r/blackhole.result 2012-03-28 08:22:31 +0000 +++ b/mysql-test/r/blackhole.result 2012-05-12 08:31:02 +0000 @@ -9,3 +9,11 @@ SELECT 1 FROM t1 WHERE a = ANY (SELECT a 1 DROP TABLE t1, t2; End of 5.5 tests +# +# Bug#13948247 DIVISION BY 0 IN GET_BEST_DISJUNCT_QUICK WITH FORCE INDEX GROUP BY +# +CREATE TABLE t1(a INT, b INT, c INT, KEY(c), UNIQUE(a)) ENGINE = BLACKHOLE; +SELECT 0 FROM t1 FORCE INDEX FOR GROUP BY(a) WHERE a = 0 OR b = 0 AND c = 0; +0 +DROP TABLE t1; +End of 5.6 tests === modified file 'mysql-test/t/blackhole.test' --- a/mysql-test/t/blackhole.test 2012-03-28 08:22:31 +0000 +++ b/mysql-test/t/blackhole.test 2012-05-12 08:31:02 +0000 @@ -19,3 +19,12 @@ DROP TABLE t1, t2; --echo End of 5.5 tests +--echo # +--echo # Bug#13948247 DIVISION BY 0 IN GET_BEST_DISJUNCT_QUICK WITH FORCE INDEX GROUP BY +--echo # + +CREATE TABLE t1(a INT, b INT, c INT, KEY(c), UNIQUE(a)) ENGINE = BLACKHOLE; +SELECT 0 FROM t1 FORCE INDEX FOR GROUP BY(a) WHERE a = 0 OR b = 0 AND c = 0; +DROP TABLE t1; + +--echo End of 5.6 tests === modified file 'sql/opt_range.cc' --- a/sql/opt_range.cc 2012-05-09 16:47:39 +0000 +++ b/sql/opt_range.cc 2012-05-12 08:31:02 +0000 @@ -2817,7 +2817,8 @@ int SQL_SELECT::test_quick_select(THD *t { // Cannot return rows in descending order. if (thd->optimizer_switch_flag(OPTIMIZER_SWITCH_INDEX_MERGE) && - interesting_order != ORDER::ORDER_DESC) + interesting_order != ORDER::ORDER_DESC && + param.table->file->stats.records) { /* Try creating index_merge/ROR-union scan. */ SEL_IMERGE *imerge; @@ -4218,6 +4219,8 @@ TABLE_READ_PLAN *get_best_disjunct_quick DBUG_ENTER("get_best_disjunct_quick"); DBUG_PRINT("info", ("Full table scan cost: %g", read_time)); + DBUG_ASSERT(param->table->file->stats.records); + Opt_trace_context * const trace= ¶m->thd->opt_trace; Opt_trace_object trace_best_disjunct(trace); if (!(range_scans= (TRP_RANGE**)alloc_root(param->mem_root, No bundle (reason: useless for push emails).