Fix ownership bug.

New toast table, toast index, and toast type should not have
been owned by the executor of pg_reorg, but by the original owner.
This commit is contained in:
Takahiro Itagaki
2009-05-14 08:19:25 +00:00
parent 0c659ed31f
commit 9a8f2e9c33
7 changed files with 424 additions and 246 deletions

61
lib/pgut/pgut-be.c Executable file
View File

@ -0,0 +1,61 @@
/*-------------------------------------------------------------------------
*
* pgut-be.c
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/
#include "postgres.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;
}
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

72
lib/pgut/pgut-be.h Executable file
View File

@ -0,0 +1,72 @@
/*-------------------------------------------------------------------------
*
* pgut-be.h
*
* Copyright (c) 2009, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
*
*-------------------------------------------------------------------------
*/
#ifndef PGUT_BE_H
#define PGUT_BE_H
#include "executor/spi.h"
#if PG_VERSION_NUM < 80300
#define PGDLLIMPORT DLLIMPORT
#define SK_BT_DESC 0 /* Always ASC */
#define SK_BT_NULLS_FIRST 0 /* Always NULLS LAST */
#define MaxHeapTupleSize MaxTupleSize
#define PG_GETARG_TEXT_PP(n) PG_GETARG_TEXT_P(n)
#define VARSIZE_ANY_EXHDR(v) (VARSIZE(v) - VARHDRSZ)
#define VARDATA_ANY(v) VARDATA(v)
#define SET_VARSIZE(v, sz) (VARATT_SIZEP(v) = (sz))
#define pg_detoast_datum_packed(v) pg_detoast_datum(v)
#define DatumGetTextPP(v) DatumGetTextP(v)
#define ItemIdIsNormal(v) ItemIdIsUsed(v)
#define IndexBuildHeapScan(heap, index, info, sync, callback, state) \
IndexBuildHeapScan((heap), (index), (info), (callback), (state))
#define planner_rt_fetch(rti, root) \
rt_fetch(rti, (root)->parse->rtable)
#define heap_sync(rel) ((void)0)
#define ItemIdIsDead(itemId) ItemIdDeleted(itemId)
#define GetCurrentCommandId(used) GetCurrentCommandId()
#define stringToQualifiedNameList(str) \
stringToQualifiedNameList((str), "pg_bulkload")
#define setNewRelfilenode(rel, xid) \
setNewRelfilenode((rel))
#define PageAddItem(page, item, size, offnum, overwrite, is_heap) \
PageAddItem((page), (item), (size), (offnum), LP_USED)
typedef void *SPIPlanPtr;
#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)
typedef void *BulkInsertState;
extern char *text_to_cstring(const text *t);
extern text *cstring_to_text(const char *s);
extern int SPI_execute_with_args(const char *src, int nargs, Oid *argtypes,
Datum *values, const char *nulls, bool read_only, long tcount);
#endif
#endif /* PGUT_BE_H */