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();
}
Test case provided by Lisheng: ------- ------- ------- ------- --- uuid(), '-','') into @oneid; insert into test1 values (@oneid, @oneid);
-------
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(
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 { $stmt);
my ($dbh, $stmt) = @_;
my $sth = $dbh->prepare(
print "$stmt\n";
$sth->execute();
return $sth;
}
sub doStmt {
my ($dbh, $stmt) = @_;
print "$stmt\n";
my $sth = $dbh->do($stmt);
return $sth;
}
sub getList { t($dbh, $stmt); >fetchrow_ arrayref( )){
my ($dbh)=@_;
my $stmt= "select uid from test1" ;
my ($ref,$sth);
my $list=();
$sth=executeStm
while( my $ref=$sth-
push @${list},@{$ref} ;
}
return $list;
}
sub deleteRow{ user,$password, $uid)=@ _; >connect( $dsn,$user, $password, {RaiseError=>1}); \'$uid\ ',\'$uid\ ')";
my ($dsn,$
my $dbh=DBI-
my $stmt="replace into test1 (id,uid) values(
doStmt($dbh,$stmt);
}
my($dbh, $dbh1,$ dbh2,$dbh3, $dbh4,$ dbh5); "password" ; mysql:database= test:host= 127.0.0. 1:port= 3306"; $dsn,$user, $password, {RaiseError=>1});
my $user="user";
my $password=
my $dsn="DBI:
$dbh = DBI->connect(
my $ref=getList($dbh); >create( \&deleteRow, $dsn,$user, $password, $uid); >create( \&deleteRow, $dsn,$user, $password, $uid); >create( \&deleteRow, $dsn,$user, $password, $uid); >create( \&deleteRow, $dsn,$user, $password, $uid); >create( \&deleteRow, $dsn,$user, $password, $uid); 1_01->join( ); 1_02->join( ); 1_03->join( ); 1_04->join( ); 1_05->join( );
foreach my $uid(@{$ref}){
my $thread_1_01 = threads-
my $thread_1_02 = threads-
my $thread_1_03 = threads-
my $thread_1_04 = threads-
my $thread_1_05 = threads-
$thread_
$thread_
$thread_
$thread_
$thread_
}