Re: Index no longer being used, destroying and recreating it restores use.

From: Michael Lewis <mlewis(at)entrata(dot)com>
To: Koen De Groote <kdg(dot)dev(at)gmail(dot)com>
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Index no longer being used, destroying and recreating it restores use.
Date: 2020-06-15 18:27:02
Message-ID: CAHOFxGqAV58PYCtmZt6Kfcw-f44Nyf2KahtFGZL3OCAB8snS2g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jun 9, 2020 at 6:24 AM Koen De Groote <kdg(dot)dev(at)gmail(dot)com> wrote:

> Right. In that case, the function I ended up with is this:
>
> create or replace function still_needs_backup(bool, bool)
> returns BOOLEAN as $$
> BEGIN
> PERFORM 1 from item where shouldbebackedup=$1 and backupperformed=$2;
> IF FOUND THEN
> RETURN TRUE;
> ELSE
> RETURN FALSE;
> END IF;
> END;
> $$
> language plpgsql;
>

I meant something like the below (not tested)-

create or replace function still_needs_backup(shouldbebackedup bool,
backupperformed bool)
returns BOOLEAN as $$
BEGIN
return $1 AND NOT $2;
END;
$$
language sql;

CREATE INDEX CONCURRENTLY index_test ON item USING btree (itemCreated)
WHERE still_needs_backup(shouldbebackedup, backupperformed);
ANALYZE item;

>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2020-06-15 18:51:23 Re: Should I enforce ssl/local socket use?
Previous Message Bruce Momjian 2020-06-15 18:09:16 Re: Move configuration files with pg_upgrade