Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 77ce50a

Browse files
committed
Fix psql lexer to avoid use of backtracking.
Per previous experimentation, backtracking slows down lexing performance significantly (by about a third). It's usually pretty easy to avoid, just need to have rules that accept an incomplete construct and do whatever the lexer would have done otherwise. The backtracking was introduced by the patch that added quoted variable substitution. Back-patch to 9.0 where that was added.
1 parent 2e95f1f commit 77ce50a

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/bin/psql/psqlscan.l

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,23 @@ other .
723723
escape_variable(true);
724724
}
725725
726+
/*
727+
* These rules just avoid the need for scanner backup if one of the
728+
* two rules above fails to match completely.
729+
*/
730+
731+
:'[A-Za-z0-9_]* {
732+
/* Throw back everything but the colon */
733+
yyless(1);
734+
ECHO;
735+
}
736+
737+
:\"[A-Za-z0-9_]* {
738+
/* Throw back everything but the colon */
739+
yyless(1);
740+
ECHO;
741+
}
742+
726743
/*
727744
* Back to backend-compatible rules.
728745
*/
@@ -913,7 +930,7 @@ other .
913930
}
914931
}
915932

916-
:[A-Za-z0-9_]* {
933+
:[A-Za-z0-9_]+ {
917934
/* Possible psql variable substitution */
918935
if (option_type == OT_VERBATIM)
919936
ECHO;
@@ -960,6 +977,20 @@ other .
960977
}
961978
}
962979
980+
:'[A-Za-z0-9_]* {
981+
/* Throw back everything but the colon */
982+
yyless(1);
983+
ECHO;
984+
BEGIN(xslashdefaultarg);
985+
}
986+
987+
:\"[A-Za-z0-9_]* {
988+
/* Throw back everything but the colon */
989+
yyless(1);
990+
ECHO;
991+
BEGIN(xslashdefaultarg);
992+
}
993+
963994
"|" {
964995
ECHO;
965996
if (option_type == OT_FILEPIPE)

0 commit comments

Comments
 (0)