Merge pull request #117 from funbringer/support_table_inheritance
Support table inheritance
This commit is contained in:
commit
1055b06a89
117
bin/pg_repack.c
117
bin/pg_repack.c
@ -240,6 +240,7 @@ static bool sqlstate_equals(PGresult *res, const char *state)
|
|||||||
static bool analyze = true;
|
static bool analyze = true;
|
||||||
static bool alldb = false;
|
static bool alldb = false;
|
||||||
static bool noorder = false;
|
static bool noorder = false;
|
||||||
|
static SimpleStringList parent_table_list = {NULL, NULL};
|
||||||
static SimpleStringList table_list = {NULL, NULL};
|
static SimpleStringList table_list = {NULL, NULL};
|
||||||
static SimpleStringList schema_list = {NULL, NULL};
|
static SimpleStringList schema_list = {NULL, NULL};
|
||||||
static char *orderby = NULL;
|
static char *orderby = NULL;
|
||||||
@ -268,6 +269,7 @@ static pgut_option options[] =
|
|||||||
{
|
{
|
||||||
{ 'b', 'a', "all", &alldb },
|
{ 'b', 'a', "all", &alldb },
|
||||||
{ 'l', 't', "table", &table_list },
|
{ 'l', 't', "table", &table_list },
|
||||||
|
{ 'l', 'I', "parent-table", &parent_table_list },
|
||||||
{ 'l', 'c', "schema", &schema_list },
|
{ 'l', 'c', "schema", &schema_list },
|
||||||
{ 'b', 'n', "no-order", &noorder },
|
{ 'b', 'n', "no-order", &noorder },
|
||||||
{ 'b', 'N', "dry-run", &dryrun },
|
{ 'b', 'N', "dry-run", &dryrun },
|
||||||
@ -310,15 +312,19 @@ main(int argc, char *argv[])
|
|||||||
if (r_index.head && table_list.head)
|
if (r_index.head && table_list.head)
|
||||||
ereport(ERROR, (errcode(EINVAL),
|
ereport(ERROR, (errcode(EINVAL),
|
||||||
errmsg("cannot specify --index (-i) and --table (-t)")));
|
errmsg("cannot specify --index (-i) and --table (-t)")));
|
||||||
|
if (r_index.head && parent_table_list.head)
|
||||||
|
ereport(ERROR, (errcode(EINVAL),
|
||||||
|
errmsg("cannot specify --index (-i) and --parent-table (-I)")));
|
||||||
else if (r_index.head && only_indexes)
|
else if (r_index.head && only_indexes)
|
||||||
ereport(ERROR, (errcode(EINVAL),
|
ereport(ERROR, (errcode(EINVAL),
|
||||||
errmsg("cannot specify --index (-i) and --only-indexes (-x)")));
|
errmsg("cannot specify --index (-i) and --only-indexes (-x)")));
|
||||||
else if (r_index.head && exclude_extension_list.head)
|
else if (r_index.head && exclude_extension_list.head)
|
||||||
ereport(ERROR, (errcode(EINVAL),
|
ereport(ERROR, (errcode(EINVAL),
|
||||||
errmsg("cannot specify --index (-i) and --exclude-extension (-C)")));
|
errmsg("cannot specify --index (-i) and --exclude-extension (-C)")));
|
||||||
else if (only_indexes && !table_list.head)
|
else if (only_indexes && !(table_list.head || parent_table_list.head))
|
||||||
ereport(ERROR, (errcode(EINVAL),
|
ereport(ERROR, (errcode(EINVAL),
|
||||||
errmsg("cannot repack all indexes of database, specify the table(s) via --table (-t)")));
|
errmsg("cannot repack all indexes of database, specify the table(s)"
|
||||||
|
"via --table (-t) or --parent-table (-I)")));
|
||||||
else if (only_indexes && exclude_extension_list.head)
|
else if (only_indexes && exclude_extension_list.head)
|
||||||
ereport(ERROR, (errcode(EINVAL),
|
ereport(ERROR, (errcode(EINVAL),
|
||||||
errmsg("cannot specify --only-indexes (-x) and --exclude-extension (-C)")));
|
errmsg("cannot specify --only-indexes (-x) and --exclude-extension (-C)")));
|
||||||
@ -346,7 +352,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (schema_list.head && table_list.head)
|
if (schema_list.head && (table_list.head || parent_table_list.head))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(EINVAL),
|
(errcode(EINVAL),
|
||||||
errmsg("cannot repack specific table(s) in schema, use schema.table notation instead")));
|
errmsg("cannot repack specific table(s) in schema, use schema.table notation instead")));
|
||||||
@ -356,12 +362,17 @@ main(int argc, char *argv[])
|
|||||||
(errcode(EINVAL),
|
(errcode(EINVAL),
|
||||||
errmsg("cannot specify --table (-t) and --exclude-extension (-C)")));
|
errmsg("cannot specify --table (-t) and --exclude-extension (-C)")));
|
||||||
|
|
||||||
|
if (exclude_extension_list.head && parent_table_list.head)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(EINVAL),
|
||||||
|
errmsg("cannot specify --parent-table (-I) and --exclude-extension (-C)")));
|
||||||
|
|
||||||
if (noorder)
|
if (noorder)
|
||||||
orderby = "";
|
orderby = "";
|
||||||
|
|
||||||
if (alldb)
|
if (alldb)
|
||||||
{
|
{
|
||||||
if (table_list.head)
|
if (table_list.head || parent_table_list.head)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(EINVAL),
|
(errcode(EINVAL),
|
||||||
errmsg("cannot repack specific table(s) in all databases")));
|
errmsg("cannot repack specific table(s) in all databases")));
|
||||||
@ -617,17 +628,22 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
|
|||||||
SimpleStringListCell *cell;
|
SimpleStringListCell *cell;
|
||||||
const char **params = NULL;
|
const char **params = NULL;
|
||||||
int iparam = 0;
|
int iparam = 0;
|
||||||
size_t num_tables;
|
size_t num_parent_tables,
|
||||||
size_t num_schemas;
|
num_tables,
|
||||||
size_t num_params;
|
num_schemas,
|
||||||
size_t num_excluded_extensions;
|
num_params,
|
||||||
|
num_excluded_extensions;
|
||||||
|
|
||||||
|
num_parent_tables = simple_string_list_size(parent_table_list);
|
||||||
num_tables = simple_string_list_size(table_list);
|
num_tables = simple_string_list_size(table_list);
|
||||||
num_schemas = simple_string_list_size(schema_list);
|
num_schemas = simple_string_list_size(schema_list);
|
||||||
num_excluded_extensions = simple_string_list_size(exclude_extension_list);
|
num_excluded_extensions = simple_string_list_size(exclude_extension_list);
|
||||||
|
|
||||||
/* 1st param is the user-specified tablespace */
|
/* 1st param is the user-specified tablespace */
|
||||||
num_params = num_excluded_extensions + num_tables + num_schemas + 1;
|
num_params = num_excluded_extensions +
|
||||||
|
num_parent_tables +
|
||||||
|
num_tables +
|
||||||
|
num_schemas + 1;
|
||||||
params = pgut_malloc(num_params * sizeof(char *));
|
params = pgut_malloc(num_params * sizeof(char *));
|
||||||
|
|
||||||
initStringInfo(&sql);
|
initStringInfo(&sql);
|
||||||
@ -650,18 +666,42 @@ repack_one_database(const char *orderby, char *errbuf, size_t errsize)
|
|||||||
" WHERE ");
|
" WHERE ");
|
||||||
|
|
||||||
params[iparam++] = tablespace;
|
params[iparam++] = tablespace;
|
||||||
if (num_tables)
|
if (num_tables || num_parent_tables)
|
||||||
{
|
{
|
||||||
appendStringInfoString(&sql, "(");
|
/* standalone tables */
|
||||||
for (cell = table_list.head; cell; cell = cell->next)
|
if (num_tables)
|
||||||
{
|
{
|
||||||
/* Construct table name placeholders to be used by PQexecParams */
|
appendStringInfoString(&sql, "(");
|
||||||
appendStringInfo(&sql, "relid = $%d::regclass", iparam + 1);
|
for (cell = table_list.head; cell; cell = cell->next)
|
||||||
params[iparam++] = cell->val;
|
{
|
||||||
if (cell->next)
|
/* Construct table name placeholders to be used by PQexecParams */
|
||||||
appendStringInfoString(&sql, " OR ");
|
appendStringInfo(&sql, "relid = $%d::regclass", iparam + 1);
|
||||||
|
params[iparam++] = cell->val;
|
||||||
|
if (cell->next)
|
||||||
|
appendStringInfoString(&sql, " OR ");
|
||||||
|
}
|
||||||
|
appendStringInfoString(&sql, ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num_tables && num_parent_tables)
|
||||||
|
appendStringInfoString(&sql, " OR ");
|
||||||
|
|
||||||
|
/* parent tables + inherited children */
|
||||||
|
if (num_parent_tables)
|
||||||
|
{
|
||||||
|
appendStringInfoString(&sql, "(");
|
||||||
|
for (cell = parent_table_list.head; cell; cell = cell->next)
|
||||||
|
{
|
||||||
|
/* Construct table name placeholders to be used by PQexecParams */
|
||||||
|
appendStringInfo(&sql,
|
||||||
|
"relid = ANY(repack.get_table_and_inheritors($%d::regclass))",
|
||||||
|
iparam + 1);
|
||||||
|
params[iparam++] = cell->val;
|
||||||
|
if (cell->next)
|
||||||
|
appendStringInfoString(&sql, " OR ");
|
||||||
|
}
|
||||||
|
appendStringInfoString(&sql, ")");
|
||||||
}
|
}
|
||||||
appendStringInfoString(&sql, ")");
|
|
||||||
}
|
}
|
||||||
else if (num_schemas)
|
else if (num_schemas)
|
||||||
{
|
{
|
||||||
@ -2050,7 +2090,7 @@ static bool
|
|||||||
repack_all_indexes(char *errbuf, size_t errsize)
|
repack_all_indexes(char *errbuf, size_t errsize)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
PGresult *res = NULL;
|
PGresult *res = NULL;
|
||||||
StringInfoData sql;
|
StringInfoData sql;
|
||||||
SimpleStringListCell *cell = NULL;
|
SimpleStringListCell *cell = NULL;
|
||||||
const char *params[1];
|
const char *params[1];
|
||||||
@ -2058,7 +2098,7 @@ repack_all_indexes(char *errbuf, size_t errsize)
|
|||||||
initStringInfo(&sql);
|
initStringInfo(&sql);
|
||||||
reconnect(ERROR);
|
reconnect(ERROR);
|
||||||
|
|
||||||
assert(r_index.head || table_list.head);
|
assert(r_index.head || table_list.head || parent_table_list.head);
|
||||||
|
|
||||||
if (!preliminary_checks(errbuf, errsize))
|
if (!preliminary_checks(errbuf, errsize))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -2073,7 +2113,7 @@ repack_all_indexes(char *errbuf, size_t errsize)
|
|||||||
|
|
||||||
cell = r_index.head;
|
cell = r_index.head;
|
||||||
}
|
}
|
||||||
else if (table_list.head)
|
else if (table_list.head || parent_table_list.head)
|
||||||
{
|
{
|
||||||
appendStringInfoString(&sql,
|
appendStringInfoString(&sql,
|
||||||
"SELECT i.relname, idx.indexrelid, idx.indisvalid, idx.indrelid, $1::text, n.nspname"
|
"SELECT i.relname, idx.indexrelid, idx.indisvalid, idx.indrelid, $1::text, n.nspname"
|
||||||
@ -2081,6 +2121,39 @@ repack_all_indexes(char *errbuf, size_t errsize)
|
|||||||
" JOIN pg_namespace n ON n.oid = i.relnamespace"
|
" JOIN pg_namespace n ON n.oid = i.relnamespace"
|
||||||
" WHERE idx.indrelid = $1::regclass ORDER BY indisvalid DESC, i.relname, n.nspname");
|
" WHERE idx.indrelid = $1::regclass ORDER BY indisvalid DESC, i.relname, n.nspname");
|
||||||
|
|
||||||
|
for (cell = parent_table_list.head; cell; cell = cell->next)
|
||||||
|
{
|
||||||
|
int nchildren, i;
|
||||||
|
|
||||||
|
params[0] = cell->val;
|
||||||
|
|
||||||
|
/* find children of this parent 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);
|
||||||
|
|
||||||
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
|
{
|
||||||
|
elog(WARNING, "%s", PQerrorMessage(connection));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
nchildren = PQntuples(res);
|
||||||
|
|
||||||
|
if (nchildren == 0)
|
||||||
|
{
|
||||||
|
elog(WARNING, "relation \"%s\" does not exist", cell->val);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* append new tables to 'table_list' */
|
||||||
|
for (i = 0; i < nchildren; i++)
|
||||||
|
simple_string_list_append(&table_list, getstr(res, i, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
CLEARPGRES(res);
|
||||||
|
|
||||||
cell = table_list.head;
|
cell = table_list.head;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2118,7 +2191,6 @@ repack_all_indexes(char *errbuf, size_t errsize)
|
|||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
CLEARPGRES(res);
|
|
||||||
disconnect();
|
disconnect();
|
||||||
termStringInfo(&sql);
|
termStringInfo(&sql);
|
||||||
return ret;
|
return ret;
|
||||||
@ -2137,6 +2209,7 @@ pgut_help(bool details)
|
|||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -a, --all repack all databases\n");
|
printf(" -a, --all repack all databases\n");
|
||||||
printf(" -t, --table=TABLE repack specific table only\n");
|
printf(" -t, --table=TABLE repack specific table only\n");
|
||||||
|
printf(" -I, --parent-table=TABLE repack specific parent table and its inheritors\n");
|
||||||
printf(" -c, --schema=SCHEMA repack tables in specific schema only\n");
|
printf(" -c, --schema=SCHEMA repack tables in specific schema only\n");
|
||||||
printf(" -s, --tablespace=TBLSPC move repacked tables to a new tablespace\n");
|
printf(" -s, --tablespace=TBLSPC move repacked tables to a new tablespace\n");
|
||||||
printf(" -S, --moveidx move repacked indexes to TBLSPC too\n");
|
printf(" -S, --moveidx move repacked indexes to TBLSPC too\n");
|
||||||
|
@ -108,6 +108,7 @@ The following options can be specified in ``OPTIONS``.
|
|||||||
Options:
|
Options:
|
||||||
-a, --all repack all databases
|
-a, --all repack all databases
|
||||||
-t, --table=TABLE repack specific table only
|
-t, --table=TABLE repack specific table only
|
||||||
|
-I, --parent-table=TABLE repack specific parent table and its inheritors
|
||||||
-c, --schema=SCHEMA repack tables in specific schema only
|
-c, --schema=SCHEMA repack tables in specific schema only
|
||||||
-s, --tablespace=TBLSPC move repacked tables to a new tablespace
|
-s, --tablespace=TBLSPC move repacked tables to a new tablespace
|
||||||
-S, --moveidx move repacked indexes to *TBLSPC* too
|
-S, --moveidx move repacked indexes to *TBLSPC* too
|
||||||
@ -150,6 +151,10 @@ Reorg Options
|
|||||||
reorganized by writing multiple ``-t`` switches. By default, all eligible
|
reorganized by writing multiple ``-t`` switches. By default, all eligible
|
||||||
tables in the target databases are reorganized.
|
tables in the target databases are reorganized.
|
||||||
|
|
||||||
|
``-I TABLE``, ``--parent-table=TABLE``
|
||||||
|
Reorganize both the specified table(s) and its inheritors. Multiple
|
||||||
|
table hierarchies may be reorganized by writing multiple ``-I`` switches.
|
||||||
|
|
||||||
``-c``, ``--schema``
|
``-c``, ``--schema``
|
||||||
Repack the tables in the specified schema(s) only. Multiple schemas may
|
Repack the tables in the specified schema(s) only. Multiple schemas may
|
||||||
be repacked by writing multiple ``-c`` switches. May be used in
|
be repacked by writing multiple ``-c`` switches. May be used in
|
||||||
@ -189,7 +194,7 @@ Reorg Options
|
|||||||
|
|
||||||
``-x``, ``--only-indexes``
|
``-x``, ``--only-indexes``
|
||||||
Repack only the indexes of the specified table(s), which must be specified
|
Repack only the indexes of the specified table(s), which must be specified
|
||||||
with the ``--table`` option.
|
with the ``--table`` or ``--parent-table`` options.
|
||||||
|
|
||||||
``-T SECS``, ``--wait-timeout=SECS``
|
``-T SECS``, ``--wait-timeout=SECS``
|
||||||
pg_repack needs to take an exclusive lock at the end of the
|
pg_repack needs to take an exclusive lock at the end of the
|
||||||
@ -222,7 +227,7 @@ Connection Options
|
|||||||
^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Options to connect to servers. You cannot use ``--all`` and ``--dbname`` or
|
Options to connect to servers. You cannot use ``--all`` and ``--dbname`` or
|
||||||
``--table`` together.
|
``--table`` or ``--parent-table`` together.
|
||||||
|
|
||||||
``-a``, ``--all``
|
``-a``, ``--all``
|
||||||
Reorganize all databases.
|
Reorganize all databases.
|
||||||
|
@ -1,19 +1,21 @@
|
|||||||
Pg_magic_func 1
|
Pg_magic_func 1
|
||||||
pg_finfo_repack_apply 2
|
pg_finfo_repack_apply 2
|
||||||
pg_finfo_repack_disable_autovacuum 3
|
pg_finfo_repack_disable_autovacuum 3
|
||||||
pg_finfo_repack_drop 4
|
pg_finfo_repack_drop 4
|
||||||
pg_finfo_repack_get_order_by 5
|
pg_finfo_repack_get_order_by 5
|
||||||
pg_finfo_repack_indexdef 6
|
pg_finfo_repack_indexdef 6
|
||||||
pg_finfo_repack_swap 7
|
pg_finfo_repack_swap 7
|
||||||
pg_finfo_repack_trigger 8
|
pg_finfo_repack_trigger 8
|
||||||
pg_finfo_repack_version 9
|
pg_finfo_repack_version 9
|
||||||
pg_finfo_repack_index_swap 10
|
pg_finfo_repack_index_swap 10
|
||||||
repack_apply 11
|
pg_finfo_repack_get_table_and_inheritors 11
|
||||||
repack_disable_autovacuum 12
|
repack_apply 12
|
||||||
repack_drop 13
|
repack_disable_autovacuum 13
|
||||||
repack_get_order_by 14
|
repack_drop 14
|
||||||
repack_indexdef 15
|
repack_get_order_by 15
|
||||||
repack_swap 16
|
repack_indexdef 16
|
||||||
repack_trigger 17
|
repack_swap 17
|
||||||
repack_version 18
|
repack_trigger 18
|
||||||
repack_index_swap 19
|
repack_version 19
|
||||||
|
repack_index_swap 20
|
||||||
|
repack_get_table_and_inheritors 21
|
||||||
|
@ -322,3 +322,7 @@ LANGUAGE C VOLATILE STRICT;
|
|||||||
CREATE FUNCTION repack.repack_index_swap(oid) RETURNS void AS
|
CREATE FUNCTION repack.repack_index_swap(oid) RETURNS void AS
|
||||||
'MODULE_PATHNAME', 'repack_index_swap'
|
'MODULE_PATHNAME', 'repack_index_swap'
|
||||||
LANGUAGE C STABLE STRICT;
|
LANGUAGE C STABLE STRICT;
|
||||||
|
|
||||||
|
CREATE FUNCTION repack.get_table_and_inheritors(regclass) RETURNS regclass[] AS
|
||||||
|
'MODULE_PATHNAME', 'repack_get_table_and_inheritors'
|
||||||
|
LANGUAGE C STABLE STRICT;
|
||||||
|
59
lib/repack.c
59
lib/repack.c
@ -25,12 +25,15 @@
|
|||||||
#include "catalog/pg_am.h"
|
#include "catalog/pg_am.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "catalog/pg_inherits_fn.h"
|
||||||
#include "catalog/pg_namespace.h"
|
#include "catalog/pg_namespace.h"
|
||||||
#include "catalog/pg_opclass.h"
|
#include "catalog/pg_opclass.h"
|
||||||
#include "catalog/pg_type.h"
|
#include "catalog/pg_type.h"
|
||||||
#include "commands/tablecmds.h"
|
#include "commands/tablecmds.h"
|
||||||
#include "commands/trigger.h"
|
#include "commands/trigger.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
|
#include "storage/lmgr.h"
|
||||||
|
#include "utils/array.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/lsyscache.h"
|
#include "utils/lsyscache.h"
|
||||||
#include "utils/rel.h"
|
#include "utils/rel.h"
|
||||||
@ -61,6 +64,7 @@ extern Datum PGUT_EXPORT repack_swap(PG_FUNCTION_ARGS);
|
|||||||
extern Datum PGUT_EXPORT repack_drop(PG_FUNCTION_ARGS);
|
extern Datum PGUT_EXPORT repack_drop(PG_FUNCTION_ARGS);
|
||||||
extern Datum PGUT_EXPORT repack_disable_autovacuum(PG_FUNCTION_ARGS);
|
extern Datum PGUT_EXPORT repack_disable_autovacuum(PG_FUNCTION_ARGS);
|
||||||
extern Datum PGUT_EXPORT repack_index_swap(PG_FUNCTION_ARGS);
|
extern Datum PGUT_EXPORT repack_index_swap(PG_FUNCTION_ARGS);
|
||||||
|
extern Datum PGUT_EXPORT repack_get_table_and_inheritors(PG_FUNCTION_ARGS);
|
||||||
|
|
||||||
PG_FUNCTION_INFO_V1(repack_version);
|
PG_FUNCTION_INFO_V1(repack_version);
|
||||||
PG_FUNCTION_INFO_V1(repack_trigger);
|
PG_FUNCTION_INFO_V1(repack_trigger);
|
||||||
@ -71,6 +75,7 @@ PG_FUNCTION_INFO_V1(repack_swap);
|
|||||||
PG_FUNCTION_INFO_V1(repack_drop);
|
PG_FUNCTION_INFO_V1(repack_drop);
|
||||||
PG_FUNCTION_INFO_V1(repack_disable_autovacuum);
|
PG_FUNCTION_INFO_V1(repack_disable_autovacuum);
|
||||||
PG_FUNCTION_INFO_V1(repack_index_swap);
|
PG_FUNCTION_INFO_V1(repack_index_swap);
|
||||||
|
PG_FUNCTION_INFO_V1(repack_get_table_and_inheritors);
|
||||||
|
|
||||||
static void repack_init(void);
|
static void repack_init(void);
|
||||||
static SPIPlanPtr repack_prepare(const char *src, int nargs, Oid *argtypes);
|
static SPIPlanPtr repack_prepare(const char *src, int nargs, Oid *argtypes);
|
||||||
@ -304,9 +309,9 @@ repack_apply(PG_FUNCTION_ARGS)
|
|||||||
* can delete all the rows we have processed at-once.
|
* can delete all the rows we have processed at-once.
|
||||||
*/
|
*/
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
appendStringInfoString(&sql_pop, pkid);
|
appendStringInfoString(&sql_pop, pkid);
|
||||||
else
|
else
|
||||||
appendStringInfo(&sql_pop, ",%s", pkid);
|
appendStringInfo(&sql_pop, ",%s", pkid);
|
||||||
pfree(pkid);
|
pfree(pkid);
|
||||||
}
|
}
|
||||||
/* i must be > 0 (and hence we must have some rows to delete)
|
/* i must be > 0 (and hence we must have some rows to delete)
|
||||||
@ -1289,3 +1294,53 @@ repack_index_swap(PG_FUNCTION_ARGS)
|
|||||||
SPI_finish();
|
SPI_finish();
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn Datum get_table_and_inheritors(PG_FUNCTION_ARGS)
|
||||||
|
* @brief Return array containing Oids of parent table and its children.
|
||||||
|
* Note that this function does not release relation locks.
|
||||||
|
*
|
||||||
|
* get_table_and_inheritors(table)
|
||||||
|
*
|
||||||
|
* @param table parent table.
|
||||||
|
* @retval regclass[]
|
||||||
|
*/
|
||||||
|
Datum
|
||||||
|
repack_get_table_and_inheritors(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
Oid parent = PG_GETARG_OID(0);
|
||||||
|
List *relations;
|
||||||
|
Datum *relations_array;
|
||||||
|
int relations_array_size;
|
||||||
|
ArrayType *result;
|
||||||
|
ListCell *lc;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
LockRelationOid(parent, AccessShareLock);
|
||||||
|
|
||||||
|
/* Check that parent table exists */
|
||||||
|
if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(parent)))
|
||||||
|
PG_RETURN_ARRAYTYPE_P(construct_empty_array(OIDOID));
|
||||||
|
|
||||||
|
/* Also check that children exist */
|
||||||
|
relations = find_all_inheritors(parent, AccessShareLock, NULL);
|
||||||
|
|
||||||
|
relations_array_size = list_length(relations);
|
||||||
|
if (relations_array_size == 0)
|
||||||
|
PG_RETURN_ARRAYTYPE_P(construct_empty_array(OIDOID));
|
||||||
|
|
||||||
|
relations_array = palloc(relations_array_size * sizeof(Datum));
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
foreach (lc, relations)
|
||||||
|
relations_array[i++] = ObjectIdGetDatum(lfirst_oid(lc));
|
||||||
|
|
||||||
|
result = construct_array(relations_array,
|
||||||
|
relations_array_size,
|
||||||
|
OIDOID, sizeof(Oid),
|
||||||
|
true, 'i');
|
||||||
|
|
||||||
|
pfree(relations_array);
|
||||||
|
|
||||||
|
PG_RETURN_ARRAYTYPE_P(result);
|
||||||
|
}
|
||||||
|
@ -474,3 +474,62 @@ INFO: repacking table "exclude_extension_schema.tbl"
|
|||||||
-- => OK
|
-- => OK
|
||||||
\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension
|
\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension
|
||||||
INFO: repacking table "exclude_extension_schema.tbl"
|
INFO: repacking table "exclude_extension_schema.tbl"
|
||||||
|
--
|
||||||
|
-- table inheritance check
|
||||||
|
--
|
||||||
|
CREATE TABLE parent_a(val integer primary key);
|
||||||
|
CREATE TABLE child_a_1(val integer primary key) INHERITS(parent_a);
|
||||||
|
CREATE TABLE child_a_2(val integer primary key) INHERITS(parent_a);
|
||||||
|
CREATE TABLE parent_b(val integer primary key);
|
||||||
|
CREATE TABLE child_b_1(val integer primary key) INHERITS(parent_b);
|
||||||
|
CREATE TABLE child_b_2(val integer primary key) INHERITS(parent_b);
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=dummy_table
|
||||||
|
ERROR: pg_repack failed with error: ERROR: relation "dummy_table" does not exist
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=dummy_index --index=dummy_index
|
||||||
|
ERROR: cannot specify --index (-i) and --parent-table (-I)
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --schema=dummy_schema
|
||||||
|
ERROR: cannot repack specific table(s) in schema, use schema.table notation instead
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --all
|
||||||
|
ERROR: cannot repack specific table(s) in all databases
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b
|
||||||
|
INFO: repacking table "parent_a"
|
||||||
|
INFO: repacking table "parent_b"
|
||||||
|
INFO: repacking table "child_b_1"
|
||||||
|
INFO: repacking table "child_b_2"
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b
|
||||||
|
INFO: repacking table "parent_a"
|
||||||
|
INFO: repacking table "child_a_1"
|
||||||
|
INFO: repacking table "child_a_2"
|
||||||
|
INFO: repacking table "parent_b"
|
||||||
|
INFO: repacking table "child_b_1"
|
||||||
|
INFO: repacking table "child_b_2"
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b --only-indexes
|
||||||
|
INFO: repacking indexes of "parent_a"
|
||||||
|
INFO: repacking index "public"."parent_a_pkey"
|
||||||
|
INFO: repacking indexes of "public.child_b_1"
|
||||||
|
INFO: repacking index "public"."child_b_1_pkey"
|
||||||
|
INFO: repacking indexes of "public.child_b_2"
|
||||||
|
INFO: repacking index "public"."child_b_2_pkey"
|
||||||
|
INFO: repacking indexes of "public.parent_b"
|
||||||
|
INFO: repacking index "public"."parent_b_pkey"
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b --only-indexes
|
||||||
|
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"
|
||||||
|
INFO: repacking indexes of "public.child_b_1"
|
||||||
|
INFO: repacking index "public"."child_b_1_pkey"
|
||||||
|
INFO: repacking indexes of "public.child_b_2"
|
||||||
|
INFO: repacking index "public"."child_b_2_pkey"
|
||||||
|
INFO: repacking indexes of "public.parent_b"
|
||||||
|
INFO: repacking index "public"."parent_b_pkey"
|
||||||
|
@ -472,3 +472,62 @@ INFO: repacking table "exclude_extension_schema.tbl"
|
|||||||
-- => OK
|
-- => OK
|
||||||
\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension
|
\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension
|
||||||
INFO: repacking table "exclude_extension_schema.tbl"
|
INFO: repacking table "exclude_extension_schema.tbl"
|
||||||
|
--
|
||||||
|
-- table inheritance check
|
||||||
|
--
|
||||||
|
CREATE TABLE parent_a(val integer primary key);
|
||||||
|
CREATE TABLE child_a_1(val integer primary key) INHERITS(parent_a);
|
||||||
|
CREATE TABLE child_a_2(val integer primary key) INHERITS(parent_a);
|
||||||
|
CREATE TABLE parent_b(val integer primary key);
|
||||||
|
CREATE TABLE child_b_1(val integer primary key) INHERITS(parent_b);
|
||||||
|
CREATE TABLE child_b_2(val integer primary key) INHERITS(parent_b);
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=dummy_table
|
||||||
|
ERROR: pg_repack failed with error: ERROR: relation "dummy_table" does not exist
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=dummy_index --index=dummy_index
|
||||||
|
ERROR: cannot specify --index (-i) and --parent-table (-I)
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --schema=dummy_schema
|
||||||
|
ERROR: cannot repack specific table(s) in schema, use schema.table notation instead
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --all
|
||||||
|
ERROR: cannot repack specific table(s) in all databases
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b
|
||||||
|
INFO: repacking table "parent_a"
|
||||||
|
INFO: repacking table "parent_b"
|
||||||
|
INFO: repacking table "child_b_1"
|
||||||
|
INFO: repacking table "child_b_2"
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b
|
||||||
|
INFO: repacking table "parent_a"
|
||||||
|
INFO: repacking table "child_a_1"
|
||||||
|
INFO: repacking table "child_a_2"
|
||||||
|
INFO: repacking table "parent_b"
|
||||||
|
INFO: repacking table "child_b_1"
|
||||||
|
INFO: repacking table "child_b_2"
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b --only-indexes
|
||||||
|
INFO: repacking indexes of "parent_a"
|
||||||
|
INFO: repacking index "public"."parent_a_pkey"
|
||||||
|
INFO: repacking indexes of "public.child_b_1"
|
||||||
|
INFO: repacking index "public"."child_b_1_pkey"
|
||||||
|
INFO: repacking indexes of "public.child_b_2"
|
||||||
|
INFO: repacking index "public"."child_b_2_pkey"
|
||||||
|
INFO: repacking indexes of "public.parent_b"
|
||||||
|
INFO: repacking index "public"."parent_b_pkey"
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b --only-indexes
|
||||||
|
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"
|
||||||
|
INFO: repacking indexes of "public.child_b_1"
|
||||||
|
INFO: repacking index "public"."child_b_1_pkey"
|
||||||
|
INFO: repacking indexes of "public.child_b_2"
|
||||||
|
INFO: repacking index "public"."child_b_2_pkey"
|
||||||
|
INFO: repacking indexes of "public.parent_b"
|
||||||
|
INFO: repacking index "public"."parent_b_pkey"
|
||||||
|
@ -296,3 +296,29 @@ CREATE TABLE exclude_extension_schema.tbl(val integer primary key);
|
|||||||
\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension
|
\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension
|
||||||
-- => OK
|
-- => OK
|
||||||
\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension
|
\! pg_repack --dbname=contrib_regression --schema=exclude_extension_schema --exclude-extension=dummy_extension --exclude-extension=dummy_extension
|
||||||
|
|
||||||
|
--
|
||||||
|
-- table inheritance check
|
||||||
|
--
|
||||||
|
CREATE TABLE parent_a(val integer primary key);
|
||||||
|
CREATE TABLE child_a_1(val integer primary key) INHERITS(parent_a);
|
||||||
|
CREATE TABLE child_a_2(val integer primary key) INHERITS(parent_a);
|
||||||
|
CREATE TABLE parent_b(val integer primary key);
|
||||||
|
CREATE TABLE child_b_1(val integer primary key) INHERITS(parent_b);
|
||||||
|
CREATE TABLE child_b_2(val integer primary key) INHERITS(parent_b);
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=dummy_table
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=dummy_index --index=dummy_index
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --schema=dummy_schema
|
||||||
|
-- => ERROR
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=dummy_table --all
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --table=parent_a --parent-table=parent_b --only-indexes
|
||||||
|
-- => OK
|
||||||
|
\! pg_repack --dbname=contrib_regression --parent-table=parent_a --parent-table=parent_b --only-indexes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user