[EMAIL PROTECTED] writes:

> my @want = qw/name1 name2 name3/; #etc ...
> sub by_big_where2 {
> # This is 'where2' when benchmark is running.
>   my @qlist = map { $dbh->quote($_) } @want;
>   my $qstring = join(', ', @qlist);
>   my $sth = $dbh->prepare("select * from tablename 
>       where name in ( $qstring )");
>   $sth->execute();
>   my @row;
>   while (@row = $sth->fetchrow_array()) {
> #    print "Row is: @row\n";
>   }
> }

You could try this.  It may or may not be faster, but it will work,
and possibly allows the DBD driver to do most of the work at the C
level:

my $qstring = join(", ", ("?") x @want);
my $sth = $dbh->prepare("SELECT * FROM TABLENAME WHERE NAME IN ($qstring)");
$sth->execute(@want);

In other words, using placeholders.  None of these methods is
particularly wonderful, though, in that it makes it difficult for the
DBD layer and the DB itself to properly cache parsed queries -- since
the query changes repeatedly, it will cache as many queries as
different numbers of params passed into the function.  This is an
improvement, though, in hardcoding the values, because then it would
possibly cache a parsed query for every different set of values passed
in.  So this isn't perfect, but it probably is better.

Chip

-- 
Chip Turner                   [EMAIL PROTECTED]
                              RHN Web Engineer

Reply via email to