diff options
-rw-r--r-- | sql/filesort.cc | 29 | ||||
-rw-r--r-- | sql/mysql_priv.h | 8 | ||||
-rw-r--r-- | sql/sql_delete.cc | 4 | ||||
-rw-r--r-- | sql/sql_select.cc | 19 | ||||
-rw-r--r-- | sql/sql_table.cc | 4 | ||||
-rw-r--r-- | sql/sql_test.cc | 4 | ||||
-rw-r--r-- | sql/sql_update.cc | 4 |
7 files changed, 28 insertions, 44 deletions
diff --git a/sql/filesort.cc b/sql/filesort.cc index 81629684a87..e1c673aca0b 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -63,24 +63,21 @@ static uint sortlength(SORT_FIELD *sortorder,uint length); table->record_pointers */ -ha_rows filesort(TABLE *table, SORT_FIELD *sortorder, uint s_length, - SQL_SELECT *select, ha_rows special, ha_rows max_rows, - ha_rows *examined_rows) +ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length, + SQL_SELECT *select, ha_rows max_rows, ha_rows *examined_rows) { int error; ulong memavl; uint maxbuffer; + uint i; BUFFPEK *buffpek; ha_rows records; uchar **sort_keys; IO_CACHE tempfile, buffpek_pointers, *selected_records_file, *outfile; SORTPARAM param; - THD *thd= current_thd; - - DBUG_ENTER("filesort"); - DBUG_EXECUTE("info",TEST_filesort(sortorder,s_length,special);); CHARSET_INFO *charset=table->table_charset; - uint i; + DBUG_ENTER("filesort"); + DBUG_EXECUTE("info",TEST_filesort(sortorder,s_length);); #ifdef SKIP_DBUG_IN_FILESORT DBUG_PUSH(""); /* No DBUG here */ #endif @@ -111,27 +108,15 @@ ha_rows filesort(TABLE *table, SORT_FIELD *sortorder, uint s_length, { statistic_increment(filesort_scan_count, &LOCK_status); } - if (select && my_b_inited(&select->file)) - { - records=special=select->records; /* purecov: deadcode */ - selected_records_file= &select->file; /* purecov: deadcode */ - reinit_io_cache(selected_records_file,READ_CACHE,0L,0,0); /* purecov: deadcode */ - } - else if (special) - { - records=special; /* purecov: deadcode */ - selected_records_file= outfile; /* purecov: deadcode */ - reinit_io_cache(selected_records_file,READ_CACHE,0L,0,0); /* purecov: deadcode */ - } #ifdef CAN_TRUST_RANGE - else if (select && select->quick && select->quick->records > 0L) + if (select && select->quick && select->quick->records > 0L) { records=min((ha_rows) (select->quick->records*2+EXTRA_RECORDS*2), table->file->records)+EXTRA_RECORDS; selected_records_file=0; } -#endif else +#endif { records=table->file->estimate_number_of_rows(); selected_records_file= 0; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index d8281af6bd1..6b8c4fd1f14 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -611,7 +611,7 @@ pthread_handler_decl(handle_manager, arg); #ifndef DBUG_OFF void print_where(COND *cond,const char *info); void print_cached_tables(void); -void TEST_filesort(SORT_FIELD *sortorder,uint s_length, ha_rows special); +void TEST_filesort(SORT_FIELD *sortorder,uint s_length); #endif void mysql_print_status(THD *thd); /* key.cc */ @@ -792,9 +792,9 @@ void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form, SQL_SELECT *select, int use_record_cache, bool print_errors); void end_read_record(READ_RECORD *info); -ha_rows filesort(TABLE *form,struct st_sort_field *sortorder, uint s_length, - SQL_SELECT *select, ha_rows special,ha_rows max_rows, - ha_rows *examined_rows); +ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder, + uint s_length, SQL_SELECT *select, + ha_rows max_rows, ha_rows *examined_rows); void change_double_for_sort(double nr,byte *to); int get_quick_record(SQL_SELECT *select); int calc_weekday(long daynr,bool sunday_first_day_of_week); diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 686fee0abe6..cb1a9db70cd 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -117,8 +117,8 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order, MYF(MY_FAE | MY_ZEROFILL)); if (setup_order(thd, &tables, fields, all_fields, order) || !(sortorder=make_unireg_sortorder(order, &length)) || - (table->found_records = filesort(table, sortorder, length, - (SQL_SELECT *) 0, 0L, HA_POS_ERROR, + (table->found_records = filesort(thd, table, sortorder, length, + (SQL_SELECT *) 0, HA_POS_ERROR, &examined_rows)) == HA_POS_ERROR) { diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c120dc9d16f..399bbbb5e66 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -112,7 +112,8 @@ static Item* part_of_refkey(TABLE *form,Field *field); static uint find_shortest_key(TABLE *table, key_map usable_keys); static bool test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order, ha_rows select_limit, bool no_changes); -static int create_sort_index(JOIN_TAB *tab,ORDER *order,ha_rows select_limit); +static int create_sort_index(THD *thd, JOIN_TAB *tab,ORDER *order, + ha_rows select_limit); static int remove_duplicates(JOIN *join,TABLE *entry,List<Item> &fields, Item *having); static int remove_dup_with_compare(THD *thd, TABLE *entry, Field **field, @@ -748,7 +749,7 @@ JOIN::exec() { DBUG_PRINT("info",("Sorting for group")); thd->proc_info="Sorting for group"; - if (create_sort_index(&join_tab[const_tables], group_list, + if (create_sort_index(thd, &join_tab[const_tables], group_list, HA_POS_ERROR) || make_sum_func_list(this, all_fields) || alloc_group_fields(this, group_list)) @@ -763,7 +764,7 @@ JOIN::exec() { DBUG_PRINT("info",("Sorting for order")); thd->proc_info="Sorting for order"; - if (create_sort_index(&join_tab[const_tables], order, + if (create_sort_index(thd, &join_tab[const_tables], order, HA_POS_ERROR)) DBUG_VOID_RETURN; order=0; @@ -866,7 +867,7 @@ JOIN::exec() if (group_list) { thd->proc_info="Creating sort index"; - if (create_sort_index(join_tab, group_list, HA_POS_ERROR) || + if (create_sort_index(thd, join_tab, group_list, HA_POS_ERROR) || alloc_group_fields(this, group_list)) { free_tmp_table(thd,tmp_table2); /* purecov: inspected */ @@ -962,7 +963,7 @@ JOIN::exec() DBUG_EXECUTE("where",print_where(conds,"having after sort");); } } - if (create_sort_index(&join_tab[const_tables], + if (create_sort_index(thd, &join_tab[const_tables], group_list ? group_list : order, (having_list || group_list || (select_options & OPTION_FOUND_ROWS)) ? @@ -5795,7 +5796,7 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit, *****************************************************************************/ static int -create_sort_index(JOIN_TAB *tab,ORDER *order,ha_rows select_limit) +create_sort_index(THD *thd, JOIN_TAB *tab,ORDER *order,ha_rows select_limit) { SORT_FIELD *sortorder; uint length; @@ -5839,8 +5840,8 @@ create_sort_index(JOIN_TAB *tab,ORDER *order,ha_rows select_limit) } if (table->tmp_table) table->file->info(HA_STATUS_VARIABLE); // Get record count - table->found_records=filesort(table,sortorder,length, - select, 0L, select_limit, &examined_rows); + table->found_records=filesort(thd, table,sortorder, length, + select, select_limit, &examined_rows); tab->records=table->found_records; // For SQL_CALC_ROWS delete select; // filesort did select tab->select=0; @@ -5938,7 +5939,7 @@ remove_duplicates(JOIN *join, TABLE *entry,List<Item> &fields, Item *having) int error; ulong reclength,offset; uint field_count; - THD *thd= current_thd; + THD *thd= join->thd; DBUG_ENTER("remove_duplicates"); entry->reginfo.lock_type=TL_WRITE; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index a71f555cdd7..bff07809861 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2099,8 +2099,8 @@ copy_data_between_tables(TABLE *from,TABLE *to, if (setup_order(thd, &tables, fields, all_fields, order) || !(sortorder=make_unireg_sortorder(order, &length)) || - (from->found_records = filesort(from, sortorder, length, - (SQL_SELECT *) 0, 0L, HA_POS_ERROR, + (from->found_records = filesort(thd, from, sortorder, length, + (SQL_SELECT *) 0, HA_POS_ERROR, &examined_rows)) == HA_POS_ERROR) goto err; diff --git a/sql/sql_test.cc b/sql/sql_test.cc index ef26a1f45fe..538417f43ea 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -97,7 +97,7 @@ void print_cached_tables(void) } -void TEST_filesort(SORT_FIELD *sortorder,uint s_length, ha_rows special) +void TEST_filesort(SORT_FIELD *sortorder,uint s_length) { char buff[256],buff2[256]; String str(buff,sizeof(buff),default_charset_info); @@ -131,8 +131,6 @@ void TEST_filesort(SORT_FIELD *sortorder,uint s_length, ha_rows special) out.append('\0'); // Purify doesn't like c_ptr() DBUG_LOCK_FILE; VOID(fputs("\nInfo about FILESORT\n",DBUG_FILE)); - if (special) - fprintf(DBUG_FILE,"Records to sort: %ld\n",special); fprintf(DBUG_FILE,"Sortorder: %s\n",out.ptr()); DBUG_UNLOCK_FILE; DBUG_VOID_RETURN; diff --git a/sql/sql_update.cc b/sql/sql_update.cc index f530c87dd61..c146b07284f 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -190,8 +190,8 @@ int mysql_update(THD *thd, MYF(MY_FAE | MY_ZEROFILL)); if (setup_order(thd, &tables, fields, all_fields, order) || !(sortorder=make_unireg_sortorder(order, &length)) || - (table->found_records = filesort(table, sortorder, length, - (SQL_SELECT *) 0, 0L, + (table->found_records = filesort(thd, table, sortorder, length, + (SQL_SELECT *) 0, HA_POS_ERROR, &examined_rows)) == HA_POS_ERROR) { |