-
Notifications
You must be signed in to change notification settings - Fork 907
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mark hypertable parent as dummy rel for UPDATE
When postgres expands an inheritance tree it also adds the parent hypertable as child relation. Since for a hypertable the parent will never have any data we can mark this relation as dummy relation so it gets ignored in later steps. This is only relevant for code paths that use the postgres inheritance code as we don't include the hypertable as child when expanding the hypertable ourself. This is similar to 3c40f92 which did the same adjustment for DELETE. This patch also moves the marking into get_relation_info_hook so it happens a bit earlier and prevents some additional cycles.
- Loading branch information
Showing
13 changed files
with
461 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
-- 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 cursor_test(time timestamptz, device_id int, temp float); | ||
SELECT create_hypertable('cursor_test','time'); | ||
NOTICE: adding not-null constraint to column "time" | ||
create_hypertable | ||
-------------------------- | ||
(1,public,cursor_test,t) | ||
(1 row) | ||
|
||
INSERT INTO cursor_test SELECT '2000-01-01',1,0.5; | ||
INSERT INTO cursor_test SELECT '2001-01-01',1,0.5; | ||
INSERT INTO cursor_test SELECT '2002-01-01',1,0.5; | ||
\set ON_ERROR_STOP 0 | ||
BEGIN; | ||
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM cursor_test; | ||
FETCH NEXT FROM c1; | ||
time | device_id | temp | ||
------------------------------+-----------+------ | ||
Sat Jan 01 00:00:00 2000 PST | 1 | 0.5 | ||
(1 row) | ||
|
||
-- this will produce an error on PG < 14 because PostgreSQL checks | ||
-- for the existence of a scan node with the relation id for every relation | ||
-- used in the update plan in the plan of the cursor. | ||
UPDATE cursor_test SET temp = 0.7 WHERE CURRENT OF c1; | ||
ERROR: cursor "c1" is not a simply updatable scan of table "cursor_test" | ||
COMMIT; | ||
-- test cursor with no chunks left after runtime exclusion | ||
BEGIN; | ||
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM cursor_test WHERE time > now(); | ||
UPDATE cursor_test SET temp = 0.7 WHERE CURRENT OF c1; | ||
ERROR: cursor "c1" is not a simply updatable scan of table "cursor_test" | ||
COMMIT; | ||
-- test cursor with no chunks left after planning exclusion | ||
BEGIN; | ||
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM cursor_test WHERE time > '2010-01-01'; | ||
UPDATE cursor_test SET temp = 0.7 WHERE CURRENT OF c1; | ||
ERROR: cursor "c1" is not a simply updatable scan of table "cursor_test" | ||
COMMIT; | ||
\set ON_ERROR_STOP 1 | ||
SET timescaledb.enable_constraint_exclusion TO off; | ||
BEGIN; | ||
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM cursor_test; | ||
FETCH NEXT FROM c1; | ||
time | device_id | temp | ||
------------------------------+-----------+------ | ||
Sat Jan 01 00:00:00 2000 PST | 1 | 0.5 | ||
(1 row) | ||
|
||
UPDATE cursor_test SET temp = 0.7 WHERE CURRENT OF c1; | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- 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 cursor_test(time timestamptz, device_id int, temp float); | ||
SELECT create_hypertable('cursor_test','time'); | ||
NOTICE: adding not-null constraint to column "time" | ||
create_hypertable | ||
-------------------------- | ||
(1,public,cursor_test,t) | ||
(1 row) | ||
|
||
INSERT INTO cursor_test SELECT '2000-01-01',1,0.5; | ||
INSERT INTO cursor_test SELECT '2001-01-01',1,0.5; | ||
INSERT INTO cursor_test SELECT '2002-01-01',1,0.5; | ||
\set ON_ERROR_STOP 0 | ||
BEGIN; | ||
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM cursor_test; | ||
FETCH NEXT FROM c1; | ||
time | device_id | temp | ||
------------------------------+-----------+------ | ||
Sat Jan 01 00:00:00 2000 PST | 1 | 0.5 | ||
(1 row) | ||
|
||
-- this will produce an error on PG < 14 because PostgreSQL checks | ||
-- for the existence of a scan node with the relation id for every relation | ||
-- used in the update plan in the plan of the cursor. | ||
UPDATE cursor_test SET temp = 0.7 WHERE CURRENT OF c1; | ||
COMMIT; | ||
-- test cursor with no chunks left after runtime exclusion | ||
BEGIN; | ||
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM cursor_test WHERE time > now(); | ||
UPDATE cursor_test SET temp = 0.7 WHERE CURRENT OF c1; | ||
ERROR: cursor "c1" is not a simply updatable scan of table "_hyper_1_1_chunk" | ||
COMMIT; | ||
-- test cursor with no chunks left after planning exclusion | ||
BEGIN; | ||
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM cursor_test WHERE time > '2010-01-01'; | ||
UPDATE cursor_test SET temp = 0.7 WHERE CURRENT OF c1; | ||
ERROR: cursor "c1" is not a simply updatable scan of table "_hyper_1_1_chunk" | ||
COMMIT; | ||
\set ON_ERROR_STOP 1 | ||
SET timescaledb.enable_constraint_exclusion TO off; | ||
BEGIN; | ||
DECLARE c1 SCROLL CURSOR FOR SELECT * FROM cursor_test; | ||
FETCH NEXT FROM c1; | ||
time | device_id | temp | ||
------------------------------+-----------+------ | ||
Sat Jan 01 00:00:00 2000 PST | 1 | 0.7 | ||
(1 row) | ||
|
||
UPDATE cursor_test SET temp = 0.7 WHERE CURRENT OF c1; | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.