本文整理汇总了C++中relation_close函数的典型用法代码示例。如果您正苦于以下问题:C++ relation_close函数的具体用法?C++ relation_close怎么用?C++ relation_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了relation_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculate_indexes_size
/*
* Calculate total on-disk size of all indexes attached to the given table.
*
* Can be applied safely to an index, but you'll just get zero.
*/
static int64
calculate_indexes_size(Oid relOid)
{
int64 size = 0;
Relation rel;
rel = relation_open(relOid, AccessShareLock);
/*
* Aggregate all indexes on the given relation
*/
if (rel->rd_rel->relhasindex)
{
List *index_oids = RelationGetIndexList(rel);
ListCell *cell;
foreach(cell, index_oids)
{
Oid idxOid = lfirst_oid(cell);
Relation idxRel;
ForkNumber forkNum;
idxRel = relation_open(idxOid, AccessShareLock);
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
size += calculate_relation_size(&(idxRel->rd_node),
idxRel->rd_backend,
forkNum);
relation_close(idxRel, AccessShareLock);
}
示例2: pg_relation_size_oid
Datum
pg_relation_size_oid(PG_FUNCTION_ARGS)
{
Oid relOid = PG_GETARG_OID(0);
Relation rel;
int64 size = 0;
if (GP_ROLE_EXECUTE == Gp_role)
{
ereport(ERROR,
(errcode(ERRCODE_GP_COMMAND_ERROR),
errmsg("pg_relation_size: cannot be executed in segment")));
}
rel = try_relation_open(relOid, AccessShareLock, false);
/*
* While we scan pg_class with an MVCC snapshot,
* someone else might drop the table. It's better to return NULL for
* already-dropped tables than throw an error and abort the whole query.
*/
if (!RelationIsValid(rel))
PG_RETURN_NULL();
if (relOid == 0 || rel->rd_node.relNode == 0)
size = 0;
else
size = calculate_relation_size(rel);
relation_close(rel, AccessShareLock);
PG_RETURN_INT64(size);
}
示例3: calculate_table_size
/*
* Calculate total on-disk size of a given table,
* including FSM and VM, plus TOAST table if any.
* Indexes other than the TOAST table's index are not included.
*
* Note that this also behaves sanely if applied to an index or toast table;
* those won't have attached toast tables, but they can have multiple forks.
*/
static int64
calculate_table_size(Oid relOid)
{
int64 size = 0;
Relation rel;
ForkNumber forkNum;
rel = relation_open(relOid, AccessShareLock);
/*
* heap size, including FSM and VM
*/
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
size += calculate_relation_size(&(rel->rd_node), rel->rd_backend,
forkNum);
/*
* Size of toast relation
*/
if (OidIsValid(rel->rd_rel->reltoastrelid))
size += calculate_toast_table_size(rel->rd_rel->reltoastrelid);
relation_close(rel, AccessShareLock);
return size;
}
示例4: currval_oid
Datum
currval_oid(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 result;
SeqTable elm;
Relation seqrel;
/* open and AccessShareLock sequence */
init_sequence(relid, &elm, &seqrel);
if (pg_class_aclcheck(elm->relid, GetUserId(),
ACL_SELECT | ACL_USAGE) != ACLCHECK_OK)
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied for sequence %s",
RelationGetRelationName(seqrel))));
if (!elm->last_valid)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("currval of sequence \"%s\" is not yet defined in this session",
RelationGetRelationName(seqrel))));
result = elm->last;
relation_close(seqrel, NoLock);
PG_RETURN_INT64(result);
}
示例5: pg_relation_size
Datum
pg_relation_size(PG_FUNCTION_ARGS)
{
Oid relOid = PG_GETARG_OID(0);
text *forkName = PG_GETARG_TEXT_P(1);
Relation rel;
int64 size;
rel = try_relation_open(relOid, AccessShareLock);
/*
* Before 9.2, we used to throw an error if the relation didn't exist, but
* that makes queries like "SELECT pg_relation_size(oid) FROM pg_class"
* less robust, because while we scan pg_class with an MVCC snapshot,
* someone else might drop the table. It's better to return NULL for
* already-dropped tables than throw an error and abort the whole query.
*/
if (rel == NULL)
PG_RETURN_NULL();
size = calculate_relation_size(&(rel->rd_node), rel->rd_backend,
forkname_to_number(text_to_cstring(forkName)));
relation_close(rel, AccessShareLock);
PG_RETURN_INT64(size);
}
示例6: lastval
Datum
lastval(PG_FUNCTION_ARGS)
{
Relation seqrel;
int64 result;
if (last_used_seq == NULL)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("lastval is not yet defined in this session")));
/* Someone may have dropped the sequence since the last nextval() */
if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(last_used_seq->relid)))
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("lastval is not yet defined in this session")));
seqrel = open_share_lock(last_used_seq);
/* nextval() must have already been called for this sequence */
Assert(last_used_seq->last_valid);
if (pg_class_aclcheck(last_used_seq->relid, GetUserId(),
ACL_SELECT | ACL_USAGE) != ACLCHECK_OK)
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied for sequence %s",
RelationGetRelationName(seqrel))));
result = last_used_seq->last;
relation_close(seqrel, NoLock);
PG_RETURN_INT64(result);
}
示例7: pg_visibility_map
/*
* Visibility map information for a single block of a relation.
*/
Datum
pg_visibility_map(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 blkno = PG_GETARG_INT64(1);
int32 mapbits;
Relation rel;
Buffer vmbuffer = InvalidBuffer;
TupleDesc tupdesc;
Datum values[2];
bool nulls[2];
rel = relation_open(relid, AccessShareLock);
if (blkno < 0 || blkno > MaxBlockNumber)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid block number")));
tupdesc = pg_visibility_tupdesc(false, false);
MemSet(nulls, 0, sizeof(nulls));
mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
if (vmbuffer != InvalidBuffer)
ReleaseBuffer(vmbuffer);
values[0] = BoolGetDatum((mapbits & VISIBILITYMAP_ALL_VISIBLE) != 0);
values[1] = BoolGetDatum((mapbits & VISIBILITYMAP_ALL_FROZEN) != 0);
relation_close(rel, AccessShareLock);
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
}
示例8: calculate_total_relation_size
/*
* Compute the on-disk size of files for the relation according to the
* stat function, including heap data, index data, and toast data.
*/
static int64
calculate_total_relation_size(Oid Relid)
{
Relation heapRel;
Oid toastOid;
int64 size;
ListCell *cell;
heapRel = relation_open(Relid, AccessShareLock);
toastOid = heapRel->rd_rel->reltoastrelid;
/* Get the heap size */
size = calculate_relation_size(&(heapRel->rd_node));
/* Include any dependent indexes */
if (heapRel->rd_rel->relhasindex)
{
List *index_oids = RelationGetIndexList(heapRel);
foreach(cell, index_oids)
{
Oid idxOid = lfirst_oid(cell);
Relation iRel;
iRel = relation_open(idxOid, AccessShareLock);
size += calculate_relation_size(&(iRel->rd_node));
relation_close(iRel, AccessShareLock);
}
示例9: table_key_index
/* Returns the relation object for the index that we're going to use as key for a
* particular table. (Indexes are relations too!) Returns null if the table is unkeyed.
* The return value is opened with a shared lock; call relation_close() when finished. */
Relation table_key_index(Relation rel) {
char replident = rel->rd_rel->relreplident;
Oid repl_ident_oid;
List *indexes;
ListCell *index_oid;
if (replident == REPLICA_IDENTITY_NOTHING) {
return NULL;
}
if (replident == REPLICA_IDENTITY_INDEX) {
repl_ident_oid = RelationGetReplicaIndex(rel);
if (repl_ident_oid != InvalidOid) {
return relation_open(repl_ident_oid, AccessShareLock);
}
}
// There doesn't seem to be a convenient way of getting the primary key index for
// a table, so we have to iterate over all the table's indexes.
indexes = RelationGetIndexList(rel);
foreach(index_oid, indexes) {
Relation index_rel = relation_open(lfirst_oid(index_oid), AccessShareLock);
Form_pg_index index = index_rel->rd_index;
if (IndexIsValid(index) && IndexIsReady(index) && index->indisprimary) {
list_free(indexes);
return index_rel;
}
relation_close(index_rel, AccessShareLock);
}
示例10: pg_truncate_visibility_map
/*
* Remove the visibility map fork for a relation. If there turn out to be
* any bugs in the visibility map code that require rebuilding the VM, this
* provides users with a way to do it that is cleaner than shutting down the
* server and removing files by hand.
*
* This is a cut-down version of RelationTruncate.
*/
Datum
pg_truncate_visibility_map(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
Relation rel;
rel = relation_open(relid, AccessExclusiveLock);
if (rel->rd_rel->relkind != RELKIND_RELATION &&
rel->rd_rel->relkind != RELKIND_MATVIEW &&
rel->rd_rel->relkind != RELKIND_TOASTVALUE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is not a table, materialized view, or TOAST table",
RelationGetRelationName(rel))));
RelationOpenSmgr(rel);
rel->rd_smgr->smgr_vm_nblocks = InvalidBlockNumber;
visibilitymap_truncate(rel, 0);
if (RelationNeedsWAL(rel))
{
xl_smgr_truncate xlrec;
xlrec.blkno = 0;
xlrec.rnode = rel->rd_node;
xlrec.flags = SMGR_TRUNCATE_VM;
XLogBeginInsert();
XLogRegisterData((char *) &xlrec, sizeof(xlrec));
XLogInsert(RM_SMGR_ID, XLOG_SMGR_TRUNCATE | XLR_SPECIAL_REL_UPDATE);
}
/*
* Release the lock right away, not at commit time.
*
* It would be a problem to release the lock prior to commit if this
* truncate operation sends any transactional invalidation messages. Other
* backends would potentially be able to lock the relation without
* processing them in the window of time between when we release the lock
* here and when we sent the messages at our eventual commit. However,
* we're currently only sending a non-transactional smgr invalidation,
* which will have been posted to shared memory immediately from within
* visibilitymap_truncate. Therefore, there should be no race here.
*
* The reason why it's desirable to release the lock early here is because
* of the possibility that someone will need to use this to blow away many
* visibility map forks at once. If we can't release the lock until
* commit time, the transaction doing this will accumulate
* AccessExclusiveLocks on all of those relations at the same time, which
* is undesirable. However, if this turns out to be unsafe we may have no
* choice...
*/
relation_close(rel, AccessExclusiveLock);
/* Nothing to return. */
PG_RETURN_VOID();
}
示例11: calculate_indexes_size
/*
* Calculate total on-disk size of all indexes attached to the given table.
*
* Can be applied safely to an index, but you'll just get zero.
*/
static int64 calculate_indexes_size(oid_t relOid)
{
int64 size = 0;
struct relation * rel;
rel = relation_open(relOid, ACCESS_SHR_LOCK);
/*
* Aggregate all indexes on the given relation
*/
if (rel->rd_rel->relhasindex) {
struct list *index_oids = rel_get_index_list(rel);
struct list_cell *cell;
foreach(cell, index_oids) {
oid_t idxOid = lfirst_oid(cell);
struct relation * idxRel;
enum fork fnr;
idxRel = relation_open(idxOid, ACCESS_SHR_LOCK);
for (fnr = 0; fnr <= MAX_FORK_NR; fnr++)
size += calculate_relation_size(&(idxRel->rd_node),
idxRel->rd_backend, fnr);
relation_close(idxRel, ACCESS_SHR_LOCK);
}
list_free(index_oids);
}
示例12: calculate_toast_table_size
/*
* Calculate total on-disk size of a TOAST relation, including its indexes.
* Must not be applied to non-TOAST relations.
*/
static int64
calculate_toast_table_size(Oid toastrelid)
{
int64 size = 0;
Relation toastRel;
ForkNumber forkNum;
ListCell *lc;
List *indexlist;
toastRel = relation_open(toastrelid, AccessShareLock);
/* toast heap size, including FSM and VM size */
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
size += calculate_relation_size(&(toastRel->rd_node),
toastRel->rd_backend, forkNum);
/* toast index size, including FSM and VM size */
indexlist = RelationGetIndexList(toastRel);
/* Size is calculated using all the indexes available */
foreach(lc, indexlist)
{
Relation toastIdxRel;
toastIdxRel = relation_open(lfirst_oid(lc),
AccessShareLock);
for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
size += calculate_relation_size(&(toastIdxRel->rd_node),
toastIdxRel->rd_backend, forkNum);
relation_close(toastIdxRel, AccessShareLock);
}
示例13: collect_visibility_data
/*
* Collect visibility data about a relation.
*/
static vbits *
collect_visibility_data(Oid relid, bool include_pd)
{
Relation rel;
BlockNumber nblocks;
vbits *info;
BlockNumber blkno;
Buffer vmbuffer = InvalidBuffer;
BufferAccessStrategy bstrategy = GetAccessStrategy(BAS_BULKREAD);
rel = relation_open(relid, AccessShareLock);
nblocks = RelationGetNumberOfBlocks(rel);
info = palloc0(offsetof(vbits, bits) + nblocks);
info->next = 0;
info->count = nblocks;
for (blkno = 0; blkno < nblocks; ++blkno)
{
int32 mapbits;
/* Make sure we are interruptible. */
CHECK_FOR_INTERRUPTS();
/* Get map info. */
mapbits = (int32) visibilitymap_get_status(rel, blkno, &vmbuffer);
if ((mapbits & VISIBILITYMAP_ALL_VISIBLE) != 0)
info->bits[blkno] |= (1 << 0);
if ((mapbits & VISIBILITYMAP_ALL_FROZEN) != 0)
info->bits[blkno] |= (1 << 1);
/*
* Page-level data requires reading every block, so only get it if
* the caller needs it. Use a buffer access strategy, too, to prevent
* cache-trashing.
*/
if (include_pd)
{
Buffer buffer;
Page page;
buffer = ReadBufferExtended(rel, MAIN_FORKNUM, blkno, RBM_NORMAL,
bstrategy);
LockBuffer(buffer, BUFFER_LOCK_SHARE);
page = BufferGetPage(buffer, NULL, NULL, BGP_NO_SNAPSHOT_TEST);
if (PageIsAllVisible(page))
info->bits[blkno] |= (1 << 2);
UnlockReleaseBuffer(buffer);
}
}
/* Clean up. */
if (vmbuffer != InvalidBuffer)
ReleaseBuffer(vmbuffer);
relation_close(rel, AccessShareLock);
return info;
}
示例14: create_distributed_table
/*
* create_distributed_table gets a table name, distribution column,
* distribution method and colocate_with option, then it creates a
* distributed table.
*/
Datum
create_distributed_table(PG_FUNCTION_ARGS)
{
Oid relationId = InvalidOid;
text *distributionColumnText = NULL;
Oid distributionMethodOid = InvalidOid;
text *colocateWithTableNameText = NULL;
Relation relation = NULL;
char *distributionColumnName = NULL;
Var *distributionColumn = NULL;
char distributionMethod = 0;
char *colocateWithTableName = NULL;
bool viaDeprecatedAPI = false;
CheckCitusVersion(ERROR);
EnsureCoordinator();
relationId = PG_GETARG_OID(0);
distributionColumnText = PG_GETARG_TEXT_P(1);
distributionMethodOid = PG_GETARG_OID(2);
colocateWithTableNameText = PG_GETARG_TEXT_P(3);
/*
* Lock target relation with an exclusive lock - there's no way to make
* sense of this table until we've committed, and we don't want multiple
* backends manipulating this relation.
*/
relation = try_relation_open(relationId, ExclusiveLock);
if (relation == NULL)
{
ereport(ERROR, (errmsg("could not create distributed table: "
"relation does not exist")));
}
/*
* We should do this check here since the codes in the following lines rely
* on this relation to have a supported relation kind. More extensive checks
* will be performed in CreateDistributedTable.
*/
EnsureRelationKindSupported(relationId);
distributionColumnName = text_to_cstring(distributionColumnText);
distributionColumn = BuildDistributionKeyFromColumnName(relation,
distributionColumnName);
distributionMethod = LookupDistributionMethod(distributionMethodOid);
colocateWithTableName = text_to_cstring(colocateWithTableNameText);
CreateDistributedTable(relationId, distributionColumn, distributionMethod,
colocateWithTableName, viaDeprecatedAPI);
relation_close(relation, NoLock);
PG_RETURN_VOID();
}
示例15: gp_statistics_estimate_reltuples_relpages_oid
/**
* Given the oid of a relation, this method calculates reltuples, relpages. This only looks up
* local information (on master or segments). It produces meaningful values for AO and
* heap tables and returns [0.0,0.0] for all other relations.
* Input:
* relationoid
* Output:
* array of two values [reltuples,relpages]
*/
Datum
gp_statistics_estimate_reltuples_relpages_oid(PG_FUNCTION_ARGS)
{
float4 relpages = 0.0;
float4 reltuples = 0.0;
Oid relOid = PG_GETARG_OID(0);
Datum values[2];
ArrayType *result;
Relation rel = try_relation_open(relOid, AccessShareLock, false);
if (rel != NULL)
{
if (rel->rd_rel->relkind == RELKIND_RELATION)
{
if (RelationIsHeap(rel))
{
gp_statistics_estimate_reltuples_relpages_heap(rel, &reltuples, &relpages);
}
else if (RelationIsAoRows(rel))
{
gp_statistics_estimate_reltuples_relpages_ao_rows(rel, &reltuples, &relpages);
}
else if (RelationIsAoCols(rel))
{
gp_statistics_estimate_reltuples_relpages_ao_cs(rel, &reltuples, &relpages);
}
}
else if (rel->rd_rel->relkind == RELKIND_INDEX)
{
reltuples = 1.0;
relpages = RelationGetNumberOfBlocks(rel);
}
else
{
/**
* Should we silently return [0.0,0.0] or error out? Currently, we choose option 1.
*/
}
relation_close(rel, AccessShareLock);
}
else
{
/**
* Should we silently return [0.0,0.0] or error out? Currently, we choose option 1.
*/
}
values[0] = Float4GetDatum(reltuples);
values[1] = Float4GetDatum(relpages);
result = construct_array(values, 2,
FLOAT4OID,
sizeof(float4), true, 'i');
PG_RETURN_ARRAYTYPE_P(result);
}