bman has asked for the wisdom of the Perl Monks concerning the following question:
I know that database is not an issue because I can query in database itself in a jiffy. No slow downs. When I look into MySQL stats, I see many "slow queries" entries. I presume that this is from the web.
This is my piece of code: snip...]
andif ($Choice eq 't_datein') { if ($Choice2 eq 't_datein') { $query .= " ORDER BY $Choice $SortOrder, t_timein $SortOrder, +$Choice2, t_timein $SortOrder"; } else { $query .= " ORDER BY $Choice $SortOrder, t_timein $SortOrder, +$Choice2"; } } else { $query .= " ORDER BY $Choice $SortOrder, $Choice2"; } if ($Top ne 'All') { $query .= " LIMIT $Top"; } $sth = $dbh->prepare($query); $sth->execute();
snip..]
That's pretty much the core what I have been doing. I think that the problem is my code. How can I speed up those queries (for example, a simple 'select count(*) from table' shouldn't take 30 seconds).if (($Top eq 'All') && (!$SearchString)) { $total = $sth->fetchrow_array (); $total = "I'm confused" if !defined ($total); print "</table style=\"border: 1 solid #000080\" align='center'>\n +"; print "<p>\n"; print "<h4>Query has returned $total number of records.</h4>\n"; print "<hr width=\"98%\" align='left'>Please, narrow down your cry +teria or make sure that if"; print "<b><font color='red'> ALL is selected</b></font>,<br>"; print "a string is provided in the query field as well!<p>\n"; } else { while (($t_datein, $t_timein, $t_dateout, $t_timeout, $t_port, $t_prot, $t_where, $t_from, $t_pkt_out, $t_pkt_in, $t_byte_in, $t_byte_out, $t_id) = $sth->fetchrow_ar +ray ()) { $skip = $i % 2; $i++; $bytes = $t_byte_out + $bytes; if ($t_where =~ /(adult|sex|oral|porn|xxx)/i) #you get an idea + { print "<tr bgcolor=\"#FF9999\">\n"; } elsif ($skip eq 0 ) { print "<tr bgcolor=\"#CCFFCC\">\n"; } else { print "<tr>\n"; } print " <td align='right' bgcolor='black' align='top'><font co +lor='white'><b>$i</b></font></td>\n"; print " <td align='right' align='top'>$t_from</td><td align +='right' align='top'>"; if ($t_where =~ /.*\.[a-z][a-z][a-z]?$/i) { print "<a href=\"http://$t_where\">$t_where</a>"; } else { print "$t_where"; } print "</td>\n"; print " <td align='right' align='top'>$t_datein $t_timein</ +td><td align='right' align='top'>$t_dateout $t_timeout</td>\n"; print "<td align='right' align='top'>$t_byte_out</td>\n"; } $bytes = ($bytes / 1024) / 1024; } ($sth)->finish(); ($dbh)->disconnect();
I really appreciate your words of wisdom. :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Speed blues
by Fastolfe (Vicar) on Oct 25, 2000 at 20:03 UTC | |
|
Re: Speed blues
by wardk (Deacon) on Oct 25, 2000 at 20:49 UTC | |
|
RE: Speed blues
by Jonathan (Curate) on Oct 25, 2000 at 20:33 UTC | |
|
Re: Speed blues
by Maclir (Curate) on Oct 26, 2000 at 01:34 UTC | |
|
Re: Speed blues
by cianoz (Friar) on Oct 26, 2000 at 04:24 UTC | |
|
RE: Speed blues
by lachoy (Parson) on Oct 25, 2000 at 21:14 UTC |