您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ HeapTupleGetOid函数代码示例

51自学网 2021-06-01 21:25:57
  C++
这篇教程C++ HeapTupleGetOid函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中HeapTupleGetOid函数的典型用法代码示例。如果您正苦于以下问题:C++ HeapTupleGetOid函数的具体用法?C++ HeapTupleGetOid怎么用?C++ HeapTupleGetOid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了HeapTupleGetOid函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: PLy_input_datum_func2

static voidPLy_input_datum_func2(PLyDatumToOb *arg, Oid typeOid, HeapTuple typeTup){	Form_pg_type typeStruct = (Form_pg_type) GETSTRUCT(typeTup);	Oid			element_type = get_element_type(typeOid);	/* Get the type's conversion information */	perm_fmgr_info(typeStruct->typoutput, &arg->typfunc);	arg->typoid = HeapTupleGetOid(typeTup);	arg->typmod = -1;	arg->typioparam = getTypeIOParam(typeTup);	arg->typbyval = typeStruct->typbyval;	arg->typlen = typeStruct->typlen;	arg->typalign = typeStruct->typalign;	/* Determine which kind of Python object we will convert to */	switch (getBaseType(element_type ? element_type : typeOid))	{		case BOOLOID:			arg->func = PLyBool_FromBool;			break;		case FLOAT4OID:			arg->func = PLyFloat_FromFloat4;			break;		case FLOAT8OID:			arg->func = PLyFloat_FromFloat8;			break;		case NUMERICOID:			arg->func = PLyFloat_FromNumeric;			break;		case INT2OID:			arg->func = PLyInt_FromInt16;			break;		case INT4OID:			arg->func = PLyInt_FromInt32;			break;		case INT8OID:			arg->func = PLyLong_FromInt64;			break;		case BYTEAOID:			arg->func = PLyBytes_FromBytea;			break;		default:			arg->func = PLyString_FromDatum;			break;	}	if (element_type)	{		char		dummy_delim;		Oid			funcid;		arg->elm = PLy_malloc0(sizeof(*arg->elm));		arg->elm->func = arg->func;		arg->func = PLyList_FromArray;		arg->elm->typoid = element_type;		arg->elm->typmod = -1;		get_type_io_data(element_type, IOFunc_output,						 &arg->elm->typlen, &arg->elm->typbyval, &arg->elm->typalign, &dummy_delim,						 &arg->elm->typioparam, &funcid);		perm_fmgr_info(funcid, &arg->elm->typfunc);	}}
开发者ID:AllenDou,项目名称:postgresql,代码行数:63,


示例2: PrepareForTupleInvalidation

/* * PrepareForTupleInvalidation *		Detect whether invalidation of this tuple implies invalidation *		of catalog/relation cache entries; if so, register inval events. */static voidPrepareForTupleInvalidation(Relation relation, HeapTuple tuple){	Oid			tupleRelId;	Oid			databaseId;	Oid			relationId;	/* Do nothing during bootstrap */	if (IsBootstrapProcessingMode())		return;	/*	 * We only need to worry about invalidation for tuples that are in system	 * relations; user-relation tuples are never in catcaches and can't affect	 * the relcache either.	 */	if (!IsSystemRelation(relation))		return;	/*	 * TOAST tuples can likewise be ignored here. Note that TOAST tables are	 * considered system relations so they are not filtered by the above test.	 */	if (IsToastRelation(relation))		return;	/*	 * First let the catcache do its thing	 */	PrepareToInvalidateCacheTuple(relation, tuple,								  RegisterCatcacheInvalidation);	/*	 * Now, is this tuple one of the primary definers of a relcache entry?	 */	tupleRelId = RelationGetRelid(relation);	if (tupleRelId == RelationRelationId)	{		Form_pg_class classtup = (Form_pg_class) GETSTRUCT(tuple);		RelFileNode rnode;		relationId = HeapTupleGetOid(tuple);		if (classtup->relisshared)			databaseId = InvalidOid;		else			databaseId = MyDatabaseId;		/*		 * We need to send out an smgr inval as well as a relcache inval. This		 * is needed because other backends might possibly possess smgr cache		 * but not relcache entries for the target relation.		 *		 * Note: during a pg_class row update that assigns a new relfilenode		 * or reltablespace value, we will be called on both the old and new		 * tuples, and thus will broadcast invalidation messages showing both		 * the old and new RelFileNode values.	This ensures that other		 * backends will close smgr references to the old file.		 *		 * XXX possible future cleanup: it might be better to trigger smgr		 * flushes explicitly, rather than indirectly from pg_class updates.		 */		if (classtup->reltablespace)			rnode.spcNode = classtup->reltablespace;		else			rnode.spcNode = MyDatabaseTableSpace;		rnode.dbNode = databaseId;		rnode.relNode = classtup->relfilenode;		RegisterSmgrInvalidation(rnode);	}	else if (tupleRelId == AttributeRelationId)	{		Form_pg_attribute atttup = (Form_pg_attribute) GETSTRUCT(tuple);		relationId = atttup->attrelid;		/*		 * KLUGE ALERT: we always send the relcache event with MyDatabaseId,		 * even if the rel in question is shared (which we can't easily tell).		 * This essentially means that only backends in this same database		 * will react to the relcache flush request. This is in fact		 * appropriate, since only those backends could see our pg_attribute		 * change anyway.  It looks a bit ugly though.		 */		databaseId = MyDatabaseId;	}	else		return;	/*	 * Yes.  We need to register a relcache invalidation event.	 */	RegisterRelcacheInvalidation(databaseId, relationId);}
开发者ID:CraigBryan,项目名称:PostgresqlFun,代码行数:99,


示例3: CacheInvalidateHeapTuple

/* * CacheInvalidateHeapTuple *		Register the given tuple for invalidation at end of command *		(ie, current command is creating or outdating this tuple). *		Also, detect whether a relcache invalidation is implied. * * For an insert or delete, tuple is the target tuple and newtuple is NULL. * For an update, we are called just once, with tuple being the old tuple * version and newtuple the new version.  This allows avoidance of duplicate * effort during an update. */voidCacheInvalidateHeapTuple(Relation relation,						 HeapTuple tuple,						 HeapTuple newtuple){	Oid			tupleRelId;	Oid			databaseId;	Oid			relationId;	/* Do nothing during bootstrap */	if (IsBootstrapProcessingMode())		return;	/*	 * We only need to worry about invalidation for tuples that are in system	 * catalogs; user-relation tuples are never in catcaches and can't affect	 * the relcache either.	 */	if (!IsCatalogRelation(relation))		return;	/*	 * IsCatalogRelation() will return true for TOAST tables of system	 * catalogs, but we don't care about those, either.	 */	if (IsToastRelation(relation))		return;	/*	 * If we're not prepared to queue invalidation messages for this	 * subtransaction level, get ready now.	 */	PrepareInvalidationState();	/*	 * First let the catcache do its thing	 */	tupleRelId = RelationGetRelid(relation);	if (RelationInvalidatesSnapshotsOnly(tupleRelId))	{		databaseId = IsSharedRelation(tupleRelId) ? InvalidOid : MyDatabaseId;		RegisterSnapshotInvalidation(databaseId, tupleRelId);	}	else		PrepareToInvalidateCacheTuple(relation, tuple, newtuple,									  RegisterCatcacheInvalidation);	/*	 * Now, is this tuple one of the primary definers of a relcache entry?	 *	 * Note we ignore newtuple here; we assume an update cannot move a tuple	 * from being part of one relcache entry to being part of another.	 */	if (tupleRelId == RelationRelationId)	{		Form_pg_class classtup = (Form_pg_class) GETSTRUCT(tuple);		relationId = HeapTupleGetOid(tuple);		if (classtup->relisshared)			databaseId = InvalidOid;		else			databaseId = MyDatabaseId;	}	else if (tupleRelId == AttributeRelationId)	{		Form_pg_attribute atttup = (Form_pg_attribute) GETSTRUCT(tuple);		relationId = atttup->attrelid;		/*		 * KLUGE ALERT: we always send the relcache event with MyDatabaseId,		 * even if the rel in question is shared (which we can't easily tell).		 * This essentially means that only backends in this same database		 * will react to the relcache flush request.  This is in fact		 * appropriate, since only those backends could see our pg_attribute		 * change anyway.  It looks a bit ugly though.  (In practice, shared		 * relations can't have schema changes after bootstrap, so we should		 * never come here for a shared rel anyway.)		 */		databaseId = MyDatabaseId;	}	else if (tupleRelId == IndexRelationId)	{		Form_pg_index indextup = (Form_pg_index) GETSTRUCT(tuple);		/*		 * When a pg_index row is updated, we should send out a relcache inval		 * for the index relation.  As above, we don't know the shared status		 * of the index, but in practice it doesn't matter since indexes of//.........这里部分代码省略.........
开发者ID:nabeelh,项目名称:postgres,代码行数:101,


示例4: DropTableSpace

/* * Drop a table space * * Be careful to check that the tablespace is empty. */voidDropTableSpace(DropTableSpaceStmt *stmt){#ifdef HAVE_SYMLINK	char	   *tablespacename = stmt->tablespacename;	HeapScanDesc scandesc;	Relation	rel;	HeapTuple	tuple;	ScanKeyData entry[1];	Oid			tablespaceoid;	/*	 * Find the target tuple	 */	rel = heap_open(TableSpaceRelationId, RowExclusiveLock);	ScanKeyInit(&entry[0],				Anum_pg_tablespace_spcname,				BTEqualStrategyNumber, F_NAMEEQ,				CStringGetDatum(tablespacename));	scandesc = heap_beginscan(rel, SnapshotNow, 1, entry);	tuple = heap_getnext(scandesc, ForwardScanDirection);	if (!HeapTupleIsValid(tuple))	{		if (!stmt->missing_ok)		{			ereport(ERROR,					(errcode(ERRCODE_UNDEFINED_OBJECT),					 errmsg("tablespace /"%s/" does not exist",							tablespacename)));		}		else		{			ereport(NOTICE,					(errmsg("tablespace /"%s/" does not exist, skipping",							tablespacename)));			/* XXX I assume I need one or both of these next two calls */			heap_endscan(scandesc);			heap_close(rel, NoLock);		}		return;	}	tablespaceoid = HeapTupleGetOid(tuple);	/* Must be tablespace owner */	if (!pg_tablespace_ownercheck(tablespaceoid, GetUserId()))		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TABLESPACE,					   tablespacename);	/* Disallow drop of the standard tablespaces, even by superuser */	if (tablespaceoid == GLOBALTABLESPACE_OID ||		tablespaceoid == DEFAULTTABLESPACE_OID)		aclcheck_error(ACLCHECK_NO_PRIV, ACL_KIND_TABLESPACE,					   tablespacename);	/* DROP hook for the tablespace being removed */	if (object_access_hook)	{		ObjectAccessDrop drop_arg;		memset(&drop_arg, 0, sizeof(ObjectAccessDrop));		InvokeObjectAccessHook(OAT_DROP, TableSpaceRelationId,							   tablespaceoid, 0, &drop_arg);	}	/*	 * Remove the pg_tablespace tuple (this will roll back if we fail below)	 */	simple_heap_delete(rel, &tuple->t_self);	heap_endscan(scandesc);	/*	 * Remove any comments or security labels on this tablespace.	 */	DeleteSharedComments(tablespaceoid, TableSpaceRelationId);	DeleteSharedSecurityLabel(tablespaceoid, TableSpaceRelationId);	/*	 * Remove dependency on owner.	 */	deleteSharedDependencyRecordsFor(TableSpaceRelationId, tablespaceoid, 0);	/*	 * Acquire TablespaceCreateLock to ensure that no TablespaceCreateDbspace	 * is running concurrently.	 */	LWLockAcquire(TablespaceCreateLock, LW_EXCLUSIVE);	/*	 * Try to remove the physical infrastructure.	 */	if (!destroy_tablespace_directories(tablespaceoid, false))//.........这里部分代码省略.........
开发者ID:fdr,项目名称:postgres,代码行数:101,


示例5: AlterTableSpaceOptions

/* * Alter table space options */voidAlterTableSpaceOptions(AlterTableSpaceOptionsStmt *stmt){	Relation	rel;	ScanKeyData entry[1];	HeapScanDesc scandesc;	HeapTuple	tup;	Datum		datum;	Datum		newOptions;	Datum		repl_val[Natts_pg_tablespace];	bool		isnull;	bool		repl_null[Natts_pg_tablespace];	bool		repl_repl[Natts_pg_tablespace];	HeapTuple	newtuple;	/* Search pg_tablespace */	rel = heap_open(TableSpaceRelationId, RowExclusiveLock);	ScanKeyInit(&entry[0],				Anum_pg_tablespace_spcname,				BTEqualStrategyNumber, F_NAMEEQ,				CStringGetDatum(stmt->tablespacename));	scandesc = heap_beginscan(rel, SnapshotNow, 1, entry);	tup = heap_getnext(scandesc, ForwardScanDirection);	if (!HeapTupleIsValid(tup))		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_OBJECT),				 errmsg("tablespace /"%s/" does not exist",						stmt->tablespacename)));	/* Must be owner of the existing object */	if (!pg_tablespace_ownercheck(HeapTupleGetOid(tup), GetUserId()))		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TABLESPACE,					   stmt->tablespacename);	/* Generate new proposed spcoptions (text array) */	datum = heap_getattr(tup, Anum_pg_tablespace_spcoptions,						 RelationGetDescr(rel), &isnull);	newOptions = transformRelOptions(isnull ? (Datum) 0 : datum,									 stmt->options, NULL, NULL, false,									 stmt->isReset);	(void) tablespace_reloptions(newOptions, true);	/* Build new tuple. */	memset(repl_null, false, sizeof(repl_null));	memset(repl_repl, false, sizeof(repl_repl));	if (newOptions != (Datum) 0)		repl_val[Anum_pg_tablespace_spcoptions - 1] = newOptions;	else		repl_null[Anum_pg_tablespace_spcoptions - 1] = true;	repl_repl[Anum_pg_tablespace_spcoptions - 1] = true;	newtuple = heap_modify_tuple(tup, RelationGetDescr(rel), repl_val,								 repl_null, repl_repl);	/* Update system catalog. */	simple_heap_update(rel, &newtuple->t_self, newtuple);	CatalogUpdateIndexes(rel, newtuple);	heap_freetuple(newtuple);	/* Conclude heap scan. */	heap_endscan(scandesc);	heap_close(rel, NoLock);}
开发者ID:fdr,项目名称:postgres,代码行数:66,


示例6: GetIndexOpClass

//.........这里部分代码省略.........	/*	 * Release 7.0 removed network_ops, timespan_ops, and datetime_ops, so we	 * ignore those opclass names so the default *_ops is used.  This can be	 * removed in some later release.  bjm 2000/02/07	 *	 * Release 7.1 removes lztext_ops, so suppress that too for a while.  tgl	 * 2000/07/30	 *	 * Release 7.2 renames timestamp_ops to timestamptz_ops, so suppress that	 * too for awhile.  I'm starting to think we need a better approach. tgl	 * 2000/10/01	 *	 * Release 8.0 removes bigbox_ops (which was dead code for a long while	 * anyway).  tgl 2003/11/11	 */	if (list_length(opclass) == 1)	{		char	   *claname = strVal(linitial(opclass));		if (strcmp(claname, "network_ops") == 0 ||			strcmp(claname, "timespan_ops") == 0 ||			strcmp(claname, "datetime_ops") == 0 ||			strcmp(claname, "lztext_ops") == 0 ||			strcmp(claname, "timestamp_ops") == 0 ||			strcmp(claname, "bigbox_ops") == 0)			opclass = NIL;	}	if (opclass == NIL)	{		/* no operator class specified, so find the default */		opClassId = GetDefaultOpClass(attrType, accessMethodId);		if (!OidIsValid(opClassId))			ereport(ERROR,					(errcode(ERRCODE_UNDEFINED_OBJECT),					 errmsg("data type %s has no default operator class for access method /"%s/"",							format_type_be(attrType), accessMethodName),					 errhint("You must specify an operator class for the index or define a default operator class for the data type.")));		return opClassId;	}	/*	 * Specific opclass name given, so look up the opclass.	 */	/* deconstruct the name list */	DeconstructQualifiedName(opclass, &schemaname, &opcname);	if (schemaname)	{		/* Look in specific schema only */		Oid			namespaceId;#if PG_VERSION_NUM >= 90300		namespaceId = LookupExplicitNamespace(schemaname, false);#else		namespaceId = LookupExplicitNamespace(schemaname);#endif		tuple = SearchSysCache3(CLAAMNAMENSP,								ObjectIdGetDatum(accessMethodId),								PointerGetDatum(opcname),								ObjectIdGetDatum(namespaceId));	}	else	{		/* Unqualified opclass name, so search the search path */		opClassId = OpclassnameGetOpcid(accessMethodId, opcname);		if (!OidIsValid(opClassId))			ereport(ERROR,					(errcode(ERRCODE_UNDEFINED_OBJECT),					 errmsg("operator class /"%s/" does not exist for access method /"%s/"",							opcname, accessMethodName)));		tuple = SearchSysCache1(CLAOID, ObjectIdGetDatum(opClassId));	}	if (!HeapTupleIsValid(tuple))	{		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_OBJECT),				 errmsg("operator class /"%s/" does not exist for access method /"%s/"",						NameListToString(opclass), accessMethodName)));	}	/*	 * Verify that the index operator class accepts this datatype.  Note we	 * will accept binary compatibility.	 */	opClassId = HeapTupleGetOid(tuple);	opInputType = ((Form_pg_opclass) GETSTRUCT(tuple))->opcintype;	if (!IsBinaryCoercible(attrType, opInputType))		ereport(ERROR,				(errcode(ERRCODE_DATATYPE_MISMATCH),				 errmsg("operator class /"%s/" does not accept data type %s",					  NameListToString(opclass), format_type_be(attrType))));	ReleaseSysCache(tuple);	return opClassId;}
开发者ID:kmosolov,项目名称:hypopg,代码行数:101,


示例7: regclassin

/* * regclassin		- converts "classname" to class OID * * We also accept a numeric OID, for symmetry with the output routine. * * '-' signifies unknown (OID 0).  In all other cases, the input must * match an existing pg_class entry. */Datumregclassin(PG_FUNCTION_ARGS){	char	   *class_name_or_oid = PG_GETARG_CSTRING(0);	Oid			result = InvalidOid;	List	   *names;	/* '-' ? */	if (strcmp(class_name_or_oid, "-") == 0)		PG_RETURN_OID(InvalidOid);	/* Numeric OID? */	if (class_name_or_oid[0] >= '0' &&		class_name_or_oid[0] <= '9' &&	strspn(class_name_or_oid, "0123456789") == strlen(class_name_or_oid))	{		result = DatumGetObjectId(DirectFunctionCall1(oidin,									CStringGetDatum(class_name_or_oid)));		PG_RETURN_OID(result);	}	/* Else it's a name, possibly schema-qualified */	/*	 * In bootstrap mode we assume the given name is not schema-qualified,	 * and just search pg_class for a match.  This is needed for	 * initializing other system catalogs (pg_namespace may not exist yet,	 * and certainly there are no schemas other than pg_catalog).	 */	if (IsBootstrapProcessingMode())	{		Relation	hdesc;		ScanKeyData skey[1];		SysScanDesc sysscan;		HeapTuple	tuple;		ScanKeyEntryInitialize(&skey[0], 0x0,							   (AttrNumber) Anum_pg_class_relname,							   (RegProcedure) F_NAMEEQ,							   CStringGetDatum(class_name_or_oid));		hdesc = heap_openr(RelationRelationName, AccessShareLock);		sysscan = systable_beginscan(hdesc, ClassNameNspIndex, true,									 SnapshotNow, 1, skey);		if (HeapTupleIsValid(tuple = systable_getnext(sysscan)))			result = HeapTupleGetOid(tuple);		else			ereport(ERROR,					(errcode(ERRCODE_UNDEFINED_TABLE),					 errmsg("relation /"%s/" does not exist", class_name_or_oid)));		/* We assume there can be only one match */		systable_endscan(sysscan);		heap_close(hdesc, AccessShareLock);		PG_RETURN_OID(result);	}	/*	 * Normal case: parse the name into components and see if it matches	 * any pg_class entries in the current search path.	 */	names = stringToQualifiedNameList(class_name_or_oid, "regclassin");	result = RangeVarGetRelid(makeRangeVarFromNameList(names), false);	PG_RETURN_OID(result);}
开发者ID:sunyangkobe,项目名称:cscd43,代码行数:78,


示例8: ProcedureCreate

//.........这里部分代码省略.........		nulls[Anum_pg_proc_proargdefaults - 1] = true;	values[Anum_pg_proc_prosrc - 1] = CStringGetTextDatum(prosrc);	if (probin)		values[Anum_pg_proc_probin - 1] = CStringGetTextDatum(probin);	else		nulls[Anum_pg_proc_probin - 1] = true;	if (proconfig != PointerGetDatum(NULL))		values[Anum_pg_proc_proconfig - 1] = proconfig;	else		nulls[Anum_pg_proc_proconfig - 1] = true;	/* proacl will be determined later */	rel = heap_open(ProcedureRelationId, RowExclusiveLock);	tupDesc = RelationGetDescr(rel);	/* Check for pre-existing definition */	oldtup = SearchSysCache3(PROCNAMEARGSNSP,							 PointerGetDatum(procedureName),							 PointerGetDatum(parameterTypes),							 ObjectIdGetDatum(procNamespace));	if (HeapTupleIsValid(oldtup))	{		/* There is one; okay to replace it? */		Form_pg_proc oldproc = (Form_pg_proc) GETSTRUCT(oldtup);		Datum		proargnames;		bool		isnull;		if (!replace)			ereport(ERROR,					(errcode(ERRCODE_DUPLICATE_FUNCTION),			errmsg("function /"%s/" already exists with same argument types",				   procedureName)));		if (!pg_proc_ownercheck(HeapTupleGetOid(oldtup), proowner))			aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC,						   procedureName);		/*		 * Not okay to change the return type of the existing proc, since		 * existing rules, views, etc may depend on the return type.		 */		if (returnType != oldproc->prorettype ||			returnsSet != oldproc->proretset)			ereport(ERROR,					(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),					 errmsg("cannot change return type of existing function"),					 errhint("Use DROP FUNCTION first.")));		/*		 * If it returns RECORD, check for possible change of record type		 * implied by OUT parameters		 */		if (returnType == RECORDOID)		{			TupleDesc	olddesc;			TupleDesc	newdesc;			olddesc = build_function_result_tupdesc_t(oldtup);			newdesc = build_function_result_tupdesc_d(allParameterTypes,													  parameterModes,													  parameterNames);			if (olddesc == NULL && newdesc == NULL)				 /* ok, both are runtime-defined RECORDs */ ;			else if (olddesc == NULL || newdesc == NULL ||					 !equalTupleDescs(olddesc, newdesc))				ereport(ERROR,
开发者ID:HunterChen,项目名称:postgres-xc,代码行数:67,


示例9: PrepareForTupleInvalidation

/* * PrepareForTupleInvalidation *		Detect whether invalidation of this tuple implies invalidation *		of catalog/relation cache entries; if so, register inval events. */static voidPrepareForTupleInvalidation(Relation relation, HeapTuple tuple){	Oid			tupleRelId;	Oid			databaseId;	Oid			relationId;	/* Do nothing during bootstrap */	if (IsBootstrapProcessingMode())		return;	/*	 * We only need to worry about invalidation for tuples that are in system	 * relations; user-relation tuples are never in catcaches and can't affect	 * the relcache either.	 */	if (!IsSystemRelation(relation))		return;	/*	 * TOAST tuples can likewise be ignored here. Note that TOAST tables are	 * considered system relations so they are not filtered by the above test.	 */	if (IsToastRelation(relation))		return;	/*	 * First let the catcache do its thing	 */	PrepareToInvalidateCacheTuple(relation, tuple,								  RegisterCatcacheInvalidation);	/*	 * Now, is this tuple one of the primary definers of a relcache entry?	 */	tupleRelId = RelationGetRelid(relation);	if (tupleRelId == RelationRelationId)	{		Form_pg_class classtup = (Form_pg_class) GETSTRUCT(tuple);		relationId = HeapTupleGetOid(tuple);		if (classtup->relisshared)			databaseId = InvalidOid;		else			databaseId = MyDatabaseId;	}	else if (tupleRelId == AttributeRelationId)	{		Form_pg_attribute atttup = (Form_pg_attribute) GETSTRUCT(tuple);		relationId = atttup->attrelid;		/*		 * KLUGE ALERT: we always send the relcache event with MyDatabaseId,		 * even if the rel in question is shared (which we can't easily tell).		 * This essentially means that only backends in this same database		 * will react to the relcache flush request.  This is in fact		 * appropriate, since only those backends could see our pg_attribute		 * change anyway.  It looks a bit ugly though.	(In practice, shared		 * relations can't have schema changes after bootstrap, so we should		 * never come here for a shared rel anyway.)		 */		databaseId = MyDatabaseId;	}	else if (tupleRelId == IndexRelationId)	{		Form_pg_index indextup = (Form_pg_index) GETSTRUCT(tuple);		/*		 * When a pg_index row is updated, we should send out a relcache inval		 * for the index relation.	As above, we don't know the shared status		 * of the index, but in practice it doesn't matter since indexes of		 * shared catalogs can't have such updates.		 */		relationId = indextup->indexrelid;		databaseId = MyDatabaseId;	}	else		return;	/*	 * Yes.  We need to register a relcache invalidation event.	 */	RegisterRelcacheInvalidation(databaseId, relationId);}
开发者ID:markwkm,项目名称:postgres,代码行数:91,


示例10: check_functional_grouping

/* * Determine whether a relation can be proven functionally dependent on * a set of grouping columns.  If so, return TRUE and add the pg_constraint * OIDs of the constraints needed for the proof to the *constraintDeps list. * * grouping_columns is a list of grouping expressions, in which columns of * the rel of interest are Vars with the indicated varno/varlevelsup. * * Currently we only check to see if the rel has a primary key that is a * subset of the grouping_columns.	We could also use plain unique constraints * if all their columns are known not null, but there's a problem: we need * to be able to represent the not-null-ness as part of the constraints added * to *constraintDeps.	FIXME whenever not-null constraints get represented * in pg_constraint. */boolcheck_functional_grouping(Oid relid,						  Index varno, Index varlevelsup,						  List *grouping_columns,						  List **constraintDeps){	bool		result = false;	Relation	pg_constraint;	HeapTuple	tuple;	SysScanDesc scan;	ScanKeyData skey[1];	/* Scan pg_constraint for constraints of the target rel */	pg_constraint = heap_open(ConstraintRelationId, AccessShareLock);	ScanKeyInit(&skey[0],				Anum_pg_constraint_conrelid,				BTEqualStrategyNumber, F_OIDEQ,				ObjectIdGetDatum(relid));	scan = systable_beginscan(pg_constraint, ConstraintRelidIndexId, true,							  SnapshotNow, 1, skey);	while (HeapTupleIsValid(tuple = systable_getnext(scan)))	{		Form_pg_constraint con = (Form_pg_constraint) GETSTRUCT(tuple);		Datum		adatum;		bool		isNull;		ArrayType  *arr;		int16	   *attnums;		int			numkeys;		int			i;		bool		found_col;		/* Only PK constraints are of interest for now, see comment above */		if (con->contype != CONSTRAINT_PRIMARY)			continue;		/* Constraint must be non-deferrable */		if (con->condeferrable)			continue;		/* Extract the conkey array, ie, attnums of PK's columns */		adatum = heap_getattr(tuple, Anum_pg_constraint_conkey,							  RelationGetDescr(pg_constraint), &isNull);		if (isNull)			elog(ERROR, "null conkey for constraint %u",				 HeapTupleGetOid(tuple));		arr = DatumGetArrayTypeP(adatum);		/* ensure not toasted */		numkeys = ARR_DIMS(arr)[0];		if (ARR_NDIM(arr) != 1 ||			numkeys < 0 ||			ARR_HASNULL(arr) ||			ARR_ELEMTYPE(arr) != INT2OID)			elog(ERROR, "conkey is not a 1-D smallint array");		attnums = (int16 *) ARR_DATA_PTR(arr);		found_col = false;		for (i = 0; i < numkeys; i++)		{			AttrNumber	attnum = attnums[i];			ListCell   *gl;			found_col = false;			foreach(gl, grouping_columns)			{				Var		   *gvar = (Var *) lfirst(gl);				if (IsA(gvar, Var) &&					gvar->varno == varno &&					gvar->varlevelsup == varlevelsup &&					gvar->varattno == attnum)				{					found_col = true;					break;				}			}			if (!found_col)				break;		}		if (found_col)		{			/* The PK is a subset of grouping_columns, so we win */			*constraintDeps = lappend_oid(*constraintDeps,										  HeapTupleGetOid(tuple));//.........这里部分代码省略.........
开发者ID:Khalefa,项目名称:postgres,代码行数:101,


示例11: RelidByRelfilenode

//.........这里部分代码省略.........	key.reltablespace = reltablespace;	key.relfilenode = relfilenode;	/*	 * Check cache and return entry if one is found. Even if no target	 * relation can be found later on we store the negative match and return a	 * InvalidOid from cache. That's not really necessary for performance	 * since querying invalid values isn't supposed to be a frequent thing,	 * but it's basically free.	 */	entry = hash_search(RelfilenodeMapHash, (void *) &key, HASH_FIND, &found);	if (found)		return entry->relid;	/* ok, no previous cache entry, do it the hard way */	/* initialize empty/negative cache entry before doing the actual lookups */	relid = InvalidOid;	if (reltablespace == GLOBALTABLESPACE_OID)	{		/*		 * Ok, shared table, check relmapper.		 */		relid = RelationMapFilenodeToOid(relfilenode, true);	}	else	{		/*		 * Not a shared table, could either be a plain relation or a		 * non-shared, nailed one, like e.g. pg_class.		 */		/* check for plain relations by looking in pg_class */		relation = heap_open(RelationRelationId, AccessShareLock);		/* copy scankey to local copy, it will be modified during the scan */		memcpy(skey, relfilenode_skey, sizeof(skey));		/* set scan arguments */		skey[0].sk_argument = ObjectIdGetDatum(reltablespace);		skey[1].sk_argument = ObjectIdGetDatum(relfilenode);		scandesc = systable_beginscan(relation,									  ClassTblspcRelfilenodeIndexId,									  true,									  NULL,									  2,									  skey);		found = false;		while (HeapTupleIsValid(ntp = systable_getnext(scandesc)))		{			if (found)				elog(ERROR,					 "unexpected duplicate for tablespace %u, relfilenode %u",					 reltablespace, relfilenode);			found = true;#ifdef USE_ASSERT_CHECKING			{				bool		isnull;				Oid			check;				check = fastgetattr(ntp, Anum_pg_class_reltablespace,									RelationGetDescr(relation),									&isnull);				Assert(!isnull && check == reltablespace);				check = fastgetattr(ntp, Anum_pg_class_relfilenode,									RelationGetDescr(relation),									&isnull);				Assert(!isnull && check == relfilenode);			}#endif			relid = HeapTupleGetOid(ntp);		}		systable_endscan(scandesc);		heap_close(relation, AccessShareLock);		/* check for tables that are mapped but not shared */		if (!found)			relid = RelationMapFilenodeToOid(relfilenode, false);	}	/*	 * Only enter entry into cache now, our opening of pg_class could have	 * caused cache invalidations to be executed which would have deleted a	 * new entry if we had entered it above.	 */	entry = hash_search(RelfilenodeMapHash, (void *) &key, HASH_ENTER, &found);	if (found)		elog(ERROR, "corrupted hashtable");	entry->relid = relid;	return relid;}
开发者ID:alvherre,项目名称:postgres,代码行数:101,


示例12: regoperin

/* * regoperin		- converts "oprname" to operator OID * * We also accept a numeric OID, for symmetry with the output routine. * * '0' signifies unknown (OID 0).  In all other cases, the input must * match an existing pg_operator entry. */Datumregoperin(PG_FUNCTION_ARGS){	char	   *opr_name_or_oid = PG_GETARG_CSTRING(0);	Oid			result = InvalidOid;	List	   *names;	FuncCandidateList clist;	/* '0' ? */	if (strcmp(opr_name_or_oid, "0") == 0)		PG_RETURN_OID(InvalidOid);	/* Numeric OID? */	if (opr_name_or_oid[0] >= '0' &&		opr_name_or_oid[0] <= '9' &&		strspn(opr_name_or_oid, "0123456789") == strlen(opr_name_or_oid))	{		result = DatumGetObjectId(DirectFunctionCall1(oidin,										  CStringGetDatum(opr_name_or_oid)));		PG_RETURN_OID(result);	}	/* Else it's a name, possibly schema-qualified */	/*	 * In bootstrap mode we assume the given name is not schema-qualified, and	 * just search pg_operator for a unique match.	This is needed for	 * initializing other system catalogs (pg_namespace may not exist yet, and	 * certainly there are no schemas other than pg_catalog).	 */	if (IsBootstrapProcessingMode())	{		int			matches = 0;		Relation	hdesc;		ScanKeyData skey[1];		SysScanDesc sysscan;		HeapTuple	tuple;		ScanKeyInit(&skey[0],					Anum_pg_operator_oprname,					BTEqualStrategyNumber, F_NAMEEQ,					CStringGetDatum(opr_name_or_oid));		hdesc = heap_open(OperatorRelationId, AccessShareLock);		sysscan = systable_beginscan(hdesc, OperatorNameNspIndexId, true,									 SnapshotNow, 1, skey);		while (HeapTupleIsValid(tuple = systable_getnext(sysscan)))		{			result = HeapTupleGetOid(tuple);			if (++matches > 1)				break;		}		systable_endscan(sysscan);		heap_close(hdesc, AccessShareLock);		if (matches == 0)			ereport(ERROR,					(errcode(ERRCODE_UNDEFINED_FUNCTION),					 errmsg("operator does not exist: %s", opr_name_or_oid)));		else if (matches > 1)			ereport(ERROR,					(errcode(ERRCODE_AMBIGUOUS_FUNCTION),					 errmsg("more than one operator named %s",							opr_name_or_oid)));		PG_RETURN_OID(result);	}	/*	 * Normal case: parse the name into components and see if it matches any	 * pg_operator entries in the current search path.	 */	names = stringToQualifiedNameList(opr_name_or_oid);	clist = OpernameGetCandidates(names, '/0');	if (clist == NULL)		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_FUNCTION),				 errmsg("operator does not exist: %s", opr_name_or_oid)));	else if (clist->next != NULL)		ereport(ERROR,				(errcode(ERRCODE_AMBIGUOUS_FUNCTION),				 errmsg("more than one operator named %s",						opr_name_or_oid)));	result = clist->oid;	PG_RETURN_OID(result);}
开发者ID:Joe-xXx,项目名称:postgres-old-soon-decommissioned,代码行数:99,


示例13: oprid

/* given operator tuple, return the operator OID */Oidoprid(Operator op){	return HeapTupleGetOid(op);}
开发者ID:BALDELab,项目名称:incubator-hawq,代码行数:6,


示例14: InitPostgres

//.........这里部分代码省略.........		/* report this backend in the PgBackendStatus array */		pgstat_bestart();		/* close the transaction we started above */		CommitTransactionCommand();		return;	}	/*	 * Set up the global variables holding database id and default tablespace.	 * But note we won't actually try to touch the database just yet.	 *	 * We take a shortcut in the bootstrap case, otherwise we have to look up	 * the db's entry in pg_database.	 */	if (bootstrap)	{		MyDatabaseId = TemplateDbOid;		MyDatabaseTableSpace = DEFAULTTABLESPACE_OID;	}	else if (in_dbname != NULL)	{		HeapTuple	tuple;		Form_pg_database dbform;		tuple = GetDatabaseTuple(in_dbname);		if (!HeapTupleIsValid(tuple))			ereport(FATAL,					(errcode(ERRCODE_UNDEFINED_DATABASE),					 errmsg("database /"%s/" does not exist", in_dbname)));		dbform = (Form_pg_database) GETSTRUCT(tuple);		MyDatabaseId = HeapTupleGetOid(tuple);		MyDatabaseTableSpace = dbform->dattablespace;		/* take database name from the caller, just for paranoia */		strlcpy(dbname, in_dbname, sizeof(dbname));	}	else	{		/* caller specified database by OID */		HeapTuple	tuple;		Form_pg_database dbform;		tuple = GetDatabaseTupleByOid(dboid);		if (!HeapTupleIsValid(tuple))			ereport(FATAL,					(errcode(ERRCODE_UNDEFINED_DATABASE),					 errmsg("database %u does not exist", dboid)));		dbform = (Form_pg_database) GETSTRUCT(tuple);		MyDatabaseId = HeapTupleGetOid(tuple);		MyDatabaseTableSpace = dbform->dattablespace;		Assert(MyDatabaseId == dboid);		strlcpy(dbname, NameStr(dbform->datname), sizeof(dbname));		/* pass the database name back to the caller */		if (out_dbname)			strcpy(out_dbname, dbname);	}	/*	 * Now, take a writer's lock on the database we are trying to connect to.	 * If there is a concurrently running DROP DATABASE on that database, this	 * will block us until it finishes (and has committed its update of	 * pg_database).	 *	 * Note that the lock is not held long, only until the end of this startup
开发者ID:seco,项目名称:pipelinedb,代码行数:67,


示例15: create_proc_lang

/* * Guts of language creation. */static voidcreate_proc_lang(const char *languageName, bool replace,				 Oid languageOwner, Oid handlerOid, Oid inlineOid,				 Oid valOid, bool trusted){	Relation	rel;	TupleDesc	tupDesc;	Datum		values[Natts_pg_language];	bool		nulls[Natts_pg_language];	bool		replaces[Natts_pg_language];	NameData	langname;	HeapTuple	oldtup;	HeapTuple	tup;	bool		is_update;	ObjectAddress myself,				referenced;	rel = heap_open(LanguageRelationId, RowExclusiveLock);	tupDesc = RelationGetDescr(rel);	/* Prepare data to be inserted */	memset(values, 0, sizeof(values));	memset(nulls, false, sizeof(nulls));	memset(replaces, true, sizeof(replaces));	namestrcpy(&langname, languageName);	values[Anum_pg_language_lanname - 1] = NameGetDatum(&langname);	values[Anum_pg_language_lanowner - 1] = ObjectIdGetDatum(languageOwner);	values[Anum_pg_language_lanispl - 1] = BoolGetDatum(true);	values[Anum_pg_language_lanpltrusted - 1] = BoolGetDatum(trusted);	values[Anum_pg_language_lanplcallfoid - 1] = ObjectIdGetDatum(handlerOid);	values[Anum_pg_language_laninline - 1] = ObjectIdGetDatum(inlineOid);	values[Anum_pg_language_lanvalidator - 1] = ObjectIdGetDatum(valOid);	nulls[Anum_pg_language_lanacl - 1] = true;	/* Check for pre-existing definition */	oldtup = SearchSysCache1(LANGNAME, PointerGetDatum(languageName));	if (HeapTupleIsValid(oldtup))	{		/* There is one; okay to replace it? */		if (!replace)			ereport(ERROR,					(errcode(ERRCODE_DUPLICATE_OBJECT),					 errmsg("language /"%s/" already exists", languageName)));		if (!pg_language_ownercheck(HeapTupleGetOid(oldtup), languageOwner))			aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_LANGUAGE,						   languageName);		/*		 * Do not change existing ownership or permissions.  Note		 * dependency-update code below has to agree with this decision.		 */		replaces[Anum_pg_language_lanowner - 1] = false;		replaces[Anum_pg_language_lanacl - 1] = false;		/* Okay, do it... */		tup = heap_modify_tuple(oldtup, tupDesc, values, nulls, replaces);		simple_heap_update(rel, &tup->t_self, tup);		ReleaseSysCache(oldtup);		is_update = true;	}	else	{		/* Creating a new language */		tup = heap_form_tuple(tupDesc, values, nulls);		simple_heap_insert(rel, tup);		is_update = false;	}	/* Need to update indexes for either the insert or update case */	CatalogUpdateIndexes(rel, tup);	/*	 * Create dependencies for the new language.  If we are updating an	 * existing language, first delete any existing pg_depend entries.	 * (However, since we are not changing ownership or permissions, the	 * shared dependencies do *not* need to change, and we leave them alone.)	 */	myself.classId = LanguageRelationId;	myself.objectId = HeapTupleGetOid(tup);	myself.objectSubId = 0;	if (is_update)		deleteDependencyRecordsFor(myself.classId, myself.objectId, true);	/* dependency on owner of language */	if (!is_update)		recordDependencyOnOwner(myself.classId, myself.objectId,								languageOwner);	/* dependency on extension */	recordDependencyOnCurrentExtension(&myself, is_update);	/* dependency on the PL handler function */	referenced.classId = ProcedureRelationId;//.........这里部分代码省略.........
开发者ID:botp,项目名称:postgres,代码行数:101,


示例16: TypeCreate

//.........这里部分代码省略.........							  ObjectIdGetDatum(typeNamespace));	if (HeapTupleIsValid(tup))	{		/*		 * check that the type is not already defined.  It may exist as a		 * shell type, however.		 */		if (((Form_pg_type) GETSTRUCT(tup))->typisdefined)			ereport(ERROR,					(errcode(ERRCODE_DUPLICATE_OBJECT),					 errmsg("type /"%s/" already exists", typeName)));		/*		 * shell type must have been created by same owner		 */		if (((Form_pg_type) GETSTRUCT(tup))->typowner != ownerId)			aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE, typeName);		/* trouble if caller wanted to force the OID */		if (OidIsValid(newTypeOid))			elog(ERROR, "cannot assign new OID to existing shell type");		/*		 * Okay to update existing shell type tuple		 */		tup = heap_modify_tuple(tup,								RelationGetDescr(pg_type_desc),								values,								nulls,								replaces);		simple_heap_update(pg_type_desc, &tup->t_self, tup);		typeObjectId = HeapTupleGetOid(tup);		rebuildDeps = true;		/* get rid of shell type's dependencies */	}	else	{		tup = heap_form_tuple(RelationGetDescr(pg_type_desc),							  values,							  nulls);		/* Force the OID if requested by caller */		if (OidIsValid(newTypeOid))			HeapTupleSetOid(tup, newTypeOid);		/* Use binary-upgrade override for pg_type.oid, if supplied. */		else if (IsBinaryUpgrade)		{			if (!OidIsValid(binary_upgrade_next_pg_type_oid))				ereport(ERROR,						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),						 errmsg("pg_type OID value not set when in binary upgrade mode")));			HeapTupleSetOid(tup, binary_upgrade_next_pg_type_oid);			binary_upgrade_next_pg_type_oid = InvalidOid;		}		/* else allow system to assign oid */		typeObjectId = simple_heap_insert(pg_type_desc, tup);	}	/* Update indexes */	CatalogUpdateIndexes(pg_type_desc, tup);	/*
开发者ID:kelvich,项目名称:postgresql,代码行数:67,


示例17: AlterLanguageOwner_internal

/* * Workhorse for AlterLanguageOwner variants */static voidAlterLanguageOwner_internal(HeapTuple tup, Relation rel, Oid newOwnerId){	Form_pg_language lanForm;	lanForm = (Form_pg_language) GETSTRUCT(tup);	/*	 * If the new owner is the same as the existing owner, consider the	 * command to have succeeded.  This is for dump restoration purposes.	 */	if (lanForm->lanowner != newOwnerId)	{		Datum		repl_val[Natts_pg_language];		bool		repl_null[Natts_pg_language];		bool		repl_repl[Natts_pg_language];		Acl		   *newAcl;		Datum		aclDatum;		bool		isNull;		HeapTuple	newtuple;		/* Otherwise, must be owner of the existing object */		if (!pg_language_ownercheck(HeapTupleGetOid(tup), GetUserId()))			aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_LANGUAGE,						   NameStr(lanForm->lanname));		/* Must be able to become new owner */		check_is_member_of_role(GetUserId(), newOwnerId);		memset(repl_null, false, sizeof(repl_null));		memset(repl_repl, false, sizeof(repl_repl));		repl_repl[Anum_pg_language_lanowner - 1] = true;		repl_val[Anum_pg_language_lanowner - 1] = ObjectIdGetDatum(newOwnerId);		/*		 * Determine the modified ACL for the new owner.  This is only		 * necessary when the ACL is non-null.		 */		aclDatum = SysCacheGetAttr(LANGNAME, tup,								   Anum_pg_language_lanacl,								   &isNull);		if (!isNull)		{			newAcl = aclnewowner(DatumGetAclP(aclDatum),								 lanForm->lanowner, newOwnerId);			repl_repl[Anum_pg_language_lanacl - 1] = true;			repl_val[Anum_pg_language_lanacl - 1] = PointerGetDatum(newAcl);		}		newtuple = heap_modify_tuple(tup, RelationGetDescr(rel),									 repl_val, repl_null, repl_repl);		simple_heap_update(rel, &newtuple->t_self, newtuple);		CatalogUpdateIndexes(rel, newtuple);		heap_freetuple(newtuple);		/* Update owner dependency reference */		changeDependencyOnOwner(LanguageRelationId, HeapTupleGetOid(tup),								newOwnerId);	}}
开发者ID:botp,项目名称:postgres,代码行数:66,


示例18: InsertRule

/* * InsertRule - *	  takes the arguments and inserts them as a row into the system *	  relation "pg_rewrite" */static OidInsertRule(char *rulname,		   int evtype,		   Oid eventrel_oid,		   AttrNumber evslot_index,		   bool evinstead,		   Node *event_qual,		   List *action,		   bool replace){	char	   *evqual = nodeToString(event_qual);	char	   *actiontree = nodeToString((Node *) action);	int			i;	Datum		values[Natts_pg_rewrite];	bool		nulls[Natts_pg_rewrite];	bool		replaces[Natts_pg_rewrite];	NameData	rname;	Relation	pg_rewrite_desc;	HeapTuple	tup,				oldtup;	Oid			rewriteObjectId;	ObjectAddress myself,				referenced;	bool		is_update = false;	/*	 * Set up *nulls and *values arrays	 */	MemSet(nulls, false, sizeof(nulls));	i = 0;	namestrcpy(&rname, rulname);	values[i++] = NameGetDatum(&rname); /* rulename */	values[i++] = ObjectIdGetDatum(eventrel_oid);		/* ev_class */	values[i++] = Int16GetDatum(evslot_index);	/* ev_attr */	values[i++] = CharGetDatum(evtype + '0');	/* ev_type */	values[i++] = CharGetDatum(RULE_FIRES_ON_ORIGIN);	/* ev_enabled */	values[i++] = BoolGetDatum(evinstead);		/* is_instead */	values[i++] = CStringGetTextDatum(evqual);	/* ev_qual */	values[i++] = CStringGetTextDatum(actiontree);		/* ev_action */	/*	 * Ready to store new pg_rewrite tuple	 */	pg_rewrite_desc = heap_open(RewriteRelationId, RowExclusiveLock);	/*	 * Check to see if we are replacing an existing tuple	 */	oldtup = SearchSysCache(RULERELNAME,							ObjectIdGetDatum(eventrel_oid),							PointerGetDatum(rulname),							0, 0);	if (HeapTupleIsValid(oldtup))	{		if (!replace)			ereport(ERROR,					(errcode(ERRCODE_DUPLICATE_OBJECT),					 errmsg("rule /"%s/" for relation /"%s/" already exists",							rulname, get_rel_name(eventrel_oid))));		/*		 * When replacing, we don't need to replace every attribute		 */		MemSet(replaces, false, sizeof(replaces));		replaces[Anum_pg_rewrite_ev_attr - 1] = true;		replaces[Anum_pg_rewrite_ev_type - 1] = true;		replaces[Anum_pg_rewrite_is_instead - 1] = true;		replaces[Anum_pg_rewrite_ev_qual - 1] = true;		replaces[Anum_pg_rewrite_ev_action - 1] = true;		tup = heap_modify_tuple(oldtup, RelationGetDescr(pg_rewrite_desc),								values, nulls, replaces);		simple_heap_update(pg_rewrite_desc, &tup->t_self, tup);		ReleaseSysCache(oldtup);		rewriteObjectId = HeapTupleGetOid(tup);		is_update = true;	}	else	{		tup = heap_form_tuple(pg_rewrite_desc->rd_att, values, nulls);		rewriteObjectId = simple_heap_insert(pg_rewrite_desc, tup);	}	/* Need to update indexes in either case */	CatalogUpdateIndexes(pg_rewrite_desc, tup);	heap_freetuple(tup);	/* If replacing, get rid of old dependencies and make new ones *///.........这里部分代码省略.........
开发者ID:PengJi,项目名称:gpdb-comments,代码行数:101,


示例19: regprocin

/* * regprocin		- converts "proname" to proc OID * * We also accept a numeric OID, for symmetry with the output routine. * * '-' signifies unknown (OID 0).  In all other cases, the input must * match an existing pg_proc entry. */Datumregprocin(PG_FUNCTION_ARGS){	char	   *pro_name_or_oid = PG_GETARG_CSTRING(0);	RegProcedure result = InvalidOid;	List	   *names;	FuncCandidateList clist;	/* '-' ? */	if (strcmp(pro_name_or_oid, "-") == 0)		PG_RETURN_OID(InvalidOid);	/* Numeric OID? */	if (pro_name_or_oid[0] >= '0' &&		pro_name_or_oid[0] <= '9' &&		strspn(pro_name_or_oid, "0123456789") == strlen(pro_name_or_oid))	{		result = DatumGetObjectId(DirectFunctionCall1(oidin,									  CStringGetDatum(pro_name_or_oid)));		PG_RETURN_OID(result);	}	/* Else it's a name, possibly schema-qualified */	/*	 * In bootstrap mode we assume the given name is not schema-qualified,	 * and just search pg_proc for a unique match.	This is needed for	 * initializing other system catalogs (pg_namespace may not exist yet,	 * and certainly there are no schemas other than pg_catalog).	 */	if (IsBootstrapProcessingMode())	{		int			matches = 0;		Relation	hdesc;		ScanKeyData skey[1];		SysScanDesc sysscan;		HeapTuple	tuple;		ScanKeyEntryInitialize(&skey[0], 0x0,							   (AttrNumber) Anum_pg_proc_proname,							   (RegProcedure) F_NAMEEQ,							   CStringGetDatum(pro_name_or_oid));		hdesc = heap_openr(ProcedureRelationName, AccessShareLock);		sysscan = systable_beginscan(hdesc, ProcedureNameNspIndex, true,									 SnapshotNow, 1, skey);		while (HeapTupleIsValid(tuple = systable_getnext(sysscan)))		{			result = (RegProcedure) HeapTupleGetOid(tuple);			if (++matches > 1)				break;		}		systable_endscan(sysscan);		heap_close(hdesc, AccessShareLock);		if (matches == 0)			ereport(ERROR,					(errcode(ERRCODE_UNDEFINED_FUNCTION),				  errmsg("function /"%s/" does not exist", pro_name_or_oid)));		else if (matches > 1)			ereport(ERROR,					(errcode(ERRCODE_AMBIGUOUS_FUNCTION),					 errmsg("more than one function named /"%s/"",							pro_name_or_oid)));		PG_RETURN_OID(result);	}	/*	 * Normal case: parse the name into components and see if it matches	 * any pg_proc entries in the current search path.	 */	names = stringToQualifiedNameList(pro_name_or_oid, "regprocin");	clist = FuncnameGetCandidates(names, -1);	if (clist == NULL)		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_FUNCTION),				 errmsg("function /"%s/" does not exist", pro_name_or_oid)));	else if (clist->next != NULL)		ereport(ERROR,				(errcode(ERRCODE_AMBIGUOUS_FUNCTION),				 errmsg("more than one function named /"%s/"",						pro_name_or_oid)));	result = clist->oid;	PG_RETURN_OID(result);}
开发者ID:sunyangkobe,项目名称:cscd43,代码行数:100,


示例20: AlterTableSpaceOwner

/* * Change tablespace owner */voidAlterTableSpaceOwner(const char *name, Oid newOwnerId){	Relation	rel;	ScanKeyData entry[1];	HeapScanDesc scandesc;	Form_pg_tablespace spcForm;	HeapTuple	tup;	/* Search pg_tablespace */	rel = heap_open(TableSpaceRelationId, RowExclusiveLock);	ScanKeyInit(&entry[0],				Anum_pg_tablespace_spcname,				BTEqualStrategyNumber, F_NAMEEQ,				CStringGetDatum(name));	scandesc = heap_beginscan(rel, SnapshotNow, 1, entry);	tup = heap_getnext(scandesc, ForwardScanDirection);	if (!HeapTupleIsValid(tup))		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_OBJECT),				 errmsg("tablespace /"%s/" does not exist", name)));	spcForm = (Form_pg_tablespace) GETSTRUCT(tup);	/*	 * If the new owner is the same as the existing owner, consider the	 * command to have succeeded.  This is for dump restoration purposes.	 */	if (spcForm->spcowner != newOwnerId)	{		Datum		repl_val[Natts_pg_tablespace];		bool		repl_null[Natts_pg_tablespace];		bool		repl_repl[Natts_pg_tablespace];		Acl		   *newAcl;		Datum		aclDatum;		bool		isNull;		HeapTuple	newtuple;		/* Otherwise, must be owner of the existing object */		if (!pg_tablespace_ownercheck(HeapTupleGetOid(tup), GetUserId()))			aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TABLESPACE,						   name);		/* Must be able to become new owner */		check_is_member_of_role(GetUserId(), newOwnerId);		/*		 * Normally we would also check for create permissions here, but there		 * are none for tablespaces so we follow what rename tablespace does		 * and omit the create permissions check.		 *		 * NOTE: Only superusers may create tablespaces to begin with and so		 * initially only a superuser would be able to change its ownership		 * anyway.		 */		memset(repl_null, false, sizeof(repl_null));		memset(repl_repl, false, sizeof(repl_repl));		repl_repl[Anum_pg_tablespace_spcowner - 1] = true;		repl_val[Anum_pg_tablespace_spcowner - 1] = ObjectIdGetDatum(newOwnerId);		/*		 * Determine the modified ACL for the new owner.  This is only		 * necessary when the ACL is non-null.		 */		aclDatum = heap_getattr(tup,								Anum_pg_tablespace_spcacl,								RelationGetDescr(rel),								&isNull);		if (!isNull)		{			newAcl = aclnewowner(DatumGetAclP(aclDatum),								 spcForm->spcowner, newOwnerId);			repl_repl[Anum_pg_tablespace_spcacl - 1] = true;			repl_val[Anum_pg_tablespace_spcacl - 1] = PointerGetDatum(newAcl);		}		newtuple = heap_modify_tuple(tup, RelationGetDescr(rel), repl_val, repl_null, repl_repl);		simple_heap_update(rel, &newtuple->t_self, newtuple);		CatalogUpdateIndexes(rel, newtuple);		heap_freetuple(newtuple);		/* Update owner dependency reference */		changeDependencyOnOwner(TableSpaceRelationId, HeapTupleGetOid(tup),								newOwnerId);	}	heap_endscan(scandesc);	heap_close(rel, NoLock);}
开发者ID:pguyot,项目名称:postgres,代码行数:97,


示例21: regtypein

/* * regtypein		- converts "typename" to type OID * * We also accept a numeric OID, for symmetry with the output routine. * * '-' signifies unknown (OID 0).  In all other cases, the input must * match an existing pg_type entry. * * In bootstrap mode the name must just equal some existing name in pg_type. * In normal mode the type name can be specified using the full type syntax * recognized by the parser; for example, DOUBLE PRECISION and INTEGER[] will * work and be translated to the correct type names.  (We ignore any typmod * info generated by the parser, however.) */Datumregtypein(PG_FUNCTION_ARGS){	char	   *typ_name_or_oid = PG_GETARG_CSTRING(0);	Oid			result = InvalidOid;	int32		typmod;	/* '-' ? */	if (strcmp(typ_name_or_oid, "-") == 0)		PG_RETURN_OID(InvalidOid);	/* Numeric OID? */	if (typ_name_or_oid[0] >= '0' &&		typ_name_or_oid[0] <= '9' &&		strspn(typ_name_or_oid, "0123456789") == strlen(typ_name_or_oid))	{		result = DatumGetObjectId(DirectFunctionCall1(oidin,									  CStringGetDatum(typ_name_or_oid)));		PG_RETURN_OID(result);	}	/* Else it's a type name, possibly schema-qualified or decorated */	/*	 * In bootstrap mode we assume the given name is not schema-qualified,	 * and just search pg_type for a match.  This is needed for	 * initializing other system catalogs (pg_namespace may not exist yet,	 * and certainly there are no schemas other than pg_catalog).	 */	if (IsBootstrapProcessingMode())	{		Relation	hdesc;		ScanKeyData skey[1];		SysScanDesc sysscan;		HeapTuple	tuple;		ScanKeyEntryInitialize(&skey[0], 0x0,							   (AttrNumber) Anum_pg_type_typname,							   (RegProcedure) F_NAMEEQ,							   CStringGetDatum(typ_name_or_oid));		hdesc = heap_openr(TypeRelationName, AccessShareLock);		sysscan = systable_beginscan(hdesc, TypeNameNspIndex, true,									 SnapshotNow, 1, skey);		if (HeapTupleIsValid(tuple = systable_getnext(sysscan)))			result = HeapTupleGetOid(tuple);		else			ereport(ERROR,					(errcode(ERRCODE_UNDEFINED_OBJECT),					 errmsg("type /"%s/" does not exist", typ_name_or_oid)));		/* We assume there can be only one match */		systable_endscan(sysscan);		heap_close(hdesc, AccessShareLock);		PG_RETURN_OID(result);	}	/*	 * Normal case: invoke the full parser to deal with special cases such	 * as array syntax.	 */	parseTypeString(typ_name_or_oid, &result, &typmod);	PG_RETURN_OID(result);}
开发者ID:sunyangkobe,项目名称:cscd43,代码行数:82,


示例22: caql_getoid_plus

/* ---------------------------------------------------------------- * caql_getoid_plus() * Return an oid column from the first tuple and end the scan. * Note: this works for regproc columns as well, but you should cast * the output as RegProcedure. * ---------------------------------------------------------------- */Oid caql_getoid_plus(cqContext *pCtx0, int *pFetchcount,					 bool *pbIsNull, cq_list *pcql){	const char *caql_str = pcql->caqlStr;	const char *filenam = pcql->filename;	int			lineno = pcql->lineno;	struct caql_hash_cookie	*pchn = cq_lookup(caql_str, strlen(caql_str), pcql);	cqContext  *pCtx;	cqContext	cqc;	HeapTuple	tuple;	Oid			result = InvalidOid;	if (NULL == pchn)		elog(ERROR, "invalid caql string: %s/nfile: %s, line %d", 			 caql_str, filenam, lineno);	Assert(!pchn->bInsert); /* INSERT not allowed */	/* use the provided context, or provide a clean local ctx  */	if (pCtx0)		pCtx = pCtx0;	else		pCtx = cqclr(&cqc);	pCtx = caql_switch(pchn, pCtx, pcql);	/* NOTE: caql_switch frees the pcql */	if (pFetchcount)		*pFetchcount = 0;	if (pbIsNull)		*pbIsNull = true;	/* use the SysCache */	if (pCtx->cq_usesyscache)	{		tuple = SearchSysCacheKeyArray(pCtx->cq_cacheId, 									   pCtx->cq_NumKeys, 									   pCtx->cq_cacheKeys);	}	else	{		tuple = systable_getnext(pCtx->cq_sysScan);	}	if (HeapTupleIsValid(tuple))	{		if (pFetchcount)			*pFetchcount = 1;				/* if attnum not set, (InvalidAttrNumber == 0)		 * use tuple oid, else extract oid from column 		 * (includes ObjectIdAttributeNumber == -2) 		 */		if (pchn->attnum <= InvalidAttrNumber) 		{			if (pbIsNull)				*pbIsNull = false;			result = HeapTupleGetOid(tuple);		}		else /* find oid column */		{			bool		isnull;			Datum		d = caql_getattr_internal(pCtx, tuple, pchn->attnum,												  &isnull);			if (!isnull)			{				switch (pchn->atttype)				{					case OIDOID:					case REGPROCOID:						result = DatumGetObjectId(d);						break;					default:						elog(ERROR, "column not an oid: %s/nfile: %s, line %d", 							 caql_str, filenam, lineno);				}			}			if (pbIsNull)				*pbIsNull = isnull;		}	} /* end HeapTupleIsValid */	if (pCtx->cq_usesyscache)	{  		if (HeapTupleIsValid(tuple))			ReleaseSysCache(tuple);	}	else	{			if (pFetchcount && HeapTupleIsValid(tuple))		{				//.........这里部分代码省略.........
开发者ID:AnLingm,项目名称:gpdb,代码行数:101,


示例23: RenameTableSpace

/* * Rename a tablespace */OidRenameTableSpace(const char *oldname, const char *newname){	Oid			tspId;	Relation	rel;	ScanKeyData entry[1];	HeapScanDesc scan;	HeapTuple	tup;	HeapTuple	newtuple;	Form_pg_tablespace newform;	/* Search pg_tablespace */	rel = heap_open(TableSpaceRelationId, RowExclusiveLock);	ScanKeyInit(&entry[0],				Anum_pg_tablespace_spcname,				BTEqualStrategyNumber, F_NAMEEQ,				CStringGetDatum(oldname));	scan = heap_beginscan(rel, SnapshotNow, 1, entry);	tup = heap_getnext(scan, ForwardScanDirection);	if (!HeapTupleIsValid(tup))		ereport(ERROR,				(errcode(ERRCODE_UNDEFINED_OBJECT),				 errmsg("tablespace /"%s/" does not exist",						oldname)));	tspId = HeapTupleGetOid(tup);	newtuple = heap_copytuple(tup);	newform = (Form_pg_tablespace) GETSTRUCT(newtuple);	heap_endscan(scan);	/* Must be owner */	if (!pg_tablespace_ownercheck(HeapTupleGetOid(newtuple), GetUserId()))		aclcheck_error(ACLCHECK_NO_PRIV, ACL_KIND_TABLESPACE, oldname);	/* Validate new name */	if (!allowSystemTableMods && IsReservedName(newname))		ereport(ERROR,				(errcode(ERRCODE_RESERVED_NAME),				 errmsg("unacceptable tablespace name /"%s/"", newname),		errdetail("The prefix /"pg_/" is reserved for system tablespaces.")));	/* Make sure the new name doesn't exist */	ScanKeyInit(&entry[0],				Anum_pg_tablespace_spcname,				BTEqualStrategyNumber, F_NAMEEQ,				CStringGetDatum(newname));	scan = heap_beginscan(rel, SnapshotNow, 1, entry);	tup = heap_getnext(scan, ForwardScanDirection);	if (HeapTupleIsValid(tup))		ereport(ERROR,				(errcode(ERRCODE_DUPLICATE_OBJECT),				 errmsg("tablespace /"%s/" already exists",						newname)));	heap_endscan(scan);	/* OK, update the entry */	namestrcpy(&(newform->spcname), newname);	simple_heap_update(rel, &newtuple->t_self, newtuple);	CatalogUpdateIndexes(rel, newtuple);	heap_close(rel, NoLock);	return tspId;}
开发者ID:fdr,项目名称:postgres,代码行数:71,


示例24: caql_getoid_only

/* ---------------------------------------------------------------- * caql_getoid_only() * Return the oid of the first tuple and end the scan * If pbOnly is not NULL, return TRUE if a second tuple is not found, * else return FALSE * ---------------------------------------------------------------- */Oid caql_getoid_only(cqContext *pCtx0, bool *pbOnly, cq_list *pcql){	const char *caql_str = pcql->caqlStr;	const char *filenam = pcql->filename;	int			lineno = pcql->lineno;	struct caql_hash_cookie	*pchn = cq_lookup(caql_str, strlen(caql_str), pcql);	cqContext  *pCtx;	cqContext	cqc;	HeapTuple	tuple;	Oid			result = InvalidOid;	if (NULL == pchn)		elog(ERROR, "invalid caql string: %s/nfile: %s, line %d", 			 caql_str, filenam, lineno);	Assert(!pchn->bInsert); /* INSERT not allowed */	/* use the provided context, or provide a clean local ctx  */	if (pCtx0)		pCtx = pCtx0;	else		pCtx = cqclr(&cqc);	pCtx = caql_switch(pchn, pCtx, pcql);	/* NOTE: caql_switch frees the pcql */	if (pbOnly)		*pbOnly = true;	/* use the SysCache */	if (pCtx->cq_usesyscache)	{		tuple = SearchSysCacheKeyArray(pCtx->cq_cacheId, 									   pCtx->cq_NumKeys, 									   pCtx->cq_cacheKeys);		if (HeapTupleIsValid(tuple))		{			result = HeapTupleGetOid(tuple);			ReleaseSysCache(tuple);			/* only one */		}		caql_heapclose(pCtx);		return (result);	}	if (HeapTupleIsValid(tuple = systable_getnext(pCtx->cq_sysScan)))	{		result = HeapTupleGetOid(tuple);		if (pbOnly)		{			*pbOnly = 				!(HeapTupleIsValid(tuple = 								   systable_getnext(pCtx->cq_sysScan)));		}	}	systable_endscan(pCtx->cq_sysScan); 	caql_heapclose(pCtx);	return (result);}
开发者ID:AnLingm,项目名称:gpdb,代码行数:68,


示例25: InitResQueues

void InitResQueues(void){	HeapTuple			tuple;	int					numQueues = 0;	bool				queuesok = true;	SysScanDesc sscan;		Assert(ResScheduler);	/*	 * Need a resource owner to keep the heapam code happy.	 */	Assert(CurrentResourceOwner == NULL);	ResourceOwner owner = ResourceOwnerCreate(NULL, "InitQueues");	CurrentResourceOwner = owner;		/**	 * The resqueue shared mem initialization must be serialized. Only the first session	 * should do the init.	 * Serialization is done the ResQueueLock LW_EXCLUSIVE. However, we must obtain all DB	 * lock before obtaining LWlock.	 * So, we must have obtained ResQueueRelationId and ResQueueCapabilityRelationId lock	 * first.	 */	/* XXX XXX: should this be rowexclusive ? */	Relation relResqueue = heap_open(ResQueueRelationId, AccessShareLock);	LockRelationOid(ResQueueCapabilityRelationId, RowExclusiveLock);	LWLockAcquire(ResQueueLock, LW_EXCLUSIVE);	if (ResScheduler->num_queues > 0)	{		/* Hash table has already been loaded */		LWLockRelease(ResQueueLock);		UnlockRelationOid(ResQueueCapabilityRelationId, RowExclusiveLock);		heap_close(relResqueue, AccessShareLock);		CurrentResourceOwner = NULL;		ResourceOwnerDelete(owner);		return;	}	sscan = systable_beginscan(relResqueue, InvalidOid, false, SnapshotNow, 0, NULL);	while (HeapTupleIsValid(tuple = systable_getnext(sscan)))	{		Form_pg_resqueue	queueform;		Oid					queueid;		bool				overcommit;		float4				ignorelimit;		Cost				thresholds[NUM_RES_LIMIT_TYPES];		char				*queuename;		numQueues++;		queueform = (Form_pg_resqueue) GETSTRUCT(tuple);		queueid = HeapTupleGetOid(tuple);		queuename = NameStr(queueform->rsqname);		thresholds[RES_COUNT_LIMIT] = queueform->rsqcountlimit;		thresholds[RES_COST_LIMIT] = queueform->rsqcostlimit;		thresholds[RES_MEMORY_LIMIT] = ResourceQueueGetMemoryLimit(queueid);		overcommit = queueform->rsqovercommit;		ignorelimit = queueform->rsqignorecostlimit;		queuesok = ResCreateQueue(queueid, thresholds, overcommit, ignorelimit);		if (!queuesok)		{			/** Break out of loop. Close relations, relinquish LWLock and then error out */ 			break;		}	}	systable_endscan(sscan);	LWLockRelease(ResQueueLock);	UnlockRelationOid(ResQueueCapabilityRelationId, RowExclusiveLock);	heap_close(relResqueue, AccessShareLock);	if (!queuesok)		ereport(PANIC,			(errcode(ERRCODE_INSUFFICIENT_RESOURCES),			 errmsg("insufficient resource queues available"),		errhint("Increase max_resource_queues to %d.", numQueues)));	elog(LOG,"initialized %d resource queues", numQueues);	CurrentResourceOwner = NULL;	ResourceOwnerDelete(owner);	return;}
开发者ID:phan-pivotal,项目名称:gpdb,代码行数:92,


示例26: lazy_scan_heap

//.........这里部分代码省略.........		nfrozen = 0;		hastup = false;		prev_dead_count = vacrelstats->num_dead_tuples;		maxoff = PageGetMaxOffsetNumber(page);		for (offnum = FirstOffsetNumber;			 offnum <= maxoff;			 offnum = OffsetNumberNext(offnum))		{			ItemId		itemid;			itemid = PageGetItemId(page, offnum);			if (!ItemIdIsUsed(itemid))			{				nunused += 1;				continue;			}			tuple.t_data = (HeapTupleHeader) PageGetItem(page, itemid);			tuple.t_len = ItemIdGetLength(itemid);			ItemPointerSet(&(tuple.t_self), blkno, offnum);			tupgone = false;			switch (HeapTupleSatisfiesVacuum(tuple.t_data, OldestXmin, buf, false))			{				case HEAPTUPLE_DEAD:					tupgone = true;		/* we can delete the tuple */					break;				case HEAPTUPLE_LIVE:					/* Tuple is good --- but let's do some validity checks */					if (onerel->rd_rel->relhasoids &&						!OidIsValid(HeapTupleGetOid(&tuple)))						elog(WARNING, "relation /"%s/" TID %u/%u: OID is invalid",							 relname, blkno, offnum);					break;				case HEAPTUPLE_RECENTLY_DEAD:					/*					 * If tuple is recently deleted then we must not remove it					 * from relation.					 */					nkeep += 1;					break;				case HEAPTUPLE_INSERT_IN_PROGRESS:					/* This is an expected case during concurrent vacuum */					break;				case HEAPTUPLE_DELETE_IN_PROGRESS:					/* This is an expected case during concurrent vacuum */					break;				default:					elog(ERROR, "unexpected HeapTupleSatisfiesVacuum result");					break;			}			if (tupgone)			{				lazy_record_dead_tuple(vacrelstats, &(tuple.t_self));				tups_vacuumed += 1;			}			else			{				num_tuples += 1;				hastup = true;
开发者ID:craig-chasseur,项目名称:gpdb,代码行数:66,


示例27: pg_resgroup_get_status

/* * Get status of resource groups */Datumpg_resgroup_get_status(PG_FUNCTION_ARGS){	FuncCallContext *funcctx;	ResGroupStatCtx *ctx;	if (SRF_IS_FIRSTCALL())	{		MemoryContext oldcontext;		TupleDesc	tupdesc;		int			nattr = 8;		funcctx = SRF_FIRSTCALL_INIT();		oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);		tupdesc = CreateTemplateTupleDesc(nattr, false);		TupleDescInitEntry(tupdesc, (AttrNumber) 1, "groupid", OIDOID, -1, 0);		TupleDescInitEntry(tupdesc, (AttrNumber) 2, "num_running", INT4OID, -1, 0);		TupleDescInitEntry(tupdesc, (AttrNumber) 3, "num_queueing", INT4OID, -1, 0);		TupleDescInitEntry(tupdesc, (AttrNumber) 4, "num_queued", INT4OID, -1, 0);		TupleDescInitEntry(tupdesc, (AttrNumber) 5, "num_executed", INT4OID, -1, 0);		TupleDescInitEntry(tupdesc, (AttrNumber) 6, "total_queue_duration", INTERVALOID, -1, 0);		TupleDescInitEntry(tupdesc, (AttrNumber) 7, "cpu_usage", JSONOID, -1, 0);		TupleDescInitEntry(tupdesc, (AttrNumber) 8, "memory_usage", JSONOID, -1, 0);		funcctx->tuple_desc = BlessTupleDesc(tupdesc);		if (IsResGroupActivated())		{			Relation	pg_resgroup_rel;			SysScanDesc	sscan;			HeapTuple	tuple;			Oid			inGroupId = PG_GETARG_OID(0);			int ctxsize = sizeof(ResGroupStatCtx) +				sizeof(ResGroupStat) * (MaxResourceGroups - 1);			(void) inGroupId;			funcctx->user_fctx = palloc(ctxsize);			ctx = (ResGroupStatCtx *) funcctx->user_fctx;			/*			 * others may be creating/dropping resource group concurrently,			 * block until creating/dropping finish to avoid inconsistent			 * resource group metadata			 */			pg_resgroup_rel = heap_open(ResGroupRelationId, ExclusiveLock);			sscan = systable_beginscan(pg_resgroup_rel, InvalidOid, false,									   NULL, 0, NULL);			while (HeapTupleIsValid(tuple = systable_getnext(sscan)))			{				Oid oid = ObjectIdGetDatum(HeapTupleGetOid(tuple));				if (inGroupId == InvalidOid || inGroupId == oid)				{					Assert(funcctx->max_calls < MaxResourceGroups);					ctx->groups[funcctx->max_calls].cpuUsage = makeStringInfo();					ctx->groups[funcctx->max_calls].memUsage = makeStringInfo();					ctx->groups[funcctx->max_calls++].groupId = oid;					if (inGroupId != InvalidOid)						break;				}			}			systable_endscan(sscan);			ctx->nGroups = funcctx->max_calls;			qsort(ctx->groups, ctx->nGroups, sizeof(ctx->groups[0]), compareRow);			if (ctx->nGroups > 0)				getResUsage(ctx, inGroupId);			heap_close(pg_resgroup_rel, ExclusiveLock);		}		MemoryContextSwitchTo(oldcontext);	}	/* stuff done on every call of the function */	funcctx = SRF_PERCALL_SETUP();	ctx = (ResGroupStatCtx *) funcctx->user_fctx;	if (funcctx->call_cntr < funcctx->max_calls)	{		/* for each row */		Datum		values[8];		bool		nulls[8];		HeapTuple	tuple;		Oid			groupId;		char		statVal[MAXDATELEN + 1];		ResGroupStat *row = &ctx->groups[funcctx->call_cntr];		MemSet(values, 0, sizeof(values));		MemSet(nulls, 0, sizeof(nulls));//.........这里部分代码省略.........
开发者ID:adam8157,项目名称:gpdb,代码行数:101,


示例28: ConversionCreate

/* * ConversionCreate * * Add a new tuple to pg_conversion. */OidConversionCreate(const char *conname, Oid connamespace,				 Oid conowner,				 int32 conforencoding, int32 contoencoding,				 Oid conproc, bool def){	int			i;	Relation	rel;	TupleDesc	tupDesc;	HeapTuple	tup;	char		nulls[Natts_pg_conversion];	Datum		values[Natts_pg_conversion];	NameData	cname;	Oid			oid;	ObjectAddress myself,				referenced;	/* sanity checks */	if (!conname)		elog(ERROR, "no conversion name supplied");	/* make sure there is no existing conversion of same name */	if (SearchSysCacheExists(CONNAMENSP,							 PointerGetDatum(conname),							 ObjectIdGetDatum(connamespace),							 0, 0))		ereport(ERROR,				(errcode(ERRCODE_DUPLICATE_OBJECT),				 errmsg("conversion /"%s/" already exists", conname)));	if (def)	{		/*		 * make sure there is no existing default <for encoding><to encoding>		 * pair in this name space		 */		if (FindDefaultConversion(connamespace,								  conforencoding,								  contoencoding))			ereport(ERROR,					(errcode(ERRCODE_DUPLICATE_OBJECT),					 errmsg("default conversion for %s to %s already exists",							pg_encoding_to_char(conforencoding),							pg_encoding_to_char(contoencoding))));	}	/* open pg_conversion */	rel = heap_open(ConversionRelationId, RowExclusiveLock);	tupDesc = rel->rd_att;	/* initialize nulls and values */	for (i = 0; i < Natts_pg_conversion; i++)	{		nulls[i] = ' ';		values[i] = (Datum) NULL;	}	/* form a tuple */	namestrcpy(&cname, conname);	values[Anum_pg_conversion_conname - 1] = NameGetDatum(&cname);	values[Anum_pg_conversion_connamespace - 1] = ObjectIdGetDatum(connamespace);	values[Anum_pg_conversion_conowner - 1] = ObjectIdGetDatum(conowner);	values[Anum_pg_conversion_conforencoding - 1] = Int32GetDatum(conforencoding);	values[Anum_pg_conversion_contoencoding - 1] = Int32GetDatum(contoencoding);	values[Anum_pg_conversion_conproc - 1] = ObjectIdGetDatum(conproc);	values[Anum_pg_conversion_condefault - 1] = BoolGetDatum(def);	tup = heap_formtuple(tupDesc, values, nulls);	/* insert a new tuple */	oid = simple_heap_insert(rel, tup);	Assert(OidIsValid(oid));	/* update the index if any */	CatalogUpdateIndexes(rel, tup);	myself.classId = ConversionRelationId;	myself.objectId = HeapTupleGetOid(tup);	myself.objectSubId = 0;	/* create dependency on conversion procedure */	referenced.classId = ProcedureRelationId;	referenced.objectId = conproc;	referenced.objectSubId = 0;	recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);	/* create dependency on owner */	recordDependencyOnOwner(ConversionRelationId, HeapTupleGetOid(tup),							conowner);	heap_freetuple(tup);	heap_close(rel, RowExclusiveLock);	return oid;}
开发者ID:alecclarke,项目名称:postgresql-8.1.4,代码行数:100,


示例29: create_proc_lang

/* * Guts of language creation. */static voidcreate_proc_lang(const char *languageName,				 Oid languageOwner, Oid handlerOid, Oid inlineOid,				 Oid valOid, bool trusted, Oid *plangoid){	Relation	rel;	TupleDesc	tupDesc;	Datum		values[Natts_pg_language];	bool		nulls[Natts_pg_language];	NameData	langname;	HeapTuple	tup;	ObjectAddress myself,				referenced;	/*	 * Insert the new language into pg_language	 */	rel = heap_open(LanguageRelationId, RowExclusiveLock);	tupDesc = rel->rd_att;	memset(values, 0, sizeof(values));	memset(nulls, false, sizeof(nulls));	namestrcpy(&langname, languageName);	values[Anum_pg_language_lanname - 1] = NameGetDatum(&langname);	values[Anum_pg_language_lanowner - 1] = ObjectIdGetDatum(languageOwner);	values[Anum_pg_language_lanispl - 1] = BoolGetDatum(true);	values[Anum_pg_language_lanpltrusted - 1] = BoolGetDatum(trusted);	values[Anum_pg_language_lanplcallfoid - 1] = ObjectIdGetDatum(handlerOid);	values[Anum_pg_language_laninline - 1] = ObjectIdGetDatum(inlineOid);	values[Anum_pg_language_lanvalidator - 1] = ObjectIdGetDatum(valOid);	nulls[Anum_pg_language_lanacl - 1] = true;	tup = heap_form_tuple(tupDesc, values, nulls);	/* Keep oids synchronized between master and segments */	if (OidIsValid(*plangoid))		HeapTupleSetOid(tup, *plangoid);	*plangoid = simple_heap_insert(rel, tup);	CatalogUpdateIndexes(rel, tup);	/*	 * Create dependencies for language	 */	myself.classId = LanguageRelationId;	myself.objectId = HeapTupleGetOid(tup);	myself.objectSubId = 0;	/* dependency on owner of language */	referenced.classId = AuthIdRelationId;	referenced.objectId = languageOwner;	referenced.objectSubId = 0;	recordSharedDependencyOn(&myself, &referenced, SHARED_DEPENDENCY_OWNER);	/* dependency on the PL handler function */	referenced.classId = ProcedureRelationId;	referenced.objectId = handlerOid;	referenced.objectSubId = 0;	recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);	/* dependency on the inline handler function, if any */	if (OidIsValid(inlineOid))	{		referenced.classId = ProcedureRelationId;		referenced.objectId = inlineOid;		referenced.objectSubId = 0;		recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);	}	/* dependency on the validator function, if any */	if (OidIsValid(valOid))	{		referenced.classId = ProcedureRelationId;		referenced.objectId = valOid;		referenced.objectSubId = 0;		recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);	}	heap_close(rel, RowExclusiveLock);}
开发者ID:LJoNe,项目名称:gpdb,代码行数:85,


示例30: PLy_output_datum_func2

static voidPLy_output_datum_func2(PLyObToDatum *arg, HeapTuple typeTup){	Form_pg_type typeStruct = (Form_pg_type) GETSTRUCT(typeTup);	Oid			element_type;	perm_fmgr_info(typeStruct->typinput, &arg->typfunc);	arg->typoid = HeapTupleGetOid(typeTup);	arg->typmod = -1;	arg->typioparam = getTypeIOParam(typeTup);	arg->typbyval = typeStruct->typbyval;	element_type = get_element_type(arg->typoid);	/*	 * Select a conversion function to convert Python objects to PostgreSQL	 * datums.	Most data types can go through the generic function.	 */	switch (getBaseType(element_type ? element_type : arg->typoid))	{		case BOOLOID:			arg->func = PLyObject_ToBool;			break;		case BYTEAOID:			arg->func = PLyObject_ToBytea;			break;		default:			arg->func = PLyObject_ToDatum;			break;	}	/* Composite types need their own input routine, though */	if (typeStruct->typtype == TYPTYPE_COMPOSITE)	{		arg->func = PLyObject_ToComposite;	}	if (element_type)	{		char		dummy_delim;		Oid			funcid;		if (type_is_rowtype(element_type))			ereport(ERROR,					(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),					 errmsg("PL/Python functions cannot return type %s",							format_type_be(arg->typoid)),					 errdetail("PL/Python does not support conversion to arrays of row types.")));		arg->elm = PLy_malloc0(sizeof(*arg->elm));		arg->elm->func = arg->func;		arg->func = PLySequence_ToArray;		arg->elm->typoid = element_type;		arg->elm->typmod = -1;		get_type_io_data(element_type, IOFunc_input,						 &arg->elm->typlen, &arg->elm->typbyval, &arg->elm->typalign, &dummy_delim,						 &arg->elm->typioparam, &funcid);		perm_fmgr_info(funcid, &arg->elm->typfunc);	}}
开发者ID:AllenDou,项目名称:postgresql,代码行数:61,



注:本文中的HeapTupleGetOid函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ HeapTupleHeaderGetXmin函数代码示例
C++ HeapSetInformation函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。