resolve conflicts
This commit is contained in:
@ -15,7 +15,7 @@ INTVERSION := $(shell echo $$(($$(echo $(VERSION) | sed 's/\([[:digit:]]\{1,\}\)
|
||||
EXTENSION = pg_repack
|
||||
MODULE_big = $(EXTENSION)
|
||||
|
||||
OBJS = repack.o pgut/pgut-be.o pgut/pgut-spi.o
|
||||
OBJS = repack.o pgut/pgut-spi.o
|
||||
|
||||
SHLIB_EXPORTS = exports.txt
|
||||
|
||||
@ -25,13 +25,7 @@ REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \
|
||||
|
||||
PG_CPPFLAGS = -DREPACK_VERSION=$(REPACK_VERSION)
|
||||
|
||||
# Support CREATE EXTENSION for PG >= 9.1 and a simple sql script for PG < 9.1
|
||||
ifeq ($(shell echo $$(($(INTVERSION) >= 901))),1)
|
||||
DATA_built = pg_repack--$(REPACK_VERSION).sql pg_repack.control
|
||||
else
|
||||
DATA_built = pg_repack.sql
|
||||
DATA = uninstall_pg_repack.sql
|
||||
endif
|
||||
|
||||
USE_PGXS = 1
|
||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
|
@ -152,6 +152,72 @@ WHERE
|
||||
$$
|
||||
LANGUAGE sql STABLE STRICT;
|
||||
|
||||
-- Get a comma-separated storage paramter for the table including
|
||||
-- paramters for the corresponding TOAST table.
|
||||
-- Note that since oid setting is always not NULL, this function
|
||||
-- never returns NULL
|
||||
CREATE FUNCTION repack.get_storage_param(oid)
|
||||
RETURNS TEXT AS
|
||||
$$
|
||||
SELECT array_to_string(array_agg(param), ', ')
|
||||
FROM (
|
||||
-- table storage parameter
|
||||
SELECT unnest(reloptions) as param
|
||||
FROM pg_class
|
||||
WHERE oid = $1
|
||||
UNION ALL
|
||||
-- TOAST table storage parameter
|
||||
SELECT ('toast.' || unnest(reloptions)) as param
|
||||
FROM (
|
||||
SELECT reltoastrelid from pg_class where oid = $1
|
||||
) as t,
|
||||
pg_class as c
|
||||
WHERE c.oid = t.reltoastrelid
|
||||
UNION ALL
|
||||
-- table oid
|
||||
SELECT 'oids = ' ||
|
||||
CASE WHEN relhasoids
|
||||
THEN 'true'
|
||||
ELSE 'false'
|
||||
END
|
||||
FROM pg_class
|
||||
WHERE oid = $1
|
||||
|
||||
) as t
|
||||
$$
|
||||
LANGUAGE sql STABLE STRICT;
|
||||
|
||||
-- GET a SQL text to set column storage option for the table.
|
||||
CREATE FUNCTION repack.get_alter_col_storage(oid)
|
||||
RETURNS text AS
|
||||
$$
|
||||
SELECT 'ALTER TABLE repack.table_' || $1 || array_to_string(column_storage, ',')
|
||||
FROM (
|
||||
SELECT
|
||||
repack.array_accum(' ALTER ' || quote_ident(attname) ||
|
||||
CASE attstorage
|
||||
WHEN 'p' THEN ' SET STORAGE PLAIN'
|
||||
WHEN 'm' THEN ' SET STORAGE MAIN'
|
||||
WHEN 'e' THEN ' SET STORAGE EXTERNAL'
|
||||
WHEN 'x' THEN ' SET STORAGE EXTENDED'
|
||||
END) AS column_storage
|
||||
FROM (
|
||||
SELECT *
|
||||
FROM pg_attribute a
|
||||
JOIN pg_type t on t.oid = atttypid
|
||||
JOIN pg_class r on r.oid = a.attrelid
|
||||
JOIN pg_namespace s on s.oid = r.relnamespace
|
||||
WHERE typstorage <> attstorage
|
||||
AND attrelid = $1
|
||||
AND attnum > 0
|
||||
AND NOT attisdropped
|
||||
ORDER BY attnum
|
||||
) T
|
||||
) T
|
||||
WHERE array_upper(column_storage , 1) > 0
|
||||
$$
|
||||
LANGUAGE sql STABLE STRICT;
|
||||
|
||||
-- includes not only PRIMARY KEYS but also UNIQUE NOT NULL keys
|
||||
CREATE VIEW repack.primary_keys AS
|
||||
SELECT indrelid, (repack.array_accum(indexrelid))[1] AS indexrelid
|
||||
@ -183,9 +249,11 @@ 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 ' AS create_table_1,
|
||||
'CREATE TABLE repack.table_' || R.oid || ' WITH (' || repack.get_storage_param(R.oid) || ') TABLESPACE ' AS create_table_1,
|
||||
coalesce(quote_ident(S.spcname), 'pg_default') as tablespace_orig,
|
||||
' AS SELECT ' || repack.get_columns_for_create_as(R.oid) || ' FROM ONLY ' || repack.oid2text(R.oid) AS create_table_2,
|
||||
'INSERT INTO repack.table_' || R.oid || ' SELECT ' || repack.get_columns_for_create_as(R.oid) || ' FROM ONLY ' || repack.oid2text(R.oid) AS copy_data,
|
||||
repack.get_alter_col_storage(R.oid) AS alter_col_storage,
|
||||
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,
|
||||
|
@ -1,71 +0,0 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pgut-be.c
|
||||
*
|
||||
* Copyright (c) 2009-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
|
||||
* Portions Copyright (c) 2012-2015, The Reorg Development Team
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
#include "access/heapam.h"
|
||||
#include "pgut-be.h"
|
||||
|
||||
#if PG_VERSION_NUM < 80400
|
||||
|
||||
char *
|
||||
text_to_cstring(const text *t)
|
||||
{
|
||||
text *tunpacked = pg_detoast_datum_packed((struct varlena *) t);
|
||||
int len = VARSIZE_ANY_EXHDR(tunpacked);
|
||||
char *result;
|
||||
|
||||
result = (char *) palloc(len + 1);
|
||||
memcpy(result, VARDATA_ANY(tunpacked), len);
|
||||
result[len] = '\0';
|
||||
|
||||
if (tunpacked != t)
|
||||
pfree(tunpacked);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
text *
|
||||
cstring_to_text(const char *s)
|
||||
{
|
||||
int len = strlen(s);
|
||||
text *result = palloc(len + VARHDRSZ);
|
||||
|
||||
SET_VARSIZE(result, len + VARHDRSZ);
|
||||
memcpy(VARDATA(result), s, len);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc,
|
||||
Datum *values, bool *isnull)
|
||||
{
|
||||
tuplestore_puttuple(state, heap_form_tuple(tdesc, values, isnull));
|
||||
}
|
||||
|
||||
Datum
|
||||
ExecFetchSlotTupleDatum(TupleTableSlot *slot)
|
||||
{
|
||||
HeapTuple tup;
|
||||
HeapTupleHeader td;
|
||||
TupleDesc tupdesc;
|
||||
|
||||
/* Make sure we can scribble on the slot contents ... */
|
||||
tup = ExecMaterializeSlot(slot);
|
||||
/* ... and set up the composite-Datum header fields, in case not done */
|
||||
td = tup->t_data;
|
||||
tupdesc = slot->tts_tupleDescriptor;
|
||||
HeapTupleHeaderSetDatumLength(td, tup->t_len);
|
||||
HeapTupleHeaderSetTypeId(td, tupdesc->tdtypeid);
|
||||
HeapTupleHeaderSetTypMod(td, tupdesc->tdtypmod);
|
||||
return PointerGetDatum(td);
|
||||
}
|
||||
|
||||
#endif
|
@ -52,116 +52,4 @@ extern int no_such_variable
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if PG_VERSION_NUM < 80400
|
||||
|
||||
#define MAIN_FORKNUM 0
|
||||
#define HEAP_INSERT_SKIP_WAL 0x0001
|
||||
#define HEAP_INSERT_SKIP_FSM 0x0002
|
||||
|
||||
#define relpath(rnode, forknum) relpath((rnode))
|
||||
#define smgrimmedsync(reln, forknum) smgrimmedsync((reln))
|
||||
#define smgrread(reln, forknum, blocknum, buffer) \
|
||||
smgrread((reln), (blocknum), (buffer))
|
||||
#define mdclose(reln, forknum) mdclose((reln))
|
||||
#define heap_insert(relation, tup, cid, options, bistate) \
|
||||
heap_insert((relation), (tup), (cid), true, true)
|
||||
#define GetBulkInsertState() (NULL)
|
||||
#define FreeBulkInsertState(bistate) ((void)0)
|
||||
#define FreeExprContext(econtext, isCommit) FreeExprContext((econtext))
|
||||
#define pgstat_init_function_usage(fcinfo, fcu) ((void)0)
|
||||
#define pgstat_end_function_usage(fcu, finalize) ((void)0)
|
||||
#define makeRangeVar(schemaname, relname, location) \
|
||||
makeRangeVar((schemaname), (relname))
|
||||
#define tuplestore_gettupleslot(state, forward, copy, slot) \
|
||||
tuplestore_gettupleslot(state, forward, slot)
|
||||
#define pgstat_track_activity_query_size PGBE_ACTIVITY_SIZE
|
||||
typedef void *BulkInsertState;
|
||||
|
||||
#define DefineCustomBoolVariable(name, short_desc, long_desc, valueAddr, bootValue, context, flags, assign_hook, show_hook) \
|
||||
do { \
|
||||
*(valueAddr) = (bootValue); \
|
||||
DefineCustomBoolVariable((name), (short_desc), (long_desc), (valueAddr), (context), (assign_hook), (show_hook)); \
|
||||
} while(0)
|
||||
#define DefineCustomIntVariable(name, short_desc, long_desc, valueAddr, bootValue, minValue, maxValue, context, flags, assign_hook, show_hook) \
|
||||
do { \
|
||||
*(valueAddr) = (bootValue); \
|
||||
DefineCustomIntVariable((name), (short_desc), (long_desc), (valueAddr), (minValue), (maxValue), (context), (assign_hook), (show_hook)); \
|
||||
} while(0)
|
||||
#define DefineCustomRealVariable(name, short_desc, long_desc, valueAddr, bootValue, minValue, maxValue, context, flags, assign_hook, show_hook) \
|
||||
do { \
|
||||
*(valueAddr) = (bootValue); \
|
||||
DefineCustomRealVariable((name), (short_desc), (long_desc), (valueAddr), (minValue), (maxValue), (context), (assign_hook), (show_hook)); \
|
||||
} while(0)
|
||||
#define DefineCustomStringVariable(name, short_desc, long_desc, valueAddr, bootValue, context, flags, assign_hook, show_hook) \
|
||||
do { \
|
||||
*(valueAddr) = (char *) (bootValue); \
|
||||
DefineCustomStringVariable((name), (short_desc), (long_desc), (valueAddr), (context), (assign_hook), (show_hook)); \
|
||||
} while(0)
|
||||
|
||||
struct config_enum_entry
|
||||
{
|
||||
const char *name;
|
||||
int val;
|
||||
bool hidden;
|
||||
};
|
||||
|
||||
extern char *text_to_cstring(const text *t);
|
||||
extern text *cstring_to_text(const char *s);
|
||||
extern void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc,
|
||||
Datum *values, bool *isnull);
|
||||
extern Datum ExecFetchSlotTupleDatum(TupleTableSlot *slot);
|
||||
|
||||
#define CStringGetTextDatum(s) PointerGetDatum(cstring_to_text(s))
|
||||
#define TextDatumGetCString(d) text_to_cstring((text *) DatumGetPointer(d))
|
||||
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 90000
|
||||
|
||||
#define reindex_index(indexId, skip_constraint_checks) \
|
||||
reindex_index((indexId))
|
||||
#define func_signature_string(funcname, nargs, argnames, argtypes) \
|
||||
func_signature_string((funcname), (nargs), (argtypes))
|
||||
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 90200
|
||||
|
||||
#define RangeVarGetRelid(relation, lockmode, missing_ok, nowait) \
|
||||
RangeVarGetRelid((relation), (missing_ok))
|
||||
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 90100
|
||||
|
||||
#define ATExecChangeOwner(relationOid, newOwnerId, recursing, lockmode) \
|
||||
ATExecChangeOwner((relationOid), (newOwnerId), (recursing))
|
||||
#define deleteDependencyRecordsFor(classId, objectId, skipExtensionDeps) \
|
||||
deleteDependencyRecordsFor((classId), (objectId))
|
||||
#define PG_GET_COLLATION() (InvalidOid)
|
||||
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 90000
|
||||
#define RelationSetNewRelfilenode(rel, xid) \
|
||||
setNewRelfilenode((rel), (xid))
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 80400
|
||||
#define FuncnameGetCandidates(names, nargs, argnames, variadic, defaults) \
|
||||
FuncnameGetCandidates((names), (nargs))
|
||||
#elif PG_VERSION_NUM < 90000
|
||||
#define FuncnameGetCandidates(names, nargs, argnames, variadic, defaults) \
|
||||
FuncnameGetCandidates((names), (nargs), (variadic), (defaults))
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 90000
|
||||
#define GetConfigOption(name, missing_ok, restrict_superuser) \
|
||||
GetConfigOption((name))
|
||||
#elif PG_VERSION_NUM < 90200
|
||||
#define GetConfigOption(name, missing_ok, restrict_superuser) \
|
||||
GetConfigOption((name), (restrict_superuser))
|
||||
#endif
|
||||
|
||||
#endif /* PGUT_BE_H */
|
||||
|
@ -115,25 +115,3 @@ execute_with_format_args(int expected, const char *format, int nargs, Oid argtyp
|
||||
|
||||
termStringInfo(&sql);
|
||||
}
|
||||
|
||||
|
||||
#if PG_VERSION_NUM < 80400
|
||||
|
||||
int
|
||||
SPI_execute_with_args(const char *src,
|
||||
int nargs, Oid *argtypes,
|
||||
Datum *values, const char *nulls,
|
||||
bool read_only, long tcount)
|
||||
{
|
||||
SPIPlanPtr plan;
|
||||
int ret;
|
||||
|
||||
plan = SPI_prepare(src, nargs, argtypes);
|
||||
if (plan == NULL)
|
||||
return SPI_result;
|
||||
ret = SPI_execute_plan(plan, values, nulls, read_only, tcount);
|
||||
SPI_freeplan(plan);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -12,11 +12,8 @@
|
||||
|
||||
#include "executor/spi.h"
|
||||
|
||||
#if PG_VERSION_NUM < 80400
|
||||
|
||||
extern int SPI_execute_with_args(const char *src, int nargs, Oid *argtypes,
|
||||
Datum *values, const char *nulls, bool read_only, long tcount);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define __attribute__(x)
|
||||
#endif
|
||||
|
||||
extern void execute(int expected, const char *sql);
|
||||
|
53
lib/repack.c
53
lib/repack.c
@ -97,14 +97,6 @@ must_be_superuser(const char *func)
|
||||
}
|
||||
|
||||
|
||||
/* Include an implementation of RenameRelationInternal for old
|
||||
* versions which don't have one.
|
||||
*/
|
||||
#if PG_VERSION_NUM < 80400
|
||||
static void RenameRelationInternal(Oid myrelid, const char *newrelname, Oid namespaceId);
|
||||
#endif
|
||||
|
||||
|
||||
/* The API of RenameRelationInternal() was changed in 9.2.
|
||||
* Use the RENAME_REL macro for compatibility across versions.
|
||||
*/
|
||||
@ -1020,19 +1012,6 @@ repack_drop(PG_FUNCTION_ARGS)
|
||||
--numobj;
|
||||
}
|
||||
|
||||
#if PG_VERSION_NUM < 80400
|
||||
/* delete autovacuum settings */
|
||||
execute_with_format(
|
||||
SPI_OK_DELETE,
|
||||
"DELETE FROM pg_catalog.pg_autovacuum v"
|
||||
" USING pg_class c, pg_namespace n"
|
||||
" WHERE relname IN ('log_%u', 'table_%u')"
|
||||
" AND n.nspname = 'repack'"
|
||||
" AND c.relnamespace = n.oid"
|
||||
" AND v.vacrelid = c.oid",
|
||||
oid, oid);
|
||||
#endif
|
||||
|
||||
/* drop temp table */
|
||||
if (numobj > 0)
|
||||
{
|
||||
@ -1056,17 +1035,10 @@ repack_disable_autovacuum(PG_FUNCTION_ARGS)
|
||||
/* connect to SPI manager */
|
||||
repack_init();
|
||||
|
||||
#if PG_VERSION_NUM >= 80400
|
||||
execute_with_format(
|
||||
SPI_OK_UTILITY,
|
||||
"ALTER TABLE %s SET (autovacuum_enabled = off)",
|
||||
get_relation_name(oid));
|
||||
#else
|
||||
execute_with_format(
|
||||
SPI_OK_INSERT,
|
||||
"INSERT INTO pg_catalog.pg_autovacuum VALUES (%u, false, -1, -1, -1, -1, -1, -1, -1, -1)",
|
||||
oid);
|
||||
#endif
|
||||
|
||||
SPI_finish();
|
||||
|
||||
@ -1322,31 +1294,6 @@ repack_index_swap(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
#if PG_VERSION_NUM < 80400
|
||||
|
||||
/* XXX: You might need to add PGDLLIMPORT into your miscadmin.h. */
|
||||
extern PGDLLIMPORT bool allowSystemTableMods;
|
||||
|
||||
static void
|
||||
RenameRelationInternal(Oid myrelid, const char *newrelname, Oid namespaceId)
|
||||
{
|
||||
bool save_allowSystemTableMods = allowSystemTableMods;
|
||||
|
||||
allowSystemTableMods = true;
|
||||
PG_TRY();
|
||||
{
|
||||
renamerel(myrelid, newrelname, OBJECT_TABLE);
|
||||
allowSystemTableMods = save_allowSystemTableMods;
|
||||
}
|
||||
PG_CATCH();
|
||||
{
|
||||
allowSystemTableMods = save_allowSystemTableMods;
|
||||
PG_RE_THROW();
|
||||
}
|
||||
PG_END_TRY();
|
||||
}
|
||||
#endif
|
||||
|
||||
Datum
|
||||
repack_get_table_and_inheritors(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
@ -1,9 +0,0 @@
|
||||
/*
|
||||
* pg_repack: lib/uninstall_repack.sql
|
||||
*
|
||||
* Portions Copyright (c) 2008-2011, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
|
||||
* Portions Copyright (c) 2011, Itagaki Takahiro
|
||||
* Portions Copyright (c) 2012-2015, The Reorg Development Team
|
||||
*/
|
||||
|
||||
DROP SCHEMA IF EXISTS repack CASCADE;
|
Reference in New Issue
Block a user