mirror of
https://github.com/postgres/postgres.git
synced 2025-05-28 05:21:27 +03:00
pgbench: fix misprocessing of some nested \if constructs.
An \if command appearing within a false (not-to-be-executed) \if branch was incorrectly treated the same as \elif. This could allow statements within the inner \if to be executed when they should not be. Also the missing inner \if stack entry would result in an assertion failure (in assert-enabled builds) when the final \endif is reached. Report and patch by Michail Nikolaev. Back-patch to all supported branches. Discussion: https://postgr.es/m/CANtu0oiA1ke=SP6tauhNqkUdv5QFsJtS1p=aOOf_iU+EhyKkjQ@mail.gmail.com
This commit is contained in:
parent
87e16d6326
commit
ff9dc96f37
@ -3879,8 +3879,14 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
|
|||||||
switch (conditional_stack_peek(st->cstack))
|
switch (conditional_stack_peek(st->cstack))
|
||||||
{
|
{
|
||||||
case IFSTATE_FALSE:
|
case IFSTATE_FALSE:
|
||||||
if (command->meta == META_IF ||
|
if (command->meta == META_IF)
|
||||||
command->meta == META_ELIF)
|
{
|
||||||
|
/* nested if in skipped branch - ignore */
|
||||||
|
conditional_stack_push(st->cstack,
|
||||||
|
IFSTATE_IGNORED);
|
||||||
|
st->command++;
|
||||||
|
}
|
||||||
|
else if (command->meta == META_ELIF)
|
||||||
{
|
{
|
||||||
/* we must evaluate the condition */
|
/* we must evaluate the condition */
|
||||||
st->state = CSTATE_START_COMMAND;
|
st->state = CSTATE_START_COMMAND;
|
||||||
@ -3899,11 +3905,7 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
|
|||||||
conditional_stack_pop(st->cstack);
|
conditional_stack_pop(st->cstack);
|
||||||
if (conditional_active(st->cstack))
|
if (conditional_active(st->cstack))
|
||||||
st->state = CSTATE_START_COMMAND;
|
st->state = CSTATE_START_COMMAND;
|
||||||
|
/* else state remains CSTATE_SKIP_COMMAND */
|
||||||
/*
|
|
||||||
* else state remains in
|
|
||||||
* CSTATE_SKIP_COMMAND
|
|
||||||
*/
|
|
||||||
st->command++;
|
st->command++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -668,6 +668,56 @@ SELECT :v0, :v1, :v2, :v3;
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
# test nested \if constructs
|
||||||
|
$node->pgbench(
|
||||||
|
'--no-vacuum --client=1 --exit-on-abort --transactions=1',
|
||||||
|
0,
|
||||||
|
[qr{actually processed}],
|
||||||
|
[qr{^$}],
|
||||||
|
'nested ifs',
|
||||||
|
{
|
||||||
|
'pgbench_nested_if' => q(
|
||||||
|
\if false
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\if true
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\elif true
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\else
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\endif
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\elif false
|
||||||
|
\if true
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\elif true
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\else
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\endif
|
||||||
|
\else
|
||||||
|
\if false
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\elif false
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\else
|
||||||
|
SELECT 'correct';
|
||||||
|
\endif
|
||||||
|
\endif
|
||||||
|
\if true
|
||||||
|
SELECT 'correct';
|
||||||
|
\else
|
||||||
|
\if true
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\elif true
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\else
|
||||||
|
SELECT 1 / 0;
|
||||||
|
\endif
|
||||||
|
\endif
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
# random determinism when seeded
|
# random determinism when seeded
|
||||||
$node->safe_psql('postgres',
|
$node->safe_psql('postgres',
|
||||||
'CREATE UNLOGGED TABLE seeded_random(seed INT8 NOT NULL, rand TEXT NOT NULL, val INTEGER NOT NULL);'
|
'CREATE UNLOGGED TABLE seeded_random(seed INT8 NOT NULL, rand TEXT NOT NULL, val INTEGER NOT NULL);'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user