Skip to content

Instantly share code, notes, and snippets.

@jasonwalkeryung
Created February 9, 2018 22:33
Show Gist options
  • Save jasonwalkeryung/186b0257f2e3f890c16afb0eb7a7f782 to your computer and use it in GitHub Desktop.
Save jasonwalkeryung/186b0257f2e3f890c16afb0eb7a7f782 to your computer and use it in GitHub Desktop.
EXPLAIN like reverse('%.example.com')
psql=> explain analyze select distinct users.id, users.name, users.email from users where reverse(users.email) like reverse('%example.com');
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------
HashAggregate (cost=54001.19..54170.10 rows=16891 width=71) (actual time=0.114..0.154 rows=25 loops=1)
Group Key: id, name, email
-> Bitmap Heap Scan on users (cost=845.69..53874.51 rows=16891 width=71) (actual time=0.036..0.092 rows=25 loops=1)
Filter: (reverse((email)::text) ~~ 'moc.elpmaxe%'::text)
Heap Blocks: exact=25
-> Bitmap Index Scan on idx_users_email_reverse (cost=0.00..841.46 rows=16891 width=0) (actual time=0.023..0.023 rows=25 loops=1)
Index Cond: ((reverse((email)::text) ~>=~ 'moc.elpmaxe'::text) AND (reverse((email)::text) ~<~ 'moc.elpmaxf'::text))
Planning time: 0.153 ms
Execution time: 0.239 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment