Skip to content

Commit 641a9b7

Browse files
committed
Avoid using large pass-by-value struct arguments in pgbench.
In the wake of commit 4a39f87, which noticeably increased the size of struct StatsData and thereby ParsedScript, Coverity started to complain that ParsedScript was unreasonably large to be passing by value. The two places that do this are only used during setup, so they're not really dragging down benchmark measurements --- but gratuitous inefficiency is not a good look in a benchmarking program. Convert to use pointers instead.
1 parent 0fb6954 commit 641a9b7

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/bin/pgbench/pgbench.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ static void doLog(TState *thread, CState *st,
832832
StatsData *agg, bool skipped, double latency, double lag);
833833
static void processXactStats(TState *thread, CState *st, pg_time_usec_t *now,
834834
bool skipped, StatsData *agg);
835-
static void addScript(ParsedScript script);
835+
static void addScript(const ParsedScript *script);
836836
static THREAD_FUNC_RETURN_TYPE THREAD_FUNC_CC threadRun(void *arg);
837837
static void finishCon(CState *st);
838838
static void setalarm(int seconds);
@@ -5743,15 +5743,15 @@ ConditionError(const char *desc, int cmdn, const char *msg)
57435743
* Partial evaluation of conditionals before recording and running the script.
57445744
*/
57455745
static void
5746-
CheckConditional(ParsedScript ps)
5746+
CheckConditional(const ParsedScript *ps)
57475747
{
57485748
/* statically check conditional structure */
57495749
ConditionalStack cs = conditional_stack_create();
57505750
int i;
57515751

5752-
for (i = 0; ps.commands[i] != NULL; i++)
5752+
for (i = 0; ps->commands[i] != NULL; i++)
57535753
{
5754-
Command *cmd = ps.commands[i];
5754+
Command *cmd = ps->commands[i];
57555755

57565756
if (cmd->type == META_COMMAND)
57575757
{
@@ -5762,20 +5762,20 @@ CheckConditional(ParsedScript ps)
57625762
break;
57635763
case META_ELIF:
57645764
if (conditional_stack_empty(cs))
5765-
ConditionError(ps.desc, i + 1, "\\elif without matching \\if");
5765+
ConditionError(ps->desc, i + 1, "\\elif without matching \\if");
57665766
if (conditional_stack_peek(cs) == IFSTATE_ELSE_FALSE)
5767-
ConditionError(ps.desc, i + 1, "\\elif after \\else");
5767+
ConditionError(ps->desc, i + 1, "\\elif after \\else");
57685768
break;
57695769
case META_ELSE:
57705770
if (conditional_stack_empty(cs))
5771-
ConditionError(ps.desc, i + 1, "\\else without matching \\if");
5771+
ConditionError(ps->desc, i + 1, "\\else without matching \\if");
57725772
if (conditional_stack_peek(cs) == IFSTATE_ELSE_FALSE)
5773-
ConditionError(ps.desc, i + 1, "\\else after \\else");
5773+
ConditionError(ps->desc, i + 1, "\\else after \\else");
57745774
conditional_stack_poke(cs, IFSTATE_ELSE_FALSE);
57755775
break;
57765776
case META_ENDIF:
57775777
if (!conditional_stack_pop(cs))
5778-
ConditionError(ps.desc, i + 1, "\\endif without matching \\if");
5778+
ConditionError(ps->desc, i + 1, "\\endif without matching \\if");
57795779
break;
57805780
default:
57815781
/* ignore anything else... */
@@ -5784,7 +5784,7 @@ CheckConditional(ParsedScript ps)
57845784
}
57855785
}
57865786
if (!conditional_stack_empty(cs))
5787-
ConditionError(ps.desc, i + 1, "\\if without matching \\endif");
5787+
ConditionError(ps->desc, i + 1, "\\if without matching \\endif");
57885788
conditional_stack_destroy(cs);
57895789
}
57905790

@@ -5916,7 +5916,7 @@ ParseScript(const char *script, const char *desc, int weight)
59165916

59175917
ps.commands[index] = NULL;
59185918

5919-
addScript(ps);
5919+
addScript(&ps);
59205920

59215921
termPQExpBuffer(&line_buf);
59225922
psql_scan_finish(sstate);
@@ -6093,11 +6093,11 @@ parseScriptWeight(const char *option, char **script)
60936093

60946094
/* append a script to the list of scripts to process */
60956095
static void
6096-
addScript(ParsedScript script)
6096+
addScript(const ParsedScript *script)
60976097
{
6098-
if (script.commands == NULL || script.commands[0] == NULL)
6098+
if (script->commands == NULL || script->commands[0] == NULL)
60996099
{
6100-
pg_log_fatal("empty command list for script \"%s\"", script.desc);
6100+
pg_log_fatal("empty command list for script \"%s\"", script->desc);
61016101
exit(1);
61026102
}
61036103

@@ -6109,7 +6109,7 @@ addScript(ParsedScript script)
61096109

61106110
CheckConditional(script);
61116111

6112-
sql_script[num_scripts] = script;
6112+
sql_script[num_scripts] = *script;
61136113
num_scripts++;
61146114
}
61156115

0 commit comments

Comments
 (0)