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

Commit7968184

Browse files
committed
Remove pgbench's restriction on placement of -M switch.
Previously the -M switch had to appear before any switch that directlyor indirectly specified a benchmarking script. This was both confusingand inadequately documented, as per gripe from Tatsuo Ishii. We canremove the restriction at the cost of making an extra pass over thelists of SQL commands, which seems like a cheap price (the string scansthemselves likely cost much more). The change is just to not extractparameters from the SQL commands until we have finished parsing theswitches and know the final value of -M.Per discussion, we'll treat this as a low-grade bug fix and sneak itinto v10, rather than holding it for v11.Tom Lane, reviewed by Tatsuo Ishii and Fabien CoelhoDiscussion:https://postgr.es/m/20170802.110328.1963639094551443169.t-ishii@sraoss.co.jpDiscussion:https://postgr.es/m/10208.1502465077@sss.pgh.pa.us
1 parenta1ef920 commit7968184

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

‎src/bin/pgbench/pgbench.c

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,15 +2844,18 @@ init(bool is_no_vacuum)
28442844
}
28452845

28462846
/*
2847-
* Parse the raw sql and replace :param to $n.
2847+
* Replace :param with $n throughout the command's SQL text, which
2848+
* is a modifiable string in cmd->argv[0].
28482849
*/
28492850
staticbool
2850-
parseQuery(Command*cmd,constchar*raw_sql)
2851+
parseQuery(Command*cmd)
28512852
{
28522853
char*sql,
28532854
*p;
28542855

2855-
sql=pg_strdup(raw_sql);
2856+
/* We don't want to scribble on cmd->argv[0] until done */
2857+
sql=pg_strdup(cmd->argv[0]);
2858+
28562859
cmd->argc=1;
28572860

28582861
p=sql;
@@ -2874,7 +2877,8 @@ parseQuery(Command *cmd, const char *raw_sql)
28742877

28752878
if (cmd->argc >=MAX_ARGS)
28762879
{
2877-
fprintf(stderr,"statement has too many arguments (maximum is %d): %s\n",MAX_ARGS-1,raw_sql);
2880+
fprintf(stderr,"statement has too many arguments (maximum is %d): %s\n",
2881+
MAX_ARGS-1,cmd->argv[0]);
28782882
pg_free(name);
28792883
return false;
28802884
}
@@ -2886,6 +2890,7 @@ parseQuery(Command *cmd, const char *raw_sql)
28862890
cmd->argc++;
28872891
}
28882892

2893+
pg_free(cmd->argv[0]);
28892894
cmd->argv[0]=sql;
28902895
return true;
28912896
}
@@ -2983,9 +2988,15 @@ process_sql_command(PQExpBuffer buf, const char *source)
29832988
my_command= (Command*)pg_malloc0(sizeof(Command));
29842989
my_command->command_num=num_commands++;
29852990
my_command->type=SQL_COMMAND;
2986-
my_command->argc=0;
29872991
initSimpleStats(&my_command->stats);
29882992

2993+
/*
2994+
* Install query text as the sole argv string. If we are using a
2995+
* non-simple query mode, we'll extract parameters from it later.
2996+
*/
2997+
my_command->argv[0]=pg_strdup(p);
2998+
my_command->argc=1;
2999+
29893000
/*
29903001
* If SQL command is multi-line, we only want to save the first line as
29913002
* the "line" label.
@@ -3000,21 +3011,6 @@ process_sql_command(PQExpBuffer buf, const char *source)
30003011
else
30013012
my_command->line=pg_strdup(p);
30023013

3003-
switch (querymode)
3004-
{
3005-
caseQUERY_SIMPLE:
3006-
my_command->argv[0]=pg_strdup(p);
3007-
my_command->argc++;
3008-
break;
3009-
caseQUERY_EXTENDED:
3010-
caseQUERY_PREPARED:
3011-
if (!parseQuery(my_command,p))
3012-
exit(1);
3013-
break;
3014-
default:
3015-
exit(1);
3016-
}
3017-
30183014
returnmy_command;
30193015
}
30203016

@@ -3896,11 +3892,6 @@ main(int argc, char **argv)
38963892
break;
38973893
case'M':
38983894
benchmarking_option_set= true;
3899-
if (num_scripts>0)
3900-
{
3901-
fprintf(stderr,"query mode (-M) should be specified before any transaction scripts (-f or -b)\n");
3902-
exit(1);
3903-
}
39043895
for (querymode=0;querymode<NUM_QUERYMODE;querymode++)
39053896
if (strcmp(optarg,QUERYMODE[querymode])==0)
39063897
break;
@@ -4006,6 +3997,24 @@ main(int argc, char **argv)
40063997
internal_script_used= true;
40073998
}
40083999

4000+
/* if not simple query mode, parse the script(s) to find parameters */
4001+
if (querymode!=QUERY_SIMPLE)
4002+
{
4003+
for (i=0;i<num_scripts;i++)
4004+
{
4005+
Command**commands=sql_script[i].commands;
4006+
intj;
4007+
4008+
for (j=0;commands[j]!=NULL;j++)
4009+
{
4010+
if (commands[j]->type!=SQL_COMMAND)
4011+
continue;
4012+
if (!parseQuery(commands[j]))
4013+
exit(1);
4014+
}
4015+
}
4016+
}
4017+
40094018
/* compute total_weight */
40104019
for (i=0;i<num_scripts;i++)
40114020
/* cannot overflow: weight is 32b, total_weight 64b */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp