Comment 4 for bug 1323235

Revision history for this message
Peiran Song (peiran-song) wrote :

Test case provided by Lisheng:
--------------------------------------
1) create table test1(id varchar(32), uid varchar(32), primary key(id), unique key uk(uid)) engine = innodb;
2) insert 100000 rows into test1:
select replace(uuid(),'-','') into @oneid; insert into test1 values (@oneid, @oneid);
3) run the following perl script in three sessions. The script does REPLACE INTO for each row and invokes 5 threads to do the same.

#!/usr/bin/perl

use DBI;
use threads;

sub executeStmt {
my ($dbh, $stmt) = @_;
my $sth = $dbh->prepare($stmt);
print "$stmt\n";
$sth->execute();
return $sth;
}

sub doStmt {
my ($dbh, $stmt) = @_;
print "$stmt\n";
my $sth = $dbh->do($stmt);
return $sth;
}

sub getList {
my ($dbh)=@_;
my $stmt= "select uid from test1" ;
my ($ref,$sth);
my $list=();
$sth=executeStmt($dbh,$stmt);
while( my $ref=$sth->fetchrow_arrayref()){
push @${list},@{$ref} ;
}
return $list;
}

sub deleteRow{
my ($dsn,$user,$password,$uid)=@_;
my $dbh=DBI->connect($dsn,$user,$password, {RaiseError=>1});
my $stmt="replace into test1 (id,uid) values(\'$uid\',\'$uid\')";
doStmt($dbh,$stmt);
}

my($dbh,$dbh1,$dbh2,$dbh3,$dbh4,$dbh5);
my $user="user";
my $password="password";
my $dsn="DBI:mysql:database=test:host=127.0.0.1:port=3306";
$dbh = DBI->connect($dsn,$user,$password, {RaiseError=>1});

my $ref=getList($dbh);
foreach my $uid(@{$ref}){
my $thread_1_01 = threads->create(\&deleteRow,$dsn,$user,$password,$uid);
my $thread_1_02 = threads->create(\&deleteRow,$dsn,$user,$password,$uid);
my $thread_1_03 = threads->create(\&deleteRow,$dsn,$user,$password,$uid);
my $thread_1_04 = threads->create(\&deleteRow,$dsn,$user,$password,$uid);
my $thread_1_05 = threads->create(\&deleteRow,$dsn,$user,$password,$uid);
$thread_1_01->join();
$thread_1_02->join();
$thread_1_03->join();
$thread_1_04->join();
$thread_1_05->join();
}