本文整理汇总了C++中RelationGetNamespace函数的典型用法代码示例。如果您正苦于以下问题:C++ RelationGetNamespace函数的具体用法?C++ RelationGetNamespace怎么用?C++ RelationGetNamespace使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RelationGetNamespace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsSystemRelation
/*
* IsSystemRelation
* True iff the relation is a system catalog relation.
*
* NB: TOAST relations are considered system relations by this test
* for compatibility with the old IsSystemRelationName function.
* This is appropriate in many places but not all. Where it's not,
* also check IsToastRelation.
*
* We now just test if the relation is in the system catalog namespace;
* so it's no longer necessary to forbid user relations from having
* names starting with pg_.
*/
bool
IsSystemRelation(Relation relation)
{
return IsSystemNamespace(RelationGetNamespace(relation)) ||
IsToastNamespace(RelationGetNamespace(relation)) ||
IsAoSegmentNamespace(RelationGetNamespace(relation));
}
示例2: DropErrorTable
/*
* DropErrorTable
*
* Drop the error table from the database. This function will be called from
* destroyCdbSreh when an autogenerated error table was not used in the COPY
* operation granted KEEP wasn't specified.
*
*/
static
void DropErrorTable(CdbSreh *cdbsreh)
{
StringInfoData dropstmt;
RangeVar *errtbl_rv;
Insist(Gp_role == GP_ROLE_DISPATCH);
ereport(NOTICE,
(errcode(ERRCODE_SUCCESSFUL_COMPLETION),
errmsg("Dropping the auto-generated unused error table"),
errhint("Use KEEP in LOG INTO clause to force keeping the error table alive")));
initStringInfo(&dropstmt);
appendStringInfo(&dropstmt, "DROP TABLE %s.%s",
quote_identifier(get_namespace_name(RelationGetNamespace(cdbsreh->errtbl))),
quote_identifier(RelationGetRelationName(cdbsreh->errtbl)));
errtbl_rv = makeRangeVar(get_namespace_name(RelationGetNamespace(cdbsreh->errtbl)),
RelationGetRelationName(cdbsreh->errtbl), -1);
/* DROP the relation on the QD */
RemoveRelation(errtbl_rv,DROP_RESTRICT, NULL, RELKIND_RELATION);
/* dispatch the DROP to the QEs */
CdbDoCommand(dropstmt.data, false, /*no txn */ false);
pfree(dropstmt.data);
}
示例3: AppendOnlySegmentFileTruncateToEOF
/*
* AppendOnlySegmentFileTruncateToEOF()
*
* Assumes that the segment file lock is already held.
*
* For the segment file is truncates to the eof.
*/
static void
AppendOnlySegmentFileTruncateToEOF(Relation aorel,
FileSegInfo *fsinfo)
{
const char* relname = RelationGetRelationName(aorel);
MirroredAppendOnlyOpen mirroredOpened;
int32 fileSegNo;
char filenamepath[MAXPGPATH];
int segno;
int64 segeof;
Assert(fsinfo);
Assert(RelationIsAoRows(aorel));
segno = fsinfo->segno;
relname = RelationGetRelationName(aorel);
segeof = (int64)fsinfo->eof;
/* Open and truncate the relation segfile beyond its eof */
MakeAOSegmentFileName(aorel, segno, -1, &fileSegNo, filenamepath);
elogif(Debug_appendonly_print_compaction, LOG,
"Opening AO relation \"%s.%s\", relation id %u, relfilenode %u (physical segment file #%d, logical EOF " INT64_FORMAT ")",
get_namespace_name(RelationGetNamespace(aorel)),
relname,
aorel->rd_id,
aorel->rd_node.relNode,
segno,
segeof);
if (OpenAOSegmentFile(aorel, filenamepath, fileSegNo, segeof, &mirroredOpened))
{
TruncateAOSegmentFile(&mirroredOpened, aorel, segeof, ERROR);
CloseAOSegmentFile(&mirroredOpened);
elogif(Debug_appendonly_print_compaction, LOG,
"Successfully truncated AO ROL relation \"%s.%s\", relation id %u, relfilenode %u (physical segment file #%d, logical EOF " INT64_FORMAT ")",
get_namespace_name(RelationGetNamespace(aorel)),
relname,
aorel->rd_id,
aorel->rd_node.relNode,
segno,
segeof);
}
else
{
elogif(Debug_appendonly_print_compaction, LOG,
"No gp_relation_node entry for AO ROW relation \"%s.%s\", relation id %u, relfilenode %u (physical segment file #%d, logical EOF " INT64_FORMAT ")",
get_namespace_name(RelationGetNamespace(aorel)),
relname,
aorel->rd_id,
aorel->rd_node.relNode,
segno,
segeof);
}
}
示例4: cdbRelMaxSegSize
/*
* Get the max size of the relation across segments
*/
int64
cdbRelMaxSegSize(Relation rel)
{
int64 size = 0;
int i;
CdbPgResults cdb_pgresults = {NULL, 0};
StringInfoData buffer;
char *schemaName;
char *relName;
/*
* Let's ask the QEs for the size of the relation
*/
initStringInfo(&buffer);
schemaName = get_namespace_name(RelationGetNamespace(rel));
if (schemaName == NULL)
elog(ERROR, "cache lookup failed for namespace %d",
RelationGetNamespace(rel));
relName = RelationGetRelationName(rel);
/*
* Safer to pass names than oids, just in case they get out of sync between QD and QE,
* which might happen with a toast table or index, I think (but maybe not)
*/
appendStringInfo(&buffer, "select pg_relation_size('%s.%s')",
quote_identifier(schemaName), quote_identifier(relName));
CdbDispatchCommand(buffer.data, DF_WITH_SNAPSHOT, &cdb_pgresults);
for (i = 0; i < cdb_pgresults.numResults; i++)
{
struct pg_result * pgresult = cdb_pgresults.pg_results[i];
if (PQresultStatus(pgresult) != PGRES_TUPLES_OK)
{
cdbdisp_clearCdbPgResults(&cdb_pgresults);
elog(ERROR,"cdbRelMaxSegSize: resultStatus not tuples_Ok: %s %s",
PQresStatus(PQresultStatus(pgresult)),PQresultErrorMessage(pgresult));
}
else
{
Assert(PQntuples(pgresult) == 1);
int64 tempsize = 0;
(void) scanint8(PQgetvalue(pgresult, 0, 0), false, &tempsize);
if (tempsize > size)
size = tempsize;
}
}
pfree(buffer.data);
cdbdisp_clearCdbPgResults(&cdb_pgresults);
return size;
}
示例5: OpenErrorTable
/*
* OpenErrorTable
*
* Open the error table for this operation, and perform all necessary checks.
*/
void OpenErrorTable(CdbSreh *cdbsreh, RangeVar *errortable)
{
AclResult aclresult;
AclMode required_access = ACL_INSERT;
Oid relOid;
/* Open and lock the error relation, using the appropriate lock type. */
cdbsreh->errtbl = heap_openrv(errortable, RowExclusiveLock);
relOid = RelationGetRelid(cdbsreh->errtbl);
/* Check relation permissions. */
aclresult = pg_class_aclcheck(relOid,
GetUserId(),
required_access);
if (aclresult != ACLCHECK_OK)
aclcheck_error(aclresult, ACL_KIND_CLASS,
RelationGetRelationName(cdbsreh->errtbl));
/* check read-only transaction */
if (XactReadOnly &&
!isTempNamespace(RelationGetNamespace(cdbsreh->errtbl)))
ereport(ERROR,
(errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
errmsg("transaction is read-only")));
/* make sure this is a regular relation */
if (cdbsreh->errtbl->rd_rel->relkind != RELKIND_RELATION)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" exists in the database but is a non table relation",
RelationGetRelationName(cdbsreh->errtbl))));
}
示例6: btinsert
/*
* btinsert() -- insert an index tuple into a btree.
*
* Descend the tree recursively, find the appropriate location for our
* new tuple, and put it there.
*/
Datum
btinsert(PG_FUNCTION_ARGS)
{
MIRROREDLOCK_BUFMGR_VERIFY_NO_LOCK_LEAK_DECLARE;
Relation rel = (Relation) PG_GETARG_POINTER(0);
Datum *values = (Datum *) PG_GETARG_POINTER(1);
bool *isnull = (bool *) PG_GETARG_POINTER(2);
ItemPointer ht_ctid = (ItemPointer) PG_GETARG_POINTER(3);
Relation heapRel = (Relation) PG_GETARG_POINTER(4);
bool checkUnique = PG_GETARG_BOOL(5);
IndexTuple itup;
MIRROREDLOCK_BUFMGR_VERIFY_NO_LOCK_LEAK_ENTER;
if (checkUnique && (
(gp_indexcheck_insert == INDEX_CHECK_ALL && RelationIsHeap(heapRel)) ||
(gp_indexcheck_insert == INDEX_CHECK_SYSTEM &&
PG_CATALOG_NAMESPACE == RelationGetNamespace(heapRel))))
{
_bt_validate_tid(rel, ht_ctid);
}
/* generate an index tuple */
itup = index_form_tuple(RelationGetDescr(rel), values, isnull);
itup->t_tid = *ht_ctid;
_bt_doinsert(rel, itup, checkUnique, heapRel);
pfree(itup);
MIRROREDLOCK_BUFMGR_VERIFY_NO_LOCK_LEAK_EXIT;
PG_RETURN_BOOL(true);
}
示例7: cluster
/*---------------------------------------------------------------------------
* This cluster code allows for clustering multiple tables at once. Because
* of this, we cannot just run everything on a single transaction, or we
* would be forced to acquire exclusive locks on all the tables being
* clustered, simultaneously --- very likely leading to deadlock.
*
* To solve this we follow a similar strategy to VACUUM code,
* clustering each relation in a separate transaction. For this to work,
* we need to:
* - provide a separate memory context so that we can pass information in
* a way that survives across transactions
* - start a new transaction every time a new relation is clustered
* - check for validity of the information on to-be-clustered relations,
* as someone might have deleted a relation behind our back, or
* clustered one on a different index
* - end the transaction
*
* The single-relation case does not have any such overhead.
*
* We also allow a relation to be specified without index. In that case,
* the indisclustered bit will be looked up, and an ERROR will be thrown
* if there is no index with the bit set.
*---------------------------------------------------------------------------
*/
void
cluster(ClusterStmt *stmt, bool isTopLevel)
{
if (stmt->relation != NULL)
{
/* This is the single-relation case. */
Oid tableOid,
indexOid = InvalidOid;
Relation rel;
RelToCluster rvtc;
/* Find and lock the table */
rel = heap_openrv(stmt->relation, AccessExclusiveLock);
tableOid = RelationGetRelid(rel);
/* Check permissions */
if (!pg_class_ownercheck(tableOid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
RelationGetRelationName(rel));
/*
* Reject clustering a remote temp table ... their local buffer
* manager is not going to cope.
*/
if (isOtherTempNamespace(RelationGetNamespace(rel)))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot cluster temporary tables of other sessions")));
if (stmt->indexname == NULL)
{
ListCell *index;
/* We need to find the index that has indisclustered set. */
foreach(index, RelationGetIndexList(rel))
{
HeapTuple idxtuple;
Form_pg_index indexForm;
indexOid = lfirst_oid(index);
idxtuple = SearchSysCache(INDEXRELID,
ObjectIdGetDatum(indexOid),
0, 0, 0);
if (!HeapTupleIsValid(idxtuple))
elog(ERROR, "cache lookup failed for index %u", indexOid);
indexForm = (Form_pg_index) GETSTRUCT(idxtuple);
if (indexForm->indisclustered)
{
ReleaseSysCache(idxtuple);
break;
}
ReleaseSysCache(idxtuple);
indexOid = InvalidOid;
}
示例8: GetNewOid
/*
* GetNewOid
* Generate a new OID that is unique within the given relation.
*
* Caller must have a suitable lock on the relation.
*
* Uniqueness is promised only if the relation has a unique index on OID.
* This is true for all system catalogs that have OIDs, but might not be
* true for user tables. Note that we are effectively assuming that the
* table has a relatively small number of entries (much less than 2^32)
* and there aren't very long runs of consecutive existing OIDs. Again,
* this is reasonable for system catalogs but less so for user tables.
*
* Since the OID is not immediately inserted into the table, there is a
* race condition here; but a problem could occur only if someone else
* managed to cycle through 2^32 OIDs and generate the same OID before we
* finish inserting our row. This seems unlikely to be a problem. Note
* that if we had to *commit* the row to end the race condition, the risk
* would be rather higher; therefore we use SnapshotDirty in the test,
* so that we will see uncommitted rows.
*/
Oid
GetNewOid(Relation relation)
{
Oid newOid;
Oid oidIndex;
Relation indexrel;
/* If relation doesn't have OIDs at all, caller is confused */
Assert(relation->rd_rel->relhasoids);
/* In bootstrap mode, we don't have any indexes to use */
if (IsBootstrapProcessingMode())
return GetNewObjectId();
/* The relcache will cache the identity of the OID index for us */
oidIndex = RelationGetOidIndex(relation);
/* If no OID index, just hand back the next OID counter value */
if (!OidIsValid(oidIndex))
{
Oid result;
/*
* System catalogs that have OIDs should *always* have a unique OID
* index; we should only take this path for user tables. Give a
* warning if it looks like somebody forgot an index.
*/
if (IsSystemRelation(relation))
elog(WARNING, "generating possibly-non-unique OID for \"%s\"",
RelationGetRelationName(relation));
result= GetNewObjectId();
if (IsSystemNamespace(RelationGetNamespace(relation)))
{
if (Gp_role == GP_ROLE_EXECUTE)
{
elog(DEBUG1,"Allocating Oid %u on relid %u %s in EXECUTE mode",result,relation->rd_id,RelationGetRelationName(relation));
}
if (Gp_role == GP_ROLE_DISPATCH)
{
elog(DEBUG5,"Allocating Oid %u on relid %u %s in DISPATCH mode",result,relation->rd_id,RelationGetRelationName(relation));
}
}
return result;
}
/* Otherwise, use the index to find a nonconflicting OID */
indexrel = index_open(oidIndex, AccessShareLock);
newOid = GetNewOidWithIndex(relation, indexrel);
index_close(indexrel, AccessShareLock);
return newOid;
}
示例9: GetNewOidWithIndex
/*
* GetNewOidWithIndex
* Guts of GetNewOid: use the supplied index
*
* This is exported separately because there are cases where we want to use
* an index that will not be recognized by RelationGetOidIndex: TOAST tables
* and pg_largeobject have indexes that are usable, but have multiple columns
* and are on ordinary columns rather than a true OID column. This code
* will work anyway, so long as the OID is the index's first column.
*
* Caller must have a suitable lock on the relation.
*/
Oid
GetNewOidWithIndex(Relation relation, Relation indexrel)
{
Oid newOid;
IndexScanDesc scan;
ScanKeyData key;
bool collides;
/* Generate new OIDs until we find one not in the table */
do
{
CHECK_FOR_INTERRUPTS();
newOid = GetNewObjectId();
ScanKeyInit(&key,
(AttrNumber) 1,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(newOid));
/* see notes above about using SnapshotDirty */
scan = index_beginscan(relation, indexrel,
SnapshotDirty, 1, &key);
collides = HeapTupleIsValid(index_getnext(scan, ForwardScanDirection));
index_endscan(scan);
} while (collides);
if (IsSystemNamespace(RelationGetNamespace(relation)))
{
if (Gp_role == GP_ROLE_EXECUTE)
{
if (relation->rd_id != 2604 /* pg_attrdef */ && relation->rd_id != 2606 /* pg_constraint */ && relation->rd_id != 2615 /* pg_namespace */)
elog(DEBUG1,"Allocating Oid %u with index on relid %u %s in EXECUTE mode",newOid,relation->rd_id, RelationGetRelationName(relation));
else
elog(DEBUG4,"Allocating Oid %u with index on relid %u %s in EXECUTE mode",newOid,relation->rd_id, RelationGetRelationName(relation));
}
if (Gp_role == GP_ROLE_DISPATCH)
{
elog(DEBUG5,"Allocating Oid %u with index on relid %u %s in DISPATCH mode",newOid,relation->rd_id, RelationGetRelationName(relation));
}
}
return newOid;
}
示例10: logicalrep_write_rel
/*
* Write relation description to the output stream.
*/
void
logicalrep_write_rel(StringInfo out, Relation rel)
{
char *relname;
pq_sendbyte(out, 'R'); /* sending RELATION */
/* use Oid as relation identifier */
pq_sendint(out, RelationGetRelid(rel), 4);
/* send qualified relation name */
logicalrep_write_namespace(out, RelationGetNamespace(rel));
relname = RelationGetRelationName(rel);
pq_sendstring(out, relname);
/* send replica identity */
pq_sendbyte(out, rel->rd_rel->relreplident);
/* send the attribute info */
logicalrep_write_attrs(out, rel);
}
示例11: RelationNeedsSynchronizedOIDs
/*
* OIDs for catalog object are normally allocated in the master, and
* executor nodes should just use the OIDs passed by the master. But
* there are some exceptions.
*/
static bool
RelationNeedsSynchronizedOIDs(Relation relation)
{
if (IsSystemNamespace(RelationGetNamespace(relation)))
{
switch(RelationGetRelid(relation))
{
/*
* pg_largeobject is more like a user table, and has
* different contents in each segment and master.
*/
case LargeObjectRelationId:
return false;
/*
* We don't currently synchronize the OIDs of these catalogs.
* It's a bit sketchy that we don't, but we get away with it
* because these OIDs don't appear in any of the Node structs
* that are dispatched from master to segments. (Except for the
* OIDs, the contents of these tables should be in sync.)
*/
case RewriteRelationId:
case TriggerRelationId:
case AccessMethodOperatorRelationId:
case AccessMethodProcedureRelationId:
return false;
}
/*
* All other system catalogs are assumed to need synchronized
* OIDs.
*/
return true;
}
return false;
}
示例12: bt_page_items
Datum
bt_page_items(PG_FUNCTION_ARGS)
{
text *relname = PG_GETARG_TEXT_P(0);
uint32 blkno = PG_GETARG_UINT32(1);
RangeVar *relrv;
Datum result;
char *values[BTPAGEITEMS_NCOLUMNS];
BTPageOpaque opaque;
HeapTuple tuple;
ItemId id;
FuncCallContext *fctx;
MemoryContext mctx;
struct user_args *uargs = NULL;
if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("must be superuser to use pgstattuple functions"))));
if (SRF_IS_FIRSTCALL())
{
fctx = SRF_FIRSTCALL_INIT();
mctx = MemoryContextSwitchTo(fctx->multi_call_memory_ctx);
uargs = palloc(sizeof(struct user_args));
uargs->tupd = RelationNameGetTupleDesc(BTPAGEITEMS_TYPE);
uargs->offset = FirstOffsetNumber;
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
uargs->rel = relation_openrv(relrv, AccessShareLock);
if (!IS_INDEX(uargs->rel) || !IS_BTREE(uargs->rel))
elog(ERROR, "bt_page_items() can be used only on b-tree index.");
/*
* Reject attempts to read non-local temporary relations; we would
* be likely to get wrong data since we have no visibility into the
* owning session's local buffers.
*/
if (isOtherTempNamespace(RelationGetNamespace(uargs->rel)))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot access temporary tables of other sessions")));
if (blkno == 0)
elog(ERROR, "Block 0 is a meta page.");
CHECK_RELATION_BLOCK_RANGE(uargs->rel, blkno);
uargs->buffer = ReadBuffer(uargs->rel, blkno);
uargs->page = BufferGetPage(uargs->buffer);
opaque = (BTPageOpaque) PageGetSpecialPointer(uargs->page);
if (P_ISDELETED(opaque))
elog(NOTICE, "bt_page_items(): this page is deleted.");
fctx->max_calls = PageGetMaxOffsetNumber(uargs->page);
fctx->user_fctx = uargs;
MemoryContextSwitchTo(mctx);
}
fctx = SRF_PERCALL_SETUP();
uargs = fctx->user_fctx;
if (fctx->call_cntr < fctx->max_calls)
{
IndexTuple itup;
id = PageGetItemId(uargs->page, uargs->offset);
if (!ItemIdIsValid(id))
elog(ERROR, "Invalid ItemId.");
itup = (IndexTuple) PageGetItem(uargs->page, id);
{
int j = 0;
BlockNumber blkno = BlockIdGetBlockNumber(&(itup->t_tid.ip_blkid));
values[j] = palloc(32);
snprintf(values[j++], 32, "%d", uargs->offset);
values[j] = palloc(32);
snprintf(values[j++], 32, "(%u,%u)", blkno, itup->t_tid.ip_posid);
values[j] = palloc(32);
snprintf(values[j++], 32, "%d", (int) IndexTupleSize(itup));
values[j] = palloc(32);
snprintf(values[j++], 32, "%c", IndexTupleHasNulls(itup) ? 't' : 'f');
values[j] = palloc(32);
snprintf(values[j++], 32, "%c", IndexTupleHasVarwidths(itup) ? 't' : 'f');
{
int off;
//.........这里部分代码省略.........
示例13: ExecRefreshMatView
//.........这里部分代码省略.........
DestReceiver *dest;
uint64 processed = 0;
bool concurrent;
LOCKMODE lockmode;
char relpersistence;
Oid save_userid;
int save_sec_context;
int save_nestlevel;
ObjectAddress address;
/* Determine strength of lock needed. */
concurrent = stmt->concurrent;
lockmode = concurrent ? ExclusiveLock : AccessExclusiveLock;
/*
* Get a lock until end of transaction.
*/
matviewOid = RangeVarGetRelidExtended(stmt->relation,
lockmode, 0,
RangeVarCallbackOwnsTable, NULL);
matviewRel = table_open(matviewOid, NoLock);
/* Make sure it is a materialized view. */
if (matviewRel->rd_rel->relkind != RELKIND_MATVIEW)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("\"%s\" is not a materialized view",
RelationGetRelationName(matviewRel))));
/* Check that CONCURRENTLY is not specified if not populated. */
if (concurrent && !RelationIsPopulated(matviewRel))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("CONCURRENTLY cannot be used when the materialized view is not populated")));
/* Check that conflicting options have not been specified. */
if (concurrent && stmt->skipData)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("CONCURRENTLY and WITH NO DATA options cannot be used together")));
/*
* Check that everything is correct for a refresh. Problems at this point
* are internal errors, so elog is sufficient.
*/
if (matviewRel->rd_rel->relhasrules == false ||
matviewRel->rd_rules->numLocks < 1)
elog(ERROR,
"materialized view \"%s\" is missing rewrite information",
RelationGetRelationName(matviewRel));
if (matviewRel->rd_rules->numLocks > 1)
elog(ERROR,
"materialized view \"%s\" has too many rules",
RelationGetRelationName(matviewRel));
rule = matviewRel->rd_rules->rules[0];
if (rule->event != CMD_SELECT || !(rule->isInstead))
elog(ERROR,
"the rule for materialized view \"%s\" is not a SELECT INSTEAD OF rule",
RelationGetRelationName(matviewRel));
actions = rule->actions;
if (list_length(actions) != 1)
elog(ERROR,
"the rule for materialized view \"%s\" is not a single action",
RelationGetRelationName(matviewRel));
/*
* Check that there is a unique index with no WHERE clause on one or more
* columns of the materialized view if CONCURRENTLY is specified.
*/
if (concurrent)
{
List *indexoidlist = RelationGetIndexList(matviewRel);
ListCell *indexoidscan;
bool hasUniqueIndex = false;
foreach(indexoidscan, indexoidlist)
{
Oid indexoid = lfirst_oid(indexoidscan);
Relation indexRel;
indexRel = index_open(indexoid, AccessShareLock);
hasUniqueIndex = is_usable_unique_index(indexRel);
index_close(indexRel, AccessShareLock);
if (hasUniqueIndex)
break;
}
list_free(indexoidlist);
if (!hasUniqueIndex)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("cannot refresh materialized view \"%s\" concurrently",
quote_qualified_identifier(get_namespace_name(RelationGetNamespace(matviewRel)),
RelationGetRelationName(matviewRel))),
errhint("Create a unique index with no WHERE clause on one or more columns of the materialized view.")));
}
示例14: DefineIndex
/*
* DefineIndex
* Creates a new index.
*
* 'heapRelation': the relation the index will apply to.
* 'indexRelationName': the name for the new index, or NULL to indicate
* that a nonconflicting default name should be picked.
* 'indexRelationId': normally InvalidOid, but during bootstrap can be
* nonzero to specify a preselected OID for the index.
* 'accessMethodName': name of the AM to use.
* 'tableSpaceName': name of the tablespace to create the index in.
* NULL specifies using the appropriate default.
* 'attributeList': a list of IndexElem specifying columns and expressions
* to index on.
* 'predicate': the partial-index condition, or NULL if none.
* 'rangetable': needed to interpret the predicate.
* 'options': reloptions from WITH (in list-of-DefElem form).
* 'unique': make the index enforce uniqueness.
* 'primary': mark the index as a primary key in the catalogs.
* 'isconstraint': index is for a PRIMARY KEY or UNIQUE constraint,
* so build a pg_constraint entry for it.
* 'is_alter_table': this is due to an ALTER rather than a CREATE operation.
* 'check_rights': check for CREATE rights in the namespace. (This should
* be true except when ALTER is deleting/recreating an index.)
* 'skip_build': make the catalog entries but leave the index file empty;
* it will be filled later.
* 'quiet': suppress the NOTICE chatter ordinarily provided for constraints.
* 'concurrent': avoid blocking writers to the table while building.
*/
void
DefineIndex(RangeVar *heapRelation,
char *indexRelationName,
Oid indexRelationId,
char *accessMethodName,
char *tableSpaceName,
List *attributeList,
Expr *predicate,
List *rangetable,
List *options,
bool unique,
bool primary,
bool isconstraint,
bool is_alter_table,
bool check_rights,
bool skip_build,
bool quiet,
bool concurrent)
{
Oid *classObjectId;
Oid accessMethodId;
Oid relationId;
Oid namespaceId;
Oid tablespaceId;
Relation rel;
HeapTuple tuple;
Form_pg_am accessMethodForm;
RegProcedure amoptions;
Datum reloptions;
IndexInfo *indexInfo;
int numberOfAttributes;
List *old_xact_list;
ListCell *lc;
uint32 ixcnt;
LockRelId heaprelid;
LOCKTAG heaplocktag;
Snapshot snapshot;
Relation pg_index;
HeapTuple indexTuple;
Form_pg_index indexForm;
/*
* count attributes in index
*/
numberOfAttributes = list_length(attributeList);
if (numberOfAttributes <= 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("must specify at least one column")));
if (numberOfAttributes > INDEX_MAX_KEYS)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_COLUMNS),
errmsg("cannot use more than %d columns in an index",
INDEX_MAX_KEYS)));
/*
* Open heap relation, acquire a suitable lock on it, remember its OID
*
* Only SELECT ... FOR UPDATE/SHARE are allowed while doing a standard
* index build; but for concurrent builds we allow INSERT/UPDATE/DELETE
* (but not VACUUM).
*/
rel = heap_openrv(heapRelation,
(concurrent ? ShareUpdateExclusiveLock : ShareLock));
relationId = RelationGetRelid(rel);
namespaceId = RelationGetNamespace(rel);
/* Note: during bootstrap may see uncataloged relation */
if (rel->rd_rel->relkind != RELKIND_RELATION &&
rel->rd_rel->relkind != RELKIND_UNCATALOGED)
//.........这里部分代码省略.........
示例15: _bt_validate_vacuum
//.........这里部分代码省略.........
* in a unique index.
*/
if (!heap_release_fetch(hrel, SnapshotAny, &htup,
&hbuf, true, NULL))
{
elog(ERROR, "btvalidatevacuum: tid (%d,%d) from index %s "
"not found in heap %s",
ItemPointerGetBlockNumber(&itup->t_tid),
ItemPointerGetOffsetNumber(&itup->t_tid),
RelationGetRelationName(irel),
RelationGetRelationName(hrel));
}
switch (HeapTupleSatisfiesVacuum(hrel, htup.t_data, oldest_xmin, hbuf))
{
case HEAPTUPLE_RECENTLY_DEAD:
case HEAPTUPLE_LIVE:
case HEAPTUPLE_INSERT_IN_PROGRESS:
case HEAPTUPLE_DELETE_IN_PROGRESS:
/* these tuples are considered alive by vacuum */
break;
case HEAPTUPLE_DEAD:
elog(ERROR, "btvalidatevacuum: vacuum did not remove "
"dead tuple (%d,%d) from heap %s and index %s",
ItemPointerGetBlockNumber(&itup->t_tid),
ItemPointerGetOffsetNumber(&itup->t_tid),
RelationGetRelationName(hrel),
RelationGetRelationName(irel));
break;
default:
elog(ERROR, "btvalidatevacuum: invalid visibility");
break;
}
switch(RelationGetRelid(irel))
{
case DatabaseOidIndexId:
case TypeOidIndexId:
case ClassOidIndexId:
case ConstraintOidIndexId:
hoid = HeapTupleGetOid(&htup);
ioid = index_getattr(itup, 1, RelationGetDescr(irel), &isnull);
if (hoid != ioid)
{
elog(ERROR,
"btvalidatevacuum: index oid(%d) != heap oid(%d)"
" tuple (%d,%d) index %s", ioid, hoid,
ItemPointerGetBlockNumber(&itup->t_tid),
ItemPointerGetOffsetNumber(&itup->t_tid),
RelationGetRelationName(irel));
}
break;
case GpRelationNodeOidIndexId:
hoid = heap_getattr(&htup, 1, RelationGetDescr(hrel), &isnull);
ioid = index_getattr(itup, 1, RelationGetDescr(irel), &isnull);
if (hoid != ioid)
{
elog(ERROR,
"btvalidatevacuum: index oid(%d) != heap oid(%d)"
" tuple (%d,%d) index %s", ioid, hoid,
ItemPointerGetBlockNumber(&itup->t_tid),
ItemPointerGetOffsetNumber(&itup->t_tid),
RelationGetRelationName(irel));
}
int4 hsegno = heap_getattr(&htup, 2, RelationGetDescr(hrel), &isnull);
int4 isegno = index_getattr(itup, 2, RelationGetDescr(irel), &isnull);
if (isegno != hsegno)
{
elog(ERROR,
"btvalidatevacuum: index segno(%d) != heap segno(%d)"
" tuple (%d,%d) index %s", isegno, hsegno,
ItemPointerGetBlockNumber(&itup->t_tid),
ItemPointerGetOffsetNumber(&itup->t_tid),
RelationGetRelationName(irel));
}
break;
default:
break;
}
if (RelationGetNamespace(irel) == PG_AOSEGMENT_NAMESPACE)
{
int4 isegno = index_getattr(itup, 1, RelationGetDescr(irel), &isnull);
int4 hsegno = heap_getattr(&htup, 1, RelationGetDescr(hrel), &isnull);
if (isegno != hsegno)
{
elog(ERROR,
"btvalidatevacuum: index segno(%d) != heap segno(%d)"
" tuple (%d,%d) index %s", isegno, hsegno,
ItemPointerGetBlockNumber(&itup->t_tid),
ItemPointerGetOffsetNumber(&itup->t_tid),
RelationGetRelationName(irel));
}
}
}
}
if (BufferIsValid(ibuf))
ReleaseBuffer(ibuf);
}
if (BufferIsValid(hbuf))
ReleaseBuffer(hbuf);
MIRROREDLOCK_BUFMGR_UNLOCK;
}