summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authormsvensson@neptunus.(none) <>2006-09-04 11:45:43 +0200
committermsvensson@neptunus.(none) <>2006-09-04 11:45:43 +0200
commit4d0430c8fde8c5c20afee073775210c7f13f7a44 (patch)
tree35ea1bfde5b4b93184a20d2ef76ea38142079cf7 /sql/sql_select.cc
parent1bea6cf1a2f0de200dd3a218161ebaa36ec960c3 (diff)
parent462c22c1ae52cc97f0a201532ecdf12d1f2cfc9c (diff)
downloadmariadb-git-4d0430c8fde8c5c20afee073775210c7f13f7a44.tar.gz
Merge dl145s:/data/tkatchaounov/5.0-bug-21787
into neptunus.(none):/home/msvensson/mysql/mysql-5.0
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc21
1 files changed, 14 insertions, 7 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 23ccb8c45b8..e9d0e003f6d 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -8994,11 +8994,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->s->max_rows, rows_limit);
- param->end_write_records= rows_limit;
- }
if (distinct && field_count != param->hidden_field_count)
{
@@ -9013,8 +9008,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->s->max_rows, rows_limit);
- param->end_write_records= rows_limit;
table->distinct= 1;
table->s->keys= 1;
if (blob_count)
@@ -9066,6 +9059,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->s->max_rows, rows_limit);
+ param->end_write_records= rows_limit;
+ }
+
if (thd->is_fatal_error) // If end of memory
goto err; /* purecov: inspected */
table->s->db_record_offset= 1;