Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #389: Do not include a declaratively partitioned table with option --only-indexes #398

Merged
merged 5 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 'r'"
" ORDER BY n.nspname, c.relname",
1, params, DEBUG2);

if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
Expand Down
43 changes: 43 additions & 0 deletions regress/expected/repack-check.out
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,46 @@ INFO: repacking table "public.tbl_cluster"
--
\! pg_repack --dbname=contrib_regression --table=tbl_cluster --switch-threshold 200
INFO: repacking table "public.tbl_cluster"
--
-- partitioned table check
--
CREATE TABLE partitioned_a(val integer NOT NULL) 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 indexes separately to support Postgres 10 which doesn't support
-- indexes on a partitioned table itself
CREATE UNIQUE INDEX partition_a_1_val_idx ON partition_a_1 (val);
CREATE UNIQUE INDEX partition_a_2_val_idx ON partition_a_2 (val);
-- These statements will fail on Postgres 10
CREATE UNIQUE INDEX partitioned_a_val_idx ON ONLY partitioned_a (val);
ALTER INDEX partitioned_a_val_idx ATTACH PARTITION partition_a_1_val_idx;
ALTER INDEX partitioned_a_val_idx ATTACH PARTITION partition_a_2_val_idx;
-- => 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_val_idx"
INFO: repacking indexes of "public.partition_a_2"
INFO: repacking index "public.partition_a_2_val_idx"
-- => 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_val_idx"
INFO: repacking indexes of "public.partition_a_2"
INFO: repacking index "public.partition_a_2_val_idx"
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"
Loading
Loading