mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-18 03:23:37 +08:00
Plans that have a result relation set (DELETE or UPDATE) should not optimize subplans that contain append nodes. This is because the PostgreSQL must turn such plans on an inheritance table into a set of similar plans on each subtable (i.e., it needs to apply UPDATE and DELETE to each subtable and not just the parent). Optimizing such plans with, e.g., ConstraintAwareAppend makes the planner believe it only needs to do the DELETE or UPDATE on the root table, which means rows in subtables won't be affected.
38 lines
1.2 KiB
PL/PgSQL
38 lines
1.2 KiB
PL/PgSQL
\o /dev/null
|
|
\ir include/insert_two_partitions.sql
|
|
\o
|
|
|
|
SELECT * FROM "two_Partitions" ORDER BY "timeCustom", device_id;
|
|
|
|
DELETE FROM "two_Partitions" WHERE series_0 = 1.5;
|
|
DELETE FROM "two_Partitions" WHERE series_0 = 100;
|
|
SELECT * FROM "two_Partitions" ORDER BY "timeCustom", device_id;
|
|
|
|
-- Make sure DELETE isn't optimized if it includes Append plans
|
|
-- Need to turn of nestloop to make append appear the same on PG96 and PG10
|
|
set enable_nestloop = 'off';
|
|
|
|
CREATE OR REPLACE FUNCTION series_val()
|
|
RETURNS integer LANGUAGE PLPGSQL STABLE AS
|
|
$BODY$
|
|
BEGIN
|
|
RETURN 5;
|
|
END;
|
|
$BODY$;
|
|
|
|
-- ConstraintAwareAppend applied for SELECT
|
|
EXPLAIN (costs off)
|
|
SELECT FROM "two_Partitions"
|
|
WHERE series_1 IN (SELECT series_1 FROM "two_Partitions" WHERE series_1 > series_val());
|
|
|
|
-- ConstraintAwareAppend NOT applied for DELETE
|
|
EXPLAIN (costs off)
|
|
DELETE FROM "two_Partitions"
|
|
WHERE series_1 IN (SELECT series_1 FROM "two_Partitions" WHERE series_1 > series_val());
|
|
|
|
|
|
SELECT * FROM "two_Partitions" ORDER BY "timeCustom", device_id;
|
|
DELETE FROM "two_Partitions"
|
|
WHERE series_1 IN (SELECT series_1 FROM "two_Partitions" WHERE series_1 > series_val());
|
|
SELECT * FROM "two_Partitions" ORDER BY "timeCustom", device_id;
|