Fix joins in RETURNING

To make it work, it is enough to properly pass the parent of the
PlanState while initializing the projection in RETURNING clause.
This commit is contained in:
Alexander Kuzmenkov 2022-08-23 18:30:20 +03:00 committed by Alexander Kuzmenkov
parent 1fa8373931
commit ae6773fca6
5 changed files with 108 additions and 1 deletions

View File

@ -20,6 +20,7 @@ accidentally triggering the load of a previous DB version.**
* #4575 Fix use of `get_partition_hash` and `get_partition_for_key` inside an IMMUTABLE function * #4575 Fix use of `get_partition_hash` and `get_partition_for_key` inside an IMMUTABLE function
* #4611 Fix a potential OOM when loading large data sets into a hypertable * #4611 Fix a potential OOM when loading large data sets into a hypertable
* #4646 Fix time_bucket_ng origin handling * #4646 Fix time_bucket_ng origin handling
* #4647 Fix the error "SubPlan found with no parent plan" that occurred if using joins in RETURNING clause.
**Thanks** **Thanks**
@AlmiS for reporting error on `get_partition_hash` executed inside an IMMUTABLE function @AlmiS for reporting error on `get_partition_hash` executed inside an IMMUTABLE function
@ -28,6 +29,7 @@ accidentally triggering the load of a previous DB version.**
@michaelkitson for reporting permission errors using default privileges on Continuous Aggregates @michaelkitson for reporting permission errors using default privileges on Continuous Aggregates
@ninjaltd and @mrksngl for reporting a potential OOM when loading large data sets into a hypertable @ninjaltd and @mrksngl for reporting a potential OOM when loading large data sets into a hypertable
@ssmoss for reporting an issue with time_bucket_ng origin handling @ssmoss for reporting an issue with time_bucket_ng origin handling
@mwahlhuetter for reporting error in joins in RETURNING clause
## 2.7.2 (2022-07-26) ## 2.7.2 (2022-07-26)

View File

@ -160,7 +160,7 @@ get_adjusted_projection_info_returning(ProjectionInfo *orig, List *returning_cla
return ExecBuildProjectionInfo(returning_clauses, return ExecBuildProjectionInfo(returning_clauses,
orig->pi_exprContext, orig->pi_exprContext,
orig->pi_state.resultslot, orig->pi_state.resultslot,
NULL, orig->pi_state.parent,
chunk_desc); chunk_desc);
} }

View File

@ -0,0 +1,58 @@
-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
CREATE TABLE standard_table (
standard_id integer PRIMARY KEY,
name text not null
);
CREATE TABLE hypertable (
time timestamptz not null,
name text not null,
standard_id integer not null
);
select * from create_hypertable('hypertable', 'time');
hypertable_id | schema_name | table_name | created
---------------+-------------+------------+---------
1 | public | hypertable | t
(1 row)
INSERT INTO standard_table (standard_id, name)
VALUES (1, 'standard_1');
INSERT INTO hypertable (time, name, standard_id)
VALUES ('2021-01-01 01:01:01+00', 'hypertable_1', 1);
INSERT INTO hypertable (time, name, standard_id)
VALUES ('2022-02-02 02:02:02+00', 'hypertable_2', 1)
RETURNING *, EXISTS (
SELECT *
FROM standard_table
WHERE standard_table.standard_id = hypertable.standard_id
);
time | name | standard_id | exists
------------------------------+--------------+-------------+--------
Tue Feb 01 18:02:02 2022 PST | hypertable_2 | 1 | t
(1 row)
INSERT INTO hypertable (time, name, standard_id)
VALUES ('2023-03-03 03:03:03+00', 'hypertable_3', 1)
RETURNING *, EXISTS (
SELECT *
FROM standard_table
WHERE standard_table.standard_id = hypertable.standard_id
);
time | name | standard_id | exists
------------------------------+--------------+-------------+--------
Thu Mar 02 19:03:03 2023 PST | hypertable_3 | 1 | t
(1 row)
INSERT INTO hypertable (time, name, standard_id)
VALUES ('2024-04-04 04:04:04+00', 'hypertable_4', 2)
RETURNING *, EXISTS (
SELECT *
FROM standard_table
WHERE standard_table.standard_id = hypertable.standard_id
);
time | name | standard_id | exists
------------------------------+--------------+-------------+--------
Wed Apr 03 21:04:04 2024 PDT | hypertable_4 | 2 | f
(1 row)

View File

@ -26,6 +26,7 @@ set(TEST_FILES
information_views.sql information_views.sql
insert_many.sql insert_many.sql
insert_single.sql insert_single.sql
insert_returning.sql
lateral.sql lateral.sql
misc.sql misc.sql
parallel.sql parallel.sql

View File

@ -0,0 +1,46 @@
-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
CREATE TABLE standard_table (
standard_id integer PRIMARY KEY,
name text not null
);
CREATE TABLE hypertable (
time timestamptz not null,
name text not null,
standard_id integer not null
);
select * from create_hypertable('hypertable', 'time');
INSERT INTO standard_table (standard_id, name)
VALUES (1, 'standard_1');
INSERT INTO hypertable (time, name, standard_id)
VALUES ('2021-01-01 01:01:01+00', 'hypertable_1', 1);
INSERT INTO hypertable (time, name, standard_id)
VALUES ('2022-02-02 02:02:02+00', 'hypertable_2', 1)
RETURNING *, EXISTS (
SELECT *
FROM standard_table
WHERE standard_table.standard_id = hypertable.standard_id
);
INSERT INTO hypertable (time, name, standard_id)
VALUES ('2023-03-03 03:03:03+00', 'hypertable_3', 1)
RETURNING *, EXISTS (
SELECT *
FROM standard_table
WHERE standard_table.standard_id = hypertable.standard_id
);
INSERT INTO hypertable (time, name, standard_id)
VALUES ('2024-04-04 04:04:04+00', 'hypertable_4', 2)
RETURNING *, EXISTS (
SELECT *
FROM standard_table
WHERE standard_table.standard_id = hypertable.standard_id
);