testing=> CREATE EXTENSION pgcrypto; CREATE EXTENSION testing=> CREATE TEMPORARY TABLE test AS SELECT string_agg(gen_random_bytes(1024)::text, '') || 'known suffix' AS value FROM generate_series(1, 512*512); SELECT 1 testing=> EXPLAIN ANALYZE SELECT COUNT(*) FROM test WHERE strpos(value, 'known') > 0; QUERY PLAN ------------------------------------------------------------------------------------------------------------- Aggregate (cost=31.53..31.54 rows=1 width=8) (actual time=2113.529..2113.530 rows=1 loops=1) -> Seq Scan on test (cost=0.00..30.40 rows=453 width=0) (actual time=2086.105..2113.521 rows=1 loops=1) Filter: (strpos(value, 'known'::text) > 0) Planning Time: 0.205 ms Execution Time: 2113.600 ms (5 rows) testing=> EXPLAIN ANALYZE SELECT COUNT(*) FROM test WHERE strpos(value, 'known') > 0 AND strpos(value, 'suffix') > 0; QUERY PLAN ------------------------------------------------------------------------------------------------------------- Aggregate (cost=37.58..37.59 rows=1 width=8) (actual time=4196.635..4196.636 rows=1 loops=1) -> Seq Scan on test (cost=0.00..37.20 rows=151 width=0) (actual time=4140.200..4196.626 rows=1 loops=1) Filter: ((strpos(value, 'known'::text) > 0) AND (strpos(value, 'suffix'::text) > 0)) Planning Time: 0.111 ms Execution Time: 4196.683 ms (5 rows) testing=> EXPLAIN ANALYZE SELECT COUNT(*) FROM test WHERE strpos(value, 'known') > 0 AND strpos(value, 'suffix') > 0 AND strpos(value, 'suffix') > 0; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=44.38..44.39 rows=1 width=8) (actual time=6269.283..6269.284 rows=1 loops=1) -> Seq Scan on test (cost=0.00..44.00 rows=151 width=0) (actual time=6179.754..6269.275 rows=1 loops=1) Filter: ((strpos(value, 'known'::text) > 0) AND (strpos(value, 'suffix'::text) > 0) AND (strpos(value, 'suffix'::text) > 0)) Planning Time: 0.101 ms Execution Time: 6269.329 ms (5 rows) testing=> EXPLAIN ANALYZE SELECT COUNT(*) FROM test WHERE strpos(value, 'known') > 0 AND strpos(value, 'suffix') > 0 AND strpos(value, 'suffix') > 0 AND strpos(value, 'suffix') > 0; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Aggregate (cost=51.18..51.19 rows=1 width=8) (actual time=8190.171..8190.172 rows=1 loops=1) -> Seq Scan on test (cost=0.00..50.80 rows=151 width=0) (actual time=8072.736..8190.162 rows=1 loops=1) Filter: ((strpos(value, 'known'::text) > 0) AND (strpos(value, 'suffix'::text) > 0) AND (strpos(value, 'suffix'::text) > 0) AND (strpos(value, 'suffix'::text) > 0)) Planning Time: 0.118 ms Execution Time: 8190.222 ms (5 rows)