Merge branch 'change-tablespace'
Conflicts: bin/pg_repack.c doc/pg_repack.rst
This commit is contained in:
@ -179,7 +179,9 @@ CREATE VIEW repack.tables AS
|
||||
'CREATE TABLE repack.log_' || R.oid || ' (id bigserial PRIMARY KEY, pk repack.pk_' || R.oid || ', row ' || repack.oid2text(R.oid) || ')' AS create_log,
|
||||
repack.get_create_trigger(R.oid, PK.indexrelid) AS create_trigger,
|
||||
repack.get_enable_trigger(R.oid) as enable_trigger,
|
||||
'CREATE TABLE repack.table_' || R.oid || ' WITH (' || array_to_string(array_append(R.reloptions, 'oids=' || CASE WHEN R.relhasoids THEN 'true' ELSE 'false' END), ',') || ') TABLESPACE ' || coalesce(quote_ident(S.spcname), 'pg_default') || ' AS SELECT ' || repack.get_columns_for_create_as(R.oid) || ' FROM ONLY ' || repack.oid2text(R.oid) AS create_table,
|
||||
'CREATE TABLE repack.table_' || R.oid || ' WITH (' || array_to_string(array_append(R.reloptions, 'oids=' || CASE WHEN R.relhasoids THEN 'true' ELSE 'false' END), ',') || ') TABLESPACE ' AS create_table_1,
|
||||
coalesce(quote_ident(S.spcname), 'pg_default') tablespace_orig,
|
||||
' AS SELECT ' || repack.get_columns_for_create_as(R.oid) || ' FROM ONLY ' || repack.oid2text(R.oid) AS create_table_2,
|
||||
repack.get_drop_columns(R.oid, 'repack.table_' || R.oid) AS drop_columns,
|
||||
'DELETE FROM repack.log_' || R.oid AS delete_log,
|
||||
'LOCK TABLE ' || repack.oid2text(R.oid) || ' IN ACCESS EXCLUSIVE MODE' AS lock_table,
|
||||
@ -205,9 +207,9 @@ CREATE VIEW repack.tables AS
|
||||
AND N.nspname NOT IN ('pg_catalog', 'information_schema')
|
||||
AND N.nspname NOT LIKE E'pg\\_temp\\_%';
|
||||
|
||||
CREATE FUNCTION repack.repack_indexdef(oid, oid) RETURNS text AS
|
||||
CREATE FUNCTION repack.repack_indexdef(oid, oid, name) RETURNS text AS
|
||||
'MODULE_PATHNAME', 'repack_indexdef'
|
||||
LANGUAGE C STABLE STRICT;
|
||||
LANGUAGE C STABLE;
|
||||
|
||||
CREATE FUNCTION repack.repack_trigger() RETURNS trigger AS
|
||||
'MODULE_PATHNAME', 'repack_trigger'
|
||||
|
47
lib/repack.c
47
lib/repack.c
@ -618,20 +618,59 @@ repack_get_order_by(PG_FUNCTION_ARGS)
|
||||
*
|
||||
* @param index Oid of target index.
|
||||
* @param table Oid of table of the index.
|
||||
* @param tablespace Namespace for the index. If NULL keep the original.
|
||||
* @retval Create index DDL for temp table.
|
||||
*/
|
||||
Datum
|
||||
repack_indexdef(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid index = PG_GETARG_OID(0);
|
||||
Oid table = PG_GETARG_OID(1);
|
||||
Oid index;
|
||||
Oid table;
|
||||
Name tablespace = NULL;
|
||||
IndexDef stmt;
|
||||
StringInfoData str;
|
||||
|
||||
if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
|
||||
PG_RETURN_NULL();
|
||||
|
||||
index = PG_GETARG_OID(0);
|
||||
table = PG_GETARG_OID(1);
|
||||
|
||||
if (!PG_ARGISNULL(2))
|
||||
tablespace = PG_GETARG_NAME(2);
|
||||
|
||||
parse_indexdef(&stmt, index, table);
|
||||
|
||||
initStringInfo(&str);
|
||||
appendStringInfo(&str, "%s index_%u ON repack.table_%u USING %s (%s)%s",
|
||||
stmt.create, index, table, stmt.type, stmt.columns, stmt.options);
|
||||
appendStringInfo(&str, "%s index_%u ON repack.table_%u USING %s (%s)",
|
||||
stmt.create, index, table, stmt.type, stmt.columns);
|
||||
|
||||
/* Replace the tablespace in the index options */
|
||||
if (tablespace == NULL)
|
||||
{
|
||||
/* tablespace is just fine */
|
||||
appendStringInfoString(&str, stmt.options);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (NULL == strstr(stmt.options, "TABLESPACE"))
|
||||
{
|
||||
/* tablespace is to append */
|
||||
appendStringInfoString(&str, " TABLESPACE ");
|
||||
appendStringInfoString(&str, NameStr(*tablespace));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* tablespace is to replace */
|
||||
char *tmp;
|
||||
tmp = skip_const(index, stmt.options, " TABLESPACE", NULL);
|
||||
appendStringInfoString(&str, stmt.options);
|
||||
appendStringInfo(&str, " %s", NameStr(*tablespace));
|
||||
tmp = skip_ident(index, tmp);
|
||||
if (*tmp)
|
||||
appendStringInfo(&str, " %s", tmp);
|
||||
}
|
||||
}
|
||||
|
||||
PG_RETURN_TEXT_P(cstring_to_text(str.data));
|
||||
}
|
||||
|
Reference in New Issue
Block a user