Given the following table:
CREATE UNLOGGED TABLE table (
col1 VARCHAR(64) NOT NULL,
col2 VARCHAR(255) NOT NULL,
CONSTRAINT table_pk PRIMARY KEY (col1,col2)
);
And following SHOW LC_COLLATE; result:
| lc_collate |
|---|
| en_US.utf8 |
The following query performs an indexed scan:
SELECT * FROM table WHERE col1 ='val1' AND col2 LIKE ('prefix%') LIMIT 2;
As can be seen by its EXPLAIN ANALYZE output:
Limit (cost=0.14..8.16 rows=1 width=662) (actual time=0.018..0.022 rows=0 loops=1)
-> Index Only Scan using table_pk on "table" (cost=0.14..8.16 rows=1 width=662) (actual time=0.008..0.012 rows=0 loops=1)
Index Cond: (col1 = 'val1'::text)
Filter: ((col2)::text ~~ 'prefix%'::text)
Heap Fetches: 0
Planning time: 4.562 ms
Execution time: 0.068 ms
The question is how does this query which contains LIKE operator performs an indexed scan?
By this article as well as this blog the case when using LIKE operator without "C" locale and without varchar_pattern_ops set on the index, should not be able to perform an indexed scan.
I am running this on a docker image of postgres:9.6