diff options
author | Sergey Petrunia <sergefp@mysql.com> | 2008-07-15 18:13:21 +0400 |
---|---|---|
committer | Sergey Petrunia <sergefp@mysql.com> | 2008-07-15 18:13:21 +0400 |
commit | 62513bb1bca33902fa909ca13b25c550046ee3ae (patch) | |
tree | e53c78a5b0f2f37f7558020f80392ae283a65bf3 /sql/filesort.cc | |
parent | d5077086f73cfa24b8c4c9451fb70bc5a77922ae (diff) | |
download | mariadb-git-62513bb1bca33902fa909ca13b25c550046ee3ae.tar.gz |
BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- In QUICK_INDEX_MERGE_SELECT::read_keys_and_merge: when we got table->sort from Unique,
tell init_read_record() not to use rr_from_cache() because a) rowids are already sorted
and b) it might be that the the data is used by filesort(), which will need record rowids
(which rr_from_cache() cannot provide).
- Fully de-initialize the table->sort read in QUICK_INDEX_MERGE_SELECT::get_next(). This fixes BUG#35477.
(bk trigger: file as fix for BUG#35478).
sql/filesort.cc:
BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- make find_all_keys() use quick->get_next() instead of init_read_record(r)/r.read_record() calls
- added dbug printout
sql/mysql_priv.h:
BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- Added parameter to init_read_record
sql/opt_range.cc:
BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- In QUICK_INDEX_MERGE_SELECT::read_keys_and_merge: when we got table->sort from Unique,
tell init_read_record() not to use rr_from_cache() because a) rowids are already sorted
and b) it might be that the the data is used by filesort(), which will need record rowids
(which rr_from_cache() cannot provide).
- Fully de-initialize the table->sort read in QUICK_INDEX_MERGE_SELECT::get_next().
sql/records.cc:
BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- Added disable_rr_cache parameter to init_read_record
- Added comment
sql/sql_acl.cc:
BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- Added parameter to init_read_record
sql/sql_delete.cc:
BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- Added parameter to init_read_record
sql/sql_help.cc:
BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- Added parameter to init_read_record
sql/sql_select.cc:
BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- Added parameter to init_read_record
sql/sql_table.cc:
BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- Added parameter to init_read_record
sql/sql_udf.cc:
BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- Added parameter to init_read_record
sql/sql_update.cc:
BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- Added parameter to init_read_record
Diffstat (limited to 'sql/filesort.cc')
-rw-r--r-- | sql/filesort.cc | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/sql/filesort.cc b/sql/filesort.cc index 70fc6937b59..f56e5b3a771 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -402,6 +402,56 @@ static byte *read_buffpek_from_file(IO_CACHE *buffpek_pointers, uint count, DBUG_RETURN(tmp); } +#ifndef DBUG_OFF +/* + Print a text, SQL-like record representation into dbug trace. + + Note: this function is a work in progress: at the moment + - column read bitmap is ignored (can print garbage for unused columns) + - there is no quoting +*/ +static void dbug_print_record(TABLE *table, bool print_rowid) +{ + char buff[1024]; + Field **pfield; + String tmp(buff,sizeof(buff),&my_charset_bin); + DBUG_LOCK_FILE; + + fprintf(DBUG_FILE, "record ("); + for (pfield= table->field; *pfield ; pfield++) + fprintf(DBUG_FILE, "%s%s", (*pfield)->field_name, (pfield[1])? ", ":""); + fprintf(DBUG_FILE, ") = "); + + fprintf(DBUG_FILE, "("); + for (pfield= table->field; *pfield ; pfield++) + { + Field *field= *pfield; + + if (field->is_null()) + fwrite("NULL", sizeof(char), 4, DBUG_FILE); + + if (field->type() == MYSQL_TYPE_BIT) + (void) field->val_int_as_str(&tmp, 1); + else + field->val_str(&tmp); + + fwrite(tmp.ptr(),sizeof(char),tmp.length(),DBUG_FILE); + if (pfield[1]) + fwrite(", ", sizeof(char), 2, DBUG_FILE); + } + fprintf(DBUG_FILE, ")"); + if (print_rowid) + { + fprintf(DBUG_FILE, " rowid "); + for (uint i=0; i < table->file->ref_length; i++) + { + fprintf(DBUG_FILE, "%x", (uchar)table->file->ref[i]); + } + } + fprintf(DBUG_FILE, "\n"); + DBUG_UNLOCK_FILE; +} +#endif /* Search after sort_keys and write them into tempfile. @@ -475,25 +525,23 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, current_thd->variables.read_buff_size); } - READ_RECORD read_record_info; if (quick_select) { if (select->quick->reset()) DBUG_RETURN(HA_POS_ERROR); - init_read_record(&read_record_info, current_thd, select->quick->head, - select, 1, 1); } for (;;) { if (quick_select) { - if ((error= read_record_info.read_record(&read_record_info))) + if ((error= select->quick->get_next())) { error= HA_ERR_END_OF_FILE; break; } file->position(sort_form->record[0]); + DBUG_EXECUTE_IF("debug_filesort", dbug_print_record(sort_form, TRUE);); } else /* Not quick-select */ { @@ -550,15 +598,7 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, if (thd->net.report_error) break; } - if (quick_select) - { - /* - index_merge quick select uses table->sort when retrieving rows, so free - resoures it has allocated. - */ - end_read_record(&read_record_info); - } - else + if (!quick_select) { (void) file->extra(HA_EXTRA_NO_CACHE); /* End cacheing of records */ if (!next_pos) |