#! /usr/bin/perl -wT use strict; use FileHandle(); MAIN: { my ($handle) = FileHandle->new(); # setting dangerous ENV variables to known states $ENV{PATH} = '/bin:/usr/bin:/usr/local/bin'; delete $ENV{IFS}; delete $ENV{CDPATH}; delete $ENV{ENV}; delete $ENV{BASH_ENV}; if (my $pid = $handle->open("|-")) { unless ($handle->print(qq[DROP TABLE IF EXISTS `test`.`alter_table_test`;\n])) { die("Failed to write CREATE TABLE to mysql:$!"); } unless ($handle->print(qq[CREATE TABLE `test`.`alter_table_test` (`a` varchar(255)) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n])) { die("Failed to write CREATE TABLE to mysql:$!"); } foreach my $idx ( 1 .. 6_000_000 ) { unless ($handle->print(qq[INSERT INTO `test`.`alter_table_test` (`a`) VALUES ('Test$idx');\n])) { die("Failed to write INSERT to mysql:$!"); } print "\r$idx"; } print "\nTable populated at " . localtime() . "\n"; unless ($handle->print(qq[CREATE INDEX `a_idx` ON `test`.`alter_table_test` (`a`);\n])) { die("Failed to write CREATE INDEX to mysql:$!"); } unless ($handle->close()) { die("Failed to close mysql:$!"); } print "CREATE INDEX completed at " . localtime() . "\n"; } elsif (defined $pid) { eval { unless (exec({ 'mysql' } 'mysql', '-u', 'root')) { die("Failed to execute mysql:$!"); } }; if ($@) { print STDERR $@; exit(1); } } else { die("Failed to fork:$!"); } }