To optimize the complex PostgreSQL query, I tried to create an index containing both scalar strings and arrays and supporting array operations ( @> , <@ and && ).
But I managed to create the BTREE index:
CREATE INDEX idx1 ON "MyTable" USING btree ("Char_1", "Array_1", "Array_2", "Array_3", "Char_2");
which do not support array operations ( @> , <@ and && ).
I tried using GIN and GiST (using the extensions btree_gin and btree_gist ), but did not find a way to use both scalar and massive columns in the same index.
GIN doesn't seem to support scalars:
ERROR: data type character has no default operator class for access method "gin" HINT: You must specify an operator class for the index or define a default operator class for the data type.
and GiST does not support arrays:
ERROR: data type character varying[] has no default operator class for access method "gist" HINT: You must specify an operator class for the index or define a default operator class for the data type.
The only way I found to create such an index is to use the to_tsvector function to convert all scalar strings to a tsvector data type. But I do not need a full text search. I even tried to create my own operator class, but quickly realized that it was outside of me.
Is there a way to create a multi- GIN / GiST index containing both scalar strings and arrays?
source share