Get access to the whole query in CustomScan path callback

Started by Aminabout 3 years ago3 messages
#1Amin
amin.fallahi@gmail.com

Hi,

The goal is to have access to all the tables that are being scanned or will
be scanned as a part of the query. Basically, the callback looks like this:

typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root,
RelOptInfo *rel,
Index rti,
RangeTblEntry *rte);

Now, the problem is when there is a nested query, the function will be
called once for the parent query and once for the subquery. However, I need
access to the whole query in this function. There seems to be no CustomScan
callback before this that has the whole query passed to it. Is there any
way I can get access to the complete query (or all the relations in the
query) by using the parameters passed to this function? Or any other
workaround?

Thank you and happy holidays!

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Amin (#1)
Re: Get access to the whole query in CustomScan path callback

Amin <amin.fallahi@gmail.com> writes:

The goal is to have access to all the tables that are being scanned or will
be scanned as a part of the query. Basically, the callback looks like this:

typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root,
RelOptInfo *rel,
Index rti,
RangeTblEntry *rte);

Now, the problem is when there is a nested query, the function will be
called once for the parent query and once for the subquery. However, I need
access to the whole query in this function. There seems to be no CustomScan
callback before this that has the whole query passed to it. Is there any
way I can get access to the complete query (or all the relations in the
query) by using the parameters passed to this function? Or any other
workaround?

Everything the planner knows is accessible via the "root" pointer.

I very strongly question the idea that a custom scan provider should
be doing what you say you want to do, but the info is there.

regards, tom lane

#3Amin
amin.fallahi@gmail.com
In reply to: Tom Lane (#2)
Re: Get access to the whole query in CustomScan path callback

I cannot find any information related to other relations in the query other
than the one which is being scanned in the root pointer. Is there any
function call which can be used to get access to it?

On Wed, Dec 21, 2022 at 9:46 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Show quoted text

Amin <amin.fallahi@gmail.com> writes:

The goal is to have access to all the tables that are being scanned or

will

be scanned as a part of the query. Basically, the callback looks like

this:

typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root,
RelOptInfo *rel,
Index rti,
RangeTblEntry *rte);

Now, the problem is when there is a nested query, the function will be
called once for the parent query and once for the subquery. However, I

need

access to the whole query in this function. There seems to be no

CustomScan

callback before this that has the whole query passed to it. Is there any
way I can get access to the complete query (or all the relations in the
query) by using the parameters passed to this function? Or any other
workaround?

Everything the planner knows is accessible via the "root" pointer.

I very strongly question the idea that a custom scan provider should
be doing what you say you want to do, but the info is there.

regards, tom lane