Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be93200

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 de63218 commit be93200

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
@@ -722,6 +722,23 @@ other .
722722
escape_variable(true);
723723
}
724724
725+
/*
726+
* These rules just avoid the need for scanner backup if one of the
727+
* two rules above fails to match completely.
728+
*/
729+
730+
:'[A-Za-z0-9_]* {
731+
/* Throw back everything but the colon */
732+
yyless(1);
733+
ECHO;
734+
}
735+
736+
:\"[A-Za-z0-9_]* {
737+
/* Throw back everything but the colon */
738+
yyless(1);
739+
ECHO;
740+
}
741+
725742
/*
726743
* Back to backend-compatible rules.
727744
*/
@@ -912,7 +929,7 @@ other .
912929
}
913930
}
914931

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

0 commit comments

Comments
 (0)