Delete in list with join using partitions generates monstrous query plan - Mailing list pgsql-bugs

From Alex
Subject Delete in list with join using partitions generates monstrous query plan
Date
Msg-id 1966497320.2175534.1608297773488@mail.yahoo.com
Whole thread Raw
List pgsql-bugs

I have a table with 80 partitions (product_property) partitioned on some column not used in the following query:

 

DELETE

FROM "product_property"

WHERE "product_property".."id" IN

    ( SELECT "product_property"."id"

     FROM "product_property"

     JOIN "product" ON "product_property"."product" = "product"."id"

     WHERE ("product"."language" = cast('ro' AS regconfig)

            AND "product_property"."secondary_meaning" = 'V') )

 

This query creates a plan where each partition uses a hash semi join with 80 index scans (one for each partition), with a total of 6643 index scans.

Interesting is that 5443 out of 6643 index scans are „never executed” .

This query also uses lots of memory (>500MB) and the planner time is ~10sec.



Querying only the subquery, returns no rows and plan uses one index scan per each partition, as expected, with a planning time of 118ms.


As the subquery plan is simple enough, I expected the delete to use something similar.

Any suggestion on improving the planned execution? Or it’s something you guys can do to optimize the planner on dev side?

 

I’ve attached the explain analyze for whole query and subquery.

Thanks

Attachment

pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #16780: Inconsistent recovery_target_xid handling across platforms
Next
From: "Colin 't Hart"
Date:
Subject: Re: BUG #16779: psql -e not showing queries