Use placeholders in search SQL

I didn't do that before in order to ensure that the planner could always
optimize the LIKE queries, but it's optimizing them just fine with
placeholders now.
This commit is contained in:
Yorhel 2016-10-09 09:30:58 +02:00
parent 3eb1cbae63
commit b023bec0cd

View file

@ -777,9 +777,9 @@ sub dbSearch {
return !$name ? [] : $s->dbAll( return !$name ? [] : $s->dbAll(
'SELECT name, section FROM man_index !W ORDER BY name, section LIMIT ?', 'SELECT name, section FROM man_index !W ORDER BY name, section LIMIT ?',
{ # Don't use wildcards in this query, prevents index usage. {
"lower(name) LIKE '\L$name\E%'" => 1, 'lower(name) LIKE ?' => escape_like(lc $name).'%',
$sect ? ("section ILIKE '\L$sect\E%'" => 1) : () $sect ? ('section ILIKE ?' => escape_like(lc $sect).'%') : (),
}, },
$limit $limit
); );