Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6eb8a1a

Browse files
committed
Avoid unnecessary computation of pgbench's script line number.
ParseScript only needs the lineno for meta-commands, so let's notbother computing it otherwise. While this doesn't save much giventhe previous patch, there's no point in doing unnecessary work.While we're at it, avoid calling psql_scan_get_location() twice fora meta-command.One reason for making this change is that the line number computedin ParseScript's main loop was actually wrong in most cases: itwould 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 linenumber, but it would be pretty pointless at present. Just move thecall to avoid the temptation to rely on that value. (Once we'velexed the backslash, the computed line number will be right.)This change also means that pgbench never inquires about thelocation before it's lexed something, so that the care taken inthe previous patch to behave sanely in that case is unnecessary.It seems best to keep that logic, though, as future callersmight 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 parentc8c74ad commit6eb8a1a

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
staticCommand*
5680-
process_backslash_command(PsqlScanStatesstate,constchar*source)
5680+
process_backslash_command(PsqlScanStatesstate,constchar*source,
5681+
intlineno,intstart_offset)
56815682
{
56825683
Command*my_command;
56835684
PQExpBufferDataword_buf;
56845685
intword_offset;
56855686
intoffsets[MAX_ARGS];/* offsets of argument words */
5686-
intstart_offset;
5687-
intlineno;
56885687
intj;
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-
intlineno;
5984-
intstart_offset;
59855978
PsqlScanResultsr;
59865979
promptStatus_tprompt;
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+
intlineno;
5997+
intstart_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)

[8]ページ先頭

©2009-2025 Movatter.jp