This is the major estimated cost:
-> Subquery Scan "*SELECT* 4" (cost=578.23..98368.80 rows=6477 width=4) -> Nested Loop (cost=578.23..98304.03 rows=6477 width=4) -> Bitmap Heap Scan on emailaddress (cost=578.23..31482.49 rows=22092 width=4) Filter: ((status = ANY ('{2,4}'::integer[])) AND (lower(email) ~~ 'david.wonderly%%'::text)) -> Bitmap Index Scan on emailaddress__lower_email__key (cost=0.00..572.71 rows=22376 width=0) Index Cond: ((lower(email) >= 'david.wonderly'::text) AND (lower(email) < 'david.wonderlz'::text)) -> Index Scan using person_pkey on person (cost=0.00..3.01 rows=1 width=4) Index Cond: (public.person.id = public.emailaddress.person)
but grabbing just that row is 36ms, so the estimate is bogus - note the row count projected (22K) vs actual (1)
This is the major estimated cost:
-> Subquery Scan "*SELECT* 4" (cost=578. 23..98368. 80 rows=6477 width=4) 23..98304. 03 rows=6477 width=4) 23..31482. 49 rows=22092 width=4)
Filter: ((status = ANY ('{2,4} '::integer[ ])) AND (lower(email) ~~ 'david. wonderly% %'::text) )
- > Bitmap Index Scan on emailaddress_ _lower_ email__ key (cost=0.00..572.71 rows=22376 width=0)
Index Cond: ((lower(email) >= 'david. wonderly' ::text) AND (lower(email) < 'david. wonderlz' ::text) )
Index Cond: (public.person.id = public. emailaddress. person)
-> Nested Loop (cost=578.
-> Bitmap Heap Scan on emailaddress (cost=578.
-> Index Scan using person_pkey on person (cost=0.00..3.01 rows=1 width=4)
but grabbing just that row is 36ms, so the estimate is bogus - note the row count projected (22K) vs actual (1)