pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Demitri Muna <postgresql@demitri.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Getting "could not read block" error when creating an index on a function.
Date: Wed, 30 Dec 2020 11:50:27 -0500
Message-ID: <2344514.1609347027@sss.pgh.pa.us> (raw)
In-Reply-To: <E88B1929-C94D-45C1-B11F-0B48B39D64B7@demitri.com>
References: <E88B1929-C94D-45C1-B11F-0B48B39D64B7@demitri.com>

Demitri Muna <postgresql@demitri.com> writes:
> I’m getting stuck on a problem I was hoping I could get some help with. I’m trying to create an index for the results of a function that touches two tables like this and get the following error:

> CREATE INDEX my_idx ON mytable (first_time(id));
> ERROR:  could not read block 0 in file "base/16386/42868": read only 0 of 8192 bytes
> CONTEXT:  SQL function "first_time" during startup

What's apparently happening is that some query in the function is trying
to examine the newly-created index before it's been populated.

I would call this a bug if it were a supported case, but really you are
doing something you are not allowed to.  Functions in indexed expressions
are required to be immutable, and a function that looks at the contents of
a table --- particularly the very table that the index is on --- is simply
not going to be that.  Marking such a function immutable to try to end-run
around the restriction is unsafe.

			regards, tom lane





view thread (8+ messages)  latest in thread

Message-ID: <2344514.1609347027@sss.pgh.pa.us>
Permalink:  ../2344514.1609347027@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2344514.1609347027@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, postgresql@demitri.com
  Subject: Re: Getting "could not read block" error when creating an index on a function.
  In-Reply-To: <2344514.1609347027@sss.pgh.pa.us>
  References: <E88B1929-C94D-45C1-B11F-0B48B39D64B7@demitri.com> <2344514.1609347027@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox