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

Commit68ab8e8

Browse files
committed
SQL commands in pgbench scripts are now ended by semicolons, not newlines.
To allow multiline SQL commands in scripts, adopt the same rules psql usesto decide what is the end of a SQL command, to wit, an unquoted semicolonnot encased in parentheses. Do this by importing the same flex lexer thatpsql uses, since coping with stuff like dollar-quoted literals is hard toget right without going the full nine yards.This makes use of the infrastructure added in commit0ea9efb tosupport independently-written flex lexers scanning the same PsqlScanStateinput-buffer data structure. Since that infrastructure isn't veryfriendly to ad-hoc parsing code such as strtok(), improve exprscan.lso that it can parse either whitespace-separated words or expressiontokens, on demand, and rewrite pgbench.c's backslash-command parsingcode to always use the lexer to fetch tokens.It's still the case that pgbench backslash commands extend to the endof the line, no more and no less. That could be changed in a fairlylocalized way now, and there was some interest in doing so, but itseems like material for a separate patch.In passing, make some marginal cleanups in syntax error reporting,const-ify a few data structures that could use it, and run some ofthis code through pgindent.I can't tell whether the MSVC build scripts need to be taught explicitlyabout the changes here or not, but the buildfarm will soon tell us.Kyotaro Horiguchi and Tom Lane
1 parent5d03201 commit68ab8e8

File tree

6 files changed

+776
-441
lines changed

6 files changed

+776
-441
lines changed

‎doc/src/sgml/ref/pgbench.sgml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -743,13 +743,25 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
743743
</para>
744744

745745
<para>
746-
The format of ascript fileis oneSQL command per line; multiline
747-
SQL commands are not supported. Empty lines and lines beginning with
748-
<literal>--</> are ignored. Scriptfile linescan alsobe
746+
Ascript filecontains oneor more SQL commands terminated by
747+
semicolons. Empty lines and lines beginning with
748+
<literal>--</> are ignored. Scriptfilescan alsocontain
749749
<quote>meta commands</>, which are interpreted by <application>pgbench</>
750750
itself, as described below.
751751
</para>
752752

753+
<note>
754+
<para>
755+
Before <productname>PostgreSQL</> 9.6, SQL commands in script files
756+
were terminated by newlines, and so they could not be continued across
757+
lines. Now a semicolon is <emphasis>required</> to separate consecutive
758+
SQL commands (though a SQL command does not need one if it is followed
759+
by a meta command). If you need to create a script file that works with
760+
both old and new versions of <application>pgbench</>, be sure to write
761+
each SQL command on a single line ending with a semicolon.
762+
</para>
763+
</note>
764+
753765
<para>
754766
There is a simple variable-substitution facility for script files.
755767
Variables can be set by the command-line <option>-D</> option,
@@ -789,7 +801,8 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
789801
</table>
790802

791803
<para>
792-
Script file meta commands begin with a backslash (<literal>\</>).
804+
Script file meta commands begin with a backslash (<literal>\</>) and
805+
extend to the end of the line.
793806
Arguments to a meta command are separated by white space.
794807
These meta commands are supported:
795808
</para>
@@ -806,9 +819,9 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
806819
from <replaceable>expression</>.
807820
The expression may contain integer constants such as <literal>5432</>,
808821
references to variables <literal>:</><replaceable>variablename</>,
809-
and expressions composed ofunary (<literal>-</>)or binary operators
822+
unaryoperators(<literal>+</>, <literal>-</>)and binary operators
810823
(<literal>+</>, <literal>-</>, <literal>*</>, <literal>/</>,
811-
<literal>%</>) with their usual associativity,
824+
<literal>%</>) with their usualprecedence andassociativity,
812825
<link linkend="pgbench-builtin-functions">function calls</>, and
813826
parentheses.
814827
</para>
@@ -938,14 +951,15 @@ f(x) = exp(-parameter * (x - min) / (max - min + 1)) / (1.0 - exp(-parameter))
938951
<listitem>
939952
<para>
940953
Sets variable <replaceable>varname</> to the result of the shell command
941-
<replaceable>command</>. The command must return an integer value
942-
through its standard output.
954+
<replaceable>command</> with the given <replaceable>argument</>(s).
955+
The command must return an integer valuethrough its standard output.
943956
</para>
944957

945-
<para><replaceable>argument</> can be either a text constant or a
946-
<literal>:</><replaceable>variablename</> reference to a variable of
947-
any types. If you want to use <replaceable>argument</> starting with
948-
colons, you need to add an additional colon at the beginning of
958+
<para>
959+
<replaceable>command</> and each <replaceable>argument</> can be either
960+
a text constant or a <literal>:</><replaceable>variablename</> reference
961+
to a variable. If you want to use an <replaceable>argument</> starting
962+
with a colon, write an additional colon at the beginning of
949963
<replaceable>argument</>.
950964
</para>
951965

@@ -964,7 +978,8 @@ f(x) = exp(-parameter * (x - min) / (max - min + 1)) / (1.0 - exp(-parameter))
964978

965979
<listitem>
966980
<para>
967-
Same as <literal>\setshell</literal>, but the result is ignored.
981+
Same as <literal>\setshell</literal>, but the result of the command
982+
is discarded.
968983
</para>
969984

970985
<para>
@@ -1010,7 +1025,7 @@ END;
10101025

10111026
<para>
10121027
The following functions are built into <application>pgbench</> and
1013-
may be used inconjunction with
1028+
may be used inexpressions appearing in
10141029
<link linkend="pgbench-metacommand-set"><literal>\set</literal></link>.
10151030
</para>
10161031

‎src/bin/pgbench/Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ subdir = src/bin/pgbench
77
top_builddir = ../../..
88
include$(top_builddir)/src/Makefile.global
99

10-
OBJS = pgbench.o exprparse.o$(WIN32RES)
10+
OBJS = pgbench.o exprparse.opsqlscan.o$(WIN32RES)
1111

12-
overrideCPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir)$(CPPFLAGS)
12+
overrideCPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir)\
13+
-I$(top_srcdir)/src/bin/psql$(CPPFLAGS)
1314

1415
ifneq ($(PORTNAME), win32)
1516
overrideCFLAGS +=$(PTHREAD_CFLAGS)
@@ -24,6 +25,15 @@ pgbench: $(OBJS) | submake-libpq submake-libpgport
2425
# exprscan is compiled as part of exprparse
2526
exprparse.o: exprscan.c
2627

28+
# we import psqlscan.o as-is from psql
29+
submake-psqlscan:
30+
$(MAKE) -C$(top_builddir)/src/bin/psql psqlscan.o
31+
32+
psqlscan.o: | submake-psqlscan
33+
rm -f$@&&$(LN_S)$(top_builddir)/src/bin/psql/psqlscan.o.
34+
35+
.PHONY: submake-psqlscan
36+
2737
distprep: exprparse.c exprscan.c
2838

2939
install: all installdirs

‎src/bin/pgbench/exprparse.y

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ static PgBenchExprList *make_elist(PgBenchExpr *exp, PgBenchExprList *list);
2222
static PgBenchExpr *make_integer_constant(int64 ival);
2323
static PgBenchExpr *make_variable(char *varname);
2424
static PgBenchExpr *make_op(yyscan_t yyscanner,constchar *operator,
25-
PgBenchExpr *lexpr, PgBenchExpr *rexpr);
26-
staticintfind_func(yyscan_t yyscanner,constchar *fname);
25+
PgBenchExpr *lexpr, PgBenchExpr *rexpr);
26+
staticintfind_func(yyscan_t yyscanner,constchar *fname);
2727
static PgBenchExpr *make_func(yyscan_t yyscanner,int fnumber, PgBenchExprList *args);
2828

2929
%}
@@ -114,28 +114,49 @@ make_op(yyscan_t yyscanner, const char *operator,
114114
* List of available functions:
115115
* - fname: function name
116116
* - nargs: number of arguments
117-
*-1 is a special value for min & max meaning #args >= 1
117+
*-1 is a special value for min & max meaning #args >= 1
118118
* - tag: function identifier from PgBenchFunction enum
119119
*/
120-
staticstruct
120+
staticconststruct
121121
{
122-
char *fname;
123-
intnargs;
122+
constchar *fname;
123+
intnargs;
124124
PgBenchFunction tag;
125-
} PGBENCH_FUNCTIONS[] = {
125+
}PGBENCH_FUNCTIONS[] =
126+
{
126127
/* parsed as operators, executed as functions*/
127-
{"+",2, PGBENCH_ADD },
128-
{"-",2, PGBENCH_SUB },
129-
{"*",2, PGBENCH_MUL },
130-
{"/",2, PGBENCH_DIV },
131-
{"%",2, PGBENCH_MOD },
128+
{
129+
"+",2, PGBENCH_ADD
130+
},
131+
{
132+
"-",2, PGBENCH_SUB
133+
},
134+
{
135+
"*",2, PGBENCH_MUL
136+
},
137+
{
138+
"/",2, PGBENCH_DIV
139+
},
140+
{
141+
"%",2, PGBENCH_MOD
142+
},
132143
/* actual functions*/
133-
{"abs",1, PGBENCH_ABS },
134-
{"min", -1, PGBENCH_MIN },
135-
{"max", -1, PGBENCH_MAX },
136-
{"debug",1, PGBENCH_DEBUG },
144+
{
145+
"abs",1, PGBENCH_ABS
146+
},
147+
{
148+
"min", -1, PGBENCH_MIN
149+
},
150+
{
151+
"max", -1, PGBENCH_MAX
152+
},
153+
{
154+
"debug",1, PGBENCH_DEBUG
155+
},
137156
/* keep as last array element*/
138-
{NULL,0,0 }
157+
{
158+
NULL,0,0
159+
}
139160
};
140161

141162
/*
@@ -147,7 +168,7 @@ static struct
147168
staticint
148169
find_func(yyscan_t yyscanner,constchar *fname)
149170
{
150-
inti =0;
171+
inti =0;
151172

152173
while (PGBENCH_FUNCTIONS[i].fname)
153174
{
@@ -166,7 +187,7 @@ find_func(yyscan_t yyscanner, const char *fname)
166187
static PgBenchExprList *
167188
make_elist(PgBenchExpr *expr, PgBenchExprList *list)
168189
{
169-
PgBenchExprLink *cons;
190+
PgBenchExprLink *cons;
170191

171192
if (list ==NULL)
172193
{
@@ -193,8 +214,8 @@ make_elist(PgBenchExpr *expr, PgBenchExprList *list)
193214
staticint
194215
elist_length(PgBenchExprList *list)
195216
{
196-
PgBenchExprLink *link = list !=NULL? list->head:NULL;
197-
intlen =0;
217+
PgBenchExprLink *link = list !=NULL? list->head:NULL;
218+
intlen =0;
198219

199220
for (;link !=NULL;link =link->next)
200221
len++;
@@ -225,7 +246,7 @@ make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args)
225246
expr->u.function.function = PGBENCH_FUNCTIONS[fnumber].tag;
226247

227248
/* only the link is used, the head/tail is not useful anymore*/
228-
expr->u.function.args = args !=NULL? args->head:NULL;
249+
expr->u.function.args = args !=NULL? args->head:NULL;
229250
if (args)
230251
pg_free(args);
231252

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp