Skip to content

Commit

Permalink
Use upstream method of forcing group by plan
Browse files Browse the repository at this point in the history
Summary:
For debug builds, the debug variable force_lis_for_group_by can be used to force a group by plan.

Squash with: D14521084 (facebook/mysql-5.6@d19291c)

Reviewed By: george-reynya

Differential Revision: D28815653

fbshipit-source-id: 7559ea5f927
  • Loading branch information
lth authored and facebook-github-bot committed Jun 3, 2021
1 parent 125380f commit 90fd80d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
8 changes: 4 additions & 4 deletions mysql-test/suite/rocksdb/r/group_min_max.result
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set global debug="+d,force_group_by";
set global debug="+d,force_lis_for_group_by";
drop table if exists t1;
create table t1 (
a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(248) default ' '
Expand Down Expand Up @@ -2679,12 +2679,12 @@ a
BB
EXPLAIN SELECT a FROM t1 WHERE a='AA' GROUP BY a;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref PRIMARY PRIMARY 7 const 1000 100.00 Using index
1 SIMPLE t1 NULL range PRIMARY PRIMARY 7 NULL 501 100.00 Using where; Using index for group-by
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 'AA') group by `test`.`t1`.`a`
EXPLAIN SELECT a FROM t1 WHERE a='BB' GROUP BY a;
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 NULL ref PRIMARY PRIMARY 7 const 1000 100.00 Using index
1 SIMPLE t1 NULL range PRIMARY PRIMARY 7 NULL 501 100.00 Using where; Using index for group-by
Warnings:
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 'BB') group by `test`.`t1`.`a`
SELECT DISTINCT a FROM t1 WHERE a='BB';
Expand Down Expand Up @@ -4042,4 +4042,4 @@ Handler_read_rnd 0
Handler_read_rnd_next 0
DROP TABLE t1;
# End of test for Bug#18109609
set global debug="-d,force_group_by";
set global debug="-d,force_lis_for_group_by";
4 changes: 2 additions & 2 deletions mysql-test/suite/rocksdb/t/group_min_max.test
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
--source include/have_debug.inc
set global debug="+d,force_group_by";
set global debug="+d,force_lis_for_group_by";

let $engine=RocksDB;
--source include/group_min_max.inc

set global debug="-d,force_group_by";
set global debug="-d,force_lis_for_group_by";

8 changes: 1 addition & 7 deletions sql/opt_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3172,15 +3172,13 @@ int test_quick_select(THD *thd, Key_map keys_to_use, table_map prev_tables,
KEY_PART *key_parts;
KEY *key_info;
PARAM param;
bool force_group_by = false;

/*
Use the 3 multiplier as range optimizer allocates big PARAM structure
and may evaluate a subquery expression
TODO During the optimization phase we should evaluate only inexpensive
single-lookup subqueries.
*/
DBUG_EXECUTE_IF("force_group_by", force_group_by = true;);
uchar buff[STACK_BUFF_ALLOC];
if (check_stack_overrun(thd, 3 * STACK_MIN_SIZE + sizeof(PARAM), buff))
return 0; // Fatal error flag is set
Expand Down Expand Up @@ -3369,13 +3367,10 @@ int test_quick_select(THD *thd, Key_map keys_to_use, table_map prev_tables,
Opt_trace_context::RANGE_OPTIMIZER);
if (unlikely(trace->is_started()))
group_trp->trace_basic_info(&param, &grp_summary);
if (group_trp->cost_est < best_cost || force_group_by) {
if (group_trp->cost_est < best_cost) {
grp_summary.add("chosen", true);
best_trp = group_trp;
best_cost = best_trp->cost_est;
if (force_group_by) {
goto force_plan;
}
} else
grp_summary.add("chosen", false).add_alnum("cause", "cost");
}
Expand Down Expand Up @@ -3479,7 +3474,6 @@ int test_quick_select(THD *thd, Key_map keys_to_use, table_map prev_tables,
}
}

force_plan:
thd->mem_root = param.old_root;

/*
Expand Down

0 comments on commit 90fd80d

Please sign in to comment.