Tore Aursand <> wrote in
news

:
> On Mon, 06 Oct 2003 13:19:29 +0800, Johnson Lau wrote:
>> #!/usr/bin/perl
>> use strict;
>> use DBI;
>> my $dbh = DBI->connect("DBI:XBase:") or die $DBI::errstr;
>> my $abc = $dbh->selectcol_arrayref("select NAME1 from table1");
>> my $def = $dbh->prepare("delete from table2 where NAME2 = ?",
>> {'MaxRows' => 1}); foreach (@$abc) {
>> $lc->execute($_);
>> }
>
> Does this really take _two hours_ to finish? I've never used FoxPro
> actually, but I didn't think that it was so slow? Doing the same in
> MySQL would have taken just a few seconds, I guess.
FoxPro doesn't really have native SQL support; DBD::XBase is providing it
through flat-file operations. It's not actually using an optimized
database engine.
If table2 isn't indexed (or DBD::XBase can't take advantage of an index)
then the algorithm reduces to a linear search of table2 for each entry in
table1, giving quadratic behavior. In that case, short of switching to a
true database engine, the OP would be best off reading in all the entries
in both tables, using standard hash methods to find their intersection, and
then doing deletes on only those keys in the intersection.