in reply to Basic Perl array intersection faster than mysql query join.
Why do you use the @col_1 and @col_2 arrays? Also it's more efficient to store just undefs in the hashes and then use exists():
$sql = "SELECT col_2 FROM theTable WHERE col_1 = $value_1"; $sth = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->errstr) +; $sth->execute() or die("Could not execute 1!" . $dbh->errstr); while ($data = $sth->fetchrow_array()) { $union{$data} = undef; } $sql = "SELECT col_2 FROM theTable WHERE col_1 = $value_2"; $sth = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->errstr) +; $sth->execute() or die("Could not execute 2!" . $dbh->errstr); while ($data = $sth->fetchrow_array()) { $isect{$data} = undef if exists $union{$data}; } @isect = keys %isect;
Jenda
|
We'd like to help you learn to help yourself Look around you, all you see are sympathetic eyes Stroll around the grounds until you feel at home -- P. Simon in Mrs. Robinson |
|
|---|