Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g5sy2-0006ev-05 for pgsql-general@arkaria.postgresql.org; Fri, 28 Sep 2018 13:38:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g5sy0-0005nk-91 for pgsql-general@arkaria.postgresql.org; Fri, 28 Sep 2018 13:38:00 +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.89) (envelope-from ) id 1g5sxz-0005nR-U8 for pgsql-general@lists.postgresql.org; Fri, 28 Sep 2018 13:38:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g5sxx-00074Z-5A for pgsql-general@postgresql.org; Fri, 28 Sep 2018 13:37:58 +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 w8SDbtGH020312; Fri, 28 Sep 2018 09:37:55 -0400 From: Tom Lane To: Arup Rakshit cc: pgsql-general@postgresql.org Subject: Re: Why my query not using index to sort? In-reply-to: References: Comments: In-reply-to Arup Rakshit message dated "Fri, 28 Sep 2018 18:14:25 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20310.1538141875.1@sss.pgh.pa.us> Date: Fri, 28 Sep 2018 09:37:55 -0400 Message-ID: <20311.1538141875@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Arup Rakshit writes: > My query is not using name index to sort the result. Given the rowcounts here, I think the planner is making the right choice. Sorting 70-some rows with a Sort node is probably cheaper than doing random disk I/O to get them in sorted order. With more rows involved, it might make the other choice. As a testing measure (don't do it in production!), you could set enable_sort = off, which will force the planner to pick a non-Sort plan if possible. Then you could see whether that's actually faster or slower, and by how much. regards, tom lane