diff options
Diffstat (limited to 'sql/filesort.cc')
-rw-r--r-- | sql/filesort.cc | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/sql/filesort.cc b/sql/filesort.cc index 6d6bbe00182..220ff69a3e8 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -38,8 +38,8 @@ if (my_b_write((file),(byte*) (from),param->ref_length)) \ typedef struct st_buffpek { /* Struktur om sorteringsbuffrarna */ my_off_t file_pos; /* Where we are in the sort file */ - ha_rows count; /* Number of rows in table */ uchar *base,*key; /* key pointers */ + ha_rows count; /* Number of rows in table */ ulong mem_count; /* numbers of keys in memory */ ulong max_keys; /* Max keys in buffert */ } BUFFPEK; @@ -98,7 +98,6 @@ ha_rows filesort(TABLE **table, SORT_FIELD *sortorder, uint s_length, BUFFPEK *buffpek; ha_rows records; uchar **sort_keys; - gptr save_1,save_2; IO_CACHE tempfile,*selected_records_file,*outfile; SORTPARAM param; DBUG_ENTER("filesort"); @@ -109,7 +108,6 @@ ha_rows filesort(TABLE **table, SORT_FIELD *sortorder, uint s_length, outfile= table[0]->io_cache; my_b_clear(&tempfile); - save_1=save_2=0; buffpek= (BUFFPEK *) NULL; sort_keys= (uchar **) NULL; error= 1; maxbuffer=1; param.ref_length= table[0]->file->ref_length; @@ -148,7 +146,7 @@ ha_rows filesort(TABLE **table, SORT_FIELD *sortorder, uint s_length, else { table[0]->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);/* Get record-count */ - records=table[0]->file->records+EXTRA_RECORDS; + records=table[0]->file->estimate_number_of_rows(); selected_records_file= 0; } if (param.sort_length == param.ref_length && records > param.max_rows) @@ -160,16 +158,11 @@ ha_rows filesort(TABLE **table, SORT_FIELD *sortorder, uint s_length, goto err; #endif - /* Reserve memory for IO_CACHE files */ - if (! (save_1=my_malloc(DISK_BUFFER_SIZE,MYF(MY_WME))) || - ! (save_2=my_malloc(DISK_BUFFER_SIZE,MYF(MY_WME)))) - goto err; - memavl=sortbuff_size; while (memavl >= MIN_SORT_MEMORY) { - if ((records+1)*(param.sort_length+sizeof(char*))+sizeof(BUFFPEK)*10 < - (ulong) memavl) + if ((ulonglong) (records+1)*(param.sort_length+sizeof(char*))+sizeof(BUFFPEK)*10 < + (ulonglong) memavl) param.keys=(uint) records+1; else { @@ -207,10 +200,6 @@ ha_rows filesort(TABLE **table, SORT_FIELD *sortorder, uint s_length, my_error(ER_OUTOFMEMORY,MYF(ME_ERROR+ME_WAITTANG),sortbuff_size); goto err; } - my_free(save_1,MYF(0)); /* Free for later use */ - my_free(save_2,MYF(0)); - save_1=save_2=0; - param.sort_form= table[0]; param.end=(param.local_sortorder=sortorder)+s_length; if ((records=find_all_keys(¶m,select,sort_keys,buffpek,&maxbuffer, @@ -252,8 +241,6 @@ ha_rows filesort(TABLE **table, SORT_FIELD *sortorder, uint s_length, #endif x_free((gptr) sort_keys); x_free((gptr) buffpek); - x_free(save_1); - x_free(save_2); close_cached_file(&tempfile); if (my_b_inited(outfile)) { @@ -382,6 +369,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, } if (*killed) { + DBUG_PRINT("info",("Sort killed by user")); (void) file->extra(HA_EXTRA_NO_CACHE); file->rnd_end(); DBUG_RETURN(HA_POS_ERROR); /* purecov: inspected */ |