Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eObfw-0003Ar-1w for pgsql-general@arkaria.postgresql.org; Tue, 12 Dec 2017 03:56:12 +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 1eObfu-00044s-J2 for pgsql-general@arkaria.postgresql.org; Tue, 12 Dec 2017 03:56:10 +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 1eObfu-00044i-Bl for pgsql-general@lists.postgresql.org; Tue, 12 Dec 2017 03:56:10 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eObfq-0006N3-T8 for pgsql-general@postgresql.org; Tue, 12 Dec 2017 03:56:09 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 76741A048258 for ; Mon, 11 Dec 2017 20:56:04 -0700 (MST) Date: Mon, 11 Dec 2017 20:56:04 -0700 (MST) From: Jim Finnerty To: pgsql-general@postgresql.org Message-ID: <1513050964482-0.post@n3.nabble.com> In-Reply-To: References: Subject: Re: Why the planner does not use index for a large amount of data? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Hmidi, Your description omits some important information, such as whether you defined your index to include all columns needed by the request, but the short answer is 'yes', if you retrieve enough rows, then it will be faster to read the entire heap instead of reading the necessary parts of the index and all the referenced pages of the heap, in index order. The decision is more complex than just this in PostgreSQL due to MVCC, the visibility bits on each page, and the alternative of doing a bitmap heap scan when the selectivity is moderate. The planner is designed to consider all these factors, cost them, and choose a minimum cost plan. If you're convinced that the planner has not picked the fastest plan, you can either try to force the plan by setting the enable_* guc variables, or you can use the pg_hint_plan extension (which sets the enable_* variables on your behalf), to get the plan you want, and then measure the performance of the query with each alternative. /Jim F -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html