Avoid unnecessary computation of pgbench's script line number.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 27 Feb 2025 15:57:55 +0000 (10:57 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 27 Feb 2025 15:57:55 +0000 (10:57 -0500)
commit6eb8a1a4f90c542d7ce9dcc381528fcb81390ab9
tree2b691f1f31cbe46301150e2ba7e88709d768fdd2
parentc8c74ad7e1cbc71b616f8ae786776c521729976b
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
src/bin/pgbench/pgbench.c