[open-ils-commits] r17174 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Aug 11 16:18:32 EDT 2010
Author: miker
Date: 2010-08-11 16:18:26 -0400 (Wed, 11 Aug 2010)
New Revision: 17174
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
Log:
Use a COALESCE/NULLIF nested structure instead of CASE (one branch, easy peasy) for 4x speedup in the core search query
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm 2010-08-11 17:13:46 UTC (rev 17173)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm 2010-08-11 20:18:26 UTC (rev 17174)
@@ -570,17 +570,13 @@
return '' if (!@$only_atoms);
if ($bump eq 'first_word') {
- return "/* first_word */ CASE WHEN naco_normalize(".$node->table_alias.".value) ".
- "LIKE naco_normalize(".$self->QueryParser->quote_value($only_atoms->[0]->content).") \|\| '\%' ".
- "THEN $multiplier ELSE 1 END";
+ return " /* first_word */ COALESCE(NULLIF( (naco_normalize(".$node->table_alias.".value) ~ ('^'||naco_normalize(".$self->QueryParser->quote_value($only_atoms->[0]->content).")))::BOOL::INT, 0 ) * $multiplier, 1)";
} elsif ($bump eq 'full_match') {
- return "/* full_match */ CASE WHEN naco_normalize(".$node->table_alias.".value) ".
- "LIKE". join( '||\'%\'||', map { " naco_normalize(".$self->QueryParser->quote_value($_->content).") " } @$only_atoms ) .
- "THEN $multiplier ELSE 1 END";
+ return " /* full_match */ COALESCE(NULLIF( (naco_normalize(".$node->table_alias.".value) ~ ('^'||".
+ join( "||' '||", map { "naco_normalize(".$self->QueryParser->quote_value($_->content).")" } @$only_atoms )."||'\$'))::BOOL::INT, 0 ) * $multiplier, 1)";
} elsif ($bump eq 'word_order') {
- return "/* word_order */ CASE WHEN naco_normalize(".$node->table_alias.".value) ".
- "LIKE '\%'||". join( '||\'%\'||', map { " naco_normalize(".$self->QueryParser->quote_value($_->content).") " } @$only_atoms ) . '||\'%\' '.
- "THEN $multiplier ELSE 1 END";
+ return " /* word_order */ COALESCE(NULLIF( (naco_normalize(".$node->table_alias.".value) ~ (".
+ join( "||'.*'||", map { "naco_normalize(".$self->QueryParser->quote_value($_->content).")" } @$only_atoms )."))::BOOL::INT, 0 ) * $multiplier, 1)";
}
return '';
@@ -634,6 +630,8 @@
next if ($used_bumps{$b});
$used_bumps{$b} = 1;
+ next if ($$bumps{$b}{multiplier} == 1); # optimization to remove unneeded bumps
+
my $bump_case = $self->rel_bump( $node, $b, $$bumps{$b}{multiplier} );
$node_rank .= "\n\t\t\t\t * " . $bump_case if ($bump_case);
}
More information about the open-ils-commits
mailing list