Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ee0Li-0007EB-QA for pgsql-performance@arkaria.postgresql.org; Tue, 23 Jan 2018 15:18:59 +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 1ee0Lh-0007jv-V1 for pgsql-performance@arkaria.postgresql.org; Tue, 23 Jan 2018 15:18:57 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ee0Lh-0007WF-41 for pgsql-performance@lists.postgresql.org; Tue, 23 Jan 2018 15:18:57 +0000 Received: from mail-it0-x22e.google.com ([2607:f8b0:4001:c0b::22e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ee0Ld-0002xv-5X for pgsql-performance@lists.postgresql.org; Tue, 23 Jan 2018 15:18:56 +0000 Received: by mail-it0-x22e.google.com with SMTP id e1so1399692ita.0 for ; Tue, 23 Jan 2018 07:18:52 -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=MJKbSpKyhT7gMdmKSuHU/HvSL6SH9+usPlJ+G9R9Xg8=; b=EDrGVjo/U+RgNCdyWQt3KmhNBYpR8BboyNz3XZtBu7Yd9N3OpnHc1o6RDV0QPjMSbf krz4ZEovcA1OzRwxBsizgGPcLbcADxJN0Y7GvRyzM5YgwUmjx/njKeSS61GTypw1q5aS ze/VHwx74n3zCBjVsP5rowjpLctAOJN6gjPKaSY57GMY2zBc/nWNqCYXVTgD2bdUCjzt FeUEIo/v6wzafE/GCu2BiV6da5GVxKPFtxBBkDyEMkMr2iIk+ljdBOrpMA6ixKv+lLJf BNvNKOhQVp4qkRQp6h7JMZK6vFhvLwzspZ1DFcznEg6QBqI2WlTq81QFdnkK5fAJVs6g 3bkg== 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=MJKbSpKyhT7gMdmKSuHU/HvSL6SH9+usPlJ+G9R9Xg8=; b=Yjl55FYNhzHBAbBB4PYv3nK57Ejaei7OjWywyG7FwVWX5zLCW1nMJdvDjFtvs5la1m Nxm3RwITbh9osdNiEPD8Y7Oybuj5CxFFh0B+6nKH31HyUXZO70gI2cKR5ywRuIqTv6n3 sE9fyQihR7X5BwkgS4atmU2B2Cpk55Ckwb74b5qSBrqxrrlJ58MVypRmMJxVke59bGxO ghlYOCrIJCLE8A41fdkWSEIYku2zNDuYtdqIXReRxJVqpmFaLRBoiNWjvm57uXcsWpje g4Ni93JIrVafiQkXQ2a2CVo0tBFwf1cIxcGGoZYjNKeVDlNT/Iy2yMaERGIBd1SWWXou zikA== X-Gm-Message-State: AKwxyte+H8KijaWQC/EwGCH8mwttLac66e4zXDL2yPorkfXsc58h5WB7 VcrAI1aw6wZYRM8MuvC+WZC9ng== X-Google-Smtp-Source: AH8x224wG/asDjYuC65fSJLrpFlhzQwrhiGHr3wDRiQ7goK1VEEPLdQ2YHzKP+4JQfvUhFXxBQ7l8g== X-Received: by 10.36.210.133 with SMTP id z127mr4265405itf.116.1516720729982; Tue, 23 Jan 2018 07:18:49 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id j10sm3120254ioo.24.2018.01.23.07.18.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jan 2018 07:18:49 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id 7E8D1800FD9; Tue, 23 Jan 2018 09:18:48 -0600 (CST) Date: Tue, 23 Jan 2018 09:18:48 -0600 From: Justin Pryzby To: Laurent Martelli Cc: pgsql-performance@lists.postgresql.org Subject: Re: Bad plan Message-ID: <20180123151848.GC25452@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.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Jan 23, 2018 at 01:03:49PM +0100, Laurent Martelli wrote: > Hello all, > > So I have a view, for which I can select all rows in about 3s (returns ~80k > rows), but if I add a where clause on a column, it takes +300s to return > the ~8k lines. > > From the plan, I see that it expects to return only 1 row and so choose to > perform some nested loops. Of course, I did run "ANALYZE", but with no > success. > > I managed to speed things up with "set enable_nestloop = false;", but is > that the only choice I have ? Should I report a bug ? > Here is the default plan : Can you resend without line breaks or paste a link to explain.depesz? The problem appears to be here: -> Nested Loop Left Join (cost=32067.09..39197.85 rows=1 width=276) (actual time=342.725..340775.031 rows=7359 loops=1) Join Filter: (sh.share_holder_partner = partner.id) Rows Removed by Join Filter: 204915707 Justin