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

📄 selfuncs.c

📁 关系型数据库 Postgresql 6.5.2
💻 C
📖 第 1 页 / 共 2 页
字号:
								 &isnull));	if (isnull)		elog(DEBUG, "gethilokey: high key is null");	*low = textout((struct varlena *)				   heap_getattr(tuple,								Anum_pg_statistic_stalokey,								RelationGetDescr(rel),								&isnull));	if (isnull)		elog(DEBUG, "gethilokey: low key is null");	heap_endscan(scan);	heap_close(rel);}float64btreesel(Oid operatorObjectId,		 Oid indrelid,		 AttrNumber attributeNumber,		 char *constValue,		 int32 constFlag,		 int32 nIndexKeys,		 Oid indexrelid){	float64		result;	if (FunctionalSelectivity(nIndexKeys, attributeNumber))	{		/*		 * Need to call the functions selectivity function here.  For now		 * simply assume it's 1/3 since functions don't currently have		 * selectivity functions		 */		result = (float64) palloc(sizeof(float64data));		*result = 1.0 / 3.0;	}	else	{		RegProcedure oprrest = get_oprrest(operatorObjectId);		/*		 * Operators used for indexes should have selectivity estimators.		 * (An alternative is to default to 0.5, as the optimizer does in		 * dealing with operators occurring in WHERE clauses, but if you		 * are going to the trouble of making index support you probably		 * don't want to miss the benefits of a good selectivity estimate.)		 */		if (!oprrest)		{#if 1			/*			 * XXX temporary fix for 6.5: rtree operators are missing their			 * selectivity estimators, so return a default estimate instead.			 * Ugh.			 */			result = (float64) palloc(sizeof(float64data));			*result = 0.5;#else			elog(ERROR,				 "Operator %u must have a restriction selectivity estimator to be used in an index",				 operatorObjectId);#endif		}		else			result = (float64) fmgr(oprrest,									(char *) operatorObjectId,									(char *) indrelid,									(char *) (int) attributeNumber,									(char *) constValue,									(char *) constFlag,									NULL);	}	if (!PointerIsValid(result))		elog(ERROR, "Btree Selectivity: bad pointer");	if (*result < 0.0 || *result > 1.0)		elog(ERROR, "Btree Selectivity: bad value %lf", *result);	return result;}float64btreenpage(Oid operatorObjectId,		   Oid indrelid,		   AttrNumber attributeNumber,		   char *constValue,		   int32 constFlag,		   int32 nIndexKeys,		   Oid indexrelid){	float64		temp,				result;	float64data tempData;	HeapTuple	atp;	int			npage;	if (FunctionalSelectivity(nIndexKeys, attributeNumber))	{		/*		 * Need to call the functions selectivity function here.  For now		 * simply assume it's 1/3 since functions don't currently have		 * selectivity functions		 */		tempData = 1.0 / 3.0;		temp = &tempData;	}	else	{		RegProcedure oprrest = get_oprrest(operatorObjectId);		/*		 * Operators used for indexes should have selectivity estimators.		 * (An alternative is to default to 0.5, as the optimizer does in		 * dealing with operators occurring in WHERE clauses, but if you		 * are going to the trouble of making index support you probably		 * don't want to miss the benefits of a good selectivity estimate.)		 */		if (!oprrest)		{#if 1			/*			 * XXX temporary fix for 6.5: rtree operators are missing their			 * selectivity estimators, so return a default estimate instead.			 * Ugh.			 */			tempData = 0.5;			temp = &tempData;#else			elog(ERROR,				 "Operator %u must have a restriction selectivity estimator to be used in an index",				 operatorObjectId);#endif		}		else			temp = (float64) fmgr(oprrest,								  (char *) operatorObjectId,								  (char *) indrelid,								  (char *) (int) attributeNumber,								  (char *) constValue,								  (char *) constFlag,								  NULL);	}	atp = SearchSysCacheTuple(RELOID,							  ObjectIdGetDatum(indexrelid),							  0, 0, 0);	if (!HeapTupleIsValid(atp))	{		elog(ERROR, "btreenpage: no index tuple %u", indexrelid);		return 0;	}	npage = ((Form_pg_class) GETSTRUCT(atp))->relpages;	result = (float64) palloc(sizeof(float64data));	*result = *temp * npage;	return result;}float64hashsel(Oid operatorObjectId,		Oid indrelid,		AttrNumber attributeNumber,		char *constValue,		int32 constFlag,		int32 nIndexKeys,		Oid indexrelid){	float64		result;	float64data resultData;	HeapTuple	atp;	int			ntuples;	if (FunctionalSelectivity(nIndexKeys, attributeNumber))	{		/*		 * Need to call the functions selectivity function here.  For now		 * simply use 1/Number of Tuples since functions don't currently		 * have selectivity functions		 */		atp = SearchSysCacheTuple(RELOID,								  ObjectIdGetDatum(indexrelid),								  0, 0, 0);		if (!HeapTupleIsValid(atp))		{			elog(ERROR, "hashsel: no index tuple %u", indexrelid);			return 0;		}		ntuples = ((Form_pg_class) GETSTRUCT(atp))->reltuples;		if (ntuples > 0)			resultData = 1.0 / (float64data) ntuples;		else			resultData = (float64data) (1.0 / 100.0);		result = &resultData;	}	else	{		RegProcedure oprrest = get_oprrest(operatorObjectId);		/*		 * Operators used for indexes should have selectivity estimators.		 * (An alternative is to default to 0.5, as the optimizer does in		 * dealing with operators occurring in WHERE clauses, but if you		 * are going to the trouble of making index support you probably		 * don't want to miss the benefits of a good selectivity estimate.)		 */		if (!oprrest)			elog(ERROR,				 "Operator %u must have a restriction selectivity estimator to be used in a hash index",				 operatorObjectId);		result = (float64) fmgr(oprrest,								(char *) operatorObjectId,								(char *) indrelid,								(char *) (int) attributeNumber,								(char *) constValue,								(char *) constFlag,								NULL);	}	if (!PointerIsValid(result))		elog(ERROR, "Hash Table Selectivity: bad pointer");	if (*result < 0.0 || *result > 1.0)		elog(ERROR, "Hash Table Selectivity: bad value %lf", *result);	return result;}float64hashnpage(Oid operatorObjectId,		  Oid indrelid,		  AttrNumber attributeNumber,		  char *constValue,		  int32 constFlag,		  int32 nIndexKeys,		  Oid indexrelid){	float64		temp,				result;	float64data tempData;	HeapTuple	atp;	int			npage;	int			ntuples;	atp = SearchSysCacheTuple(RELOID,							  ObjectIdGetDatum(indexrelid),							  0, 0, 0);	if (!HeapTupleIsValid(atp))	{		elog(ERROR, "hashsel: no index tuple %u", indexrelid);		return 0;	}	if (FunctionalSelectivity(nIndexKeys, attributeNumber))	{		/*		 * Need to call the functions selectivity function here.  For now,		 * use 1/Number of Tuples since functions don't currently have		 * selectivity functions		 */		ntuples = ((Form_pg_class) GETSTRUCT(atp))->reltuples;		if (ntuples > 0)			tempData = 1.0 / (float64data) ntuples;		else			tempData = (float64data) (1.0 / 100.0);		temp = &tempData;	}	else	{		RegProcedure oprrest = get_oprrest(operatorObjectId);		/*		 * Operators used for indexes should have selectivity estimators.		 * (An alternative is to default to 0.5, as the optimizer does in		 * dealing with operators occurring in WHERE clauses, but if you		 * are going to the trouble of making index support you probably		 * don't want to miss the benefits of a good selectivity estimate.)		 */		if (!oprrest)			elog(ERROR,				 "Operator %u must have a restriction selectivity estimator to be used in a hash index",				 operatorObjectId);		temp = (float64) fmgr(oprrest,							  (char *) operatorObjectId,							  (char *) indrelid,							  (char *) (int) attributeNumber,							  (char *) constValue,							  (char *) constFlag,							  NULL);	}	npage = ((Form_pg_class) GETSTRUCT(atp))->relpages;	result = (float64) palloc(sizeof(float64data));	*result = *temp * npage;	return result;}float64rtsel(Oid operatorObjectId,	  Oid indrelid,	  AttrNumber attributeNumber,	  char *constValue,	  int32 constFlag,	  int32 nIndexKeys,	  Oid indexrelid){	return (btreesel(operatorObjectId, indrelid, attributeNumber,					 constValue, constFlag, nIndexKeys, indexrelid));}float64rtnpage(Oid operatorObjectId,		Oid indrelid,		AttrNumber attributeNumber,		char *constValue,		int32 constFlag,		int32 nIndexKeys,		Oid indexrelid){	return (btreenpage(operatorObjectId, indrelid, attributeNumber,					   constValue, constFlag, nIndexKeys, indexrelid));}float64gistsel(Oid operatorObjectId,		Oid indrelid,		AttrNumber attributeNumber,		char *constValue,		int32 constFlag,		int32 nIndexKeys,		Oid indexrelid){	return (btreesel(operatorObjectId, indrelid, attributeNumber,					 constValue, constFlag, nIndexKeys, indexrelid));}float64gistnpage(Oid operatorObjectId,		  Oid indrelid,		  AttrNumber attributeNumber,		  char *constValue,		  int32 constFlag,		  int32 nIndexKeys,		  Oid indexrelid){	return (btreenpage(operatorObjectId, indrelid, attributeNumber,					   constValue, constFlag, nIndexKeys, indexrelid));}

⌨️ 快捷键说明

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