Commit c172fe2c authored by unknown's avatar unknown

Merge ssmith@bk-internal.mysql.com:/home/bk/mysql-5.0-jonas

into  mysql.com:/home/stewart/Documents/MySQL/5.0/jonas

parents cfee84be cc12c914
...@@ -4811,6 +4811,17 @@ begin ...@@ -4811,6 +4811,17 @@ begin
declare x int; declare x int;
select id from t1 order by x; select id from t1 order by x;
end| end|
drop procedure if exists bug14945|
create table t3 (id int not null auto_increment primary key)|
create procedure bug14945() deterministic truncate t3|
insert into t3 values (null)|
call bug14945()|
insert into t3 values (null)|
select * from t3|
id
1
drop table t3|
drop procedure bug14945|
create procedure bug16474_2(x int) create procedure bug16474_2(x int)
select id from t1 order by x| select id from t1 order by x|
call bug16474_1()| call bug16474_1()|
......
...@@ -5666,6 +5666,21 @@ begin ...@@ -5666,6 +5666,21 @@ begin
select id from t1 order by x; select id from t1 order by x;
end| end|
#
# BUG#14945: Truncate table doesn't reset the auto_increment counter
#
--disable_warnings
drop procedure if exists bug14945|
--enable_warnings
create table t3 (id int not null auto_increment primary key)|
create procedure bug14945() deterministic truncate t3|
insert into t3 values (null)|
call bug14945()|
insert into t3 values (null)|
select * from t3|
drop table t3|
drop procedure bug14945|
# This does NOT order by column index; variable is an expression. # This does NOT order by column index; variable is an expression.
create procedure bug16474_2(x int) create procedure bug16474_2(x int)
select id from t1 order by x| select id from t1 order by x|
......
...@@ -123,8 +123,11 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) ...@@ -123,8 +123,11 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
If the storage manager of 'tl' gives exact row count, compute the total If the storage manager of 'tl' gives exact row count, compute the total
number of rows. If there are no outer table dependencies, this count number of rows. If there are no outer table dependencies, this count
may be used as the real count. may be used as the real count.
Schema tables are filled after this function is invoked, so we can't
get row count
*/ */
if (tl->table->file->table_flags() & HA_NOT_EXACT_COUNT) if ((tl->table->file->table_flags() & HA_NOT_EXACT_COUNT) ||
tl->schema_table)
{ {
is_exact_count= FALSE; is_exact_count= FALSE;
count= 1; // ensure count != 0 count= 1; // ensure count != 0
...@@ -149,31 +152,15 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) ...@@ -149,31 +152,15 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
switch (item_sum->sum_func()) { switch (item_sum->sum_func()) {
case Item_sum::COUNT_FUNC: case Item_sum::COUNT_FUNC:
/* /*
If the expr in count(expr) can never be null we can change this If the expr in COUNT(expr) can never be null we can change this
to the number of rows in the tables if this number is exact and to the number of rows in the tables if this number is exact and
there are no outer joins. there are no outer joins.
*/ */
if (!conds && !((Item_sum_count*) item)->args[0]->maybe_null && if (!conds && !((Item_sum_count*) item)->args[0]->maybe_null &&
!outer_tables && is_exact_count) !outer_tables && is_exact_count)
{ {
longlong count= 1; ((Item_sum_count*) item)->make_const(count);
TABLE_LIST *table; recalc_const_item= 1;
for (table= tables; table; table= table->next_leaf)
{
if (outer_tables || (table->table->file->table_flags() &
HA_NOT_EXACT_COUNT) || table->schema_table)
{
const_result= 0; // Can't optimize left join
break;
}
tables->table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
count*= table->table->file->records;
}
if (!table)
{
((Item_sum_count*) item)->make_const(count);
recalc_const_item= 1;
}
} }
else else
const_result= 0; const_result= 0;
......
...@@ -842,8 +842,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) ...@@ -842,8 +842,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
table_list->db, table_list->table_name); table_list->db, table_list->table_name);
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE) if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE))
|| thd->lex->sphead)
goto trunc_by_del; goto trunc_by_del;
if (lock_and_wait_for_table_name(thd, table_list)) if (lock_and_wait_for_table_name(thd, table_list))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
......
...@@ -3350,7 +3350,7 @@ mysql_execute_command(THD *thd) ...@@ -3350,7 +3350,7 @@ mysql_execute_command(THD *thd)
Don't allow this within a transaction because we want to use Don't allow this within a transaction because we want to use
re-generate table re-generate table
*/ */
if ((thd->locked_tables && !lex->sphead) || thd->active_transaction()) if (thd->locked_tables || thd->active_transaction())
{ {
my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
......
...@@ -72,6 +72,10 @@ else ...@@ -72,6 +72,10 @@ else
libexecdir="$basedir/libexec" libexecdir="$basedir/libexec"
fi fi
# datadir_set is used to determine if datadir was set (and so should be
# *not* set inside of the --basedir= handler.)
datadir_set=
# #
# Use LSB init script functions for printing messages, if possible # Use LSB init script functions for printing messages, if possible
# #
...@@ -105,11 +109,15 @@ parse_server_arguments() { ...@@ -105,11 +109,15 @@ parse_server_arguments() {
case "$arg" in case "$arg" in
--basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` --basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`
bindir="$basedir/bin" bindir="$basedir/bin"
datadir="$basedir/data" if test -z "$datadir_set"; then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin" sbindir="$basedir/sbin"
libexecdir="$basedir/libexec" libexecdir="$basedir/libexec"
;; ;;
--datadir=*) datadir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;; --datadir=*) datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`
datadir_set=1
;;
--user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;; --user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
--pid-file=*) server_pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;; --pid-file=*) server_pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
--use-mysqld_safe) use_mysqld_safe=1;; --use-mysqld_safe) use_mysqld_safe=1;;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment