Skip to content

Commit

Permalink
Issue #389: Do not include a declaratively partitioned table with opt…
Browse files Browse the repository at this point in the history
…ion --only-indexes
  • Loading branch information
za-arthur committed May 16, 2024
1 parent aae9f2f commit 0a05d4e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
14 changes: 12 additions & 2 deletions bin/pg_repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -2285,11 +2285,21 @@ repack_all_indexes(char *errbuf, size_t errsize)

params[0] = cell->val;

/* find children of this parent table */
/*
* Find children of this parent table.
*
* The query returns fully qualified table names of all children and
* the parent table. If the parent table is a declaratively
* partitioned table then it isn't included into the result. It
* doesn't make sense to repack indexes of a declaratively partitioned
* table.
*/
res = execute_elevel("SELECT quote_ident(n.nspname) || '.' || quote_ident(c.relname)"
" FROM pg_class c JOIN pg_namespace n on n.oid = c.relnamespace"
" WHERE c.oid = ANY (repack.get_table_and_inheritors($1::regclass))"
" ORDER BY n.nspname, c.relname", 1, params, DEBUG2);
" AND c.relkind != 'p'"
" ORDER BY n.nspname, c.relname",
1, params, DEBUG2);

if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
Expand Down
36 changes: 36 additions & 0 deletions regress/expected/repack-check.out
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,42 @@ INFO: repacking index "public.child_b_2_pkey"
INFO: repacking indexes of "public.parent_b"
INFO: repacking index "public.parent_b_pkey"
--
-- partitioned table check
--
CREATE TABLE partitioned_a(val integer primary key) PARTITION BY RANGE (val);
CREATE TABLE partition_a_1 PARTITION OF partitioned_a FOR VALUES FROM (0) TO (1000);
CREATE TABLE partition_a_2 PARTITION OF partitioned_a FOR VALUES FROM (1000) TO (2000);
CREATE TABLE partition_a_default PARTITION OF partitioned_a DEFAULT
-- => OK
\! pg_repack --dbname=contrib_regression --parent-table=partitioned_a
INFO: repacking table "public.partition_a_1"
INFO: repacking table "public.partition_a_2"
-- => OK
\! pg_repack --dbname=contrib_regression --parent-table=partitioned_a --only-indexes
INFO: repacking indexes of "public.partition_a_1"
INFO: repacking index "public.partition_a_1_pkey"
INFO: repacking indexes of "public.partition_a_2"
INFO: repacking index "public.partition_a_2_pkey"
-- => OK
\! pg_repack --dbname=contrib_regression --parent-table=partitioned_a --parent-table=parent_a
INFO: repacking table "public.child_a_1"
INFO: repacking table "public.child_a_2"
INFO: repacking table "public.parent_a"
INFO: repacking table "public.partition_a_1"
INFO: repacking table "public.partition_a_2"
-- => OK
\! pg_repack --dbname=contrib_regression --parent-table=partitioned_a --parent-table=parent_a --only-indexes
INFO: repacking indexes of "public.partition_a_1"
INFO: repacking index "public.partition_a_1_pkey"
INFO: repacking indexes of "public.partition_a_2"
INFO: repacking index "public.partition_a_2_pkey"
INFO: repacking indexes of "public.child_a_1"
INFO: repacking index "public.child_a_1_pkey"
INFO: repacking indexes of "public.child_a_2"
INFO: repacking index "public.child_a_2_pkey"
INFO: repacking indexes of "public.parent_a"
INFO: repacking index "public.parent_a_pkey"
--
-- Apply count
--
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --apply-count 1234
Expand Down
16 changes: 16 additions & 0 deletions regress/sql/repack-check.sql
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ CREATE TABLE child_b_2(val integer primary key) INHERITS(parent_b);
-- => OK
\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b --only-indexes

--
-- partitioned table check
--
CREATE TABLE partitioned_a(val integer primary key) PARTITION BY RANGE (val);
CREATE TABLE partition_a_1 PARTITION OF partitioned_a FOR VALUES FROM (0) TO (1000);
CREATE TABLE partition_a_2 PARTITION OF partitioned_a FOR VALUES FROM (1000) TO (2000);
CREATE TABLE partition_a_default PARTITION OF partitioned_a DEFAULT
-- => OK
\! pg_repack --dbname=contrib_regression --parent-table=partitioned_a
-- => OK
\! pg_repack --dbname=contrib_regression --parent-table=partitioned_a --only-indexes
-- => OK
\! pg_repack --dbname=contrib_regression --parent-table=partitioned_a --parent-table=parent_a
-- => OK
\! pg_repack --dbname=contrib_regression --parent-table=partitioned_a --parent-table=parent_a --only-indexes

--
-- Apply count
--
Expand Down

0 comments on commit 0a05d4e

Please sign in to comment.