Re: Adding a column with default value possibly corrupting a functional index.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Rajesh Kumar Mallah" <mallah(dot)rajesh(at)gmail(dot)com>
Cc: "Lista Postgres" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Adding a column with default value possibly corrupting a functional index.
Date: 2006-12-17 03:36:44
Message-ID: 10285.1166326604@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

"Rajesh Kumar Mallah" <mallah(dot)rajesh(at)gmail(dot)com> writes:
> On 12/16/06, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> I think the proximate cause of the problem is that the function's
>> SELECT is trying to use an index on the category_id column,
>> and the REINDEX done by ALTER TABLE happens to rebuild the two indexes
>> in the other order, such that the one on category_id isn't valid yet
>> when the functional index is rebuilt.

> why does ALTER TABLE ADD new_col int default 0 rebuilds
> existing indexes ?

Because it has to rewrite the whole table to insert the default value
in every row. A REINDEX is way more efficient for recovering from that
than any row-by-row update would be.

>> I wonder whether we need to do something to actively prevent functions
>> used in an index from querying the database? It's not too hard to
>> imagine crashing the backend by playing this sort of game.

> the game was seemingly fulfilling a requirement. dunno what
> i should be doing now.

It sorta looks to me like you're trying to get the effect of a
materialized view --- have you looked at the techdocs pages about
how to do those in Postgres?

regards, tom lane

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Rajesh Kumar Mallah 2006-12-17 04:00:30 Re: Adding a column with default value possibly corrupting a functional index.
Previous Message Rajesh Kumar Mallah 2006-12-17 02:40:50 Re: Adding a column with default value possibly corrupting a functional index.