Commit 25ee7051 authored by Alvaro Herrera's avatar Alvaro Herrera

pgbench: Remove \cset

Partial revert of commit 6260cc55, "pgbench: add \cset and \gset
commands".

While \gset is widely considered a useful and necessary tool for user-
defined benchmarks, \cset does not have as much value, and its
implementation was considered "not to be up to project standards"
(though I, Álvaro, can't quite understand exactly how).  Therefore,
remove \cset.

Author: Fabien Coelho
Discussion: https://postgr.es/m/alpine.DEB.2.21.1903230716030.18811@lancre
Discussion: https://postgr.es/m/201901101900.mv7zduch6sad@alvherre.pgsql
parent 6f97457e
......@@ -963,48 +963,6 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
</para>
<variablelist>
<varlistentry id='pgbench-metacommand-cset'>
<term>
<literal>\cset [<replaceable>prefix</replaceable>]</literal>
</term>
<listitem>
<para>
This command may be used to end SQL queries, replacing an embedded
semicolon (<literal>\;</literal>) within a compound SQL command.
</para>
<para>
When this command is used, the preceding SQL query is expected to
return one row, the columns of which are stored into variables named after
column names, and prefixed with <replaceable>prefix</replaceable> if provided.
</para>
<para>
The following example sends four queries as one compound SQL command,
inducing one message sent at the protocol level.
The result of the first query is stored into variable <replaceable>one</replaceable>,
the results of the third query are stored into variables <replaceable>z_three</replaceable>
and <replaceable>z_four</replaceable>,
whereas the results of the other queries are discarded.
<programlisting>
-- compound of four queries
SELECT 1 AS one \cset
SELECT 2 AS two \;
SELECT 3 AS three, 4 AS four \cset z_
SELECT 5;
</programlisting>
</para>
<note>
<para>
<literal>\cset</literal> does not work when empty SQL queries appear
within a compound SQL command.
</para>
</note>
</listitem>
</varlistentry>
<varlistentry id='pgbench-metacommand-gset'>
<term>
<literal>\gset [<replaceable>prefix</replaceable>]</literal>
......@@ -1012,8 +970,8 @@ SELECT 5;
<listitem>
<para>
This command may be used to end SQL queries, replacing a final semicolon
(<literal>;</literal>).
This command may be used to end SQL queries, taking the place of the
terminating semicolon (<literal>;</literal>).
</para>
<para>
......@@ -1026,7 +984,7 @@ SELECT 5;
The following example puts the final account balance from the first query
into variable <replaceable>abalance</replaceable>, and fills variables
<replaceable>p_two</replaceable> and <replaceable>p_three</replaceable>
with integers from the last query.
with integers from the third query.
The result of the second query is discarded.
<programlisting>
UPDATE pgbench_accounts
......@@ -1038,13 +996,6 @@ SELECT 1 \;
SELECT 2 AS two, 3 AS three \gset p_
</programlisting>
</para>
<note>
<para>
<literal>\gset</literal> does not work when empty SQL queries appear
within a compound SQL command.
</para>
</note>
</listitem>
</varlistentry>
......
This diff is collapsed.
......@@ -538,22 +538,18 @@ pgbench(
}
});
# working \gset and \cset
# working \gset
pgbench(
'-t 1', 0,
[ qr{type: .*/001_pgbench_gset_and_cset}, qr{processed: 1/1} ],
[ qr{type: .*/001_pgbench_gset}, qr{processed: 1/1} ],
[ qr{command=3.: int 0\b},
qr{command=5.: int 1\b},
qr{command=6.: int 2\b},
qr{command=8.: int 3\b},
qr{command=9.: int 4\b},
qr{command=10.: int 5\b},
qr{command=12.: int 6\b},
qr{command=13.: int 7\b},
qr{command=14.: int 8\b},
qr{command=16.: int 9\b} ],
'pgbench gset and cset commands',
{ '001_pgbench_gset_and_cset' => q{-- test gset and cset
qr{command=10.: int 4\b},
qr{command=12.: int 5\b} ],
'pgbench gset command',
{ '001_pgbench_gset' => q{-- test gset
-- no columns
SELECT \gset
-- one value
......@@ -563,21 +559,15 @@ SELECT 0 AS i0 \gset
SELECT 1 AS i1, 2 AS i2 \gset
\set i debug(:i1)
\set i debug(:i2)
-- cset & gset to follow
SELECT :i2 + 1 AS i3, :i2 * :i2 AS i4 \cset
SELECT 5 AS i5 \gset
\set i debug(:i3)
\set i debug(:i4)
\set i debug(:i5)
-- with prefix
SELECT 6 AS i6, 7 AS i7 \cset x_
SELECT 8 AS i8 \gset y_
\set i debug(:x_i6)
\set i debug(:x_i7)
\set i debug(:y_i8)
SELECT 3 AS i3 \gset x_
\set i debug(:x_i3)
-- overwrite existing variable
SELECT 0 AS i9, 9 AS i9 \gset
\set i debug(:i9)
SELECT 0 AS i4, 4 AS i4 \gset
\set i debug(:i4)
-- work on the last SQL command under \;
\; \; SELECT 0 AS i5 \; SELECT 5 AS i5 \; \; \gset
\set i debug(:i5)
} });
# trigger many expression errors
......@@ -772,20 +762,17 @@ SELECT LEAST(}.join(', ', (':i') x 256).q{)}
[ 'bad boolean', 2,
[qr{malformed variable.*trueXXX}], q{\set b :badtrue or true} ],
# GSET & CSET
# GSET
[ 'gset no row', 2,
[qr{expected one row, got 0\b}], q{SELECT WHERE FALSE \gset} ],
[ 'cset no row', 2,
[qr{expected one row, got 0\b}], q{SELECT WHERE FALSE \cset
SELECT 1 AS i\gset}, 1 ],
[ 'gset alone', 1, [qr{gset/cset cannot start a script}], q{\gset} ],
[ 'gset alone', 1, [qr{gset must follow a SQL command}], q{\gset} ],
[ 'gset no SQL', 1,
[qr{gset/cset must follow a SQL command}], q{\set i +1
[qr{gset must follow a SQL command}], q{\set i +1
\gset} ],
[ 'gset too many arguments', 1,
[qr{too many arguments}], q{SELECT 1 \gset a b} ],
[ 'gset after gset', 1,
[qr{gset/cset cannot follow one another}], q{SELECT 1 AS i \gset
[qr{gset must follow a SQL command}], q{SELECT 1 AS i \gset
\gset} ],
[ 'gset non SELECT', 2,
[qr{expected one row, got 0}],
......
......@@ -693,15 +693,8 @@ other .
* substitution. We want these before {self}, also.
*/
"\\"; {
/* Count semicolons in compound commands */
cur_state->escaped_semicolons++;
/* Force a semicolon into the query buffer */
psqlscan_emit(cur_state, yytext + 1, 1);
}
"\\": {
/* Force a colon into the query buffer */
"\\"[;:] {
/* Force a semi-colon or colon into the query buffer */
psqlscan_emit(cur_state, yytext + 1, 1);
}
......@@ -1072,9 +1065,6 @@ psql_scan(PsqlScanState state,
/* Set current output target */
state->output_buf = query_buf;
/* Reset number of escaped semicolons seen */
state->escaped_semicolons = 0;
/* Set input source */
if (state->buffer_stack != NULL)
yy_switch_to_buffer(state->buffer_stack->buf, state->scanner);
......@@ -1218,16 +1208,6 @@ psql_scan_reset(PsqlScanState state)
state->dolqstart = NULL;
}
/*
* Return the number of escaped semicolons in the lexed string seen by the
* previous psql_scan call.
*/
int
psql_scan_get_escaped_semicolons(PsqlScanState state)
{
return state->escaped_semicolons;
}
/*
* Reselect this lexer (psqlscan.l) after using another one.
*
......
......@@ -90,8 +90,6 @@ extern PsqlScanResult psql_scan(PsqlScanState state,
extern void psql_scan_reset(PsqlScanState state);
extern int psql_scan_get_escaped_semicolons(PsqlScanState state);
extern void psql_scan_reselect_sql_lexer(PsqlScanState state);
extern bool psql_scan_in_quote(PsqlScanState state);
......
......@@ -112,7 +112,6 @@ typedef struct PsqlScanStateData
int start_state; /* yylex's starting/finishing state */
int paren_depth; /* depth of nesting in parentheses */
int xcdepth; /* depth of nesting in slash-star comments */
int escaped_semicolons; /* number of embedded (\;) semicolons */
char *dolqstart; /* current $foo$ quote start string */
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment