Skip to content

Instantly share code, notes, and snippets.

@stephencweiss
Created November 21, 2018 20:27
Show Gist options
  • Save stephencweiss/dabe29f6f4439c34585ff4a48c91cc60 to your computer and use it in GitHub Desktop.
Save stephencweiss/dabe29f6f4439c34585ff4a48c91cc60 to your computer and use it in GitHub Desktop.
//psql
sdc=# EXPLAIN ANALYZE SELECT * FROM descriptions WHERE product_id = 98242;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------
Gather (cost=1000.00..671780.94 rows=1 width=461) (actual time=28182.350..28187.140 rows=1 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Parallel Seq Scan on descriptions (cost=0.00..670780.84 rows=1 width=461) (actual time=19120.669..28177.305 rows=0 loops=3)
Filter: (product_id = 98242)
Rows Removed by Filter: 33334
Planning time: 0.187 ms
Execution time: 28187.219 ms
(8 rows)
sdc=# CREATE INDEX desc_prod_id_index ON descriptions (product_id);
CREATE
sdc=# EXPLAIN ANALYZE SELECT * FROM descriptions WHERE product_id = 98242;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on descriptions (cost=4.30..8.31 rows=1 width=461) (actual time=0.022..0.023 rows=1 loops=1)
Recheck Cond: (product_id = 98242)
Heap Blocks: exact=1
-> Bitmap Index Scan on desc_prod_id_index (cost=0.00..4.30 rows=1 width=0) (actual time=0.016..0.016 rows=1 loops=1)
Index Cond: (product_id = 98242)
Planning time: 2.790 ms
Execution time: 3.579 ms
(7 rows)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment