I'm dealing with a ~20M line table in Postgres 10.9 that has a text column in that is a bunch of comma delimited strings. This table gets joined all over to many tables that are much longer, and every time the previous authors did so, they join with the on clause being some_other_string = Any(string_to_array(col, ','))
I'm trying to implement a quick optimization to make queries faster while I work on a better solution with the following index:
My functional index:
create index string_to_array_index on happy_table (string_to_array(col));
Test query:
select string_to_array(col, ',') from happy_table;
When I execute an explain on the test query in order to see if the index is being used, I can see that it isn't. I see examples of functional indexes on strings where they lowercase the string or perform some basic operation like that. Do functional indexes work with string_to_array?
select a.id
from joyful_table a
join happy_table b on a.col = any(string_to_array(b.col, ','));