Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Zr2zr-00063N-Bz for pgsql-performance@arkaria.postgresql.org; Tue, 27 Oct 2015 12:04:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Zr2zq-0001Xi-8p for pgsql-performance@arkaria.postgresql.org; Tue, 27 Oct 2015 12:04:58 +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) (envelope-from ) id 1Zr2yD-00086S-GL for pgsql-performance@postgresql.org; Tue, 27 Oct 2015 12:03:17 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Zr2yB-00079P-41 for pgsql-performance@postgresql.org; Tue, 27 Oct 2015 12:03:17 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t9RC3CDk021873; Tue, 27 Oct 2015 08:03:12 -0400 From: Tom Lane To: Bertrand Paquet cc: pgsql-performance@postgresql.org Subject: Re: Query planner wants to use seq scan In-reply-to: References: Comments: In-reply-to Bertrand Paquet message dated "Tue, 27 Oct 2015 10:35:27 +0100" Date: Tue, 27 Oct 2015 08:03:12 -0400 Message-ID: <21872.1445947392@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 Bertrand Paquet writes: > We have a slow query. After analyzing, the planner decision seems to be > discutable : the query is faster when disabling seqscan. See below the two > query plan, and an extract from pg_stats. > Any idea about what to change to help the planner ? Neither one of those plans is very good: you're just hoping that the Filter condition will let a tuple through sooner rather than later. If you care about the performance of this type of query, I'd consider creating an index on (organization_id, status, handled_by) so that all the conditions can be checked in the index. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance