http://www.perlmonks.org?node_id=953562
punkish has asked for the wisdom of the Perl Monks concerning the following question:

I have a Postgres table with more than 8 million rows. Given the following two ways of doing the same query, I get wildly different results.

$q .= '%'; ## query 1 my $sql = qq{ SELECT a, b, c FROM t WHERE Lower( a ) LIKE '$q' }; my $sth1 = $dbh->prepare($sql); $sth1->execute(); ## query 2 my $sth2 = $dbh->prepare(qq{ SELECT a, b, c FROM t WHERE Lower( a ) LIKE ? }); $sth2->execute($q);

query 2 is at least an order of magnitude slower than query 1... seems like it is not using the indexes, while query 1 is using the index.

Would love hear why.



when small people start casting long shadows, it is time to go to bed