explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 9H1NQ

Settings
# exclusive inclusive rows x rows loops node
1. 0.009 139.983 ↑ 1.0 10 1

Limit (cost=21,449.10..21,449.12 rows=10 width=36) (actual time=139.976..139.983 rows=10 loops=1)

2. 0.029 139.974 ↑ 662.4 10 1

Sort (cost=21,449.10..21,465.66 rows=6,624 width=36) (actual time=139.974..139.974 rows=10 loops=1)

  • Sort Key: (sum(invoice_line_items.subtotal)) DESC NULLS LAST
  • Sort Method: top-N heapsort Memory: 25kB
3. 4.822 139.945 ↑ 301.1 22 1

HashAggregate (cost=21,223.15..21,305.95 rows=6,624 width=36) (actual time=139.909..139.945 rows=22 loops=1)

  • Group Key: CASE WHEN (invoices.user_id IS NOT NULL) THEN invoices.user_id ELSE vendor_orders.user_id END
4. 4.875 135.123 ↑ 1.1 19,723 1

Hash Left Join (cost=4,168.80..21,110.51 rows=22,529 width=9) (actual time=16.342..135.123 rows=19,723 loops=1)

  • Hash Cond: (invoices.vendor_order_id = vendor_orders.id)
  • Filter: (CASE WHEN (invoices.user_id IS NOT NULL) THEN invoices.user_id ELSE vendor_orders.user_id END IS NOT NULL)
  • Rows Removed by Filter: 6464
5. 54.834 124.355 ↓ 1.2 26,187 1

Hash Join (cost=3,703.99..20,555.46 rows=22,642 width=13) (actual time=10.333..124.355 rows=26,187 loops=1)

  • Hash Cond: (invoice_line_items.invoice_id = invoices.id)
6. 60.774 60.774 ↑ 1.0 536,804 1

Seq Scan on invoice_line_items (cost=0.00..14,612.04 rows=536,804 width=9) (actual time=0.033..60.774 rows=536,804 loops=1)

7. 1.140 8.747 ↓ 1.2 8,397 1

Hash (cost=3,614.46..3,614.46 rows=7,162 width=12) (actual time=8.747..8.747 rows=8,397 loops=1)

  • Buckets: 16384 (originally 8192) Batches: 1 (originally 1) Memory Usage: 451kB
8. 5.484 7.607 ↓ 1.2 8,397 1

Bitmap Heap Scan on invoices (cost=551.63..3,614.46 rows=7,162 width=12) (actual time=2.349..7.607 rows=8,397 loops=1)

  • Recheck Cond: (vendor_id = 815)
  • Filter: (invoice_date > '2017-12-04'::date)
  • Rows Removed by Filter: 14423
  • Heap Blocks: exact=665
9. 2.123 2.123 ↓ 1.0 23,506 1

Bitmap Index Scan on index_invoices_on_vendor_id (cost=0.00..549.84 rows=22,589 width=0) (actual time=2.123..2.123 rows=23,506 loops=1)

  • Index Cond: (vendor_id = 815)
10. 2.685 5.893 ↓ 1.0 11,967 1

Hash (cost=315.47..315.47 rows=11,947 width=8) (actual time=5.893..5.893 rows=11,967 loops=1)

  • Buckets: 16384 Batches: 1 Memory Usage: 596kB
11. 3.208 3.208 ↓ 1.0 11,967 1

Seq Scan on vendor_orders (cost=0.00..315.47 rows=11,947 width=8) (actual time=0.172..3.208 rows=11,967 loops=1)