⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lsyscache.c

📁 PostgreSQL 8.1.4的源码 适用于Linux下的开源数据库系统
💻 C
📖 第 1 页 / 共 3 页
字号:
	{		Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);		Oid			result;		result = optup->oprnegate;		ReleaseSysCache(tp);		return result;	}	else		return InvalidOid;}/* * get_oprrest * *		Returns procedure id for computing selectivity of an operator. */RegProcedureget_oprrest(Oid opno){	HeapTuple	tp;	tp = SearchSysCache(OPEROID,						ObjectIdGetDatum(opno),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);		RegProcedure result;		result = optup->oprrest;		ReleaseSysCache(tp);		return result;	}	else		return (RegProcedure) InvalidOid;}/* * get_oprjoin * *		Returns procedure id for computing selectivity of a join. */RegProcedureget_oprjoin(Oid opno){	HeapTuple	tp;	tp = SearchSysCache(OPEROID,						ObjectIdGetDatum(opno),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);		RegProcedure result;		result = optup->oprjoin;		ReleaseSysCache(tp);		return result;	}	else		return (RegProcedure) InvalidOid;}/*				---------- FUNCTION CACHE ----------					 *//* * get_func_name *	  returns the name of the function with the given funcid * * Note: returns a palloc'd copy of the string, or NULL if no such function. */char *get_func_name(Oid funcid){	HeapTuple	tp;	tp = SearchSysCache(PROCOID,						ObjectIdGetDatum(funcid),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_proc functup = (Form_pg_proc) GETSTRUCT(tp);		char	   *result;		result = pstrdup(NameStr(functup->proname));		ReleaseSysCache(tp);		return result;	}	else		return NULL;}/* * get_func_rettype *		Given procedure id, return the function's result type. */Oidget_func_rettype(Oid funcid){	HeapTuple	tp;	Oid			result;	tp = SearchSysCache(PROCOID,						ObjectIdGetDatum(funcid),						0, 0, 0);	if (!HeapTupleIsValid(tp))		elog(ERROR, "cache lookup failed for function %u", funcid);	result = ((Form_pg_proc) GETSTRUCT(tp))->prorettype;	ReleaseSysCache(tp);	return result;}/* * get_func_nargs *		Given procedure id, return the number of arguments. */intget_func_nargs(Oid funcid){	HeapTuple	tp;	int			result;	tp = SearchSysCache(PROCOID,						ObjectIdGetDatum(funcid),						0, 0, 0);	if (!HeapTupleIsValid(tp))		elog(ERROR, "cache lookup failed for function %u", funcid);	result = ((Form_pg_proc) GETSTRUCT(tp))->pronargs;	ReleaseSysCache(tp);	return result;}/* * get_func_signature *		Given procedure id, return the function's argument and result types. *		(The return value is the result type.) * * The arguments are returned as a palloc'd array. */Oidget_func_signature(Oid funcid, Oid **argtypes, int *nargs){	HeapTuple	tp;	Form_pg_proc procstruct;	Oid			result;	tp = SearchSysCache(PROCOID,						ObjectIdGetDatum(funcid),						0, 0, 0);	if (!HeapTupleIsValid(tp))		elog(ERROR, "cache lookup failed for function %u", funcid);	procstruct = (Form_pg_proc) GETSTRUCT(tp);	result = procstruct->prorettype;	*nargs = (int) procstruct->pronargs;	Assert(*nargs == procstruct->proargtypes.dim1);	*argtypes = (Oid *) palloc(*nargs * sizeof(Oid));	memcpy(*argtypes, procstruct->proargtypes.values, *nargs * sizeof(Oid));	ReleaseSysCache(tp);	return result;}/* * get_func_retset *		Given procedure id, return the function's proretset flag. */boolget_func_retset(Oid funcid){	HeapTuple	tp;	bool		result;	tp = SearchSysCache(PROCOID,						ObjectIdGetDatum(funcid),						0, 0, 0);	if (!HeapTupleIsValid(tp))		elog(ERROR, "cache lookup failed for function %u", funcid);	result = ((Form_pg_proc) GETSTRUCT(tp))->proretset;	ReleaseSysCache(tp);	return result;}/* * func_strict *		Given procedure id, return the function's proisstrict flag. */boolfunc_strict(Oid funcid){	HeapTuple	tp;	bool		result;	tp = SearchSysCache(PROCOID,						ObjectIdGetDatum(funcid),						0, 0, 0);	if (!HeapTupleIsValid(tp))		elog(ERROR, "cache lookup failed for function %u", funcid);	result = ((Form_pg_proc) GETSTRUCT(tp))->proisstrict;	ReleaseSysCache(tp);	return result;}/* * func_volatile *		Given procedure id, return the function's provolatile flag. */charfunc_volatile(Oid funcid){	HeapTuple	tp;	char		result;	tp = SearchSysCache(PROCOID,						ObjectIdGetDatum(funcid),						0, 0, 0);	if (!HeapTupleIsValid(tp))		elog(ERROR, "cache lookup failed for function %u", funcid);	result = ((Form_pg_proc) GETSTRUCT(tp))->provolatile;	ReleaseSysCache(tp);	return result;}/*				---------- RELATION CACHE ----------					 *//* * get_relname_relid *		Given name and namespace of a relation, look up the OID. * * Returns InvalidOid if there is no such relation. */Oidget_relname_relid(const char *relname, Oid relnamespace){	return GetSysCacheOid(RELNAMENSP,						  PointerGetDatum(relname),						  ObjectIdGetDatum(relnamespace),						  0, 0);}#ifdef NOT_USED/* * get_relnatts * *		Returns the number of attributes for a given relation. */intget_relnatts(Oid relid){	HeapTuple	tp;	tp = SearchSysCache(RELOID,						ObjectIdGetDatum(relid),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp);		int			result;		result = reltup->relnatts;		ReleaseSysCache(tp);		return result;	}	else		return InvalidAttrNumber;}#endif/* * get_rel_name *		Returns the name of a given relation. * * Returns a palloc'd copy of the string, or NULL if no such relation. * * NOTE: since relation name is not unique, be wary of code that uses this * for anything except preparing error messages. */char *get_rel_name(Oid relid){	HeapTuple	tp;	tp = SearchSysCache(RELOID,						ObjectIdGetDatum(relid),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp);		char	   *result;		result = pstrdup(NameStr(reltup->relname));		ReleaseSysCache(tp);		return result;	}	else		return NULL;}/* * get_rel_namespace * *		Returns the pg_namespace OID associated with a given relation. */Oidget_rel_namespace(Oid relid){	HeapTuple	tp;	tp = SearchSysCache(RELOID,						ObjectIdGetDatum(relid),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp);		Oid			result;		result = reltup->relnamespace;		ReleaseSysCache(tp);		return result;	}	else		return InvalidOid;}/* * get_rel_type_id * *		Returns the pg_type OID associated with a given relation. * * Note: not all pg_class entries have associated pg_type OIDs; so be * careful to check for InvalidOid result. */Oidget_rel_type_id(Oid relid){	HeapTuple	tp;	tp = SearchSysCache(RELOID,						ObjectIdGetDatum(relid),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp);		Oid			result;		result = reltup->reltype;		ReleaseSysCache(tp);		return result;	}	else		return InvalidOid;}/* * get_rel_relkind * *		Returns the relkind associated with a given relation. */charget_rel_relkind(Oid relid){	HeapTuple	tp;	tp = SearchSysCache(RELOID,						ObjectIdGetDatum(relid),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp);		char		result;		result = reltup->relkind;		ReleaseSysCache(tp);		return result;	}	else		return '\0';}/*				---------- TYPE CACHE ----------						 *//* * get_typisdefined * *		Given the type OID, determine whether the type is defined *		(if not, it's only a shell). */boolget_typisdefined(Oid typid){	HeapTuple	tp;	tp = SearchSysCache(TYPEOID,						ObjectIdGetDatum(typid),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);		bool		result;		result = typtup->typisdefined;		ReleaseSysCache(tp);		return result;	}	else		return false;}/* * get_typlen * *		Given the type OID, return the length of the type. */int16get_typlen(Oid typid){	HeapTuple	tp;	tp = SearchSysCache(TYPEOID,						ObjectIdGetDatum(typid),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);		int16		result;		result = typtup->typlen;		ReleaseSysCache(tp);		return result;	}	else		return 0;}/* * get_typbyval * *		Given the type OID, determine whether the type is returned by value or *		not.  Returns true if by value, false if by reference. */boolget_typbyval(Oid typid){	HeapTuple	tp;	tp = SearchSysCache(TYPEOID,						ObjectIdGetDatum(typid),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);		bool		result;		result = typtup->typbyval;		ReleaseSysCache(tp);		return result;	}	else		return false;}/* * get_typlenbyval * *		A two-fer: given the type OID, return both typlen and typbyval. * *		Since both pieces of info are needed to know how to copy a Datum, *		many places need both.	Might as well get them with one cache lookup *		instead of two.  Also, this routine raises an error instead of *		returning a bogus value when given a bad type OID. */voidget_typlenbyval(Oid typid, int16 *typlen, bool *typbyval){	HeapTuple	tp;	Form_pg_type typtup;	tp = SearchSysCache(TYPEOID,						ObjectIdGetDatum(typid),						0, 0, 0);	if (!HeapTupleIsValid(tp))		elog(ERROR, "cache lookup failed for type %u", typid);	typtup = (Form_pg_type) GETSTRUCT(tp);	*typlen = typtup->typlen;	*typbyval = typtup->typbyval;	ReleaseSysCache(tp);}/* * get_typlenbyvalalign * *		A three-fer: given the type OID, return typlen, typbyval, typalign. */voidget_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval,					 char *typalign){	HeapTuple	tp;	Form_pg_type typtup;	tp = SearchSysCache(TYPEOID,						ObjectIdGetDatum(typid),						0, 0, 0);	if (!HeapTupleIsValid(tp))		elog(ERROR, "cache lookup failed for type %u", typid);	typtup = (Form_pg_type) GETSTRUCT(tp);	*typlen = typtup->typlen;	*typbyval = typtup->typbyval;	*typalign = typtup->typalign;	ReleaseSysCache(tp);}/* * getTypeIOParam *		Given a pg_type row, select the type OID to pass to I/O functions * * Formerly, all I/O functions were passed pg_type.typelem as their second * parameter, but we now have a more complex rule about what to pass. * This knowledge is intended to be centralized here --- direct references * to typelem elsewhere in the code are wrong, if they are associated with * I/O calls and not with actual subscripting operations!  (But see * bootstrap.c, which can't conveniently use this routine.) * * As of PostgreSQL 8.1, output functions receive only the value itself * and not any auxiliary parameters, so the name of this routine is now * a bit of a misnomer ... it should be getTypeInputParam. */OidgetTypeIOParam(HeapTuple typeTuple){	Form_pg_type typeStruct = (Form_pg_type) GETSTRUCT(typeTuple);	/*	 * Array types get their typelem as parameter; everybody else gets their	 * own type OID as parameter.  (This is a change from 8.0, in which only	 * composite types got their own OID as parameter.)	 */	if (OidIsValid(typeStruct->typelem))		return typeStruct->typelem;	else		return HeapTupleGetOid(typeTuple);}/* * get_type_io_data * *		A six-fer:	given the type OID, return typlen, typbyval, typalign, *					typdelim, typioparam, and IO function OID. The IO function *					returned is controlled by IOFuncSelector */voidget_type_io_data(Oid typid,				 IOFuncSelector which_func,				 int16 *typlen,				 bool *typbyval,				 char *typalign,				 char *typdelim,				 Oid *typioparam,				 Oid *func){	HeapTuple	typeTuple;	Form_pg_type typeStruct;	typeTuple = SearchSysCache(TYPEOID,							   ObjectIdGetDatum(typid),							   0, 0, 0);	if (!HeapTupleIsValid(typeTuple))		elog(ERROR, "cache lookup failed for type %u", typid);	typeStruct = (Form_pg_type) GETSTRUCT(typeTuple);	*typlen = typeStruct->typlen;	*typbyval = typeStruct->typbyval;	*typalign = typeStruct->typalign;	*typdelim = typeStruct->typdelim;	*typioparam = getTypeIOParam(typeTuple);	switch (which_func)	{		case IOFunc_input:			*func = typeStruct->typinput;			break;		case IOFunc_output:			*func = typeStruct->typoutput;			break;		case IOFunc_receive:			*func = typeStruct->typreceive;			break;		case IOFunc_send:			*func = typeStruct->typsend;			break;	}	ReleaseSysCache(typeTuple);}#ifdef NOT_USEDcharget_typalign(Oid typid){	HeapTuple	tp;	tp = SearchSysCache(TYPEOID,						ObjectIdGetDatum(typid),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);		char		result;		result = typtup->typalign;		ReleaseSysCache(tp);		return result;	}	else		return 'i';}#endifcharget_typstorage(Oid typid){	HeapTuple	tp;	tp = SearchSysCache(TYPEOID,						ObjectIdGetDatum(typid),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);		char		result;		result = typtup->typstorage;		ReleaseSysCache(tp);		return result;	}	else		return 'p';}/* * get_typtypmod * *		Given the type OID, return the typtypmod field (domain's typmod *		for base type) */int32get_typtypmod(Oid typid){	HeapTuple	tp;	tp = SearchSysCache(TYPEOID,						ObjectIdGetDatum(typid),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_type typtup = (Form_pg_type) GETSTRUCT(tp);		int32		result;		result = typtup->typtypmod;		ReleaseSysCache(tp);		return result;	}	else		return -1;}/* * get_typdefault *	  Given a type OID, return the type's default value, if any. * *	  The result is a palloc'd expression node tree, or NULL if there *	  is no defined default for the datatype. * * NB: caller should be prepared to coerce result to correct datatype; * the returned expression tree might produce something of the wrong type. */Node *get_typdefault(Oid typid)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -