Corruption with IMMUTABLE functions in index expression.

From: Prabhat Sahu <prabhat(dot)sahu(at)enterprisedb(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Corruption with IMMUTABLE functions in index expression.
Date: 2021-10-11 14:44:59
Message-ID: CANEvxPo__EAAtjO6SWmRD-nvTLGQ6r6q2JFyT2cmpOY0-aqATA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,

While using IMMUTABLE functions in index expression, we are getting below
corruption on HEAD.

postgres=# CREATE TABLE tab1 (c1 numeric, c2 numeric);
CREATE TABLE

postgres=# INSERT INTO tab1 values (10, 100);
INSERT 0 1

postgres=# CREATE OR REPLACE FUNCTION func1(var1 numeric)
RETURNS NUMERIC AS $$
DECLARE
result numeric;
BEGIN
SELECT c2 into result FROM tab1 WHERE c1=var1;
RETURN result;
END;
$$ LANGUAGE plpgsql IMMUTABLE;
CREATE FUNCTION

-- When using the IMMUTABLE function in creating an index for the first
time, it is working fine.
postgres=# CREATE INDEX idx1 ON tab1(func1(c1));
CREATE INDEX

-- Executing the similar query for 2nd time, We are getting the error
postgres=# CREATE INDEX idx2 ON tab1(func1(c1));
ERROR: could not read block 0 in file "base/13675/16391": read only 0 of
8192 bytes
CONTEXT: SQL statement "SELECT c2 FROM tab1 WHERE c1=var1"
PL/pgSQL function func1(numeric) line 5 at SQL statement

--

With Regards,
Prabhat Kumar Sahu
EnterpriseDB: http://www.enterprisedb.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2021-10-11 14:48:54 Re: More business with $Test::Builder::Level in the TAP tests
Previous Message Dilip Kumar 2021-10-11 14:37:18 Re: row filtering for logical replication