Query performance in PostgreSQL using 'similar to'

前端 未结 4 1015
伪装坚强ぢ
伪装坚强ぢ 2021-01-20 14:00

I need to retrieve certain rows from a table depending on certain values in a specific column, named columnX in the example:

select *
from t         


        
4条回答
  •  不知归路
    2021-01-20 14:25

    If you are only going to search lists of one-character values, then split each string into an array of characters and index the array:

    CREATE INDEX
            ix_tablename_columnxlist
    ON      tableName
    USING   GIN((REGEXP_SPLIT_TO_ARRAY(columnX, '')))
    

    then search against the index:

    SELECT  *
    FROM    tableName
    WHERE   REGEXP_SPLIT_TO_ARRAY(columnX, '') && ARRAY['A', 'B', 'C', '1', '2', '3']
    

提交回复
热议问题