introduce option --parent-table (-I, stands for 'inheritance'), fix function repack_one_database(), introduce function repack.get_table_and_inheritors()
This commit is contained in:
@ -1,19 +1,21 @@
|
||||
Pg_magic_func 1
|
||||
pg_finfo_repack_apply 2
|
||||
pg_finfo_repack_disable_autovacuum 3
|
||||
pg_finfo_repack_drop 4
|
||||
pg_finfo_repack_get_order_by 5
|
||||
pg_finfo_repack_indexdef 6
|
||||
pg_finfo_repack_swap 7
|
||||
pg_finfo_repack_trigger 8
|
||||
pg_finfo_repack_version 9
|
||||
pg_finfo_repack_index_swap 10
|
||||
repack_apply 11
|
||||
repack_disable_autovacuum 12
|
||||
repack_drop 13
|
||||
repack_get_order_by 14
|
||||
repack_indexdef 15
|
||||
repack_swap 16
|
||||
repack_trigger 17
|
||||
repack_version 18
|
||||
repack_index_swap 19
|
||||
Pg_magic_func 1
|
||||
pg_finfo_repack_apply 2
|
||||
pg_finfo_repack_disable_autovacuum 3
|
||||
pg_finfo_repack_drop 4
|
||||
pg_finfo_repack_get_order_by 5
|
||||
pg_finfo_repack_indexdef 6
|
||||
pg_finfo_repack_swap 7
|
||||
pg_finfo_repack_trigger 8
|
||||
pg_finfo_repack_version 9
|
||||
pg_finfo_repack_index_swap 10
|
||||
pg_finfo_repack_get_table_and_inheritors 11
|
||||
repack_apply 12
|
||||
repack_disable_autovacuum 13
|
||||
repack_drop 14
|
||||
repack_get_order_by 15
|
||||
repack_indexdef 16
|
||||
repack_swap 17
|
||||
repack_trigger 18
|
||||
repack_version 19
|
||||
repack_index_swap 20
|
||||
repack_get_table_and_inheritors 21
|
||||
|
@ -254,3 +254,8 @@ LANGUAGE C VOLATILE STRICT;
|
||||
CREATE FUNCTION repack.repack_index_swap(oid) RETURNS void AS
|
||||
'MODULE_PATHNAME', 'repack_index_swap'
|
||||
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;
|
||||
|
||||
|
41
lib/repack.c
41
lib/repack.c
@ -25,12 +25,14 @@
|
||||
#include "catalog/pg_am.h"
|
||||
#endif
|
||||
|
||||
#include "catalog/pg_inherits_fn.h"
|
||||
#include "catalog/pg_namespace.h"
|
||||
#include "catalog/pg_opclass.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/tablecmds.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "miscadmin.h"
|
||||
#include "utils/array.h"
|
||||
#include "utils/builtins.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/rel.h"
|
||||
@ -61,6 +63,7 @@ extern Datum PGUT_EXPORT repack_swap(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_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_trigger);
|
||||
@ -71,6 +74,7 @@ PG_FUNCTION_INFO_V1(repack_swap);
|
||||
PG_FUNCTION_INFO_V1(repack_drop);
|
||||
PG_FUNCTION_INFO_V1(repack_disable_autovacuum);
|
||||
PG_FUNCTION_INFO_V1(repack_index_swap);
|
||||
PG_FUNCTION_INFO_V1(repack_get_table_and_inheritors);
|
||||
|
||||
static void repack_init(void);
|
||||
static SPIPlanPtr repack_prepare(const char *src, int nargs, Oid *argtypes);
|
||||
@ -312,9 +316,9 @@ repack_apply(PG_FUNCTION_ARGS)
|
||||
* can delete all the rows we have processed at-once.
|
||||
*/
|
||||
if (i == 0)
|
||||
appendStringInfoString(&sql_pop, pkid);
|
||||
appendStringInfoString(&sql_pop, pkid);
|
||||
else
|
||||
appendStringInfo(&sql_pop, ",%s", pkid);
|
||||
appendStringInfo(&sql_pop, ",%s", pkid);
|
||||
pfree(pkid);
|
||||
}
|
||||
/* i must be > 0 (and hence we must have some rows to delete)
|
||||
@ -1342,3 +1346,36 @@ RenameRelationInternal(Oid myrelid, const char *newrelname, Oid namespaceId)
|
||||
PG_END_TRY();
|
||||
}
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
||||
relations = find_all_inheritors(parent, NoLock, 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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user