Added implementation for --moveidx
Note: if original namespace is "foo bar", repack_indexdef gives a bad result. This is weird as apparently skip_ident can deal with spaces in a quoted identifier. Committing as I'm going home, will deal with that later.
This commit is contained in:
@ -207,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'
|
||||
|
50
lib/repack.c
50
lib/repack.c
@ -618,20 +618,62 @@ 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
|
||||
{
|
||||
const char *pos;
|
||||
if (NULL == (pos = strstr(stmt.options, " TABLESPACE ")))
|
||||
{
|
||||
/* tablespace is to append */
|
||||
appendStringInfoString(&str, " TABLESPACE ");
|
||||
appendStringInfoString(&str, NameStr(*tablespace));
|
||||
}
|
||||
else
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
/* tablespace is to replace */
|
||||
tmp = skip_const(index, stmt.options, " TABLESPACE ", NULL);
|
||||
appendStringInfoString(&str, stmt.options);
|
||||
appendStringInfoString(&str, NameStr(*tablespace));
|
||||
/* FIXME: not working if original ts has a space. But skip_ident
|
||||
* should deal with that. Stupid mistake somewhere? */
|
||||
tmp = skip_ident(index, tmp);
|
||||
appendStringInfoString(&str, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
PG_RETURN_TEXT_P(cstring_to_text(str.data));
|
||||
}
|
||||
|
Reference in New Issue
Block a user