0

Is it possible in PostgreSQL (as of version 13) to automate index creation without making use of external dependencies?

As an example, imagine we are adding partial indexes on a date field, and we want to keep a separate index for each month (ex. orders_february_2021, orders_march_2022, etc).

Would it be possible to automatically create a new index every time a row with a non-indexed (new) month is inserted?

Z. M.
  • 329
  • 5
  • 13
  • 1
    Why are you using partial indices for these if you actually want one index for all values of that column? – Bergi Jul 28 '21 at 14:46
  • Why? What problem are you trying to solve? How many orders do you have in a single month, what size are your tables, etc. – Frank Heikens Jul 28 '21 at 15:06
  • Beyond creating the indexes, how would you expect Postgres to use them. Seems it would have to look at the value (for each row) and change the execution plan. That would take longer (if it could, which it can not) than no index. If you **need** to separate by month consider creating partitions. – Belayer Jul 28 '21 at 18:41

0 Answers0