Re: EXPLAIN PLAN for DELETE CASCADE or DELETE not using pkey index despite EXPLAINing that it would?

2019-03-21 Thread Tom Lane
Gunther writes: > I have 250 rows to delete, but they are a target to a bunch of child > tables with foreign key on delete cascade. > EXPLAIN DELETE FROM Foo WHERE id = (SELECT fooId FROM Garbage); > shows me that it uses the nested loop by Foo_pkey index to find the 250 > items from Garbage t

EXPLAIN PLAN for DELETE CASCADE or DELETE not using pkey index despite EXPLAINing that it would?

2019-03-21 Thread Gunther
Hi, I have 250 rows to delete, but they are a target to a bunch of child tables with foreign key on delete cascade. EXPLAIN DELETE FROM Foo WHERE id = (SELECT fooId FROM Garbage); shows me that it uses the nested loop by Foo_pkey index to find the 250 items from Garbage to be deleted. But

Re: Poor man's partitioned index .... not being used?

2019-03-21 Thread Gunther
Thanks David Rowley and Andrew Gierth. On 3/20/2019 23:46, Andrew Gierth wrote: If you did WHERE mod(id,2) = mod(8934,2) AND id = 8934 then the index would likely be used - because the prover can then treat mod(id,2) as an atom (call it X), constant-fold mod(8934,2) to 0 because mod() is immut