Scans are offloaded to SeqScan instead of CustomScan when there are multiple relations in the same query

Started by Aminover 2 years ago5 messages
#1Amin
amin.fallahi@gmail.com

Hi there,

In my implementation of CustomScan, when I have a query that scans multiple
tables (select c from t1,t2,t3), the planner always picks one table to be
scanned by CustomScan and offloads the rest to SeqScan. I tried assigning a
cost of 0 to the CustomScan path, but still not working. BeginCustomScan
gets executed, ExecCustomScan is skipped, and then EndCustomScan is
executed for all the tables that are offloaded to Seq Scan. EXPLAIN shows
that always only one table is picked to be executed by CustomScan. Any idea
what I might be doing wrong? Like a value in a struct I might be setting
incorrectly?

Thanks!

#2Amin
amin.fallahi@gmail.com
In reply to: Amin (#1)
Re: Scans are offloaded to SeqScan instead of CustomScan when there are multiple relations in the same query

To simplify: Can CustomScan scan multiple relations in the same query or it
will always be assigned to one or zero relations?

On Fri, Apr 14, 2023 at 4:33 PM Amin <amin.fallahi@gmail.com> wrote:

Show quoted text

Hi there,

In my implementation of CustomScan, when I have a query that scans
multiple tables (select c from t1,t2,t3), the planner always picks one
table to be scanned by CustomScan and offloads the rest to SeqScan. I tried
assigning a cost of 0 to the CustomScan path, but still not working.
BeginCustomScan gets executed, ExecCustomScan is skipped, and then
EndCustomScan is executed for all the tables that are offloaded to Seq
Scan. EXPLAIN shows that always only one table is picked to be executed by
CustomScan. Any idea what I might be doing wrong? Like a value in a struct
I might be setting incorrectly?

Thanks!

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Amin (#2)
Re: Scans are offloaded to SeqScan instead of CustomScan when there are multiple relations in the same query

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

To simplify: Can CustomScan scan multiple relations in the same query or it
will always be assigned to one or zero relations?

There's barely any code in the core planner that is specific to custom
scans. Almost certainly this misbehavior is the fault of your
custom-path-creation code. Maybe you're labeling the paths with the
wrong parent relation, or forgetting to submit them to add_path,
or assigning them costs that are high enough to get them rejected?

regards, tom lane

#4Amin
amin.fallahi@gmail.com
In reply to: Tom Lane (#3)
Re: Scans are offloaded to SeqScan instead of CustomScan when there are multiple relations in the same query

Hi Tom,

I made sure EXPLAIN returns CustomScan for all scans in the query. But
still, ExecCustomScan is only called once while the rest of the functions
are called for each scan separately. Is this expected behavior? How to work
around this?

Thank you!

On Mon, Apr 17, 2023 at 3:45 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Show quoted text

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

To simplify: Can CustomScan scan multiple relations in the same query or

it

will always be assigned to one or zero relations?

There's barely any code in the core planner that is specific to custom
scans. Almost certainly this misbehavior is the fault of your
custom-path-creation code. Maybe you're labeling the paths with the
wrong parent relation, or forgetting to submit them to add_path,
or assigning them costs that are high enough to get them rejected?

regards, tom lane

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Amin (#4)
Re: Scans are offloaded to SeqScan instead of CustomScan when there are multiple relations in the same query

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

I made sure EXPLAIN returns CustomScan for all scans in the query. But
still, ExecCustomScan is only called once while the rest of the functions
are called for each scan separately. Is this expected behavior? How to work
around this?

[shrug...] There's some bug in your code, which you've not shown us
(not that I'm volunteering to review it in any detail).

regards, tom lane