diff options
author | unknown <timour/timka@lamia.home> | 2006-09-01 17:21:49 +0300 |
---|---|---|
committer | unknown <timour/timka@lamia.home> | 2006-09-01 17:21:49 +0300 |
commit | b133be170a01ce454e8ef0bd62469c499a79d3c0 (patch) | |
tree | 9b502751dba02536c557436c2cb88778e0250e00 /sql/sql_select.cc | |
parent | 49e2267ebda7809a1f93e61b4544ae800ed0705a (diff) | |
parent | b017caefbd5f95fcdc81f1f545fdc944a454d168 (diff) | |
download | mariadb-git-b133be170a01ce454e8ef0bd62469c499a79d3c0.tar.gz |
Merge lamia.home:/home/timka/mysql/src/4.1-virgin
into lamia.home:/home/timka/mysql/src/4.1-bug-21787
sql/sql_select.cc:
Auto merged
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r-- | sql/sql_select.cc | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index bb0895b3117..3b973f5d092 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -5616,11 +5616,6 @@ 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) { @@ -5683,6 +5678,20 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, 0 : FIELDFLAG_BINARY; } } + + /* + Push the LIMIT clause to the temporary table creation, so that we + materialize only up to 'rows_limit' records instead of all result records. + This optimization is not applicable when there is GROUP BY or there is + no GROUP BY, but there are aggregate functions, because both must be + computed for all result rows. + */ + if (!group && !thd->lex->current_select->with_sum_func) + { + set_if_smaller(table->max_rows, rows_limit); + param->end_write_records= rows_limit; + } + if (thd->is_fatal_error) // If end of memory goto err; /* purecov: inspected */ table->db_record_offset=1; |