selectivity function - Mailing list pgsql-hackers

From Greg Hennessy
Subject selectivity function
Date
Msg-id CA+mZaOO8GkK9eNEbFjAwHnCEZsBJAK48gOFbF-G9D=BUyj96XA@mail.gmail.com
Whole thread Raw
Responses Re: selectivity function
List pgsql-hackers

I'm trying to include a sensitivity operator in a function. My issue is that when I have my function, I get a call to SupportRequestSimplify, but not SupportRequestSensitivity. It is not obvious what I am doing that is incorrect.

My c (stub) function is:

PG_FUNCTION_INFO_V1(pgq3c_join_selectivity);
Datum pgq3c_join_selectivity(PG_FUNCTION_ARGS)
{  Node     *rawreq = (Node *) PG_GETARG_POINTER(0);  Node     *ret = NULL;
  elog(WARNING,"in pgq3c_join_selectivity %d %d %d",       rawreq->type,T_SupportRequestSelectivity,T_SupportRequestSimplify);
    if (IsA(rawreq, SupportRequestSelectivity))    {      elog(WARNING,"found SupportRequestSelectivity");    }  if (IsA(rawreq, SupportRequestSimplify))    {      elog(WARNING,"found SupportRequestSimplify");    }
  PG_RETURN_POINTER(ret);
}

my sql function code is:

-- a selectivity function for the q3c join function
CREATE OR REPLACE FUNCTION q3c_join_selectivity(internal)       RETURNS internal       AS 'MODULE_PATHNAME', 'pgq3c_join_selectivity'       LANGUAGE C IMMUTABLE STRICT ;

and my function definition is:

    CREATE OR REPLACE FUNCTION q3c_join(leftra double precision, leftdec double precision,                    rightra double precision, rightdec double precision,                    radius double precision)        RETURNS boolean AS
'
SELECT (((q3c_ang2ipix($3,$4)>=(q3c_nearby_it($1,$2,$5,0))) AND (q3c_ang2ipix($3,$4)<=(q3c_nearby_it($1,$2,$5,1))))    OR ((q3c_ang2ipix($3,$4)>=(q3c_nearby_it($1,$2,$5,2))) AND (q3c_ang2ipix($3,$4)<=(q3c_nearby_it($1,$2,$5,3))))    OR ((q3c_ang2ipix($3,$4)>=(q3c_nearby_it($1,$2,$5,4))) AND (q3c_ang2ipix($3,$4)<=(q3c_nearby_it($1,$2,$5,5))))    OR ((q3c_ang2ipix($3,$4)>=(q3c_nearby_it($1,$2,$5,6))) AND (q3c_ang2ipix($3,$4)<=(q3c_nearby_it($1,$2,$5,7)))))     AND q3c_sindist($1,$2,$3,$4)<POW(SIN(RADIANS($5)/2),2)    AND ($5::double precision ==<<>>== ($1,$2,$3,$4)::q3c_type)
' LANGUAGE SQL IMMUTABLE COST 10 SUPPORT q3c_join_selectivity;

When I run my function, I get:

(base) [greg.hennessy@localhost ~]$ psql q3c_test
Timing is on.
Output format is unaligned.
psql (13.4)
Type "help" for help.

q3c_test=# select count(*) from test as a, test1 as b where  q3c_join(a.ra,a.dec,b.ra,b.dec,.01);
WARNING:  in pgq3c_join_selectivity 417 418 417
WARNING:  found SupportRequestSimplify
count
153
(1 row)
Time: 9701.717 ms (00:09.702)
q3c_test=# 

So, I see a call where I am asked for a SupportRequestSimplify, but not a SupportRequestSelectivity.

I admit to not being an expert in postgres internals hacking. Is there something obvious I am doing incorrect? How do I ensure my support Function is asked for a SupportRequestSelectivity?

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: postgres and initdb not working inside docker
Next
From: Tom Lane
Date:
Subject: Re: selectivity function