diff options
author | unknown <gkodinov@mysql.com> | 2006-06-19 13:22:42 +0300 |
---|---|---|
committer | unknown <gkodinov@mysql.com> | 2006-06-19 13:22:42 +0300 |
commit | 124cb126fa65fc1099256be5e269277bde815703 (patch) | |
tree | 106aa086fe749f7dd8a500936751d54dcad4ef40 /sql | |
parent | 6297d1ab38d1b2eb56c965c3cb682ac20b97296b (diff) | |
download | mariadb-git-124cb126fa65fc1099256be5e269277bde815703.tar.gz |
* Bug #9676: INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big
tables
Currently in INSERT ... SELECT ... LIMIT ... the compiler uses a
temporary table to store the results of SELECT ... LIMIT .. and then
uses that table as a source for INSERT. The problem is that in some cases
it actually skips the LIMIT clause in doing that and materializes the
whole SELECT result set regardless of the LIMIT.
This fix is limiting the process of filling up the temp table with only
that much rows that will be actually used by propagating the LIMIT value.
mysql-test/r/insert_select.result:
* Bug #9676: INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big
tables
- a test demonstrating the code path
mysql-test/t/insert_select.test:
* Bug #9676: INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big
tables
- a test demonstrating the code path
sql/sql_select.cc:
* Bug #9676: INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big
tables
- pass through the real LIMIT number if the temp table is created for
buffering results.
- set the counter for all the cases when the temp table is not used for
grouping
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_select.cc | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5a7e9e52aed..709ff9726bb 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -888,8 +888,9 @@ JOIN::optimize() group_list ? 0 : select_distinct, group_list && simple_group, select_options, - (order == 0 || skip_sort_order) ? select_limit : - HA_POS_ERROR, + (order == 0 || skip_sort_order || + test(select_options & OPTION_BUFFER_RESULT)) ? + select_limit : HA_POS_ERROR, (char *) ""))) DBUG_RETURN(1); @@ -5530,6 +5531,11 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, keyinfo->key_length+= key_part_info->length; } } + else + { + set_if_smaller(table->max_rows, rows_limit); + param->end_write_records= rows_limit; + } if (distinct && field_count != param->hidden_field_count) { @@ -5544,8 +5550,6 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, null_pack_length-=hidden_null_pack_length; keyinfo->key_parts= ((field_count-param->hidden_field_count)+ test(null_pack_length)); - set_if_smaller(table->max_rows, rows_limit); - param->end_write_records= rows_limit; table->distinct=1; table->keys=1; if (blob_count) |