Re: Using DBI, better option than importing into @array
- From: usenet@xxxxxxxxxxxxxxx
- Date: Mon, 30 Jul 2007 22:26:42 -0000
On Jul 30, 2:30 pm, Jason <jwcarl...@xxxxxxxxx> wrote:
The most current problem is SPEED!
Yeah, I imagine so. The killer is that you are submitting a full
selectall inside a loop. You should generally NEVER do that. By
constructing a different SQL statement each time (because you hard-
code the id in the SQL) it means the statement will never be found in
your database server's cache, so the server must compute an execution
plan over and over again. Instead, you should always use the prepare
method (outside of the loop) and then an execute (inside the loop).
The array is almost surely also a problem, but I'm not fully
understanding your intent. It would be very helpful to see a few
sample rows (or mock-up rows) from each table. I think you should be
doing a table straight join to avoid the need to pre-load the array,
but it would be far easier to make a recommendation if I saw some
sample data and you gave a specific example of what you want to do
with this data.
On other points related to style (and having nothing to do with
whether these points should be used in your instance, because I don't
think they should):
for ($count=0; $count < 20; $count++) {
($id, $lastmodified, $subject) = split(/\|:\|/, $filenames[$count]);
It's more Perlish to do a simple iterative loop like this:
for (0..20) { #Perl ain't C!
But your intent seems to be just to do an array slice. If you want to
take an array slice, don't create a counter and increment it; just
slice the array directly, such as:
foreach my $line_of_the_array ( @array[0..20] ) {
Oh, and, also:
$dbh->quote($id)
If you are sure your $id cannot be tainted (such as it has an integer
type imposed by the database) then you don't need to quote it (and
doing so further slows you down).
Show me some sample rows and I'll respond with some more specific
info...
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
.
- Follow-Ups:
- References:
- Prev by Date: Re: Using DBI, better option than importing into @array
- Next by Date: Re: Using DBI, better option than importing into @array
- Previous by thread: Re: Using DBI, better option than importing into @array
- Next by thread: Re: Using DBI, better option than importing into @array
- Index(es):
Relevant Pages
|