pgsql: Avoid unnecessary computation of pgbench's script line number.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid unnecessary computation of pgbench's script line number.
Date: 2025-02-27 15:58:27
Message-ID: E1tngHL-0000OB-1P@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)manitou-mail(dot)org>
Discussion: https://postgr.es/m/84a8a89e-adb8-47a9-9d34-c13f7150ee45@manitou-mail.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6eb8a1a4f90c542d7ce9dcc381528fcb81390ab9

Modified Files
--------------
src/bin/pgbench/pgbench.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2025-02-27 16:15:46 pgsql: Generalize hash and ordering support in amapi
Previous Message Alexander Korotkov 2025-02-27 09:28:01 pgsql: Get rid of ojrelid local variable in remove_rel_from_query()