Scully4Ever has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I'm somewhat new to Perl and inexperienced with SQL. I've been using DBIx::Simple to pull information from various tables and it has worked great until I have an array of about 40,000 values that I need to match in @all_ids. I've tried a few other methods but run out of memory or it takes too long to complete. After I pull these values, I then need to get the number of unique parts. What is the most efficient way to query an sql table involving a large array?
my @data = $dbh->select( 'table', '*', { ww => [@ww], id => [@all_ids], } )->hashes; my $counter = 0; for (my $i = 0; $i < @data; $i++) { my $part = $data[$i]{'part'}; my $n_value = $data[$i]{'n'}; if ($part !~ m/^0000000.*/) { if (!$seen{$part}) { $seen{$part} = 1; $counter++; } } elsif (!$seen{$n_value}) { $seen{$n_value} = 1; $counter++; } } print "The uin count is $counter\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SQL Select
by Mr. Muskrat (Canon) on Feb 03, 2016 at 22:40 UTC | |
by Scully4Ever (Novice) on Feb 03, 2016 at 23:40 UTC | |
|
Re: SQL Select
by NetWallah (Canon) on Feb 03, 2016 at 22:15 UTC | |
by Scully4Ever (Novice) on Feb 03, 2016 at 23:28 UTC | |
|
Re: SQL Select
by poj (Abbot) on Feb 03, 2016 at 20:35 UTC | |
by Scully4Ever (Novice) on Feb 03, 2016 at 23:24 UTC | |
by poj (Abbot) on Feb 04, 2016 at 14:14 UTC | |
by chacham (Prior) on Feb 04, 2016 at 15:23 UTC |