mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-23 14:39:15 +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.
37 lines
1.1 KiB
PL/PgSQL
37 lines
1.1 KiB
PL/PgSQL
\o /dev/null
|
|
\ir include/insert_single.sql
|
|
\o
|
|
|
|
-- Make sure UPDATE 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 "one_Partition"
|
|
WHERE series_1 IN (SELECT series_1 FROM "one_Partition" WHERE series_1 > series_val());
|
|
|
|
-- ConstraintAwareAppend NOT applied for UPDATE
|
|
EXPLAIN (costs off)
|
|
UPDATE "one_Partition"
|
|
SET series_1 = 8
|
|
WHERE series_1 IN (SELECT series_1 FROM "one_Partition" WHERE series_1 > series_val());
|
|
|
|
SELECT * FROM "one_Partition" ORDER BY "timeCustom", device_id;
|
|
UPDATE "one_Partition"
|
|
SET series_1 = 8
|
|
WHERE series_1 IN (SELECT series_1 FROM "one_Partition" WHERE series_1 > series_val());
|
|
SELECT * FROM "one_Partition" ORDER BY "timeCustom", device_id;
|
|
|
|
UPDATE "one_Partition" SET series_1 = 47;
|
|
UPDATE "one_Partition" SET series_bool = true;
|
|
SELECT * FROM "one_Partition" ORDER BY "timeCustom", device_id;
|