summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <dlenev@mockturtle.local>2006-10-03 08:19:06 +0400
committerunknown <dlenev@mockturtle.local>2006-10-03 08:19:06 +0400
commit69e970a5ea9bc170217bd81c8d35c9212fd86de8 (patch)
tree80f891e304e98234086f12340de4a2932e6a1f74 /sql
parent9076d70e5b6a73b9280b198382764849904c7f6f (diff)
parent5d46e2993389f3cffe2a37374ba61334f86f7e5e (diff)
downloadmariadb-git-69e970a5ea9bc170217bd81c8d35c9212fd86de8.tar.gz
Merge bk-internal.mysql.com:/home/bk/mysql-4.1
into mockturtle.local:/home/dlenev/src/mysql-4.1-rt-merge sql/sql_select.cc: Auto merged
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_select.cc43
-rw-r--r--sql/sql_table.cc5
2 files changed, 27 insertions, 21 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 74a9fc573c4..33e923e1553 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -933,17 +933,28 @@ JOIN::optimize()
tmp_table_param.hidden_field_count= (all_fields.elements -
fields_list.elements);
+ ORDER *tmp_group= ((!simple_group && !procedure &&
+ !(test_flags & TEST_NO_KEY_GROUP)) ? group_list :
+ (ORDER*) 0);
+ /*
+ Pushing LIMIT to the temporary table creation is not applicable
+ when there is ORDER BY or GROUP BY or there is no GROUP BY, but
+ there are aggregate functions, because in all these cases we need
+ all result rows.
+ */
+ ha_rows tmp_rows_limit= ((order == 0 || skip_sort_order ||
+ test(select_options & OPTION_BUFFER_RESULT)) &&
+ !tmp_group &&
+ !thd->lex->current_select->with_sum_func) ?
+ select_limit : HA_POS_ERROR;
+
if (!(exec_tmp_table1 =
create_tmp_table(thd, &tmp_table_param, all_fields,
- ((!simple_group && !procedure &&
- !(test_flags & TEST_NO_KEY_GROUP)) ?
- group_list : (ORDER*) 0),
+ tmp_group,
group_list ? 0 : select_distinct,
group_list && simple_group,
select_options,
- (order == 0 || skip_sort_order ||
- test(select_options & OPTION_BUFFER_RESULT)) ?
- select_limit : HA_POS_ERROR,
+ tmp_rows_limit,
(char *) "")))
DBUG_RETURN(1);
@@ -5567,6 +5578,13 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
thd->variables.max_heap_table_size) :
thd->variables.tmp_table_size)/ table->reclength);
set_if_bigger(table->max_rows,1); // For dummy start options
+ /*
+ Push the LIMIT clause to the temporary table creation, so that we
+ materialize only up to 'rows_limit' records instead of all result records.
+ */
+ set_if_smaller(table->max_rows, rows_limit);
+ param->end_write_records= rows_limit;
+
keyinfo=param->keyinfo;
if (group)
@@ -5687,19 +5705,6 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
}
}
- /*
- 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;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index a5cb0d45664..da66b556b5e 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -214,7 +214,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
bool some_tables_deleted=0, tmp_table_deleted=0, foreign_key_error=0;
DBUG_ENTER("mysql_rm_table_part2");
- if (lock_table_names(thd, tables))
+ if (!drop_temporary && lock_table_names(thd, tables))
DBUG_RETURN(1);
for (table=tables ; table ; table=table->next)
@@ -311,7 +311,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
}
}
- unlock_table_names(thd, tables);
+ if (!drop_temporary)
+ unlock_table_names(thd, tables);
DBUG_RETURN(error);
}