From: Dmitry Bogatov <dbogatov@interfacefinancial.com>
To: pgsql-general@postgresql.org
Subject: Unexpected plan width with foreign data wrapper
Date: Fri, 4 Oct 2019 15:35:51 +0100
Message-ID: <20191004143550.GA30189@debian> (raw)
Hello.
I work on fixing test suite (make installcheck) failures in Multicorn
project[1]. The purpose of project is to make it possible to write
Foreign Data Wrappers[2] in Python, not in C[3].
Test suite executes SQL statements with psql and compares output with
expected. If they are different, test is considered failed.
Major source of test failures is width estimation in query plan
explaination. For example, for following statements:
CREATE EXTENSION multicorn;
CREATE server multicorn_srv foreign data wrapper multicorn options (
wrapper 'multicorn.testfdw.TestForeignDataWrapper'
);
CREATE user mapping for postgres server multicorn_srv options (usermapping 'test');
CREATE foreign table testmulticorn (
test1 date,
test2 timestamp
) server multicorn_srv options (
option1 'option1',
test_type 'date'
);
-- Test sort pushdown asked
EXPLAIN SELECT * FROM testmulticorn ORDER BY test1 DESC;
I have mismatch, described by this `diff expected actual`:
- Foreign Scan on testmulticorn (cost=10.00..400.00 rows=20 width=20)
+ Foreign Scan on testmulticorn (cost=10.00..400.00 rows=20 width=12)
Width 20 is understandable: this is value assigned to
`baserel->reltarget->width` in GetForeignRelSize callback function.
Origin of value `12' is unknown to me. I have some observations on how
width estimate propagates through callback functions, though.
Behaviour differs on different versions of postgresql:
1. Postgresql-11
* Value assigned to `baserel->reltarget->width` in GetForeignRelSize
callback stays same in GetForeignPaths, but in GetForeignPlan it is
changed. In this test, from 20 to 12.
* If I assign it in GetForeignPlan function back to value 20 (value can be
transfered via `baserel->fdw_private` field), expected value 20 will
appear in output of `psql`. Test fixed, but with no understanding
why.
2. Postgresql-9.6
* Value assigned to `baserel->reltarget->width` in GetForeignRelSize
stays the same in GetForeignPaths and GetForeignPlan, but `psql`
still outputs another value. Test failed.
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: dbogatov@interfacefinancial.com
Subject: Re: Unexpected plan width with foreign data wrapper
In-Reply-To: <20191004143550.GA30189@debian>
References: <20191004143550.GA30189@debian>
* 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