Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d3A1g-0006Zq-T1 for pgsql-performance@arkaria.postgresql.org; Tue, 25 Apr 2017 23:37:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1d3A1g-0001is-1A for pgsql-performance@arkaria.postgresql.org; Tue, 25 Apr 2017 23:37:44 +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 1d39zt-00075K-Gz for pgsql-performance@postgresql.org; Tue, 25 Apr 2017 23:35:53 +0000 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1d39zl-0003lB-S5 for pgsql-performance@postgresql.org; Tue, 25 Apr 2017 23:35:52 +0000 Received: by mail-wm0-x231.google.com with SMTP id r190so110300131wme.1 for ; Tue, 25 Apr 2017 16:35:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=l4SgXTX0Tj3X7p4KUcp2HxJx/i57nEOXQO5p9xILKXM=; b=0Vgl2mRMQ+AH8J87zdHWHnmJA3wQbT71IyHKWmB+HV+Ur3TlDBQmSgg33F1D/CHu6k 9hPvCIKGxP8h1u+e8u4A7I7xceHCAx8s52XlHmBHj8t87L3pJNVO2qdKJZ8+HbxmI6zn Ta7f54NpIIc60kLYLxq/lMGjfVOt0E1mzRKUNx41DqL4mlG0YdDZmNJ/lDJvXU//4eFG rFak2cEUB5MlBRcj6ITXJuUFz8yPBxBdUze20FXA4ddxvh8llHZh10P8Fp5RpWRCJKOC 3rxE/JqFEgklc5EtpFmlfNESJCmenN818ZBO3KeqxEytpRU4C7cO+6INJuzT6I6+E2Vv TDJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=l4SgXTX0Tj3X7p4KUcp2HxJx/i57nEOXQO5p9xILKXM=; b=WCbLwxMuLbNEcNXnYDpmmHO+ikjPnOE6eswmSgaafTFDaQ0yTEVT+5jkXKEwsul37j 4sPynySbQY9xkWz2mdWosIX9hWrAd9GW9sKnYoy3/OHr/nGVZo8oOmxphx+0zCPus8f4 vBv6c3JVxMaZL6YFyJXoj0pMbSK14QqR1xirj+skGoiXDr1NEaG9FyI1dlyhKoOcjAwL PgEy6JoY7ljcPXQ1Hd9qufKPq0hHWSeIzN7ESie4yIpi+ro1j6hM2xAUB+4Dqj5zbURx X71IhrozRZXypxa9KfgZrPM02c4/kEis1zHSh5gYJxGpiCP4gz5PVbXnKWRuRT9VBODo pVWA== X-Gm-Message-State: AN3rC/7fx/jG7M5pAvjfTKvJBxL01qVLz4i4xYMGEQalJPurt2xQI2zv nIjnwOQKxk/fKlP+wojcVeSxI5KdJTGiAOTrYogniAkJr0u++v7MxyIKJOQwhlEp3n4H+ckvGQl x8xdckIKOYEskycTjmZpx8IUeHija90AOlvM1siLNbtjNOUV5SYxlePDFGpeD5+lm3Emw0/9u8o Ex6Q== X-Received: by 10.28.222.70 with SMTP id v67mr3297622wmg.65.1493163342864; Tue, 25 Apr 2017 16:35:42 -0700 (PDT) Received: from [10.137.2.17] (ip-89-177-46-65.net.upcbroadband.cz. [89.177.46.65]) by smtp.gmail.com with ESMTPSA id 39sm2921442wru.50.2017.04.25.16.35.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 16:35:41 -0700 (PDT) Subject: Re: Delete, foreign key, index usage To: Johann Spies , pgsql-performance@postgresql.org References: <54e42679-7ec5-b097-db7b-f04c9abfc3c6@2ndquadrant.com> From: Tomas Vondra Message-ID: <8ad602a3-d623-d8d2-2f1a-c1b55b3258bf@2ndquadrant.com> Date: Wed, 26 Apr 2017 01:35:38 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 04/25/2017 08:28 AM, Johann Spies wrote: > On 24 April 2017 at 15:17, Tomas Vondra wrote: >> On 04/24/2017 08:48 AM, Johann Spies wrote: >>> >>> >>> Why would the planner prefer the use the gin index and not the btree >>> index in this case? >>> >> >> You'll need to show what queries are you running - that's a quite important >> piece of information, and I don't see it anywhere in this thread. Seeing >> explain plans would also be helpful. > > It is a simple "delete from wos_2017_1.article;" which causes a domino > effect deletes due to foreign keys. In the case of one table with more > than 50 million records where the primary key was also the foreign > key, the process only started to use the index when we built a gin > index. In the case of the "belongs_to" table (shown in my first > email) we first built a btree index on the foreign key - and it was > ignored. Only after the gin index was created did it use the index. > > Regards. > Johann Wouldn't it be easier to simply show the queries (with the exact condition) and the associated explain plans? I understand you're doing your best to explain what's happening, but the explain plans contain a lot of information that you might have missed. I suppose you actually did explain analyze to verify the query was not using the btree index and then started using the gin index. Or how did you verify that? Also, which PostgreSQL version have you observed this on? I see you've mentioned 9.6 when talking about parallel scans, but I suppose the issue was originally observed on some older version. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance