Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVNbi-0004Wo-7a for pgsql-performance@arkaria.postgresql.org; Thu, 14 Nov 2019 22:28:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVNbh-0000YJ-1Y for pgsql-performance@arkaria.postgresql.org; Thu, 14 Nov 2019 22:28:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVNbg-0000YC-LM for pgsql-performance@lists.postgresql.org; Thu, 14 Nov 2019 22:28:52 +0000 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVNbd-0000C7-Iy for pgsql-performance@lists.postgresql.org; Thu, 14 Nov 2019 22:28:52 +0000 Received: by mail-yb1-xb42.google.com with SMTP id k17so3269059ybp.1 for ; Thu, 14 Nov 2019 14:28:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=R6Pk1K/08CVPR8vr+Pi8VX4sk6xuIM5djVVamtFxfSw=; b=0V8vgXQ/CEdUsYw+g7bZFDRGkgaptmxZaoBtQSLNH9e+OtNUaf94UWjgcPiFvpXq3F mwuc+MXHsYIlFUMrkTPzaj6VSuIScx6XTS3bad1iId9AvqwPYPZ5QzYFOSBlp4Zouy2a jQXE0nMUiqjlf9Zjbh5N2MliyWzgPiodW01fE86Z5GxPL5cb+q7Dl5UhBPCzgcvWUsO8 0feLzcuUFrDaTWKrFih45O1z0atsImlSkQfMlMMMhLTIG0W2yHpdeIHUBNlKYtc/OII2 OYcV3IpX1Ky4Vl3Nl2XNltFLHFr1z78K2vRfxmUR2KwZpRsW2OK48bLluTNwmFeVOrWh 2Ucw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=R6Pk1K/08CVPR8vr+Pi8VX4sk6xuIM5djVVamtFxfSw=; b=Gs4vE2ThKYvHVFJv9kKmAiIkUCmTn1CcJm37h9FXBkpu2DlS6p2ugxrk6pwzYCF+bQ 1jY2WLdYUwfEORbtYkp43XWfZRjfnBBiMVHe/2pB+TpPuvPsST2eiNUA5B5Up874TTHN icsz2w9jt9fKWFZjaWOOAMJZaoEFJf6V4vMKrXT1gAmMiNSKR5vaponzUPizAPRqZqhA RgT6Z5v5xTLI678G/zWpczZ+IMTd5iOTgYqxVYNHtoMLx+GvP6DD2vTnw2xqnukbDY+R H4PAN+zrsj9ECL1F87Vlh518kDGKzZsAwOU2Z2CQQQF00o4kjSTs5f21tbVlnC5rByTj 11dQ== X-Gm-Message-State: APjAAAXrOu0etawNTi9vfOKArY+UZSodFSxGpvP+MhnHEJYLA9uERwnX G6DJJMhtO8a9j/vjKD1hEQ+5uw== X-Google-Smtp-Source: APXvYqz1PdRpKjC3r7KJpUlyNHljSMcSvhXpVmqWSGWehWLolJAvjtveDMaqpJBTz7DqFXc5Sn/Dkg== X-Received: by 2002:a25:2086:: with SMTP id g128mr9400320ybg.261.1573770527609; Thu, 14 Nov 2019 14:28:47 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id m20sm2298396ywd.104.2019.11.14.14.28.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Nov 2019 14:28:46 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id 8B1D9800AA7; Thu, 14 Nov 2019 16:28:45 -0600 (CST) Date: Thu, 14 Nov 2019 16:28:45 -0600 From: Justin Pryzby To: Craig James Cc: pgsql-performance@lists.postgresql.org Subject: Re: Simple DELETE on modest-size table runs 100% CPU forever Message-ID: <20191114222845.GW2923@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Nov 14, 2019 at 02:19:51PM -0800, Craig James 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: > > explain analyze > select count(1) from registry.categories > where category_id = 15 and id in > (select c.id from registry.categories c > left join registry.category_staging_15 st on (c.id = st.id) where > c.category_id = 15 and st.id is null); > > If I leave out the "analyze", here's what I get (note that the Do you mean that you're doing DELETE..USING, and that's an explain for SELECT COUNT() with same join conditions ? Can you show explain for the DELETE, and \d for the tables ? If there's FKs, do the other tables have indices on their referencING columns ? https://www.postgresql.org/docs/devel/static/ddl-constraints.html#DDL-CONSTRAINTS-FK "Since a DELETE of a row from the referenced table [...] will require a scan of the referencing table for rows matching the old value, it is often a good idea to index the referencing columns too." Justin