Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMGvp-0008V4-5x for pgsql-performance@arkaria.postgresql.org; Tue, 05 Dec 2017 17:22:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMGvn-0003yv-Uc for pgsql-performance@arkaria.postgresql.org; Tue, 05 Dec 2017 17:22:55 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eMGvn-0003ym-IQ for pgsql-performance@lists.postgresql.org; Tue, 05 Dec 2017 17:22:55 +0000 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eMGvk-0006SV-RV for pgsql-performance@lists.postgresql.org; Tue, 05 Dec 2017 17:22:54 +0000 Received: by mail-qt0-x242.google.com with SMTP id f2so2536195qtj.4 for ; Tue, 05 Dec 2017 09:22:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=/ev3uExRAhAkmQSPEpEe6wDzyBUhPr5PPzIZDUi5Q/w=; b=kZRqrp8cR1f54OblMnR0Uvyl2HKzLXHJ76J0xS2/4ZTwDlO5BRSVvFSsdfh+bNVr/O siDRibL9o5IzfgXsI+z/zLAtTI3fPn4X+6uG+OpKwMjTO+qd/yUbqxjwQgn/9OB7m7Mp XVodSXoUpg+L+ctaKwg7LAKYzMmPLZP/fc2HLSQ13cSJrzk1s9WLLn+VBaT7Gof4zJwn xglyDkuFGiwfV3IKkiwBkGpwi/K8X0IgPPRwHhGC/hQQU+ejEgQw5Pdt/T/y1VHGjN2B /q4cN9Fr/k50xsrV++gei1Ueyo+DVBp1oHJ1ly1TDgIIQlvgy3sOslxVktovjis0zxtd Dw6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=/ev3uExRAhAkmQSPEpEe6wDzyBUhPr5PPzIZDUi5Q/w=; b=njjzwyUu+/Ei90taxJW4o8f4Ty/fC2ld0dXe7dU7DMBBcg29uRSrtnxN+7/5oi2fsx flIr7PDeiMsQ/To/cECR5nWPHv/OYkW5ByfYnuuTHL303yYJA+NDOXUV3UWel+r0dPAE Oisd8+wGITnsgkdmKWBvAsjemsN2YSBX6d9Ch1CDCGmRYaQj8JucGstemeqdOTQpL0Dn w8WlYHNMKojkckgFPjeUeZowepHUQg5sEUbGnoPt5erj65OTL1vVtsiAWI4dRf2Z2RVB MykA3+XdWpvLSVSstSx/awGNQ4Ks0TdjBoqtAIWdQk5+FQzdyNZx7Um3Ev+LQzXc2DwN ViTA== X-Gm-Message-State: AKGB3mKeSXG/8Bts3KmFQyfN9U7MnGIbuVE0JjU6feJ2Ip8ON+G+00oy 38Iatf4GnmXqQbfBUBmzzrOUiA== X-Google-Smtp-Source: AGs4zMaSHa+sKD2iO9r0wH2AvhHQ0aoxB2NkmkPKkjVC1fxE+M4+uolB0KypY3DAsJMzhZ5/1vD8ww== X-Received: by 10.55.201.11 with SMTP id q11mr22140914qki.303.1512494571405; Tue, 05 Dec 2017 09:22:51 -0800 (PST) Received: from [192.168.1.6] ([181.213.88.188]) by smtp.gmail.com with ESMTPSA id o64sm360157qte.62.2017.12.05.09.22.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Dec 2017 09:22:49 -0800 (PST) Subject: Re: Extremely slow DELETE with cascade foreign keys To: Alvaro Herrera Cc: pgsql-performance@lists.postgresql.org References: <20171205164328.6t4w3abfpzp54y2y@alvherre.pgsql> From: Rodrigo Rosenfeld Rosas Message-ID: <3c0737b6-091b-9de4-7d7a-51f78544fc0d@gmail.com> Date: Tue, 5 Dec 2017 15:22:45 -0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20171205164328.6t4w3abfpzp54y2y@alvherre.pgsql> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: pt-BR List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Em 05-12-2017 14:43, Alvaro Herrera escreveu: > Rodrigo Rosenfeld Rosas wrote: > >> explain analyze delete from field_values where transaction_id=226; >> QUERY PLAN >> --------------------------------------------------------------------------------------------------------------------------------------------------------------- >>  Delete on field_values  (cost=0.43..257.93 rows=481 width=6) (actual >> time=367375.805..367375.805 rows=0 loops=1) >>    ->  Index Scan using index_field_values_on_transaction_id on >> field_values  (cost=0.43..257.93 rows=481 width=6) (actual time=0.223..4.216 >> rows=651 loops=1) >>          Index Cond: (transaction_id = 226) >>  Planning time: 0.234 ms >>  Execution time: 367375.882 ms >> (5 registros) >> >> Time: 367377,085 ms (06:07,377) > Normally this is because you lack indexes on the referencing columns, so > the query that scans the table to find the referencing rows is a > seqscan. > Thank you, Álvaro, that was indeed the case, just like Tom Lane suggested as well. I found the missing index and fixed it. Thanks :)