Commit 7a45e7f2 authored by monty@hundin.mysql.fi's avatar monty@hundin.mysql.fi
Browse files

Fixed bug in UPDATE .. ORDER BY

parent 578ab3f1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -46491,6 +46491,8 @@ Our TODO section contains what we plan to have in 4.0. @xref{TODO MySQL 4.0}.
@itemize @bullet
@item
Fixed core dump bug in @code{UPDATE ... ORDER BY }.
@item
Changed @code{INSERT INTO .. SELECT} to by default stop on errors.
@item
Ignore @code{DATA DIRECTORY} and @code{INDEX DIRECTORY} directives on windows.
+10 −0
Original line number Diff line number Diff line
@@ -102,3 +102,13 @@ select status from t1;
status
1
drop table t1;
create table t1 (a int not null, b int not null);
insert into t1 values (1,1),(1,2),(1,3);
update t1 set b=4 where a=1 order by b asc limit 1;
update t1 set b=4 where a=1 order by b desc limit 1;
select * from t1;
a	b
1	4
1	4
1	2
drop table t1;
+11 −0
Original line number Diff line number Diff line
@@ -76,3 +76,14 @@ alter table t1 change lfdnr lfdnr int(10) unsigned default 0 not null auto_incre
update t1 set status=1 where type='Open';
select status from t1;
drop table t1;

#
# Test of ORDER BY
#

create table t1 (a int not null, b int not null);
insert into t1 values (1,1),(1,2),(1,3);
update t1 set b=4 where a=1 order by b asc limit 1;
update t1 set b=4 where a=1 order by b desc limit 1;
select * from t1;
drop table t1;
+1 −1
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ int mysql_update(THD *thd,
    used_key_is_modified=check_if_key_used(table, used_index, fields);
  else
    used_key_is_modified=0;
  if (used_key_is_modified)
  if (used_key_is_modified || order)
  {
    /*
    ** We can't update table directly;  We must first search after all
+4 −4
Original line number Diff line number Diff line
@@ -2305,10 +2305,6 @@ values:

update:
	UPDATE_SYM opt_low_priority opt_ignore table_name
        SET update_list 
        where_clause 
        opt_order_clause
        delete_limit_clause
	{ 
	  LEX *lex=Lex;
          lex->sql_command = SQLCOM_UPDATE;
@@ -2316,6 +2312,10 @@ update:
          lex->select->order_list.first=0;
          lex->select->order_list.next= (byte**) &lex->select->order_list.first;
        }
        SET update_list 
        where_clause 
        opt_order_clause
        delete_limit_clause

update_list:
	update_list ',' simple_ident equal expr