We have an use case where we need to perform cascading deletions across multiple tables in our database. For this purpose, I have found that using GIN indexes as suggested in this answer is quite efficient, taking up 5-10 times less space than BTREE indexes for the same columns.
We're comfortable with explicitly type casting the values of conditions in our delete queries, such as
DELETE FROM table WHERE id IN (SELECT id FROM table WHERE user_id = 10::bigint)
The issue arises when considering our other SELECT queries. We're creating foreign key indexes on almost all the foreign keys for all the tables, and we want these indexes to be utilized efficiently. However, it's not feasible to apply type casting to the values in the WHERE conditions throughout the app. We are using Sequelize as our ORM.
Is there a way to configure Postgres such that the query planner uses the index efficiently, even when the values aren't type casted, in the same manner it does for BTREE indexes? Any guidance would be greatly appreciated.