Using PostgreSQL, EntityFramework, C#.
My index was created by:
CREATE UNIQUE INDEX "IX_MyObjects_MyColumn"
ON "Manufacturing"."MyObjects" USING btree
(LOWER("MyColumn") COLLATE pg_catalog."default" varchar_pattern_ops ASC NULLS LAST)
TABLESPACE pg_default;
and it is working as expected for like query with a wildcard:
EXPLAIN SELECT * FROM "Manufacturing"."MyObjects" WHERE lower("MyColumn") LIKE lower('tj%');
Bitmap Heap Scan on "MyObjects" (cost=8.24..10.39 rows=10 width=1755)
Filter: (lower(("MyColumn")::text) ~~ 'tj%'::text)
-> Bitmap Index Scan on "IX_MyObjects_MyColumn" (cost=0.00..8.23 rows=10 width=0)
Index Cond: ((lower(("MyColumn")::text) ~>=~ 'tj'::text) AND (lower(("MyColumn")::text) ~<~ 'tk'::text))
but only if it is not a starting character in a search string.
EXPLAIN SELECT * FROM "Manufacturing"."MyObjects" WHERE lower("MyColumn") LIKE lower('%tj%');
Seq Scan on "MyObjects" (cost=10000000000.00..10000000002.15 rows=3 width=1755)
Filter: (lower(("MyColumn")::text) ~~ '%tj%'::text)
Is there any way to make it working for search text with starting wildcard?
Limiting the substring search to only the ones with a correct prefix is not acceptable from the perspective of requirements and best user experience.