[Commits] 2c33e6d29d7: c
revision-id: 2c33e6d29d7d9807641f9e3aec74c7a9b188905d (mariadb-10.3.6-138-g2c33e6d29d7) parent(s): 97e7676834c9a31c4ea10f7a10a69fa43b7d1a57 author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2019-02-18 23:40:30 +0100 message: c --- sql/group_by_handler.cc | 5 +++- sql/opt_subselect.cc | 3 --- sql/sql_class.cc | 13 ---------- sql/sql_class.h | 8 ++++++ sql/sql_delete.cc | 1 + sql/sql_error.cc | 2 +- sql/sql_insert.cc | 2 -- sql/sql_lex.h | 27 ++++++-------------- sql/sql_profile.cc | 2 +- sql/sql_repl.cc | 2 +- sql/sql_select.cc | 67 ++++++++++++++++++++++++++----------------------- sql/sql_union.cc | 3 --- 12 files changed, 59 insertions(+), 76 deletions(-) diff --git a/sql/group_by_handler.cc b/sql/group_by_handler.cc index f5ed24370b1..70a8d2a88cf 100644 --- a/sql/group_by_handler.cc +++ b/sql/group_by_handler.cc @@ -97,7 +97,10 @@ int Pushdown_query::execute(JOIN *join) { int error; /* result < 0 if row was not accepted and should not be counted */ - if (unlikely((error= join->result->send_data(*join->fields)))) + if (unlikely((error= + join->result->send_data_with_check(*join->fields, + join->unit, + join->send_records)))) { handler->end_scan(); DBUG_RETURN(error < 0 ? 0 : -1); diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 5362af5cdde..910c9485d56 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -5581,9 +5581,6 @@ int select_value_catcher::send_data(List<Item> &items) DBUG_ASSERT(!assigned); DBUG_ASSERT(items.elements == n_elements); - if (unit->lim.check_and_move_offset()) - DBUG_RETURN(0); // Using limit offset,count - Item *val_item; List_iterator_fast<Item> li(items); for (uint i= 0; (val_item= li++); i++) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 9166fd203b8..524b58fd9f3 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -2977,9 +2977,6 @@ int select_send::send_data(List<Item> &items) Protocol *protocol= thd->protocol; DBUG_ENTER("select_send::send_data"); - /* unit is not set when using 'delete ... returning' */ - if (unit && unit->lim.check_and_move_offset()) - DBUG_RETURN(FALSE); // using limit offset,count if (thd->killed == ABORT_QUERY) DBUG_RETURN(FALSE); @@ -3244,8 +3241,6 @@ int select_export::send_data(List<Item> &items) String tmp(buff,sizeof(buff),&my_charset_bin),*res; tmp.length(0); - if (unit->lim.check_and_move_offset()) - DBUG_RETURN(0); // using limit offset,count if (thd->killed == ABORT_QUERY) DBUG_RETURN(0); row_count++; @@ -3501,8 +3496,6 @@ int select_dump::send_data(List<Item> &items) Item *item; DBUG_ENTER("select_dump::send_data"); - if (unit->lim.check_and_move_offset()) - DBUG_RETURN(0); // using limit offset,count if (thd->killed == ABORT_QUERY) DBUG_RETURN(0); @@ -3541,8 +3534,6 @@ int select_singlerow_subselect::send_data(List<Item> &items) MYF(current_thd->lex->ignore ? ME_WARNING : 0)); DBUG_RETURN(1); } - if (unit->lim.check_and_move_offset()) - DBUG_RETURN(0); // Using limit offset,count if (thd->killed == ABORT_QUERY) DBUG_RETURN(0); List_iterator_fast<Item> li(items); @@ -3679,8 +3670,6 @@ int select_exists_subselect::send_data(List<Item> &items) { DBUG_ENTER("select_exists_subselect::send_data"); Item_exists_subselect *it= (Item_exists_subselect *)item; - if (unit->lim.check_and_move_offset()) - DBUG_RETURN(0); // Using limit offset,count if (thd->killed == ABORT_QUERY) DBUG_RETURN(0); it->value= 1; @@ -4085,8 +4074,6 @@ int select_dumpvar::send_data(List<Item> &items) { DBUG_ENTER("select_dumpvar::send_data"); - if (unit->lim.check_and_move_offset()) - DBUG_RETURN(0); // using limit offset,count if (row_count++) { my_message(ER_TOO_MANY_ROWS, ER_THD(thd, ER_TOO_MANY_ROWS), MYF(0)); diff --git a/sql/sql_class.h b/sql/sql_class.h index fc8ac86c9e0..befc7a1229b 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -5114,6 +5114,14 @@ class select_result_sink: public Sql_alloc public: THD *thd; select_result_sink(THD *thd_arg): thd(thd_arg) {} + inline int send_data_with_check(List<Item> &items, + SELECT_LEX_UNIT *u, + ha_rows sent) + { + if (u->lim.check_offset(sent)) + return 0; + return send_data(items); + } /* send_data returns 0 on ok, 1 on error and -1 if data was ignored, for example for a duplicate row entry written to a temp table. diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 1630d335559..c55d3ee9143 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -742,6 +742,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, break; } + // no LIMIT / OFFSET if (with_select && result->send_data(select_lex->item_list) < 0) { error=1; diff --git a/sql/sql_error.cc b/sql/sql_error.cc index 6bb36dbb089..e20b7422630 100644 --- a/sql/sql_error.cc +++ b/sql/sql_error.cc @@ -813,7 +813,7 @@ bool mysqld_show_warnings(THD *thd, ulong levels_to_show) /* Skip levels that the user is not interested in */ if (!(levels_to_show & ((ulong) 1 << err->get_level()))) continue; - if (unit->lim.check_and_move_offset()) + if (unit->lim.check_offset(idx)) continue; // using limit offset,count if (idx > unit->lim.get_select_limit()) break; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index cd010ebc462..979f4ad6896 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3838,8 +3838,6 @@ int select_insert::send_data(List<Item> &values) DBUG_ENTER("select_insert::send_data"); bool error=0; - if (unit->lim.check_and_move_offset()) - DBUG_RETURN(0); // using limit offset,count if (unlikely(thd->killed == ABORT_QUERY)) DBUG_RETURN(0); diff --git a/sql/sql_lex.h b/sql/sql_lex.h index c251972b8ea..e49ff16c06b 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -826,51 +826,38 @@ bool print_explain_for_slow_log(LEX *lex, THD *thd, String *str); class Select_limit_counters { - ha_rows offset_limit_cnt_start, - select_limit_cnt, offset_limit_cnt; + ha_rows select_limit_cnt, offset_limit_cnt; public: Select_limit_counters(): - offset_limit_cnt_start(0), select_limit_cnt(0), offset_limit_cnt(0) {}; void set_limit(ha_rows limit, ha_rows offset) { - offset_limit_cnt_start= offset; + offset_limit_cnt= offset; select_limit_cnt= limit; - if (select_limit_cnt + offset_limit_cnt_start >= + if (select_limit_cnt + offset_limit_cnt >= select_limit_cnt) - select_limit_cnt+= offset_limit_cnt_start; + select_limit_cnt+= offset_limit_cnt; else select_limit_cnt= HA_POS_ERROR; - reset(); } void set_single_row() { - offset_limit_cnt= offset_limit_cnt_start= 0; + offset_limit_cnt= 0; select_limit_cnt= 1; } - void reset() - { - offset_limit_cnt= offset_limit_cnt_start; - } - bool is_unlimited() { return select_limit_cnt == HA_POS_ERROR; } void set_unlimited() { select_limit_cnt= HA_POS_ERROR; offset_limit_cnt= 0; } - bool check_and_move_offset() + bool check_offset(ha_rows sent) { - if (offset_limit_cnt) - { - offset_limit_cnt--; - return TRUE; - } - return FALSE; + return sent < offset_limit_cnt; } void remove_offset() { offset_limit_cnt= 0; } diff --git a/sql/sql_profile.cc b/sql/sql_profile.cc index e2b7b18faac..0e937aba6ff 100644 --- a/sql/sql_profile.cc +++ b/sql/sql_profile.cc @@ -438,7 +438,7 @@ bool PROFILING::show_profiles() double query_time_usecs= prof->m_end_time_usecs - prof->m_start_time_usecs; - if (unit->lim.check_and_move_offset()) + if (unit->lim.check_offset(idx)) continue; if (idx > unit->lim.get_select_limit()) break; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 26ff0e4ece3..64d3f845901 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -4011,7 +4011,7 @@ bool mysql_show_binlog_events(THD* thd) description_event, opt_master_verify_checksum)); ) { - if (!unit->lim.check_and_move_offset() && + if (!unit->lim.check_offset(event_count) && ev->net_send(protocol, linfo.log_file_name, pos)) { errmsg = "Net error"; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2b9f82f7a85..d96b00e0443 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3877,8 +3877,6 @@ JOIN::reinit() { DBUG_ENTER("JOIN::reinit"); - unit->lim.reset(); - first_record= false; group_sent= false; cleaned= false; @@ -4149,7 +4147,8 @@ void JOIN::exec_inner() { if (do_send_rows && (procedure ? (procedure->send_row(procedure_fields_list) || - procedure->end_of_records()) : result->send_data(fields_list)> 0)) + procedure->end_of_records()): + result->send_data_with_check(fields_list, unit, 0)> 0)) error= 1; else send_records= ((select_options & OPTION_FOUND_ROWS) ? 1 : @@ -13974,7 +13973,7 @@ return_zero_rows(JOIN *join, select_result *result, List<TABLE_LIST> &tables, { bool send_error= FALSE; if (send_row) - send_error= result->send_data(fields) > 0; + send_error= result->send_data_with_check(fields, join->unit, 0) > 0; if (likely(!send_error)) result->send_eof(); // Should be safe } @@ -19403,33 +19402,34 @@ do_select(JOIN *join, Procedure *procedure) HAVING will be checked after processing aggregate functions, But WHERE should checked here (we alredy have read tables). Notice that make_join_select() splits all conditions in this case - into two groups exec_const_cond and outer_ref_cond. - If join->table_count == join->const_tables then it is - sufficient to check only the condition pseudo_bits_cond. - */ - DBUG_ASSERT(join->outer_ref_cond == NULL); - if (!join->pseudo_bits_cond || join->pseudo_bits_cond->val_int()) - { - // HAVING will be checked by end_select - error= (*end_select)(join, 0, 0); - if (error >= NESTED_LOOP_OK) - error= (*end_select)(join, 0, 1); - - /* - If we don't go through evaluate_join_record(), do the counting - here. join->send_records is increased on success in end_send(), - so we don't touch it here. + into two groups exec_const_cond and outer_ref_cond. + If join->table_count == join->const_tables then it is + sufficient to check only the condition pseudo_bits_cond. */ - join->join_examined_rows++; - DBUG_ASSERT(join->join_examined_rows <= 1); - } - else if (join->send_row_on_empty_set()) - { - if (!join->having || join->having->val_int()) + DBUG_ASSERT(join->outer_ref_cond == NULL); + if (!join->pseudo_bits_cond || join->pseudo_bits_cond->val_int()) { - List<Item> *columns_list= (procedure ? &join->procedure_fields_list : + // HAVING will be checked by end_select + error= (*end_select)(join, 0, 0); + if (error >= NESTED_LOOP_OK) + error= (*end_select)(join, 0, 1); + + /* + If we don't go through evaluate_join_record(), do the counting + here. join->send_records is increased on success in end_send(), + so we don't touch it here. + */ + join->join_examined_rows++; + DBUG_ASSERT(join->join_examined_rows <= 1); + } + else if (join->send_row_on_empty_set()) + { + if (!join->having || join->having->val_int()) + { + List<Item> *columns_list= (procedure ? &join->procedure_fields_list : join->fields); - rc= join->result->send_data(*columns_list) > 0; + rc= join->result->send_data_with_check(*columns_list, + join->unit, 0) > 0; } } /* @@ -21104,7 +21104,9 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), { int error; /* result < 0 if row was not accepted and should not be counted */ - if (unlikely((error= join->result->send_data(*fields)))) + if (unlikely((error= join->result->send_data_with_check(*fields, + join->unit, + 0)))) { if (error > 0) DBUG_RETURN(NESTED_LOOP_ERROR); @@ -21252,7 +21254,9 @@ end_send_group(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), { if (join->do_send_rows) { - error=join->result->send_data(*fields); + error= join->result->send_data_with_check(*fields, + join->unit, + join->send_records); if (unlikely(error < 0)) { /* Duplicate row, don't count */ @@ -25401,7 +25405,8 @@ int JOIN::rollup_send_data(uint idx) if ((!having || having->val_int())) { if (send_records < unit->lim.get_select_limit() && do_send_rows && - (res= result->send_data(rollup.fields[i])) > 0) + (res= result->send_data_with_check(rollup.fields[i], + unit, send_records)) > 0) return 1; if (!res) send_records++; diff --git a/sql/sql_union.cc b/sql/sql_union.cc index d563301a339..6a841f178e1 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -110,8 +110,6 @@ int select_unit::send_data(List<Item> &values) { int rc; int not_reported_error= 0; - if (unit->lim.check_and_move_offset()) - return 0; // using limit offset,count if (thd->killed == ABORT_QUERY) return 0; if (table->no_rows_with_nulls) @@ -1474,7 +1472,6 @@ bool st_select_lex_unit::exec() } if (!sl->tvc) saved_error= sl->join->error; - lim.reset(); if (likely(!saved_error)) { examined_rows+= thd->get_examined_row_count();
participants (1)
-
Oleksandr Byelkin