How to use many LIKE operators and use index
问题 In my query I want find rows that match one of many LIKE operators. I know 3 ways of doing that but only one of them can use index. Lets start with table: CREATE TABLE dir ( id BIGSERIAL PRIMARY KEY, path TEXT NOT NULL ); CREATE INDEX path_idx ON dir(path TEXT_pattern_ops); After inserting sample data I can do: EXPLAIN ANALYZE SELECT id, path FROM dir WHERE path LIKE 'A%' OR path LIKE 'B%' OR path LIKE 'C%'; Above query use index correctly. Second way: EXPLAIN ANALYZE SELECT id, path FROM dir