Commit 59a64c2b authored by unknown's avatar unknown

Merge from 5.0


mysql-test/r/ndb_trigger.result:
  Re-generated
sql/mysql_priv.h:
  Merge
sql/sql_insert.cc:
  Merge
sql/sql_load.cc:
  Merge
sql/sql_update.cc:
  Merge
parent 655a58d8
......@@ -141,4 +141,175 @@ a b
drop trigger t4_au;
drop trigger t4_ad;
drop table t1, t2, t3, t4, t5;
CREATE TABLE t1 (
id INT NOT NULL PRIMARY KEY,
xy INT
) ENGINE=ndbcluster;
INSERT INTO t1 VALUES (1, 0);
CREATE TRIGGER t1_update AFTER UPDATE ON t1 FOR EACH ROW BEGIN REPLACE INTO t2 SELECT * FROM t1 WHERE t1.id = NEW.id; END //
CREATE TABLE t2 (
id INT NOT NULL PRIMARY KEY,
xy INT
) ENGINE=ndbcluster;
INSERT INTO t2 VALUES (2, 0);
CREATE TABLE t3 (id INT NOT NULL PRIMARY KEY) ENGINE=ndbcluster;
INSERT INTO t3 VALUES (1);
CREATE TABLE t4 LIKE t1;
CREATE TRIGGER t4_update AFTER UPDATE ON t4 FOR EACH ROW BEGIN REPLACE INTO t5 SELECT * FROM t4 WHERE t4.id = NEW.id; END //
CREATE TABLE t5 LIKE t2;
UPDATE t1 SET xy = 3 WHERE id = 1;
SELECT xy FROM t1 where id = 1;
xy
3
SELECT xy FROM t2 where id = 1;
xy
3
UPDATE t1 SET xy = 4 WHERE id IN (SELECT id FROM t3 WHERE id = 1);
SELECT xy FROM t1 where id = 1;
xy
4
SELECT xy FROM t2 where id = 1;
xy
4
INSERT INTO t4 SELECT * FROM t1;
INSERT INTO t5 SELECT * FROM t2;
UPDATE t1,t4 SET t1.xy = 3, t4.xy = 3 WHERE t1.id = 1 AND t4.id = 1;
SELECT xy FROM t1 where id = 1;
xy
3
SELECT xy FROM t2 where id = 1;
xy
3
SELECT xy FROM t4 where id = 1;
xy
3
SELECT xy FROM t5 where id = 1;
xy
3
UPDATE t1,t4 SET t1.xy = 4, t4.xy = 4 WHERE t1.id IN (SELECT id FROM t3 WHERE id = 1) AND t4.id IN (SELECT id FROM t3 WHERE id = 1);
SELECT xy FROM t1 where id = 1;
xy
4
SELECT xy FROM t2 where id = 1;
xy
4
SELECT xy FROM t4 where id = 1;
xy
4
SELECT xy FROM t5 where id = 1;
xy
4
INSERT INTO t1 VALUES (1,0) ON DUPLICATE KEY UPDATE xy = 5;
SELECT xy FROM t1 where id = 1;
xy
5
SELECT xy FROM t2 where id = 1;
xy
5
DROP TRIGGER t1_update;
DROP TRIGGER t4_update;
CREATE TRIGGER t1_delete AFTER DELETE ON t1 FOR EACH ROW BEGIN REPLACE INTO t2 SELECT * FROM t1 WHERE t1.id > 4; END //
CREATE TRIGGER t4_delete AFTER DELETE ON t4 FOR EACH ROW BEGIN REPLACE INTO t5 SELECT * FROM t4 WHERE t4.id > 4; END //
INSERT INTO t1 VALUES (5, 0),(6,0);
INSERT INTO t2 VALUES (5, 1),(6,1);
INSERT INTO t3 VALUES (5);
SELECT * FROM t1 order by id;
id xy
1 5
5 0
6 0
SELECT * FROM t2 order by id;
id xy
1 5
2 0
5 1
6 1
DELETE FROM t1 WHERE id IN (SELECT id FROM t3 WHERE id = 5);
SELECT * FROM t1 order by id;
id xy
1 5
6 0
SELECT * FROM t2 order by id;
id xy
1 5
2 0
5 1
6 0
INSERT INTO t1 VALUES (5,0);
UPDATE t2 SET xy = 1 WHERE id = 6;
TRUNCATE t4;
INSERT INTO t4 SELECT * FROM t1;
TRUNCATE t5;
INSERT INTO t5 SELECT * FROM t2;
SELECT * FROM t1 order by id;
id xy
1 5
5 0
6 0
SELECT * FROM t2 order by id;
id xy
1 5
2 0
5 1
6 1
SELECT * FROM t4 order by id;
id xy
1 5
5 0
6 0
SELECT * FROM t5 order by id;
id xy
1 5
2 0
5 1
6 1
DELETE FROM t1,t4 USING t1,t3,t4 WHERE t1.id IN (SELECT id FROM t3 WHERE id = 5) AND t4.id IN (SELECT id FROM t3 WHERE id = 5);
SELECT * FROM t1 order by id;
id xy
1 5
6 0
SELECT * FROM t2 order by id;
id xy
1 5
2 0
5 1
6 0
SELECT * FROM t4 order by id;
id xy
1 5
6 0
SELECT * FROM t5 order by id;
id xy
1 5
2 0
5 1
6 0
INSERT INTO t1 VALUES (5, 0);
REPLACE INTO t2 VALUES (6,1);
SELECT * FROM t1 order by id;
id xy
1 5
5 0
6 0
SELECT * FROM t2 order by id;
id xy
1 5
2 0
5 1
6 1
REPLACE INTO t1 VALUES (5, 1);
SELECT * FROM t1 order by id;
id xy
1 5
5 1
6 0
SELECT * FROM t2 order by id;
id xy
1 5
2 0
5 1
6 0
DROP TRIGGER t1_delete;
DROP TRIGGER t4_delete;
DROP TABLE t1, t2, t3, t4, t5;
End of 5.1 tests
......@@ -974,8 +974,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
bool ignore);
int check_that_all_fields_are_given_values(THD *thd, TABLE *entry,
TABLE_LIST *table_list);
void prepare_triggers_for_insert_stmt(THD *thd, TABLE *table,
enum_duplicates duplic);
void prepare_triggers_for_insert_stmt(TABLE *table);
bool mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
SQL_LIST *order, ha_rows rows, ulonglong options,
......
......@@ -340,14 +340,12 @@ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list,
return 0;
}
/*
Prepare triggers for INSERT-like statement.
SYNOPSIS
prepare_triggers_for_insert_stmt()
thd The current thread
table Table to which insert will happen
duplic Type of duplicate handling for insert which will happen
NOTE
Prepare triggers for INSERT-like statement by marking fields
......@@ -355,8 +353,7 @@ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list,
cannot be done if there are BEFORE UPDATE/DELETE triggers.
*/
void prepare_triggers_for_insert_stmt(THD *thd, TABLE *table,
enum_duplicates duplic)
void prepare_triggers_for_insert_stmt(TABLE *table)
{
if (table->triggers)
{
......@@ -380,12 +377,11 @@ void prepare_triggers_for_insert_stmt(THD *thd, TABLE *table,
*/
(void) table->file->extra(HA_EXTRA_UPDATE_CANNOT_BATCH);
}
mark_fields_used_by_triggers_for_insert_stmt(thd, table, duplic);
}
table->mark_columns_needed_for_insert();
}
/*
bool mysql_insert(THD *thd,TABLE_LIST *table_list,
List<Item> &fields,
List<List_item> &values_list,
......@@ -584,7 +580,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
error= 1;
}
table->mark_columns_needed_for_insert();
prepare_triggers_for_insert_stmt(table);
if (table_list->prepare_where(thd, 0, TRUE) ||
table_list->prepare_check_option(thd))
......@@ -2602,7 +2599,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
table_list->prepare_check_option(thd));
if (!res)
table->mark_columns_needed_for_insert();
prepare_triggers_for_insert_stmt(table);
DBUG_RETURN(res);
}
......
......@@ -226,7 +226,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
DBUG_RETURN(TRUE);
}
table->mark_columns_needed_for_insert();
prepare_triggers_for_insert_stmt(table);
uint tot_length=0;
bool use_blobs= 0, use_vars= 0;
......
......@@ -1129,10 +1129,8 @@ int multi_update::prepare(List<Item> &not_used_values,
table->no_keyread=1;
table->used_keys.clear_all();
table->pos_in_table_list= tl;
if (table->triggers)
{
table->triggers->mark_fields_used(thd, TRG_EVENT_UPDATE);
if (table->triggers->has_triggers(TRG_EVENT_UPDATE,
if (table->triggers &&
table->triggers->has_triggers(TRG_EVENT_UPDATE,
TRG_ACTION_AFTER))
{
/*
......@@ -1144,7 +1142,6 @@ int multi_update::prepare(List<Item> &not_used_values,
}
}
}
}
table_count= update.elements;
......
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