Re: Column reset all values - Mailing list pgsql-general

From Peter J. Holzer
Subject Re: Column reset all values
Date
Msg-id 20200516104215.GB8152@hjp.at
Whole thread Raw
In response to Re: Column reset all values  (otar shavadze <oshavadze@gmail.com>)
List pgsql-general
On 2020-05-14 16:32:41 +0400, otar shavadze wrote:
> also nor index drop is an option, because I need re-create index as I use this
> table in procedure, so index is necessary for  further queries. So total
> runtime will not decreased.

A full index on a column where all the values are the same (NULL in this
case) is useless. For querys which check for the existing value, the
optimizer will notice that a full table scan is faster. For query which
use any other value, you expect 0 results: So all the optimizer want to know is
that the value is indeed not in the column so that it can skip the table
entirely. You can do that with a partial index (WHERE col IS NOT NULL)
or maybe even a constraint.

So I would drop the full index, update the table and then create a
partial index.

        hp

--
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment

pgsql-general by date:

Previous
From: "Peter J. Holzer"
Date:
Subject: Re: Enforcing uniqueness on [real estate/postal] addresses
Next
From: RAJAMOHAN
Date:
Subject: Pgpool is crashing when terminating user session