Re: Simple DELETE on modest-size table runs 100% CPU forever

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Craig James <cjames(at)emolecules(dot)com>
Cc: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Simple DELETE on modest-size table runs 100% CPU forever
Date: 2019-11-15 22:44:48
Message-ID: CAMkU=1xR=Ydki=tb5ZLHMdFJewipA01ECZGKtvomDdqSsXNTAw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Thu, Nov 14, 2019 at 5:20 PM Craig James <cjames(at)emolecules(dot)com> wrote:

> I'm completely baffled by this problem: I'm doing a delete that joins
> three modest-sized tables, and it gets completely stuck: 100% CPU use
> forever. Here's the query:
>
>
> Aggregate (cost=193.54..193.55 rows=1 width=8)
> -> Nested Loop Semi Join (cost=0.84..193.54 rows=1 width=0)
> Join Filter: (categories.id = c.id)
> -> Index Scan using i_categories_category_id on categories
> (cost=0.42..2.44 rows=1 width=4)
> Index Cond: (category_id = 23)
> -> Nested Loop Anti Join (cost=0.42..191.09 rows=1 width=4)
> Join Filter: (c.id = st.id)
> -> Index Scan using i_categories_category_id on categories
> c (cost=0.42..2.44 rows=1 width=4)
> Index Cond: (category_id = 23)
> -> Seq Scan on category_staging_23 st (cost=0.00..99.40
> rows=7140 width=4)
>

If the estimates were correct, this shouldn't be slow. But how can it
screw up the estimate for this by much, when the conditions are so simple?
How many rows are there actually in categories where category_id=23?

What do you see in `select * from pg_stats where tablename='categories' and
attname='category_id' \x\g\x`?

Since it thinks the seq scan of category_staging_23 is only going to
happen once (at the bottom of two nested loops, but each executing just
once) it sees no benefit in hashing that table. Of course it is actually
happening a lot more than once.

Cheers,

Jeff

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Craig James 2019-11-16 00:26:55 Re: Simple DELETE on modest-size table runs 100% CPU forever
Previous Message Ravi Rai 2019-11-15 21:11:41 RE: Simple DELETE on modest-size table runs 100% CPU forever