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

Commit 6eb8a1a

Browse files
committed
Avoid unnecessary computation of pgbench's script line number.
ParseScript only needs the lineno for meta-commands, so let's not bother computing it otherwise. While this doesn't save much given the previous patch, there's no point in doing unnecessary work. While we're at it, avoid calling psql_scan_get_location() twice for a meta-command. One reason for making this change is that the line number computed in ParseScript's main loop was actually wrong in most cases: it would point just past the semicolon of the previous SQL command, not at what the user thinks the current command's line number is. We could add some code to skip whitespace before capturing the line number, but it would be pretty pointless at present. Just move the call to avoid the temptation to rely on that value. (Once we've lexed the backslash, the computed line number will be right.) This change also means that pgbench never inquires about the location before it's lexed something, so that the care taken in the previous patch to behave sanely in that case is unnecessary. It seems best to keep that logic, though, as future callers might depend on it. Author: Daniel Vérité <daniel@manitou-mail.org> Discussion: https://postgr.es/m/84a8a89e-adb8-47a9-9d34-c13f7150ee45@manitou-mail.org
1 parent c8c74ad commit 6eb8a1a

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5677,22 +5677,17 @@ postprocess_sql_command(Command *my_command)
56775677
* At call, we have scanned only the initial backslash.
56785678
*/
56795679
static Command *
5680-
process_backslash_command(PsqlScanState sstate, const char *source)
5680+
process_backslash_command(PsqlScanState sstate, const char *source,
5681+
int lineno, int start_offset)
56815682
{
56825683
Command *my_command;
56835684
PQExpBufferData word_buf;
56845685
int word_offset;
56855686
int offsets[MAX_ARGS]; /* offsets of argument words */
5686-
int start_offset;
5687-
int lineno;
56885687
int j;
56895688

56905689
initPQExpBuffer(&word_buf);
56915690

5692-
/* Remember location of the backslash */
5693-
psql_scan_get_location(sstate, &lineno, &start_offset);
5694-
start_offset--;
5695-
56965691
/* Collect first word of command */
56975692
if (!expr_lex_one_word(sstate, &word_buf, &word_offset))
56985693
{
@@ -5980,16 +5975,12 @@ ParseScript(const char *script, const char *desc, int weight)
59805975

59815976
for (;;)
59825977
{
5983-
int lineno;
5984-
int start_offset;
59855978
PsqlScanResult sr;
59865979
promptStatus_t prompt;
59875980
Command *command = NULL;
59885981

59895982
resetPQExpBuffer(&line_buf);
59905983

5991-
psql_scan_get_location(sstate, &lineno, &start_offset);
5992-
59935984
sr = psql_scan(sstate, &line_buf, &prompt);
59945985

59955986
/* If we collected a new SQL command, process that */
@@ -6002,7 +5993,15 @@ ParseScript(const char *script, const char *desc, int weight)
60025993
/* If we reached a backslash, process that */
60035994
if (sr == PSCAN_BACKSLASH)
60045995
{
6005-
command = process_backslash_command(sstate, desc);
5996+
int lineno;
5997+
int start_offset;
5998+
5999+
/* Capture location of the backslash */
6000+
psql_scan_get_location(sstate, &lineno, &start_offset);
6001+
start_offset--;
6002+
6003+
command = process_backslash_command(sstate, desc,
6004+
lineno, start_offset);
60066005

60076006
if (command)
60086007
{

0 commit comments

Comments
 (0)