diff options
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2889e1e1549..899cd05f712 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1,5 +1,5 @@ /* Copyright (c) 2000, 2016 Oracle and/or its affiliates. - Copyright (c) 2009, 2016 MariaDB + Copyright (c) 2009, 2017 MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -788,10 +788,15 @@ JOIN::prepare(TABLE_LIST *tables_init, if (mixed_implicit_grouping && tbl->table) tbl->table->maybe_null= 1; } + + uint real_og_num= og_num; + if (skip_order_by && + select_lex != select_lex->master_unit()->global_parameters()) + real_og_num+= select_lex->order_list.elements; if (setup_wild(thd, tables_list, fields_list, &all_fields, wild_num)) DBUG_RETURN(-1); - if (select_lex->setup_ref_array(thd, og_num)) + if (select_lex->setup_ref_array(thd, real_og_num)) DBUG_RETURN(-1); ref_ptrs= ref_ptr_array_slice(0); @@ -13010,9 +13015,12 @@ COND *Item_cond_and::build_equal_items(THD *thd, COND_EQUAL cond_equal; cond_equal.upper_levels= inherited; + if (check_stack_overrun(thd, STACK_MIN_SIZE, NULL)) + return this; // Fatal error flag is set! + List<Item> eq_list; List<Item> *cond_args= argument_list(); - + List_iterator<Item> li(*cond_args); Item *item; @@ -13022,7 +13030,7 @@ COND *Item_cond_and::build_equal_items(THD *thd, that are subject to substitution by multiple equality items and removing each such predicate from the conjunction after having found/created a multiple equality whose inference the predicate is. - */ + */ while ((item= li++)) { /* @@ -17826,7 +17834,7 @@ do_select(JOIN *join, Procedure *procedure) } join->procedure= procedure; - join->send_records=0; + join->duplicate_rows= join->send_records= 0; if (join->only_const_tables() && !join->need_tmp) { Next_select_func end_select= setup_end_select_func(join, NULL); @@ -17889,7 +17897,7 @@ do_select(JOIN *join, Procedure *procedure) error= join->first_select(join,join_tab,1); } - join->thd->limit_found_rows= join->send_records; + join->thd->limit_found_rows= join->send_records - join->duplicate_rows; if (error == NESTED_LOOP_NO_MORE_ROWS || join->thd->killed == ABORT_QUERY) error= NESTED_LOOP_OK; @@ -19503,10 +19511,14 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), } if (join->do_send_rows) { - int error; /* result < 0 if row was not accepted and should not be counted */ - if ((error= join->result->send_data(*fields))) - DBUG_RETURN(error < 0 ? NESTED_LOOP_OK : NESTED_LOOP_ERROR); + if (int error= join->result->send_data(*fields)) + { + if (error > 0) + DBUG_RETURN(NESTED_LOOP_ERROR); + // error < 0 => duplicate row + join->duplicate_rows++; + } } ++join->send_records; @@ -19652,7 +19664,7 @@ end_send_group(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), if (error < 0) { /* Duplicate row, don't count */ - join->send_records--; + join->duplicate_rows++; error= 0; } } |