我正在try 用PostgreSQL编写一个支持函数来设置 Select 性.
我有一个功能
PG_FUNCTION_INFO_V1(pgq3c_sindist_5);
Datum pgq3c_sindist_5(PG_FUNCTION_ARGS)
我希望有一个辅助功能来设定 Select 性. 函数pgq3c_sindist_5返回布尔值,我有一个 支持功能
PG_FUNCTION_INFO_V1(pgq3c_join_selectivity);
Datum pgq3c_join_selectivity(PG_FUNCTION_ARGS)
{
Node *rawreq = (Node *) PG_GETARG_POINTER(0);
Node *unknown = (Node *) PG_GETARG_POINTER(1);
Node *ret = NULL;
Datum radDatum;
double rad;
if (IsA(rawreq, SupportRequestSelectivity))
{
SupportRequestSelectivity *req = (SupportRequestSelectivity *) rawreq;
radDatum = llast_node(Datum,req->args);
rad = DatumGetFloat8(radDatum);
elog(WARNING,"rad = %lf",rad);
/* I would like to make the selectivity a function of rad */
req->selectivity = 0.05;
ret = (Node *) req;
}
我的非支持函数有五个参数.我希望我的支持功能 在我的支持中使用第五个参数pgq3c_sindist_5 功能.我的代码不转储代码,但我的rad总是以0.0结尾, 当我百分之百确定我没有将零作为我的任何参数传递时 我的主要职能.
如果我对源代码的理解是正确的,那么SupportRequestSelectivity具有 的
/* Input fields: */
struct PlannerInfo *root; /* Planner's infrastructure */
Oid funcid; /* function we are inquiring about */
List *args; /* pre-simplified arguments to function */
Oid inputcollid; /* function's input collation */
bool is_join; /* is this a join or restriction case? */
int varRelid; /* if restriction, RTI of target relation */
JoinType jointype; /* if join, outer join type */
struct SpecialJoinInfo *sjinfo; /* if outer join, info about join */
由此,我认为List*args应该是我的main函数的参数, 我应该能够解析这个.
我完全找错人了吗?
我想要在我的Support函数中找到Main函数的参数的值.
编辑:我的新代码看起来像
PG_FUNCTION_INFO_V1(pgq3c_join_selectivity);
Datum pgq3c_join_selectivity(PG_FUNCTION_ARGS)
{
Node *rawreq = (Node *) PG_GETARG_POINTER(0);
Node *ret = NULL;
Datum radDatum;
double rad;
double ratio;
Node *dummy = NULL;
if (IsA(rawreq, SupportRequestSelectivity))
{
SupportRequestSelectivity *req = (SupportRequestSelectivity *) rawreq;
Selectivity s1;
dummy = (Node *) lfirst(list_nth_cell(req->args, 4));
if (IsA(dummy,Const))
{
Const *con = (Const *) dummy;
radDatum = PointerGetDatum(con->constvalue);
rad = DatumGetFloat8(radDatum);
ratio = 3.14 * rad * rad / 41252.; /* pi*r^2/whole_sky_area */
/* clamp at 0, 1*/
CLAMP_PROBABILITY(ratio);
//elog(WARNING, "HERE0.... %e", ratio);
req->selectivity = ratio;
ret = (Node *) req;
}
}
if (IsA(rawreq, SupportRequestSimplify))
{
SupportRequestSimplify *req = (SupportRequestSimplify *) rawreq;
PG_RETURN_POINTER((Node *)0);
}
if (IsA(rawreq, SupportRequestCost))
{
elog(WARNING,"found SupportRequestCost");
/* Provide some generic estimate */
SupportRequestCost *req = (SupportRequestCost *) rawreq;
/* not yet implemented */
ret = (Node *) req;
}
PG_RETURN_POINTER(ret);
}