From: Dmitry Ivanov <d.ivanov@postgrespro.ru>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Dmitry Ivanov <d.ivanov@postgrespro.ru>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Possible problem in Custom Scan API
Date: Tue, 11 Apr 2017 23:28:17 +0300
Message-ID: <f7590622-182b-4362-b148-c21de109ad2a@postgrespro.ru> (raw)
In-Reply-To: <367.1491940070@sss.pgh.pa.us>
References: <e29ddd30-8ef9-4da5-a50b-2bb7b8c7198d@postgrespro.ru>
<20021.1491933424@sss.pgh.pa.us>
<1ef85b46-1385-4810-bb80-97cd977da1d5@postgrespro.ru>
<367.1491940070@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
Tom Lane wrote:
> Reading between the lines, I think the problem may be that you're not
> being careful about how you set up custom_scan_tlist. But since the
> core code has zero involvement in that decision, it's hard to see why
> it would be a core code bug.
I'm sorry, but you didn't understand. It's *the core code* that builds the
targetlist, and sometimes it may decide to provide a physical targetlist,
not the one that's *really needed*. The broader targetlist has Vars that
cannot be supplied by the IndexOnlyScan node, hence the error.
We cannot come up with our own targetlist because we don't know if it's a
top node and we should return exactly the same tuple (CP_EXACT_TLIST) or
it's just the stray optimization that made us think so.
Append works only because it doesn't allow projections, and it can never
get a physical targetlist if an index doesn't contain all columns.
But everything changes when we use CustomScan: PostgreSQL will not pay
attention. For example, if our CustomScan is a child of NestLoop, the
former will call this (create_nestloop_plan):
inner_plan = create_plan_recurse(root, best_path->innerjoinpath, 0);
Since NestLoop can make projections, it doesn't enforce CP_EXACT_TLIST
flag, and our CustomScan may end up with a full physical targetlist (see
the code of create_scan_plan() if you don't believe me), INSTEAD OF the one
it really has been asked to produce. Meanwhile, Append will behave as it
should, since it doesn't care about physical tlists.
It's not just my imagination.
--
Dmitry Ivanov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: d.ivanov@postgrespro.ru, tgl@sss.pgh.pa.us
Subject: Re: Possible problem in Custom Scan API
In-Reply-To: <f7590622-182b-4362-b148-c21de109ad2a@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox