Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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"; } }

In reply to For a better efficiency and speed question! by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (10)
    As of 2016-10-20 20:25 GMT
    Find Nodes?
      Voting Booth?
      How many different varieties (color, size, etc) of socks do you have in your sock drawer?

      Results (281 votes). Check out past polls.