Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
552d1086
Commit
552d1086
authored
Apr 04, 2007
by
mskold/marty@linux.site
Browse files
Options
Browse Files
Download
Plain Diff
Merge mysql.com:/windows/Linux_space/MySQL/mysql-5.1
into mysql.com:/windows/Linux_space/MySQL/mysql-5.1-new-ndb
parents
d5d2a1fd
6c8f5c58
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
409 additions
and
10 deletions
+409
-10
include/my_base.h
include/my_base.h
+9
-1
mysql-test/r/ndb_trigger.result
mysql-test/r/ndb_trigger.result
+171
-0
mysql-test/t/ndb_trigger.test
mysql-test/t/ndb_trigger.test
+107
-0
sql/ha_ndbcluster.cc
sql/ha_ndbcluster.cc
+19
-4
sql/ha_ndbcluster.h
sql/ha_ndbcluster.h
+2
-0
sql/mysql_priv.h
sql/mysql_priv.h
+1
-0
sql/sql_delete.cc
sql/sql_delete.cc
+25
-1
sql/sql_insert.cc
sql/sql_insert.cc
+44
-2
sql/sql_load.cc
sql/sql_load.cc
+1
-1
sql/sql_trigger.h
sql/sql_trigger.h
+5
-0
sql/sql_update.cc
sql/sql_update.cc
+25
-1
No files found.
include/my_base.h
View file @
552d1086
...
@@ -172,7 +172,15 @@ enum ha_extra_function {
...
@@ -172,7 +172,15 @@ enum ha_extra_function {
Off by default.
Off by default.
*/
*/
HA_EXTRA_WRITE_CAN_REPLACE
,
HA_EXTRA_WRITE_CAN_REPLACE
,
HA_EXTRA_WRITE_CANNOT_REPLACE
HA_EXTRA_WRITE_CANNOT_REPLACE
,
/*
Inform handler that delete_row()/update_row() cannot batch deletes/updates
and should perform them immediately. This may be needed when table has
AFTER DELETE/UPDATE triggers which access to subject table.
These flags are reset by the handler::extra(HA_EXTRA_RESET) call.
*/
HA_EXTRA_DELETE_CANNOT_BATCH
,
HA_EXTRA_UPDATE_CANNOT_BATCH
};
};
/* The following is parameter to ha_panic() */
/* The following is parameter to ha_panic() */
...
...
mysql-test/r/ndb_trigger.result
View file @
552d1086
...
@@ -141,4 +141,175 @@ a b
...
@@ -141,4 +141,175 @@ a b
drop trigger t4_au;
drop trigger t4_au;
drop trigger t4_ad;
drop trigger t4_ad;
drop table t1, t2, t3, t4, t5;
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
End of 5.1 tests
mysql-test/t/ndb_trigger.test
View file @
552d1086
...
@@ -110,5 +110,112 @@ drop trigger t4_au;
...
@@ -110,5 +110,112 @@ drop trigger t4_au;
drop
trigger
t4_ad
;
drop
trigger
t4_ad
;
drop
table
t1
,
t2
,
t3
,
t4
,
t5
;
drop
table
t1
,
t2
,
t3
,
t4
,
t5
;
# Test for bug#26242
# Verify that AFTER UPDATE/DELETE triggers are executed
# after the change has actually taken place
CREATE
TABLE
t1
(
id
INT
NOT
NULL
PRIMARY
KEY
,
xy
INT
)
ENGINE
=
ndbcluster
;
INSERT
INTO
t1
VALUES
(
1
,
0
);
DELIMITER
//;
CREATE
TRIGGER
t1_update
AFTER
UPDATE
ON
t1
FOR
EACH
ROW
BEGIN
REPLACE
INTO
t2
SELECT
*
FROM
t1
WHERE
t1
.
id
=
NEW
.
id
;
END
//
DELIMITER
;
//
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
;
DELIMITER
//;
CREATE
TRIGGER
t4_update
AFTER
UPDATE
ON
t4
FOR
EACH
ROW
BEGIN
REPLACE
INTO
t5
SELECT
*
FROM
t4
WHERE
t4
.
id
=
NEW
.
id
;
END
//
DELIMITER
;
//
CREATE
TABLE
t5
LIKE
t2
;
UPDATE
t1
SET
xy
=
3
WHERE
id
=
1
;
SELECT
xy
FROM
t1
where
id
=
1
;
SELECT
xy
FROM
t2
where
id
=
1
;
UPDATE
t1
SET
xy
=
4
WHERE
id
IN
(
SELECT
id
FROM
t3
WHERE
id
=
1
);
SELECT
xy
FROM
t1
where
id
=
1
;
SELECT
xy
FROM
t2
where
id
=
1
;
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
;
SELECT
xy
FROM
t2
where
id
=
1
;
SELECT
xy
FROM
t4
where
id
=
1
;
SELECT
xy
FROM
t5
where
id
=
1
;
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
;
SELECT
xy
FROM
t2
where
id
=
1
;
SELECT
xy
FROM
t4
where
id
=
1
;
SELECT
xy
FROM
t5
where
id
=
1
;
INSERT
INTO
t1
VALUES
(
1
,
0
)
ON
DUPLICATE
KEY
UPDATE
xy
=
5
;
SELECT
xy
FROM
t1
where
id
=
1
;
SELECT
xy
FROM
t2
where
id
=
1
;
DROP
TRIGGER
t1_update
;
DROP
TRIGGER
t4_update
;
DELIMITER
//;
CREATE
TRIGGER
t1_delete
AFTER
DELETE
ON
t1
FOR
EACH
ROW
BEGIN
REPLACE
INTO
t2
SELECT
*
FROM
t1
WHERE
t1
.
id
>
4
;
END
//
DELIMITER
;
//
DELIMITER
//;
CREATE
TRIGGER
t4_delete
AFTER
DELETE
ON
t4
FOR
EACH
ROW
BEGIN
REPLACE
INTO
t5
SELECT
*
FROM
t4
WHERE
t4
.
id
>
4
;
END
//
DELIMITER
;
//
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
;
SELECT
*
FROM
t2
order
by
id
;
DELETE
FROM
t1
WHERE
id
IN
(
SELECT
id
FROM
t3
WHERE
id
=
5
);
SELECT
*
FROM
t1
order
by
id
;
SELECT
*
FROM
t2
order
by
id
;
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
;
SELECT
*
FROM
t2
order
by
id
;
SELECT
*
FROM
t4
order
by
id
;
SELECT
*
FROM
t5
order
by
id
;
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
;
SELECT
*
FROM
t2
order
by
id
;
SELECT
*
FROM
t4
order
by
id
;
SELECT
*
FROM
t5
order
by
id
;
INSERT
INTO
t1
VALUES
(
5
,
0
);
REPLACE
INTO
t2
VALUES
(
6
,
1
);
SELECT
*
FROM
t1
order
by
id
;
SELECT
*
FROM
t2
order
by
id
;
REPLACE
INTO
t1
VALUES
(
5
,
1
);
SELECT
*
FROM
t1
order
by
id
;
SELECT
*
FROM
t2
order
by
id
;
DROP
TRIGGER
t1_delete
;
DROP
TRIGGER
t4_delete
;
DROP
TABLE
t1
,
t2
,
t3
,
t4
,
t5
;
--
echo
End
of
5.1
tests
--
echo
End
of
5.1
tests
sql/ha_ndbcluster.cc
View file @
552d1086
...
@@ -2999,8 +2999,13 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
...
@@ -2999,8 +2999,13 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
if
(
thd
->
slave_thread
)
if
(
thd
->
slave_thread
)
op
->
setAnyValue
(
thd
->
server_id
);
op
->
setAnyValue
(
thd
->
server_id
);
// Execute update operation
/*
if
(
!
cursor
&&
execute_no_commit
(
this
,
trans
,
FALSE
)
!=
0
)
{
Execute update operation if we are not doing a scan for update
and there exist UPDATE AFTER triggers
*/
if
((
!
cursor
||
m_update_cannot_batch
)
&&
execute_no_commit
(
this
,
trans
,
false
)
!=
0
)
{
no_uncommitted_rows_execute_failure
();
no_uncommitted_rows_execute_failure
();
DBUG_RETURN
(
ndb_err
(
trans
));
DBUG_RETURN
(
ndb_err
(
trans
));
}
}
...
@@ -3057,7 +3062,7 @@ int ha_ndbcluster::delete_row(const byte *record)
...
@@ -3057,7 +3062,7 @@ int ha_ndbcluster::delete_row(const byte *record)
if
(
thd
->
slave_thread
)
if
(
thd
->
slave_thread
)
((
NdbOperation
*
)
trans
->
getLastDefinedOperation
())
->
setAnyValue
(
thd
->
server_id
);
((
NdbOperation
*
)
trans
->
getLastDefinedOperation
())
->
setAnyValue
(
thd
->
server_id
);
if
(
!
m_primary_key_update
)
if
(
!
(
m_primary_key_update
||
m_delete_cannot_batch
)
)
// If deleting from cursor, NoCommit will be handled in next_result
// If deleting from cursor, NoCommit will be handled in next_result
DBUG_RETURN
(
0
);
DBUG_RETURN
(
0
);
}
}
...
@@ -3902,7 +3907,13 @@ int ha_ndbcluster::extra(enum ha_extra_function operation)
...
@@ -3902,7 +3907,13 @@ int ha_ndbcluster::extra(enum ha_extra_function operation)
DBUG_PRINT
(
"info"
,
(
"Turning OFF use of write instead of insert"
));
DBUG_PRINT
(
"info"
,
(
"Turning OFF use of write instead of insert"
));
m_use_write
=
FALSE
;
m_use_write
=
FALSE
;
break
;
break
;
default:
case
HA_EXTRA_DELETE_CANNOT_BATCH
:
DBUG_PRINT
(
"info"
,
(
"HA_EXTRA_DELETE_CANNOT_BATCH"
));
m_delete_cannot_batch
=
TRUE
;
break
;
case
HA_EXTRA_UPDATE_CANNOT_BATCH
:
DBUG_PRINT
(
"info"
,
(
"HA_EXTRA_UPDATE_CANNOT_BATCH"
));
m_update_cannot_batch
=
TRUE
;
break
;
break
;
}
}
...
@@ -3913,6 +3924,8 @@ int ha_ndbcluster::extra(enum ha_extra_function operation)
...
@@ -3913,6 +3924,8 @@ int ha_ndbcluster::extra(enum ha_extra_function operation)
int
ha_ndbcluster
::
reset
()
int
ha_ndbcluster
::
reset
()
{
{
DBUG_ENTER
(
"ha_ndbcluster::reset"
);
DBUG_ENTER
(
"ha_ndbcluster::reset"
);
m_delete_cannot_batch
=
FALSE
;
m_update_cannot_batch
=
FALSE
;
cond_clear
();
cond_clear
();
/*
/*
Regular partition pruning will set the bitmap appropriately.
Regular partition pruning will set the bitmap appropriately.
...
@@ -5922,6 +5935,8 @@ ha_ndbcluster::ha_ndbcluster(handlerton *hton, TABLE_SHARE *table_arg):
...
@@ -5922,6 +5935,8 @@ ha_ndbcluster::ha_ndbcluster(handlerton *hton, TABLE_SHARE *table_arg):
m_bulk_insert_rows
((
ha_rows
)
1024
),
m_bulk_insert_rows
((
ha_rows
)
1024
),
m_rows_changed
((
ha_rows
)
0
),
m_rows_changed
((
ha_rows
)
0
),
m_bulk_insert_not_flushed
(
FALSE
),
m_bulk_insert_not_flushed
(
FALSE
),
m_delete_cannot_batch
(
FALSE
),
m_update_cannot_batch
(
FALSE
),
m_ops_pending
(
0
),
m_ops_pending
(
0
),
m_skip_auto_increment
(
TRUE
),
m_skip_auto_increment
(
TRUE
),
m_blobs_pending
(
0
),
m_blobs_pending
(
0
),
...
...
sql/ha_ndbcluster.h
View file @
552d1086
...
@@ -964,6 +964,8 @@ static void set_tabname(const char *pathname, char *tabname);
...
@@ -964,6 +964,8 @@ static void set_tabname(const char *pathname, char *tabname);
ha_rows
m_bulk_insert_rows
;
ha_rows
m_bulk_insert_rows
;
ha_rows
m_rows_changed
;
ha_rows
m_rows_changed
;
bool
m_bulk_insert_not_flushed
;
bool
m_bulk_insert_not_flushed
;
bool
m_delete_cannot_batch
;
bool
m_update_cannot_batch
;
ha_rows
m_ops_pending
;
ha_rows
m_ops_pending
;
bool
m_skip_auto_increment
;
bool
m_skip_auto_increment
;
bool
m_blobs_pending
;
bool
m_blobs_pending
;
...
...
sql/mysql_priv.h
View file @
552d1086
...
@@ -1007,6 +1007,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
...
@@ -1007,6 +1007,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
bool
ignore
);
bool
ignore
);
int
check_that_all_fields_are_given_values
(
THD
*
thd
,
TABLE
*
entry
,
int
check_that_all_fields_are_given_values
(
THD
*
thd
,
TABLE
*
entry
,
TABLE_LIST
*
table_list
);
TABLE_LIST
*
table_list
);
void
prepare_triggers_for_insert_stmt
(
TABLE
*
table
);
bool
mysql_prepare_delete
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
Item
**
conds
);
bool
mysql_prepare_delete
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
Item
**
conds
);
bool
mysql_delete
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
COND
*
conds
,
bool
mysql_delete
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
COND
*
conds
,
SQL_LIST
*
order
,
ha_rows
rows
,
ulonglong
options
,
SQL_LIST
*
order
,
ha_rows
rows
,
ulonglong
options
,
...
...
sql/sql_delete.cc
View file @
552d1086
...
@@ -221,6 +221,19 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
...
@@ -221,6 +221,19 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
init_ftfuncs
(
thd
,
select_lex
,
1
);
init_ftfuncs
(
thd
,
select_lex
,
1
);
thd
->
proc_info
=
"updating"
;
thd
->
proc_info
=
"updating"
;
if
(
table
->
triggers
&&
table
->
triggers
->
has_triggers
(
TRG_EVENT_DELETE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER DELETE triggers that might access to subject table
and therefore might need delete to be done immediately. So we turn-off
the batching.
*/
(
void
)
table
->
file
->
extra
(
HA_EXTRA_DELETE_CANNOT_BATCH
);
will_batch
=
FALSE
;
}
else
will_batch
=
!
table
->
file
->
start_bulk_delete
();
will_batch
=
!
table
->
file
->
start_bulk_delete
();
...
@@ -563,6 +576,17 @@ multi_delete::initialize_tables(JOIN *join)
...
@@ -563,6 +576,17 @@ multi_delete::initialize_tables(JOIN *join)
transactional_tables
=
1
;
transactional_tables
=
1
;
else
else
normal_tables
=
1
;
normal_tables
=
1
;
if
(
tbl
->
triggers
&&
tbl
->
triggers
->
has_triggers
(
TRG_EVENT_DELETE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER DELETE triggers that might access to subject
table and therefore might need delete to be done immediately.
So we turn-off the batching.
*/
(
void
)
tbl
->
file
->
extra
(
HA_EXTRA_DELETE_CANNOT_BATCH
);
}
tbl
->
prepare_for_position
();
tbl
->
prepare_for_position
();
tbl
->
mark_columns_needed_for_delete
();
tbl
->
mark_columns_needed_for_delete
();
}
}
...
...
sql/sql_insert.cc
View file @
552d1086
...
@@ -341,6 +341,47 @@ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list,
...
@@ -341,6 +341,47 @@ static int check_update_fields(THD *thd, TABLE_LIST *insert_table_list,
return
0
;
return
0
;
}
}
/*
Prepare triggers for INSERT-like statement.
SYNOPSIS
prepare_triggers_for_insert_stmt()
table Table to which insert will happen
NOTE
Prepare triggers for INSERT-like statement by marking fields
used by triggers and inform handlers that batching of UPDATE/DELETE
cannot be done if there are BEFORE UPDATE/DELETE triggers.
*/
void
prepare_triggers_for_insert_stmt
(
TABLE
*
table
)
{
if
(
table
->
triggers
)
{
if
(
table
->
triggers
->
has_triggers
(
TRG_EVENT_DELETE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER DELETE triggers that might access to
subject table and therefore might need delete to be done
immediately. So we turn-off the batching.
*/
(
void
)
table
->
file
->
extra
(
HA_EXTRA_DELETE_CANNOT_BATCH
);
}
if
(
table
->
triggers
->
has_triggers
(
TRG_EVENT_UPDATE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER UPDATE triggers that might access to subject
table and therefore might need update to be done immediately.
So we turn-off the batching.
*/
(
void
)
table
->
file
->
extra
(
HA_EXTRA_UPDATE_CANNOT_BATCH
);
}
}
table
->
mark_columns_needed_for_insert
();
}
bool
mysql_insert
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
bool
mysql_insert
(
THD
*
thd
,
TABLE_LIST
*
table_list
,
List
<
Item
>
&
fields
,
List
<
Item
>
&
fields
,
...
@@ -575,7 +616,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
...
@@ -575,7 +616,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
(
MODE_STRICT_TRANS_TABLES
|
(
MODE_STRICT_TRANS_TABLES
|
MODE_STRICT_ALL_TABLES
)));
MODE_STRICT_ALL_TABLES
)));
table
->
mark_columns_needed_for_insert
();
prepare_triggers_for_insert_stmt
(
table
);
if
(
table_list
->
prepare_where
(
thd
,
0
,
TRUE
)
||
if
(
table_list
->
prepare_where
(
thd
,
0
,
TRUE
)
||
table_list
->
prepare_check_option
(
thd
))
table_list
->
prepare_check_option
(
thd
))
...
@@ -2646,7 +2688,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
...
@@ -2646,7 +2688,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
table_list
->
prepare_check_option
(
thd
));
table_list
->
prepare_check_option
(
thd
));
if
(
!
res
)
if
(
!
res
)
table
->
mark_columns_needed_for_insert
(
);
prepare_triggers_for_insert_stmt
(
table
);
DBUG_RETURN
(
res
);
DBUG_RETURN
(
res
);
}
}
...
...
sql/sql_load.cc
View file @
552d1086
...
@@ -226,7 +226,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
...
@@ -226,7 +226,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
DBUG_RETURN
(
TRUE
);
DBUG_RETURN
(
TRUE
);
}
}
table
->
mark_columns_needed_for_insert
(
);
prepare_triggers_for_insert_stmt
(
table
);
uint
tot_length
=
0
;
uint
tot_length
=
0
;
bool
use_blobs
=
0
,
use_vars
=
0
;
bool
use_blobs
=
0
,
use_vars
=
0
;
...
...
sql/sql_trigger.h
View file @
552d1086
...
@@ -110,6 +110,11 @@ class Table_triggers_list: public Sql_alloc
...
@@ -110,6 +110,11 @@ class Table_triggers_list: public Sql_alloc
const
char
*
old_table
,
const
char
*
old_table
,
const
char
*
new_db
,
const
char
*
new_db
,
const
char
*
new_table
);
const
char
*
new_table
);
bool
has_triggers
(
trg_event_type
event_type
,
trg_action_time_type
action_time
)
{
return
(
bodies
[
event_type
][
action_time
]);
}
bool
has_delete_triggers
()
bool
has_delete_triggers
()
{
{
return
(
bodies
[
TRG_EVENT_DELETE
][
TRG_ACTION_BEFORE
]
||
return
(
bodies
[
TRG_EVENT_DELETE
][
TRG_ACTION_BEFORE
]
||
...
...
sql/sql_update.cc
View file @
552d1086
...
@@ -452,6 +452,19 @@ int mysql_update(THD *thd,
...
@@ -452,6 +452,19 @@ int mysql_update(THD *thd,
(
thd
->
variables
.
sql_mode
&
(
thd
->
variables
.
sql_mode
&
(
MODE_STRICT_TRANS_TABLES
|
(
MODE_STRICT_TRANS_TABLES
|
MODE_STRICT_ALL_TABLES
)));
MODE_STRICT_ALL_TABLES
)));
if
(
table
->
triggers
&&
table
->
triggers
->
has_triggers
(
TRG_EVENT_UPDATE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER UPDATE triggers that might access to subject
table and therefore might need update to be done immediately.
So we turn-off the batching.
*/
(
void
)
table
->
file
->
extra
(
HA_EXTRA_UPDATE_CANNOT_BATCH
);
will_batch
=
FALSE
;
}
else
will_batch
=
!
table
->
file
->
start_bulk_update
();
will_batch
=
!
table
->
file
->
start_bulk_update
();
/*
/*
...
@@ -1121,6 +1134,17 @@ int multi_update::prepare(List<Item> ¬_used_values,
...
@@ -1121,6 +1134,17 @@ int multi_update::prepare(List<Item> ¬_used_values,
table
->
no_keyread
=
1
;
table
->
no_keyread
=
1
;
table
->
covering_keys
.
clear_all
();
table
->
covering_keys
.
clear_all
();
table
->
pos_in_table_list
=
tl
;
table
->
pos_in_table_list
=
tl
;
if
(
table
->
triggers
&&
table
->
triggers
->
has_triggers
(
TRG_EVENT_UPDATE
,
TRG_ACTION_AFTER
))
{
/*
The table has AFTER UPDATE triggers that might access to subject
table and therefore might need update to be done immediately.
So we turn-off the batching.
*/
(
void
)
table
->
file
->
extra
(
HA_EXTRA_UPDATE_CANNOT_BATCH
);
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment