Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXqYu-0001rm-1q for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2019 17:48:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iXqYs-0005TN-Nu for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Nov 2019 17:48:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iXqYs-0005Rd-CT for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2019 17:48:10 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iXqYl-0005sw-Qe for pgsql-bugs@lists.postgresql.org; Thu, 21 Nov 2019 17:48:09 +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 xALHm0ZL023662; Thu, 21 Nov 2019 12:48:01 -0500 From: Tom Lane To: mayur555b@protonmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16130: planner does not pick unique btree index and goes for seq scan but unsafe hash index works. In-reply-to: <16130-d936946edf14de14@postgresql.org> References: <16130-d936946edf14de14@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Thu, 21 Nov 2019 16:46:58 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <23660.1574358480.1@sss.pgh.pa.us> Date: Thu, 21 Nov 2019 12:48:00 -0500 Message-ID: <23661.1574358480@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > Planner does not pick unique btree index and goes for seq scan but unsafe > hash index works. I couldn't reproduce this from the given instructions. Looking at the code, it looks like it might be possible to explain it with a combination of (1) old_snapshot_threshold being enabled (not -1), and (2) something holding back global xmin, such as a long-running transaction. (Maybe you have an uncommitted prepared transaction?) In that situation a newly-created index won't be used until all older transactions have gone away. But the existence of an unlogged index (hash index) disables the snapshot threshold feature for the associated table. There may be some additional condition needed to cause it, because I still couldn't reproduce the behavior with those two conditions set up. IMO old_snapshot_threshold is a complete kluge and you should not have it turned on unless you desperately need it. It has a lot of poorly-documented drawbacks, including this one. regards, tom lane