lsyscache.c

来自「postgresql8.3.4源码,开源数据库」· C语言 代码 · 共 2,698 行 · 第 1/5 页

C
2,698
字号
	{		Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);		result = optup->oprcanmerge;		ReleaseSysCache(tp);	}	return result;}/* * op_hashjoinable * * Returns true if the operator is hashjoinable.  (There must be a suitable * hash opfamily entry for this operator if it is so marked.) */boolop_hashjoinable(Oid opno){	HeapTuple	tp;	bool		result = false;	tp = SearchSysCache(OPEROID,						ObjectIdGetDatum(opno),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);		result = optup->oprcanhash;		ReleaseSysCache(tp);	}	return result;}/* * op_strict * * Get the proisstrict flag for the operator's underlying function. */boolop_strict(Oid opno){	RegProcedure funcid = get_opcode(opno);	if (funcid == (RegProcedure) InvalidOid)		elog(ERROR, "operator %u does not exist", opno);	return func_strict((Oid) funcid);}/* * op_volatile * * Get the provolatile flag for the operator's underlying function. */charop_volatile(Oid opno){	RegProcedure funcid = get_opcode(opno);	if (funcid == (RegProcedure) InvalidOid)		elog(ERROR, "operator %u does not exist", opno);	return func_volatile((Oid) funcid);}/* * get_commutator * *		Returns the corresponding commutator of an operator. */Oidget_commutator(Oid opno){	HeapTuple	tp;	tp = SearchSysCache(OPEROID,						ObjectIdGetDatum(opno),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		Form_pg_operator optup = (Form_pg_operator) GETSTRUCT(tp);		Oid			result;		result = optup->oprcom;		ReleaseSysCache(tp);		return result;	}	else		return InvalidOid;}/* * get_negator * *		Returns the corresponding negator of an operator. */Oidget_negator(Oid opno){	HeapTuple	tp;	tp = SearchSysCache(OPEROID,						ObjectIdGetDatum(opno),						0, 0, 0);	if (HeapTupleIsValid(tp))	{		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;}/* * get_func_cost *		Given procedure id, return the function's procost field. */float4get_func_cost(Oid funcid){	HeapTuple	tp;	float4		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))->procost;	ReleaseSysCache(tp);	return result;}/* * get_func_rows *		Given procedure id, return the function's prorows field. */float4get_func_rows(Oid funcid){	HeapTuple	tp;	float4		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))->prorows;	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';}/* * get_rel_tablespace * *		Returns the pg_tablespace OID associated with a given relation. * * Note: InvalidOid might mean either that we couldn't find the relation,

⌨️ 快捷键说明

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