Hi hackers!

While testing pgbench initialization on current master with Kirill,
we noticed that the --unlogged-tables tweak from [0] with
--partitions=N silently downgrades not only pgbench_accounts'
partitioned parent, but also the plain tables pgbench_branches,
pgbench_tellers and pgbench_history to PERMANENT.  So
the option's documented meaning silently depends on an unrelated
option:

    $ pgbench -i -I dt --unlogged-tables --partitions=2 -s 1 pq
    $ psql -d pq -tc "select relname, relpersistence from pg_class
                      where relname like 'pgbench_%' order by relname"
     pgbench_accounts   | p
     pgbench_accounts_1 | u
     pgbench_accounts_2 | u
     pgbench_branches   | p   <- three plain tables should be unlogged
     pgbench_tellers    | p   <-
     pgbench_history    | p   <-

The obvious fix - restrict the PART_NONE exception to pgbench_accounts
- is however incomplete: it makes pgbench_branches unlogged, while the
accounts foreign key is declared on the permanent partitioned parent,
and "constraints on permanent tables may reference only permanent
tables".  The combination --unlogged-tables --partitions --foreign-keys
then fails.

So the attached patch keeps PERMANENT, when partitioning is in use, for
exactly two tables: pgbench_accounts and pgbench_branches. Seems like
making the branches exception conditional on --foreign-keys would brake
separately-runnable init steps ('... -I dt' then '... -I f')..

[0] - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=e2bab2d7920

--
Best regards,
Roman Khapov

Attachment: 0001-pgbench-honor-unlogged-tables-for-non-partitioned-ta.patch
Description: Binary data

Reply via email to