Commit c50f4be3 authored by unknown's avatar unknown
Browse files

Merge mysql.com:/usr/local/bk/mysql-5.0

into mysql.com:/home/pem/work/mysql-5.0


sql/item_subselect.cc:
  Auto merged
sql/mysql_priv.h:
  Auto merged
sql/sql_parse.cc:
  Auto merged
parents 2e113ada b1480cc0
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -133,13 +133,13 @@ Table Op Msg_type Msg_text
test.t3	analyze	status	Table is already up to date
explain select a1, min(a2) from t1 group by a1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	NULL	idx_t1_1	65	NULL	5	Using index for group-by
1	SIMPLE	t1	range	NULL	idx_t1_1	130	NULL	5	Using index for group-by
explain select a1, max(a2) from t1 group by a1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	NULL	idx_t1_1	65	NULL	5	Using index for group-by
explain select a1, min(a2), max(a2) from t1 group by a1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	NULL	idx_t1_1	65	NULL	5	Using index for group-by
1	SIMPLE	t1	range	NULL	idx_t1_1	130	NULL	5	Using index for group-by
explain select a1, a2, b, min(c), max(c) from t1 group by a1,a2,b;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	NULL	idx_t1_1	147	NULL	17	Using index for group-by
@@ -151,13 +151,13 @@ id select_type table type possible_keys key key_len ref rows Extra
1	SIMPLE	t2	range	NULL	idx_t2_1	#	NULL	#	Using index for group-by
explain select min(a2), a1, max(a2), min(a2), a1 from t1 group by a1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	NULL	idx_t1_1	65	NULL	5	Using index for group-by
1	SIMPLE	t1	range	NULL	idx_t1_1	130	NULL	5	Using index for group-by
explain select a1, b, min(c), a1, max(c), b, a2, max(c), max(c) from t1 group by a1, a2, b;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	NULL	idx_t1_1	147	NULL	17	Using index for group-by
explain select min(a2) from t1 group by a1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	NULL	idx_t1_1	65	NULL	5	Using index for group-by
1	SIMPLE	t1	range	NULL	idx_t1_1	130	NULL	5	Using index for group-by
explain select a2, min(c), max(c) from t1 group by a1,a2,b;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	NULL	idx_t1_1	147	NULL	17	Using index for group-by
@@ -1404,7 +1404,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1	SIMPLE	t2	range	idx_t2_0,idx_t2_1,idx_t2_2	idx_t2_1	163	NULL	#	Using where; Using index for group-by
explain select a1,a2,b,min(c) from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	range	idx_t2_0,idx_t2_1,idx_t2_2	idx_t2_1	146	NULL	#	Using where; Using index for group-by
1	SIMPLE	t2	range	idx_t2_0,idx_t2_1,idx_t2_2	idx_t2_1	163	NULL	#	Using where; Using index for group-by
select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;
a1	a2	b	min(c)	max(c)
a	a	b	e112	h112
@@ -1838,7 +1838,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1	SIMPLE	t1	range	idx_t1_0,idx_t1_1,idx_t1_2	idx_t1_1	147	NULL	10	Using where; Using index for group-by
explain select concat(ord(min(b)),ord(max(b))),min(b),max(b) from t1 group by a1,a2;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	NULL	idx_t1_1	130	NULL	9	Using index for group-by
1	SIMPLE	t1	range	NULL	idx_t1_1	147	NULL	9	Using index for group-by
select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b;
a1	a2	b	concat(min(c), max(c))
a	a	a	a111d111
+2 −2
Original line number Diff line number Diff line
@@ -470,7 +470,7 @@ s1
drop table t1;
SHOW CREATE TABLE INFORMATION_SCHEMA.character_sets;
Table	Create Table
character_sets	CREATE TEMPORARY TABLE `character_sets` (
CHARACTER_SETS	CREATE TEMPORARY TABLE `CHARACTER_SETS` (
  `CHARACTER_SET_NAME` varchar(64) NOT NULL default '',
  `DEFAULT_COLLATE_NAME` varchar(64) NOT NULL default '',
  `DESCRIPTION` varchar(60) NOT NULL default '',
@@ -479,7 +479,7 @@ character_sets CREATE TEMPORARY TABLE `character_sets` (
set names latin2;
SHOW CREATE TABLE INFORMATION_SCHEMA.character_sets;
Table	Create Table
character_sets	CREATE TEMPORARY TABLE `character_sets` (
CHARACTER_SETS	CREATE TEMPORARY TABLE `CHARACTER_SETS` (
  `CHARACTER_SET_NAME` varchar(64) NOT NULL default '',
  `DEFAULT_COLLATE_NAME` varchar(64) NOT NULL default '',
  `DESCRIPTION` varchar(60) NOT NULL default '',
+167 −0
Original line number Diff line number Diff line
@@ -315,3 +315,170 @@ i j k @b
3	4	3	Fired
5	6	5	Fired
drop table t1;
create table t1 (i int, at int, k int, key(k)) engine=myisam;
create table t2 (i int);
insert into t1 values (1, 1, 1);
insert into t2 values (1), (2), (3);
create trigger ai after insert on t1 for each row set @a:= new.at;
create trigger au after update on t1 for each row set @a:= new.at;
create trigger ad after delete on t1 for each row set @a:= old.at;
alter table t1 drop column at;
select * from t1;
i	k
1	1
insert into t1 values (2, 1);
ERROR 42S22: Unknown column 'at' in 'NEW'
select * from t1;
i	k
1	1
2	1
update t1 set k = 2 where i = 2;
ERROR 42S22: Unknown column 'at' in 'NEW'
select * from t1;
i	k
1	1
2	2
delete from t1 where i = 2;
ERROR 42S22: Unknown column 'at' in 'OLD'
select * from t1;
i	k
1	1
load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (i, k);
ERROR 42S22: Unknown column 'at' in 'NEW'
select * from t1;
i	k
1	1
1	2
insert into t1 select 3, 3;
ERROR 42S22: Unknown column 'at' in 'NEW'
select * from t1;
i	k
1	1
1	2
3	3
update t1, t2 set k = k + 10 where t1.i = t2.i;
ERROR 42S22: Unknown column 'at' in 'NEW'
select * from t1;
i	k
1	11
1	2
3	3
update t1, t2 set k = k + 10 where t1.i = t2.i and k < 3;
ERROR 42S22: Unknown column 'at' in 'NEW'
select * from t1;
i	k
1	11
1	12
3	3
delete t1, t2 from t1 straight_join t2 where t1.i = t2.i;
ERROR 42S22: Unknown column 'at' in 'OLD'
select * from t1;
i	k
1	12
3	3
delete t2, t1 from t2 straight_join t1 where t1.i = t2.i;
ERROR 42S22: Unknown column 'at' in 'OLD'
select * from t1;
i	k
3	3
alter table t1 add primary key (i);
insert into t1 values (3, 4) on duplicate key update k= k + 10;
ERROR 42S22: Unknown column 'at' in 'NEW'
select * from t1;
i	k
3	13
replace into t1 values (3, 3);
ERROR 42S22: Unknown column 'at' in 'NEW'
select * from t1;
i	k
3	3
alter table t1 add ts timestamp default now();
replace into t1 (i, k) values (3, 13);
ERROR 42S22: Unknown column 'at' in 'OLD'
select * from t1;
i	k	ts
drop table t1, t2;
create table t1 (i int, bt int, k int, key(k)) engine=myisam;
create table t2 (i int);
insert into t1 values (1, 1, 1), (2, 2, 2);
insert into t2 values (1), (2), (3);
create trigger bi before insert on t1 for each row set @a:= new.bt;
create trigger bu before update on t1 for each row set @a:= new.bt;
create trigger bd before delete on t1 for each row set @a:= old.bt;
alter table t1 drop column bt;
insert into t1 values (3, 3);
ERROR 42S22: Unknown column 'bt' in 'NEW'
select * from t1;
i	k
1	1
2	2
update t1 set i = 2;
ERROR 42S22: Unknown column 'bt' in 'NEW'
select * from t1;
i	k
1	1
2	2
delete from t1;
ERROR 42S22: Unknown column 'bt' in 'OLD'
select * from t1;
i	k
1	1
2	2
load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (i, k);
ERROR 42S22: Unknown column 'bt' in 'NEW'
select * from t1;
i	k
1	1
2	2
insert into t1 select 3, 3;
ERROR 42S22: Unknown column 'bt' in 'NEW'
select * from t1;
i	k
1	1
2	2
update t1, t2 set k = k + 10 where t1.i = t2.i;
ERROR 42S22: Unknown column 'bt' in 'NEW'
select * from t1;
i	k
1	1
2	2
update t1, t2 set k = k + 10 where t1.i = t2.i and k < 2;
ERROR 42S22: Unknown column 'bt' in 'NEW'
select * from t1;
i	k
1	1
2	2
delete t1, t2 from t1 straight_join t2 where t1.i = t2.i;
ERROR 42S22: Unknown column 'bt' in 'OLD'
select * from t1;
i	k
1	1
2	2
delete t2, t1 from t2 straight_join t1 where t1.i = t2.i;
ERROR 42S22: Unknown column 'bt' in 'OLD'
select * from t1;
i	k
1	1
2	2
alter table t1 add primary key (i);
drop trigger t1.bi;
insert into t1 values (2, 4) on duplicate key update k= k + 10;
ERROR 42S22: Unknown column 'bt' in 'NEW'
select * from t1;
i	k
1	1
2	2
replace into t1 values (2, 4);
ERROR 42S22: Unknown column 'bt' in 'NEW'
select * from t1;
i	k
1	1
2	2
alter table t1 add ts timestamp default now();
replace into t1 (i, k) values (2, 11);
ERROR 42S22: Unknown column 'bt' in 'OLD'
select * from t1;
i	k	ts
1	1	0000-00-00 00:00:00
2	2	0000-00-00 00:00:00
drop table t1, t2;
+127 −0
Original line number Diff line number Diff line
@@ -367,3 +367,130 @@ load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated
select *, @b from t1;
# This also will drop triggers
drop table t1;

# Test for bug #5894 "Triggers with altered tables cause corrupt databases"
# Also tests basic error handling for various kinds of triggers.
create table t1 (i int, at int, k int, key(k)) engine=myisam;
create table t2 (i int);
insert into t1 values (1, 1, 1);
# We need at least 3 elements in t2 to test multi-update properly
insert into t2 values (1), (2), (3);
# Create and then break "after" triggers
create trigger ai after insert on t1 for each row set @a:= new.at;
create trigger au after update on t1 for each row set @a:= new.at;
create trigger ad after delete on t1 for each row set @a:= old.at;
alter table t1 drop column at;
# We still should be able select data from tables.
select * from t1;
# The following statements changing t1 should fail, but still cause
# their main effect. This is because operation on the table row is
# executed before "after" trigger and its effect cannot be rolled back
# when whole statement fails, because t1 is MyISAM table.
--error 1054
insert into t1 values (2, 1);
select * from t1;
--error 1054
update t1 set k = 2 where i = 2;
select * from t1;
--error 1054
delete from t1 where i = 2;
select * from t1;
# Should fail and insert only 1 row
--error 1054
load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (i, k);
select * from t1;
--error 1054
insert into t1 select 3, 3;
select * from t1;
# Multi-update working on the fly, again it will update only
# one row even if more matches
--error 1054
update t1, t2 set k = k + 10 where t1.i = t2.i;
select * from t1;
# The same for multi-update via temp table
--error 1054
update t1, t2 set k = k + 10 where t1.i = t2.i and k < 3;
select * from t1;
# Multi-delete on the fly
--error 1054
delete t1, t2 from t1 straight_join t2 where t1.i = t2.i;
select * from t1;
# And via temporary storage
--error 1054
delete t2, t1 from t2 straight_join t1 where t1.i = t2.i;
select * from t1;
# Prepare table for testing of REPLACE and INSERT ... ON DUPLICATE KEY UPDATE
alter table t1 add primary key (i);
--error 1054
insert into t1 values (3, 4) on duplicate key update k= k + 10;
select * from t1;
--error 1054
replace into t1 values (3, 3);
select * from t1;
# Change table in such way that REPLACE will delete row
alter table t1 add ts timestamp default now();
--error 1054
replace into t1 (i, k) values (3, 13);
select * from t1;
# Also drops all triggers
drop table t1, t2;

create table t1 (i int, bt int, k int, key(k)) engine=myisam;
create table t2 (i int);
insert into t1 values (1, 1, 1), (2, 2, 2);
insert into t2 values (1), (2), (3);
# Create and then break "before" triggers
create trigger bi before insert on t1 for each row set @a:= new.bt;
create trigger bu before update on t1 for each row set @a:= new.bt;
create trigger bd before delete on t1 for each row set @a:= old.bt;
alter table t1 drop column bt;
# The following statements changing t1 should fail and should not
# cause any effect on table, since "before" trigger is executed 
# before operation on the table row.
--error 1054
insert into t1 values (3, 3);
select * from t1;
--error 1054
update t1 set i = 2;
select * from t1;
--error 1054
delete from t1;
select * from t1;
--error 1054
load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (i, k);
select * from t1;
--error 1054
insert into t1 select 3, 3;
select * from t1;
# Both types of multi-update (on the fly and via temp table)
--error 1054
update t1, t2 set k = k + 10 where t1.i = t2.i;
select * from t1;
--error 1054
update t1, t2 set k = k + 10 where t1.i = t2.i and k < 2;
select * from t1;
# Both types of multi-delete
--error 1054
delete t1, t2 from t1 straight_join t2 where t1.i = t2.i;
select * from t1;
--error 1054
delete t2, t1 from t2 straight_join t1 where t1.i = t2.i;
select * from t1;
# Let us test REPLACE/INSERT ... ON DUPLICATE KEY UPDATE.
# To test properly code-paths different from those that are used
# in ordinary INSERT we need to drop "before insert" trigger.
alter table t1 add primary key (i);
drop trigger t1.bi;
--error 1054
insert into t1 values (2, 4) on duplicate key update k= k + 10;
select * from t1;
--error 1054
replace into t1 values (2, 4);
select * from t1;
# Change table in such way that REPLACE will delete row
alter table t1 add ts timestamp default now();
--error 1054
replace into t1 (i, k) values (2, 11);
select * from t1;
# Also drops all triggers
drop table t1, t2;
+9 −12
Original line number Diff line number Diff line
@@ -537,8 +537,6 @@ Item_exists_subselect::Item_exists_subselect(st_select_lex *select_lex):
  null_value= 0; //can't be NULL
  maybe_null= 0; //can't be NULL
  value= 0;
  // We need only 1 row to determinate existence
  select_lex->master_unit()->global_parameters->select_limit= 1;
  DBUG_VOID_RETURN;
}

@@ -605,6 +603,8 @@ void Item_exists_subselect::fix_length_and_dec()
   decimals= 0;
   max_length= 1;
   max_columns= engine->cols();
   /* We need only 1 row to determinate existence */
  unit->global_parameters->select_limit= 1;
}

double Item_exists_subselect::val_real()
@@ -854,9 +854,6 @@ Item_in_subselect::single_value_transformer(JOIN *join,
    else
    {
      Item_maxmin_subselect *item;
      // remove LIMIT placed  by ALL/ANY subquery
      select_lex->master_unit()->global_parameters->select_limit=
	HA_POS_ERROR;
      subs= item= new Item_maxmin_subselect(thd, this, select_lex, func->l_op());
      if (upper_item)
        upper_item->set_sub_test(item);
@@ -1286,13 +1283,10 @@ subselect_single_select_engine(st_select_lex *select,
			       select_subselect *result,
			       Item_subselect *item)
  :subselect_engine(item, result),
   prepared(0), optimized(0), executed(0), join(0)
   prepared(0), optimized(0), executed(0),
   select_lex(select), join(0)
{
  select_lex= select;
  SELECT_LEX_UNIT *unit= select_lex->master_unit();
  unit->set_limit(unit->global_parameters, select_lex);
  unit->item= item;
  this->select_lex= select_lex;
  select_lex->master_unit()->item= item;
}


@@ -1440,7 +1434,10 @@ int subselect_single_select_engine::exec()
  thd->lex->current_select= select_lex;
  if (!optimized)
  {
    SELECT_LEX_UNIT *unit= select_lex->master_unit();

    optimized= 1;
    unit->set_limit(unit->global_parameters);
    if (join->optimize())
    {
      thd->where= save_where;
Loading