1

I need indexes on some large tables to support ON DELETE CASCADE, but the size of btree indexes would be a problem. I therefore tried with BRIN, since the performance isn't critical. However, it seems they are never used, or at least the deletes are about as slow as without indexes. Could someone confirm that the planner can use BRIN indexes for cascading deletes? Is there a way I could examine the plan?

Rasmus
  • 69
  • 7

1 Answers1

2

Use auto_explain with these settings:

auto_explain.log_min_duration = '0ms'
auto_explain.log_nested_statements=on

and you will get the plan for the cascading delete.

And with this setting, it will get sent to your client and you won't have to go dig it out of the log file:

set client_min_messages = log;

BRIN indexes can be used. But if the table is not suitable for BRIN indexes (the rows are not nearly in order by the key column) using one will not actually be faster.

jjanes
  • 37,812
  • 5
  • 27
  • 34