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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
1f746cb0
Commit
1f746cb0
authored
Nov 10, 2011
by
Marko Mäkelä
Browse files
Options
Browse Files
Download
Plain Diff
Merge mysql-5.1 to mysql-5.5.
parents
08d5cbf1
a0a51251
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
279 additions
and
13 deletions
+279
-13
mysql-test/suite/innodb/r/innodb_replace.result
mysql-test/suite/innodb/r/innodb_replace.result
+77
-0
mysql-test/suite/innodb/t/innodb_replace.test
mysql-test/suite/innodb/t/innodb_replace.test
+186
-0
sql/sql_insert.cc
sql/sql_insert.cc
+5
-0
storage/innobase/handler/ha_innodb.cc
storage/innobase/handler/ha_innodb.cc
+7
-9
storage/innobase/row/row0ins.c
storage/innobase/row/row0ins.c
+4
-4
No files found.
mysql-test/suite/innodb/r/innodb_replace.result
0 → 100644
View file @
1f746cb0
#
#Bug#11759688 52020: InnoDB can still deadlock
#on just INSERT...ON DUPLICATE KEY
#a.k.a. Bug#7975 deadlock without any locking, simple select and update
#
CREATE TABLE t1 (a INT PRIMARY KEY, b INT NOT NULL) ENGINE=InnoDB;
INSERT INTO t1 VALUES(3,1);
BEGIN;
SET DEBUG_SYNC='write_row_noreplace SIGNAL insert1 WAIT_FOR select1';
INSERT INTO t1 VALUES(3,2);
SET DEBUG_SYNC='now WAIT_FOR insert1';
SELECT * FROM t1 LOCK IN SHARE MODE;
a b
3 1
SELECT * FROM t1 FOR UPDATE;
SET DEBUG_SYNC='now SIGNAL select1';
ERROR 23000: Duplicate entry '3' for key 'PRIMARY'
INSERT INTO t1 VALUES(3,3) ON DUPLICATE KEY UPDATE b=b+10;
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
COMMIT;
SET DEBUG_SYNC='write_row_replace SIGNAL insert2 WAIT_FOR select2';
REPLACE INTO t1 VALUES(3,4);
SET DEBUG_SYNC='now WAIT_FOR insert2';
SELECT * FROM t1;
a b
3 11
SELECT * FROM t1 LOCK IN SHARE MODE;
SET DEBUG_SYNC='now SIGNAL select2';
SET DEBUG_SYNC='write_row_replace SIGNAL insert3 WAIT_FOR select3';
INSERT INTO t1 VALUES(3,5) ON DUPLICATE KEY UPDATE b=b+20;
a b
3 4
SET DEBUG_SYNC='now WAIT_FOR insert3';
SELECT b FROM t1 LOCK IN SHARE MODE;
SET DEBUG_SYNC='now SIGNAL select3';
b
24
SET DEBUG_SYNC='write_row_noreplace SIGNAL insert4 WAIT_FOR select4';
LOAD DATA INFILE '../../std_data/loaddata5.dat' INTO TABLE t1 FIELDS TERMINATED BY '' ENCLOSED BY '' (a, b);
SET DEBUG_SYNC='now WAIT_FOR insert4';
SELECT b FROM t1 WHERE a=3 LOCK IN SHARE MODE;
b
24
SELECT b FROM t1 WHERE a=3 FOR UPDATE;
SET DEBUG_SYNC='now SIGNAL select4';
b
24
ERROR 23000: Duplicate entry '3' for key 'PRIMARY'
SET DEBUG_SYNC='write_row_noreplace SIGNAL insert5 WAIT_FOR select5';
LOAD DATA INFILE '../../std_data/loaddata5.dat' IGNORE INTO TABLE t1 FIELDS TERMINATED BY '' ENCLOSED BY '' (a, b);
SET DEBUG_SYNC='now WAIT_FOR insert5';
SELECT * FROM t1;
a b
3 24
SELECT * FROM t1 WHERE a=3 LOCK IN SHARE MODE;
a b
3 24
SELECT * FROM t1 WHERE a=3 FOR UPDATE;
SET DEBUG_SYNC='now SIGNAL select5';
a b
3 24
SET DEBUG_SYNC='write_row_replace SIGNAL insert6 WAIT_FOR select6';
LOAD DATA INFILE '../../std_data/loaddata5.dat' REPLACE INTO TABLE t1 FIELDS TERMINATED BY '' ENCLOSED BY '' (a, b);
SET DEBUG_SYNC='now WAIT_FOR insert6';
SELECT * FROM t1;
a b
1 2
3 24
5 6
SELECT a,b FROM t1 LOCK IN SHARE MODE;
SET DEBUG_SYNC='now SIGNAL select6';
a b
1 2
3 4
5 6
SET DEBUG_SYNC='RESET';
DROP TABLE t1;
mysql-test/suite/innodb/t/innodb_replace.test
0 → 100644
View file @
1f746cb0
--
source
include
/
have_innodb
.
inc
--
source
include
/
have_debug_sync
.
inc
--
echo
#
--
echo
#Bug#11759688 52020: InnoDB can still deadlock
--
echo
#on just INSERT...ON DUPLICATE KEY
--
echo
#a.k.a. Bug#7975 deadlock without any locking, simple select and update
--
echo
#
CREATE
TABLE
t1
(
a
INT
PRIMARY
KEY
,
b
INT
NOT
NULL
)
ENGINE
=
InnoDB
;
INSERT
INTO
t1
VALUES
(
3
,
1
);
connect
(
con1
,
localhost
,
root
,,);
connect
(
con2
,
localhost
,
root
,,);
connection
con1
;
BEGIN
;
# normal INSERT of a duplicate should only S-lock the existing record (3,1)
SET
DEBUG_SYNC
=
'write_row_noreplace SIGNAL insert1 WAIT_FOR select1'
;
--
send
INSERT
INTO
t1
VALUES
(
3
,
2
);
connection
default
;
SET
DEBUG_SYNC
=
'now WAIT_FOR insert1'
;
# this should S-lock (3,1); no conflict
SELECT
*
FROM
t1
LOCK
IN
SHARE
MODE
;
# this should X-lock (3,1), conflicting with con1
--
send
SELECT
*
FROM
t1
FOR
UPDATE
;
connection
con2
;
# Check that the above SELECT is blocked
let
$wait_condition
=
select
count
(
*
)
=
1
from
information_schema
.
processlist
where
state
=
'Sending data'
and
info
=
'SELECT * FROM t1 FOR UPDATE'
;
--
source
include
/
wait_condition
.
inc
SET
DEBUG_SYNC
=
'now SIGNAL select1'
;
connection
con1
;
--
error
ER_DUP_ENTRY
reap
;
# We are still holding an S-lock on (3,1) after the failed INSERT.
# The following will upgrade it to an X-lock, causing a deadlock.
# InnoDB should resolve the deadlock by aborting the blocked SELECT.
INSERT
INTO
t1
VALUES
(
3
,
3
)
ON
DUPLICATE
KEY
UPDATE
b
=
b
+
10
;
connection
default
;
--
error
ER_LOCK_DEADLOCK
reap
;
connection
con1
;
COMMIT
;
SET
DEBUG_SYNC
=
'write_row_replace SIGNAL insert2 WAIT_FOR select2'
;
--
send
REPLACE
INTO
t1
VALUES
(
3
,
4
);
connection
default
;
SET
DEBUG_SYNC
=
'now WAIT_FOR insert2'
;
SELECT
*
FROM
t1
;
--
send
SELECT
*
FROM
t1
LOCK
IN
SHARE
MODE
;
connection
con2
;
# Check that the above SELECT is blocked because of X lock.
let
$wait_condition
=
select
count
(
*
)
=
1
from
information_schema
.
processlist
where
state
=
'Sending data'
and
info
=
'SELECT * FROM t1 LOCK IN SHARE MODE'
;
--
source
include
/
wait_condition
.
inc
SET
DEBUG_SYNC
=
'now SIGNAL select2'
;
connection
con1
;
reap
;
SET
DEBUG_SYNC
=
'write_row_replace SIGNAL insert3 WAIT_FOR select3'
;
--
send
INSERT
INTO
t1
VALUES
(
3
,
5
)
ON
DUPLICATE
KEY
UPDATE
b
=
b
+
20
;
connection
default
;
reap
;
SET
DEBUG_SYNC
=
'now WAIT_FOR insert3'
;
--
send
SELECT
b
FROM
t1
LOCK
IN
SHARE
MODE
;
connection
con2
;
# Check that the above SELECT is blocked because of X lock.
let
$wait_condition
=
select
count
(
*
)
=
1
from
information_schema
.
processlist
where
state
=
'Sending data'
and
info
=
'SELECT b FROM t1 LOCK IN SHARE MODE'
;
--
source
include
/
wait_condition
.
inc
SET
DEBUG_SYNC
=
'now SIGNAL select3'
;
connection
default
;
reap
;
connection
con1
;
reap
;
SET
DEBUG_SYNC
=
'write_row_noreplace SIGNAL insert4 WAIT_FOR select4'
;
--
send
LOAD
DATA
INFILE
'../../std_data/loaddata5.dat'
INTO
TABLE
t1
FIELDS
TERMINATED
BY
''
ENCLOSED
BY
''
(
a
,
b
);
connection
default
;
SET
DEBUG_SYNC
=
'now WAIT_FOR insert4'
;
# this should S-lock (3,1); no conflict
SELECT
b
FROM
t1
WHERE
a
=
3
LOCK
IN
SHARE
MODE
;
# this should X-lock (3,1), conflicting with con1
--
send
SELECT
b
FROM
t1
WHERE
a
=
3
FOR
UPDATE
;
connection
con2
;
# Check that the above SELECT is blocked
let
$wait_condition
=
select
count
(
*
)
=
1
from
information_schema
.
processlist
where
state
=
'statistics'
and
info
=
'SELECT b FROM t1 WHERE a=3 FOR UPDATE'
;
--
source
include
/
wait_condition
.
inc
SET
DEBUG_SYNC
=
'now SIGNAL select4'
;
connection
default
;
reap
;
connection
con1
;
--
error
ER_DUP_ENTRY
reap
;
SET
DEBUG_SYNC
=
'write_row_noreplace SIGNAL insert5 WAIT_FOR select5'
;
--
send
LOAD
DATA
INFILE
'../../std_data/loaddata5.dat'
IGNORE
INTO
TABLE
t1
FIELDS
TERMINATED
BY
''
ENCLOSED
BY
''
(
a
,
b
);
connection
default
;
SET
DEBUG_SYNC
=
'now WAIT_FOR insert5'
;
SELECT
*
FROM
t1
;
# this should S-lock; no conflict
SELECT
*
FROM
t1
WHERE
a
=
3
LOCK
IN
SHARE
MODE
;
# this should X-lock, conflicting with the S-lock of the IGNORE in con1
--
send
SELECT
*
FROM
t1
WHERE
a
=
3
FOR
UPDATE
;
connection
con2
;
# Check that the above SELECT is blocked
let
$wait_condition
=
select
count
(
*
)
=
1
from
information_schema
.
processlist
where
state
=
'statistics'
and
info
=
'SELECT * FROM t1 WHERE a=3 FOR UPDATE'
;
--
source
include
/
wait_condition
.
inc
SET
DEBUG_SYNC
=
'now SIGNAL select5'
;
connection
con1
;
reap
;
connection
default
;
reap
;
connection
con1
;
SET
DEBUG_SYNC
=
'write_row_replace SIGNAL insert6 WAIT_FOR select6'
;
--
send
LOAD
DATA
INFILE
'../../std_data/loaddata5.dat'
REPLACE
INTO
TABLE
t1
FIELDS
TERMINATED
BY
''
ENCLOSED
BY
''
(
a
,
b
);
connection
default
;
SET
DEBUG_SYNC
=
'now WAIT_FOR insert6'
;
SELECT
*
FROM
t1
;
# this should conflict with the X-lock acquired by the REPLACE
--
send
SELECT
a
,
b
FROM
t1
LOCK
IN
SHARE
MODE
;
connection
con2
;
# Check that the above SELECT is blocked
let
$wait_condition
=
select
count
(
*
)
=
1
from
information_schema
.
processlist
where
state
=
'Sending data'
and
info
=
'SELECT a,b FROM t1 LOCK IN SHARE MODE'
;
--
source
include
/
wait_condition
.
inc
SET
DEBUG_SYNC
=
'now SIGNAL select6'
;
connection
con1
;
reap
;
connection
default
;
reap
;
disconnect
con1
;
disconnect
con2
;
connection
default
;
SET
DEBUG_SYNC
=
'RESET'
;
DROP
TABLE
t1
;
sql/sql_insert.cc
View file @
1f746cb0
...
@@ -77,6 +77,8 @@
...
@@ -77,6 +77,8 @@
#include "transaction.h"
#include "transaction.h"
#include "sql_audit.h"
#include "sql_audit.h"
#include "debug_sync.h"
#ifndef EMBEDDED_LIBRARY
#ifndef EMBEDDED_LIBRARY
static
bool
delayed_get_table
(
THD
*
thd
,
MDL_request
*
grl_protection_request
,
static
bool
delayed_get_table
(
THD
*
thd
,
MDL_request
*
grl_protection_request
,
TABLE_LIST
*
table_list
);
TABLE_LIST
*
table_list
);
...
@@ -1541,6 +1543,8 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
...
@@ -1541,6 +1543,8 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
error
=
HA_ERR_FOUND_DUPP_KEY
;
/* Database can't find key */
error
=
HA_ERR_FOUND_DUPP_KEY
;
/* Database can't find key */
goto
err
;
goto
err
;
}
}
DEBUG_SYNC
(
thd
,
"write_row_replace"
);
/* Read all columns for the row we are going to replace */
/* Read all columns for the row we are going to replace */
table
->
use_all_columns
();
table
->
use_all_columns
();
/*
/*
...
@@ -1729,6 +1733,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
...
@@ -1729,6 +1733,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
}
}
else
if
((
error
=
table
->
file
->
ha_write_row
(
table
->
record
[
0
])))
else
if
((
error
=
table
->
file
->
ha_write_row
(
table
->
record
[
0
])))
{
{
DEBUG_SYNC
(
thd
,
"write_row_noreplace"
);
if
(
!
info
->
ignore
||
if
(
!
info
->
ignore
||
table
->
file
->
is_fatal_error
(
error
,
HA_CHECK_DUP
))
table
->
file
->
is_fatal_error
(
error
,
HA_CHECK_DUP
))
goto
err
;
goto
err
;
...
...
storage/innobase/handler/ha_innodb.cc
View file @
1f746cb0
...
@@ -5063,8 +5063,7 @@ no_commit:
...
@@ -5063,8 +5063,7 @@ no_commit:
switch
(
sql_command
)
{
switch
(
sql_command
)
{
case
SQLCOM_LOAD
:
case
SQLCOM_LOAD
:
if
((
trx
->
duplicates
if
(
trx
->
duplicates
)
{
&
(
TRX_DUP_IGNORE
|
TRX_DUP_REPLACE
)))
{
goto
set_max_autoinc
;
goto
set_max_autoinc
;
}
}
...
@@ -5339,8 +5338,7 @@ ha_innobase::update_row(
...
@@ -5339,8 +5338,7 @@ ha_innobase::update_row(
&&
table
->
next_number_field
&&
table
->
next_number_field
&&
new_row
==
table
->
record
[
0
]
&&
new_row
==
table
->
record
[
0
]
&&
thd_sql_command
(
user_thd
)
==
SQLCOM_INSERT
&&
thd_sql_command
(
user_thd
)
==
SQLCOM_INSERT
&&
(
trx
->
duplicates
&
(
TRX_DUP_IGNORE
|
TRX_DUP_REPLACE
))
&&
trx
->
duplicates
)
{
==
TRX_DUP_IGNORE
)
{
ulonglong
auto_inc
;
ulonglong
auto_inc
;
ulonglong
col_max_value
;
ulonglong
col_max_value
;
...
@@ -8845,6 +8843,7 @@ ha_innobase::extra(
...
@@ -8845,6 +8843,7 @@ ha_innobase::extra(
break
;
break
;
case
HA_EXTRA_RESET_STATE
:
case
HA_EXTRA_RESET_STATE
:
reset_template
(
prebuilt
);
reset_template
(
prebuilt
);
thd_to_trx
(
ha_thd
())
->
duplicates
=
0
;
break
;
break
;
case
HA_EXTRA_NO_KEYREAD
:
case
HA_EXTRA_NO_KEYREAD
:
prebuilt
->
read_just_key
=
0
;
prebuilt
->
read_just_key
=
0
;
...
@@ -8862,19 +8861,18 @@ ha_innobase::extra(
...
@@ -8862,19 +8861,18 @@ ha_innobase::extra(
parameters below. We must not invoke update_thd()
parameters below. We must not invoke update_thd()
either, because the calling threads may change.
either, because the calling threads may change.
CAREFUL HERE, OR MEMORY CORRUPTION MAY OCCUR! */
CAREFUL HERE, OR MEMORY CORRUPTION MAY OCCUR! */
case
HA_EXTRA_I
GNORE_DUP_KEY
:
case
HA_EXTRA_I
NSERT_WITH_UPDATE
:
thd_to_trx
(
ha_thd
())
->
duplicates
|=
TRX_DUP_IGNORE
;
thd_to_trx
(
ha_thd
())
->
duplicates
|=
TRX_DUP_IGNORE
;
break
;
break
;
case
HA_EXTRA_NO_IGNORE_DUP_KEY
:
thd_to_trx
(
ha_thd
())
->
duplicates
&=
~
TRX_DUP_IGNORE
;
break
;
case
HA_EXTRA_WRITE_CAN_REPLACE
:
case
HA_EXTRA_WRITE_CAN_REPLACE
:
thd_to_trx
(
ha_thd
())
->
duplicates
|=
TRX_DUP_REPLACE
;
thd_to_trx
(
ha_thd
())
->
duplicates
|=
TRX_DUP_REPLACE
;
break
;
break
;
case
HA_EXTRA_WRITE_CANNOT_REPLACE
:
case
HA_EXTRA_WRITE_CANNOT_REPLACE
:
thd_to_trx
(
ha_thd
())
->
duplicates
&=
~
TRX_DUP_REPLACE
;
thd_to_trx
(
ha_thd
())
->
duplicates
&=
~
TRX_DUP_REPLACE
;
break
;
break
;
case
HA_EXTRA_NO_IGNORE_DUP_KEY
:
thd_to_trx
(
ha_thd
())
->
duplicates
&=
~
(
TRX_DUP_IGNORE
|
TRX_DUP_REPLACE
);
break
;
default:
/* Do nothing */
default:
/* Do nothing */
;
;
}
}
...
...
storage/innobase/row/row0ins.c
View file @
1f746cb0
...
@@ -1652,7 +1652,7 @@ row_ins_scan_sec_index_for_duplicate(
...
@@ -1652,7 +1652,7 @@ row_ins_scan_sec_index_for_duplicate(
ulint
n_fields_cmp
;
ulint
n_fields_cmp
;
btr_pcur_t
pcur
;
btr_pcur_t
pcur
;
ulint
err
=
DB_SUCCESS
;
ulint
err
=
DB_SUCCESS
;
u
nsigned
allow_duplicates
;
u
lint
allow_duplicates
;
mtr_t
mtr
;
mtr_t
mtr
;
mem_heap_t
*
heap
=
NULL
;
mem_heap_t
*
heap
=
NULL
;
ulint
offsets_
[
REC_OFFS_NORMAL_SIZE
];
ulint
offsets_
[
REC_OFFS_NORMAL_SIZE
];
...
@@ -1683,7 +1683,7 @@ row_ins_scan_sec_index_for_duplicate(
...
@@ -1683,7 +1683,7 @@ row_ins_scan_sec_index_for_duplicate(
btr_pcur_open
(
index
,
entry
,
PAGE_CUR_GE
,
BTR_SEARCH_LEAF
,
&
pcur
,
&
mtr
);
btr_pcur_open
(
index
,
entry
,
PAGE_CUR_GE
,
BTR_SEARCH_LEAF
,
&
pcur
,
&
mtr
);
allow_duplicates
=
thr_get_trx
(
thr
)
->
duplicates
&
TRX_DUP_IGNORE
;
allow_duplicates
=
thr_get_trx
(
thr
)
->
duplicates
;
/* Scan index records and check if there is a duplicate */
/* Scan index records and check if there is a duplicate */
...
@@ -1817,7 +1817,7 @@ row_ins_duplicate_error_in_clust(
...
@@ -1817,7 +1817,7 @@ row_ins_duplicate_error_in_clust(
sure that in roll-forward we get the same duplicate
sure that in roll-forward we get the same duplicate
errors as in original execution */
errors as in original execution */
if
(
trx
->
duplicates
&
TRX_DUP_IGNORE
)
{
if
(
trx
->
duplicates
)
{
/* If the SQL-query will update or replace
/* If the SQL-query will update or replace
duplicate key we will take X-lock for
duplicate key we will take X-lock for
...
@@ -1861,7 +1861,7 @@ row_ins_duplicate_error_in_clust(
...
@@ -1861,7 +1861,7 @@ row_ins_duplicate_error_in_clust(
offsets
=
rec_get_offsets
(
rec
,
cursor
->
index
,
offsets
,
offsets
=
rec_get_offsets
(
rec
,
cursor
->
index
,
offsets
,
ULINT_UNDEFINED
,
&
heap
);
ULINT_UNDEFINED
,
&
heap
);
if
(
trx
->
duplicates
&
TRX_DUP_IGNORE
)
{
if
(
trx
->
duplicates
)
{
/* If the SQL-query will update or replace
/* If the SQL-query will update or replace
duplicate key we will take X-lock for
duplicate key we will take X-lock for
...
...
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