Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jl8Od-0006Ch-La for pgsql-general@arkaria.postgresql.org; Tue, 16 Jun 2020 10:00:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jl8Ob-0002hN-Tt for pgsql-general@arkaria.postgresql.org; Tue, 16 Jun 2020 10:00:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jl8Ob-0002hF-MM for pgsql-general@lists.postgresql.org; Tue, 16 Jun 2020 10:00:45 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jl8OY-0004wQ-Sz for pgsql-general@lists.postgresql.org; Tue, 16 Jun 2020 10:00:44 +0000 Received: from bruce by momjian.us with local (Exim 4.92) (envelope-from ) id 1jl8OU-0003ds-Va; Tue, 16 Jun 2020 06:00:38 -0400 Date: Tue, 16 Jun 2020 06:00:38 -0400 From: Bruce Momjian To: Koen De Groote Cc: Michael Lewis , Adrian Klaver , Tom Lane , PostgreSQL General Subject: Re: Index no longer being used, destroying and recreating it restores use. Message-ID: <20200616100038.GA31183@momjian.us> References: <92ea007a-abe0-1dd2-7e5c-080da70c2e2c@aklaver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Jun 16, 2020 at 11:49:15AM +0200, Koen De Groote wrote: > Alright, I've done that, and that seems to be a very good result: https:// > explain.depesz.com/s/xIph > > The method I ended up using: > > create or replace function still_needs_backup(shouldbebackedup bool, > backupperformed bool) > returns BOOLEAN as $$ >    select $1 AND NOT $2; > $$ > language sql immutable; > > And the index is as suggested. > > It seems the amount of rows we end up with has improved. > > Thank you for your help. I wasn't aware functions could interact with indexes > in such a manner. This blog entry explains how statistics on expression/function indexes can help: https://momjian.us/main/blogs/pgblog/2017.html#February_20_2017 -- Bruce Momjian https://momjian.us EnterpriseDB https://enterprisedb.com The usefulness of a cup is in its emptiness, Bruce Lee