diff options
| author | Pavan Deolasee | 2017-08-18 05:43:32 +0000 |
|---|---|---|
| committer | Pavan Deolasee | 2017-08-18 05:43:32 +0000 |
| commit | eea51611515116fd3eff1ab795c9f2fdcf6a08cc (patch) | |
| tree | 4d3e9eab417d94912201967edc679854d3ad9267 /src/bin/pgbench | |
| parent | 0b69492af7186538d831823a6fce3b64616be197 (diff) | |
| parent | 21d304dfedb4f26d0d6587d9ac39b1b5c499bb55 (diff) | |
Merge commit '21d304dfedb4f26d0d6587d9ac39b1b5c499bb55'
This is the merge-base of PostgreSQL's master branch and REL_10_STABLE branch.
This should be the last merge from PG's master branch into XL 10 branch.
Subsequent merges must happen from REL_10_STABLE branch
Diffstat (limited to 'src/bin/pgbench')
| -rw-r--r-- | src/bin/pgbench/Makefile | 5 | ||||
| -rw-r--r-- | src/bin/pgbench/pgbench.c | 59 |
2 files changed, 37 insertions, 27 deletions
diff --git a/src/bin/pgbench/Makefile b/src/bin/pgbench/Makefile index 1503d00e12..8a8e516896 100644 --- a/src/bin/pgbench/Makefile +++ b/src/bin/pgbench/Makefile @@ -10,17 +10,18 @@ include $(top_builddir)/src/Makefile.global OBJS = pgbench.o exprparse.o $(WIN32RES) override CPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir) $(CPPFLAGS) -LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils -lpq +override LDFLAGS := -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_pgport) $(LDFLAGS) ifneq ($(PORTNAME), win32) override CFLAGS += $(PTHREAD_CFLAGS) endif +LIBS += $(PTHREAD_LIBS) all: pgbench pgbench: $(OBJS) | submake-libpq submake-libpgport submake-libpgfeutils - $(CC) $(CFLAGS) $^ $(libpq_pgport) $(PTHREAD_LIBS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X) + $(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X) # exprscan is compiled as part of exprparse exprparse.o: exprscan.c diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 077bdf4a02..d06c8a9ecd 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -2957,15 +2957,18 @@ init(bool is_no_vacuum) } /* - * Parse the raw sql and replace :param to $n. + * Replace :param with $n throughout the command's SQL text, which + * is a modifiable string in cmd->argv[0]. */ static bool -parseQuery(Command *cmd, const char *raw_sql) +parseQuery(Command *cmd) { char *sql, *p; - sql = pg_strdup(raw_sql); + /* We don't want to scribble on cmd->argv[0] until done */ + sql = pg_strdup(cmd->argv[0]); + cmd->argc = 1; p = sql; @@ -2987,7 +2990,8 @@ parseQuery(Command *cmd, const char *raw_sql) if (cmd->argc >= MAX_ARGS) { - fprintf(stderr, "statement has too many arguments (maximum is %d): %s\n", MAX_ARGS - 1, raw_sql); + fprintf(stderr, "statement has too many arguments (maximum is %d): %s\n", + MAX_ARGS - 1, cmd->argv[0]); pg_free(name); return false; } @@ -2999,6 +3003,7 @@ parseQuery(Command *cmd, const char *raw_sql) cmd->argc++; } + pg_free(cmd->argv[0]); cmd->argv[0] = sql; return true; } @@ -3096,10 +3101,16 @@ process_sql_command(PQExpBuffer buf, const char *source) my_command = (Command *) pg_malloc0(sizeof(Command)); my_command->command_num = num_commands++; my_command->type = SQL_COMMAND; - my_command->argc = 0; initSimpleStats(&my_command->stats); /* + * Install query text as the sole argv string. If we are using a + * non-simple query mode, we'll extract parameters from it later. + */ + my_command->argv[0] = pg_strdup(p); + my_command->argc = 1; + + /* * If SQL command is multi-line, we only want to save the first line as * the "line" label. */ @@ -3113,21 +3124,6 @@ process_sql_command(PQExpBuffer buf, const char *source) else my_command->line = pg_strdup(p); - switch (querymode) - { - case QUERY_SIMPLE: - my_command->argv[0] = pg_strdup(p); - my_command->argc++; - break; - case QUERY_EXTENDED: - case QUERY_PREPARED: - if (!parseQuery(my_command, p)) - exit(1); - break; - default: - exit(1); - } - return my_command; } @@ -4034,11 +4030,6 @@ main(int argc, char **argv) break; case 'M': benchmarking_option_set = true; - if (num_scripts > 0) - { - fprintf(stderr, "query mode (-M) should be specified before any transaction scripts (-f or -b)\n"); - exit(1); - } for (querymode = 0; querymode < NUM_QUERYMODE; querymode++) if (strcmp(optarg, QUERYMODE[querymode]) == 0) break; @@ -4155,6 +4146,24 @@ main(int argc, char **argv) internal_script_used = true; } + /* if not simple query mode, parse the script(s) to find parameters */ + if (querymode != QUERY_SIMPLE) + { + for (i = 0; i < num_scripts; i++) + { + Command **commands = sql_script[i].commands; + int j; + + for (j = 0; commands[j] != NULL; j++) + { + if (commands[j]->type != SQL_COMMAND) + continue; + if (!parseQuery(commands[j])) + exit(1); + } + } + } + /* compute total_weight */ for (i = 0; i < num_scripts; i++) /* cannot overflow: weight is 32b, total_weight 64b */ |
