Skip to content

Commit

Permalink
Bug #30528604: DELETE THE PRE-ITERATOR EXECUTOR
Browse files Browse the repository at this point in the history
No queries should run in the pre-iterator executor anymore, so it is dead code.
(The sole exception was certain cases in the secondary engine mock, which has
been fixed in this patch.) Thus, remove it, as much as we can -- we are still
in the situation where the optimizer sets up data structures for an executor
that doesn't exist, but that's how it will be in the foreseeable future.

Many places used function pointers (e.g. sub_select and sub_select_op); these
have been replaced with enums, so that we can remove the functions in question
altogether. In particular, qep_tab[-1].next_select has been replaced with
a new qep_tab->op_type everywhere, that identifies which operation the given
QEP_TAB is supposed to do, e.g. materialization, grouping + materialization,
BNL, BKA, etc.. This means we need to allocate one extra QEP_TAB for now.

RAPID has been given a new hook for taking over the execution, since first_select
is gone.

There are many cleanups that would be possible but are too complex to be within
scope for this patch. As an example, Query_result_union_direct is all but dead
and could probably be removed; this would allow refactoring Query_result_union
(which now is nearly only about creating temporary tables) to not be a query
result anymore, which in turn would leave Query_result_interceptor up for removal,
and so on. In the same vein, the notion of SELECT_LEX having a Query_result on
its own is probably up for deletion.

All in all, this is a net deletion of more than 6500 lines of code.

Change-Id: I476b0491b9c7035128655ea83ec6c4dd168b0882
  • Loading branch information
Steinar H. Gunderson committed Dec 20, 2019
1 parent c73c493 commit ef166f8
Show file tree
Hide file tree
Showing 22 changed files with 2,412 additions and 9,034 deletions.
15 changes: 0 additions & 15 deletions mysql-test/r/derived_correlated.result
Original file line number Diff line number Diff line change
Expand Up @@ -2705,21 +2705,6 @@ trace
"join_explain": {
"select#": 1,
"steps": [
{
"creating_tmp_table": {
"tmp_table_info": {
"table": " `dt`",
"in_plan_at_position": 2,
"columns": 1,
"row_length": 5,
"key_length": 0,
"unique_constraint": false,
"makes_grouped_rows": false,
"cannot_insert_duplicates": false,
"location": "TempTable"
}
}
},
{
"join_explain": {
"select#": 2,
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/r/with_non_recursive.result
Original file line number Diff line number Diff line change
Expand Up @@ -2223,4 +2223,4 @@ with qn as (select 1) select * from qn;
use test;
show status like 'Created_tmp_disk_tables';
Variable_name Value
Created_tmp_disk_tables 23
Created_tmp_disk_tables 17
4 changes: 2 additions & 2 deletions mysql-test/r/with_recursive.result
Original file line number Diff line number Diff line change
Expand Up @@ -2643,7 +2643,7 @@ sum(n)
5050
show status like 'Created_tmp_disk_tables';
Variable_name Value
Created_tmp_disk_tables 53
Created_tmp_disk_tables 48
# Too long key (>3000 bytes in latin1)
with recursive cte as
(
Expand Down Expand Up @@ -2697,4 +2697,4 @@ Note 1003 with recursive `qn` as (/* select#2 */ select 1 AS `a` from `test`.`t1
drop table t1;
show status like 'Created_tmp_disk_tables';
Variable_name Value
Created_tmp_disk_tables 58
Created_tmp_disk_tables 51
4 changes: 2 additions & 2 deletions mysql-test/r/with_recursive_innodb_tmp_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ Warnings:
Note 1003 with recursive `q` (`b`) as (/* select#2 */ select 1 AS `1` union all /* select#3 */ select (1 + `q`.`b`) AS `1+b` from `q` where (`q`.`b` < 2000)) /* select#1 */ select min(`q`.`b`) AS `min(b)`,max(`q`.`b`) AS `max(b)`,avg(`q`.`b`) AS `avg(b)` from `q` where (`q`.`b` = 300)
show status like 'Created_tmp_disk_tables';
Variable_name Value
Created_tmp_disk_tables 2
Created_tmp_disk_tables 1
with recursive q (b) as
(select 1 union all select 1+b from q where b<2000)
select min(b),max(b),avg(b) from q where b=300;
min(b) max(b) avg(b)
300 300 300.0000
show status like 'Created_tmp_disk_tables';
Variable_name Value
Created_tmp_disk_tables 3
Created_tmp_disk_tables 2
# Verify that rows come out in insertion order.
# If they didn't, the sequences of @c and of 'b'
# would not be identical and the sum wouldn't be
Expand Down
40 changes: 5 additions & 35 deletions mysql-test/suite/opt_trace/r/general_no_prot_all.result
Original file line number Diff line number Diff line change
Expand Up @@ -4143,16 +4143,10 @@ WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2 IN ( 1 ) ) {
"table": "`t1`"
},
{
"table": "`t2`",
"unknown_key_1": {
"constant_condition_in_bnl": "(`t2`.`c2` = 1)"
}
"table": "`t2`"
},
{
"table": "`t2`",
"unknown_key_2": {
"constant_condition_in_bnl": "(`t2`.`c2` = 1)"
}
"table": "`t2`"
}
] /* refine_plan */
}
Expand Down Expand Up @@ -8721,10 +8715,7 @@ select * from t6 where d in (select f1() from t2 where s="c") {
"table": "`t6`"
},
{
"table": "`t2`",
"unknown_key_1": {
"constant_condition_in_bnl": "(`t2`.`s` = 'c')"
}
"table": "`t2`"
}
] /* refine_plan */
}
Expand Down Expand Up @@ -9778,10 +9769,7 @@ select d into res from t6 where d in (select f1() from t2 where s=arg) {
"table": "`t6`"
},
{
"table": "`t2`",
"unknown_key_1": {
"constant_condition_in_bnl": "(`t2`.`s` = <cache>(arg@0))"
}
"table": "`t2`"
}
] /* refine_plan */
}
Expand Down Expand Up @@ -11972,10 +11960,7 @@ select d into res from t6 where d in (select f1() from t2 where s=arg) {
"table": "`t6`"
},
{
"table": "`t2`",
"unknown_key_1": {
"constant_condition_in_bnl": "(`t2`.`s` = <cache>(arg@0))"
}
"table": "`t2`"
}
] /* refine_plan */
}
Expand Down Expand Up @@ -13192,21 +13177,6 @@ explain select * from v1 where id="b" {
"join_explain": {
"select#": 1,
"steps": [
{
"creating_tmp_table": {
"tmp_table_info": {
"table": "`v1`",
"in_plan_at_position": 0,
"columns": 2,
"row_length": 69,
"key_length": 64,
"unique_constraint": false,
"makes_grouped_rows": false,
"cannot_insert_duplicates": false,
"location": "TempTable"
} /* tmp_table_info */
} /* creating_tmp_table */
},
{
"join_explain": {
"select#": 2,
Expand Down
15 changes: 0 additions & 15 deletions mysql-test/suite/opt_trace/r/general_no_prot_none.result
Original file line number Diff line number Diff line change
Expand Up @@ -11895,21 +11895,6 @@ explain select * from v1 where id="b" {
"join_explain": {
"select#": 1,
"steps": [
{
"creating_tmp_table": {
"tmp_table_info": {
"table": "`v1`",
"in_plan_at_position": 0,
"columns": 2,
"row_length": 69,
"key_length": 64,
"unique_constraint": false,
"makes_grouped_rows": false,
"cannot_insert_duplicates": false,
"location": "TempTable"
} /* tmp_table_info */
} /* creating_tmp_table */
},
{
"join_explain": {
"select#": 2,
Expand Down
5 changes: 1 addition & 4 deletions mysql-test/suite/opt_trace/r/subquery_no_prot.result
Original file line number Diff line number Diff line change
Expand Up @@ -1771,10 +1771,7 @@ table2.`col_int_nokey` <> any ( select 5 from t2 ) ) and table1.`pk` in
"table_condition_attached": null
},
{
"table": "`t1` `table2`",
"unknown_key_1": {
"constant_condition_in_bnl": "<nop>(<in_optimizer>(`table2`.`col_int_nokey`,<exists>(/* select#3 */ select 5 from `t2` where <if>(outer_field_is_not_null, (<cache>(`table2`.`col_int_nokey`) <> 5), true))))"
}
"table": "`t1` `table2`"
}
] /* refine_plan */
}
Expand Down
7 changes: 3 additions & 4 deletions sql/abstract_query_plan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,9 @@ Join_plan::Join_plan(const JOIN *join)
from the next operation using a join buffer (instead of plain nested loop).
@return True if using a join buffer.
*/
bool Table_access::uses_join_cache() const
{
return get_qep_tab()->op &&
get_qep_tab()->op->type() == QEP_operation::OT_CACHE;
bool Table_access::uses_join_cache() const {
return get_qep_tab()->op_type == QEP_TAB::OT_BNL ||
get_qep_tab()->op_type == QEP_TAB::OT_BKA;
}

/**
Expand Down
24 changes: 0 additions & 24 deletions sql/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2084,30 +2084,6 @@ type_conversion_status Field_str::store_decimal(const my_decimal *d) {
return (err != E_DEC_OK) ? decimal_err_to_type_conv_status(err) : res;
}

uint Field::fill_cache_field(CACHE_FIELD *copy) {
uint store_length;
copy->str = ptr;
copy->length = pack_length();
copy->field = this;
if (flags & BLOB_FLAG || is_array()) {
copy->type = CACHE_BLOB;
copy->length -= portable_sizeof_char_ptr;
return copy->length;
} else if (!zero_pack() && (type() == MYSQL_TYPE_STRING &&
copy->length >= 4 && copy->length < 256)) {
copy->type = CACHE_STRIPPED; /* Remove end space */
store_length = 2;
} else if (type() == MYSQL_TYPE_VARCHAR) {
copy->type =
pack_length() - row_pack_length() == 1 ? CACHE_VARSTR1 : CACHE_VARSTR2;
store_length = 0;
} else {
copy->type = 0;
store_length = 0;
}
return copy->length + store_length;
}

bool Field::get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const {
char buff[MAX_DATE_STRING_REP_LENGTH];
String tmp(buff, sizeof(buff), &my_charset_bin), *res;
Expand Down
2 changes: 0 additions & 2 deletions sql/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -1566,8 +1566,6 @@ class Field {

void copy_data(ptrdiff_t src_record_offset);

uint fill_cache_field(CACHE_FIELD *copy);

virtual bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const;

virtual bool get_time(MYSQL_TIME *ltime) const;
Expand Down
20 changes: 8 additions & 12 deletions sql/item_cmpfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6611,18 +6611,14 @@ void Item_equal::print(const THD *thd, String *str,

longlong Item_func_trig_cond::val_int() {
if (trig_var == nullptr) {
DBUG_ASSERT(m_join != nullptr && m_idx >= 0);
switch (trig_type) {
case IS_NOT_NULL_COMPL:
trig_var = &m_join->qep_tab[m_idx].not_null_compl;
break;
case FOUND_MATCH:
trig_var = &m_join->qep_tab[m_idx].found;
break;
default:
DBUG_ASSERT(false); /* purecov: inspected */
return 0;
}
// We don't use trigger conditions for IS_NOT_NULL_COMPL / FOUND_MATCH in
// the iterator executor (except for figuring out which conditions are join
// conditions and which are from WHERE), so we remove them whenever we can.
// However, we don't prune them entirely from the query tree, so they may be
// left within e.g. sub-conditions of ORs. Open up the conditions so
// that we don't have conditions that are disabled during execution.
DBUG_ASSERT(trig_type == IS_NOT_NULL_COMPL || trig_type == FOUND_MATCH);
return args[0]->val_int();
}
return *trig_var ? args[0]->val_int() : 1;
}
Expand Down
8 changes: 3 additions & 5 deletions sql/opt_explain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1578,13 +1578,11 @@ bool Explain_join::explain_extra() {
if (tab->has_guarded_conds() && push_extra(ET_FULL_SCAN_ON_NULL_KEY))
return true;

if (tab->op && tab->op->type() == QEP_operation::OT_CACHE) {
const JOIN_CACHE::enum_join_cache_type t =
static_cast<JOIN_CACHE *>(tab->op)->cache_type();
if (tab->op_type == QEP_TAB::OT_BNL || tab->op_type == QEP_TAB::OT_BKA) {
StringBuffer<64> buff(cs);
if (t == JOIN_CACHE::ALG_BNL)
if (tab->op_type == QEP_TAB::OT_BNL)
buff.append("Block Nested Loop");
else if (t == JOIN_CACHE::ALG_BKA)
else if (tab->op_type == QEP_TAB::OT_BKA)
buff.append("Batched Key Access");
else
DBUG_ASSERT(0); /* purecov: inspected */
Expand Down
Loading

0 comments on commit ef166f8

Please sign in to comment.