Using indexes through a plpgsql procedure

From: Ciaran Doherty <cad106uk(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Using indexes through a plpgsql procedure
Date: 2021-04-07 11:15:37
Message-ID: CA+kYa_Ff=1Y4YafbJqrGg0sJbSrPUV422-ET7wGbGZKfv1PHtw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

Thank you for taking the time to read this.

As a quick question. Can Postgres make use of indexes on a table when the
data from that table is being returned from a procedure?

Some more details. I have a big table which has a long running query
running on it. This table gets rebuilt from scratch on a weekly basis.
Currently, I cannot update/replace the table in a timely manner, I have to
wait for the long running queries to finish before we can update the table
(the total time can be 5+ hours).

I am currently trying to build a procedure which will return data from the
latest version of the table (by dynamically choosing the table name,
something like
https://stackoverflow.com/questions/35559093/how-to-use-variable-as-table-name-in-plpgsql)
. To get a consistent return type I am having to use the `create type` to
build a custom return type. The problem (I think) I am having is that the
indexes on the underlying tables are not usable after calling this
procedure

(e.g.
```
select *
from example_table as et
join example_procedure() as ep on et.exapmle_column = ep.example_column
```
there will be no index on the column ep.example_column)

Is there a way to make sure indexes are used even if the data is accessed
threw a procdure?

Thank you

--
while (e) { kyoatie(); }

Responses

Browse pgsql-general by date

  From Date Subject
Next Message PegoraroF10 2021-04-07 11:16:06 Cascade publication with pg_stat_replication empty
Previous Message Mihalidesová Jana 2021-04-07 09:24:56 RE: Upgrade from 11.3 to 13.1 failed with out of memory