Skip to content

Instantly share code, notes, and snippets.

@EvanCarroll
Created February 18, 2010 20:36
Show Gist options
  • Save EvanCarroll/308033 to your computer and use it in GitHub Desktop.
Save EvanCarroll/308033 to your computer and use it in GitHub Desktop.
dealermade=# EXPLAIN ANALYZE select * from inventory.vehicles where vin = coalesce ( '1FTYR10C6YPB35818', vin );
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on vehicles (cost=4.29..12.18 rows=2 width=834) (actual time=0.035..0.037 rows=1 loops=1)
Recheck Cond: ((vin)::text = '1FTYR10C6YPB35818'::text)
-> Bitmap Index Scan on vehicles__vin_textpatternops (cost=0.00..4.29 rows=2 width=0) (actual time=0.024..0.024 rows=1 loops=1)
Index Cond: ((vin)::text = '1FTYR10C6YPB35818'::text)
Total runtime: 0.155 ms
(5 rows)
dealermade=# EXPLAIN ANALYZE select * from inventory.vehicles where vin = coalesce ( null, vin );
QUERY PLAN
---------------------------------------------------------------------------------------------------------------
Seq Scan on vehicles (cost=0.00..4556.94 rows=308 width=834) (actual time=0.026..129.859 rows=61687 loops=1)
Filter: ((vin)::text = COALESCE((vin)::text))
Total runtime: 189.145 ms
(3 rows)
dealermade=# EXPLAIN ANALYZE select * from inventory.vehicles ;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------
Seq Scan on vehicles (cost=0.00..4402.75 rows=61675 width=834) (actual time=0.016..112.196 rows=61687 loops=1)
Total runtime: 169.774 ms
(2 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment