1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-14 08:21:07 +03:00

Optimize nested ConvertRowtypeExpr nodes.

A ConvertRowtypeExpr is used to translate a whole-row reference of a
child to that of a parent. The planner produces nested
ConvertRowtypeExpr while translating whole-row reference of a leaf
partition in a multi-level partition hierarchy. Executor then
translates the whole-row reference from the leaf partition into all
the intermediate parent's whole-row references before arriving at the
final whole-row reference. It could instead translate the whole-row
reference from the leaf partition directly to the top-most parent's
whole-row reference skipping any intermediate translations.

Ashutosh Bapat, with tests by Kyotaro Horiguchi and some
editorialization by me. Reviewed by Andres Freund, Pavel Stehule,
Kyotaro Horiguchi, Dmitry Dolgov, Tom Lane.
This commit is contained in:
Andrew Gierth
2018-11-06 14:19:40 +00:00
parent c24dcd0cfd
commit 5613da4cc7
3 changed files with 69 additions and 0 deletions

View File

@ -764,6 +764,8 @@ NOTICE: drop cascades to table c1
-- tables. See the pgsql-hackers thread beginning Dec. 4/04
create table base (i integer);
create table derived () inherits (base);
create table more_derived (like derived, b int) inherits (derived);
NOTICE: merging column "i" with inherited definition
insert into derived (i) values (0);
select derived::base from derived;
derived
@ -777,6 +779,22 @@ select NULL::derived::base;
(1 row)
-- remove redundant conversions.
explain (verbose on, costs off) select row(i, b)::more_derived::derived::base from more_derived;
QUERY PLAN
-------------------------------------------
Seq Scan on public.more_derived
Output: (ROW(i, b)::more_derived)::base
(2 rows)
explain (verbose on, costs off) select (1, 2)::more_derived::derived::base;
QUERY PLAN
-----------------------
Result
Output: '(1)'::base
(2 rows)
drop table more_derived;
drop table derived;
drop table base;
create table p1(ff1 int);

View File

@ -237,9 +237,14 @@ drop table p1 cascade;
-- tables. See the pgsql-hackers thread beginning Dec. 4/04
create table base (i integer);
create table derived () inherits (base);
create table more_derived (like derived, b int) inherits (derived);
insert into derived (i) values (0);
select derived::base from derived;
select NULL::derived::base;
-- remove redundant conversions.
explain (verbose on, costs off) select row(i, b)::more_derived::derived::base from more_derived;
explain (verbose on, costs off) select (1, 2)::more_derived::derived::base;
drop table more_derived;
drop table derived;
drop table base;