respondent_id: response_x, response_y, ...
####
respondent_1: 123, 456, 789, 23, 1574, ...
respondent_2: 65, 1893, 2853, 753, ...
etc.
####
count all respondents who gave response x and response y
####
CREATE TABLE `theTable` (
`response` smallint(5) unsigned NOT NULL default '0',
`respondent` smallint(5) unsigned NOT NULL default '0',
PRIMARY KEY (`response`,`respondent`) )
####
CREATE TABLE `theTable` ( `respondent` smallint(5) unsigned NOT NULL
default '0', `response` smallint(5) unsigned NOT NULL default '0', PRIMARY
KEY (`respondent`,`response`), KEY `respondent` (`respondent`), KEY `response`
(`response`)
)
####
for $i (1 .. $num_responses) {
$sql = "CREATE TABLE r".$i." (respondent smallint unsigned, PRIMARY KEY (respondent))
$sth = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->errstr);
$sth->execute() or die("Could not execute!" . $sth->errstr);
}
####
for $i (1 .. $num_responses) {
$file = ">response_".$i;
open(FILE, $file) or dienice("cannot open file : $_[0] $!");
}
####
$sql = "appropriate select statement";
$sth = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->errstr);
$start_2 = new Benchmark;
for $i (0 .. $iterations) {
$sth->execute() or die("Could not execute 1!" . $dbh->errstr);
}
$count = $sth->fetchrow_array();
$end_2 = new Benchmark;
$diff_2 = timediff($end_2, $start_2);
####
$sql = "appropriate select for response_id_1"
$sth = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->errstr);
$sql = "appropriate select for response_id_2"
$stm = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->errstr);
$start_1 = new Benchmark;
for $i (0 .. $iterations) {
$sth->execute() or die("Could not execute 1!" . $dbh->errstr);
while ($data = $sth->fetchrow_array()) {
$union{$data} = undef;
}
$stm->execute() or die("Could not execute 2!" . $dbh->errstr);
while ($data = $stm->fetchrow_array()) {
$isect{$data} = undef if exists $union{$data};
}
@isect = keys %isect;
}
$end_1 = new Benchmark;
$diff = timediff($end_1, $start_1);
####
$start_1 = new Benchmark;
for $i (0 .. $iterations) {
$table = "<".$db_dir."/r".$response_id;
open(FILE, $table) or dienice("cannot open file : $table $!");
while ($data = ) {
$union{$data} = undef;
}
close(FILE);
$table = "<".$db_dir."/r6000";
open(FILE, $table) or dienice("cannot open file : $table $!");
while ($data = ) {
$isect{$data} = undef if exists $union{$data};
}
close(FILE);
@isect = keys %isect;
$response_id++;
}
$end_1 = new Benchmark;
$diff = timediff($end_1, $start_1);