Re: Dangers of mislabelled immutable functions

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "'Jeff Janes *EXTERN*'" <jeff(dot)janes(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Dangers of mislabelled immutable functions
Date: 2015-08-21 07:10:55
Message-ID: A737B7A37273E048B164557ADEF4A58B50F946E3@ntex2010i.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jeff Janes wrote:
> I want to index the textual representations of a table's rows.
>
> You can cast a row to text by using the name of the table where you would usually use the name of a
> column, like "table_name::text". But this is not immutable and so can't be used in an expression
> index.
>
> I can easily make a pl/perl function which does the same thing as the text cast, and label it as
> immutable and use it in an index. But are the dangers of doing this?
>
> I know that configuration changes to the date and time formats could change the way that the data is
> shown in ways that would cause the rows inserted under a different configuration to be missed. That
> doesn't bother me.

That's exactly the danger: your index will become corrupted if the function turns out not to
be immutable after all. So if you know that such configuration changes will not happen,
you can safely do that.
But how do you keep people from running "SET DateStyle=..."?

> I know that if I drop a table column, the contents of the column will still be in the index. That
> doesn't bother me either, as all the indexes I plan to use are lossy and so will do a recheck anyway.

I don't understand.
If you drop a column, all indexes that depend on that column will be dropped as well.

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2015-08-21 07:34:14 Re: Problem with pl/python procedure connecting to the internet
Previous Message Igor Sosa Mayor 2015-08-21 05:30:35 Problem with pl/python procedure connecting to the internet