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

Commit2a23dbc

Browse files
committed
pgbench: fix misprocessing of some nested \if constructs.
An \if command appearing within a false (not-to-be-executed) \ifbranch was incorrectly treated the same as \elif. This could allowstatements within the inner \if to be executed when they shouldnot be. Also the missing inner \if stack entry would result in anassertion failure (in assert-enabled builds) when the final \endifis reached.Report and patch by Michail Nikolaev. Back-patch to allsupported branches.Discussion:https://postgr.es/m/CANtu0oiA1ke=SP6tauhNqkUdv5QFsJtS1p=aOOf_iU+EhyKkjQ@mail.gmail.com
1 parentc7f3c41 commit2a23dbc

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

‎src/bin/pgbench/pgbench.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3446,8 +3446,14 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
34463446
switch (conditional_stack_peek(st->cstack))
34473447
{
34483448
caseIFSTATE_FALSE:
3449-
if (command->meta==META_IF||
3450-
command->meta==META_ELIF)
3449+
if (command->meta==META_IF)
3450+
{
3451+
/* nested if in skipped branch - ignore */
3452+
conditional_stack_push(st->cstack,
3453+
IFSTATE_IGNORED);
3454+
st->command++;
3455+
}
3456+
elseif (command->meta==META_ELIF)
34513457
{
34523458
/* we must evaluate the condition */
34533459
st->state=CSTATE_START_COMMAND;
@@ -3466,11 +3472,7 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
34663472
conditional_stack_pop(st->cstack);
34673473
if (conditional_active(st->cstack))
34683474
st->state=CSTATE_START_COMMAND;
3469-
3470-
/*
3471-
* else state remains in
3472-
* CSTATE_SKIP_COMMAND
3473-
*/
3475+
/* else state remains CSTATE_SKIP_COMMAND */
34743476
st->command++;
34753477
}
34763478
break;

‎src/bin/pgbench/t/001_pgbench_with_server.pl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,56 @@
622622
}
623623
});
624624

625+
# test nested \if constructs
626+
$node->pgbench(
627+
'--no-vacuum --client=1 --transactions=1',
628+
0,
629+
[qr{actually processed}],
630+
[qr{^$}],
631+
'nested ifs',
632+
{
633+
'pgbench_nested_if'=>q(
634+
\if false
635+
SELECT 1 / 0;
636+
\if true
637+
SELECT 1 / 0;
638+
\elif true
639+
SELECT 1 / 0;
640+
\else
641+
SELECT 1 / 0;
642+
\endif
643+
SELECT 1 / 0;
644+
\elif false
645+
\if true
646+
SELECT 1 / 0;
647+
\elif true
648+
SELECT 1 / 0;
649+
\else
650+
SELECT 1 / 0;
651+
\endif
652+
\else
653+
\if false
654+
SELECT 1 / 0;
655+
\elif false
656+
SELECT 1 / 0;
657+
\else
658+
SELECT 'correct';
659+
\endif
660+
\endif
661+
\if true
662+
SELECT 'correct';
663+
\else
664+
\if true
665+
SELECT 1 / 0;
666+
\elif true
667+
SELECT 1 / 0;
668+
\else
669+
SELECT 1 / 0;
670+
\endif
671+
\endif
672+
)
673+
});
674+
625675
# random determinism when seeded
626676
$node->safe_psql('postgres',
627677
'CREATE UNLOGGED TABLE seeded_random(seed INT8 NOT NULL, rand TEXT NOT NULL, val INTEGER NOT NULL);'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp