Hi Monks!
I am having speed issues with this code. I put together this sample code so I can get
some suggestions. The block of commented out code is the explicit way of the code right
after it. I am suspecting that the line
my $control_num = join ( ',', ('?') x @control );
where I am joining all the control numbers from the array "@control" is
slowing down the query results. I wonder if anyone here would have a suggestion on how
I could improve( speed up) this code or query if someone has done something similar.
Thanks for looking!!!
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
$| = 1; # Disable buffering
my $q = new CGI;
my $db = 'TESTDB';
my $dbh = test::test->connect( $db );
print "\nTesting\n\n";
=code
my $sql = $dbh->exec_select("
SELECT acc, name,date
FROM mytable
WHERE mame<>''
AND ((date + 1 YEAR) >= (CURRENT_DATE))
AND ((date + 1 YEAR) < (CURRENT_DATE + 240 DAYS))
AND controlnum IN ('12345','8877788','23334455','223445988','222339000
+','2222333','223475699','22339668','2223999','009999','11220000','777
+66','88776'
,'9988888','11223756','22388577','9998888','998888','77665555','999988
+8','88877777','666555555','88777766666','112223333','9998877','998887
+7'
,'888777666666','00988777','887777654')
and date between '2010-11-11' and '2011-11-11' order by date desc");
=cut
#=code
my @control = qw(12345 8877788 23334455 223445988 222339000 2222333 22
+3475699 22339668 2223999 009999 11220000 77766 88776
9988888 11223756 22388577 9998888 998888 77665555 999
+9888 88877777 666555555 88777766666 112223333 9998877 9988877 8887776
+66666 00988777 887777654);
my $control_num = join ( ',', ('?') x @control );
my $sql = $dbh->exec_select( "SELECT acc, name,date
FROM mytable
WHERE mame<>''
AND ((date + 1 YEAR) >= (CURRENT_DATE))
AND ((date + 1 YEAR) < (CURRENT_DATE + 2
+40 DAYS))
AND controlnum IN ($control_num)
and date between '2010-11-11' and '2011-
+11-11' order by date desc
", @control);
#=cut
if(@$sql)
{
for(my $i = 0; $i < @$sql; $i++)
{
my $acc = $sql->[$i]{'acc'} || '';
my $name = $sql->[$i]{'name'} || '';
my $date = $sql->[$i]{'date'} || '';
print "\n$acc - $name - $date\n";
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|