explain.depesz.com

PostgreSQL's explain analyze made readable

Result: lpeq : Optimization for: Optimization for: Optimization for: plan #LkCI; plan #ztu; plan #HT8bA

Settings

Optimization path:

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 1.861 105.080 ↓ 4.9 322 1

Sort (cost=13,981.25..13,981.42 rows=66 width=310) (actual time=104.585..105.080 rows=322 loops=1)

  • Output: s.settlement_id, ((COALESCE((sum(prev.sum)), '0'::numeric) - COALESCE((sum(rs_1.sum)), '0'::numeric))), (sum(cs.sum)), (sum(CASE WHEN (es.source_moneystorage_id IS NOT NULL) THEN (- es.sum) ELSE es.sum END)), (count(*) FILTER (WHERE (es.settlement_id IS NOT NULL))), (((COALESCE((sum(cs.sum)), '0'::numeric) - COALESCE((sum(CASE WHEN (es.source_moneystorage_id IS NOT NULL) THEN (- es.sum) ELSE es.sum END)), '0'::numeric)) - (COALESCE((sum(prev.sum)), '0'::numeric) - COALESCE((sum(rs_1.sum)), '0'::numeric)))), s.counttime, ((((u.firstname)::text || ' '::text) || (u.lastname)::text)), s.settlementnote, s.source_moneystorage_id, (date_part('epoch'::text, s.counttime)), s."timestamp", (date_part('epoch'::text, rs."timestamp")), (COALESCE(row_to_json((ROW(rs.settlement_id, rs."timestamp"))), '{}'::json))
  • Sort Key: s.counttime DESC
  • Sort Method: quicksort Memory: 110kB
  • Buffers: shared hit=12,782
2. 3.559 103.219 ↓ 4.9 322 1

Nested Loop Left Join (cost=356.16..13,979.26 rows=66 width=310) (actual time=3.725..103.219 rows=322 loops=1)

  • Output: s.settlement_id, (COALESCE((sum(prev.sum)), '0'::numeric) - COALESCE((sum(rs_1.sum)), '0'::numeric)), (sum(cs.sum)), (sum(CASE WHEN (es.source_moneystorage_id IS NOT NULL) THEN (- es.sum) ELSE es.sum END)), (count(*) FILTER (WHERE (es.settlement_id IS NOT NULL))), ((COALESCE((sum(cs.sum)), '0'::numeric) - COALESCE((sum(CASE WHEN (es.source_moneystorage_id IS NOT NULL) THEN (- es.sum) ELSE es.sum END)), '0'::numeric)) - (COALESCE((sum(prev.sum)), '0'::numeric) - COALESCE((sum(rs_1.sum)), '0'::numeric))), s.counttime, (((u.firstname)::text || ' '::text) || (u.lastname)::text), s.settlementnote, s.source_moneystorage_id, date_part('epoch'::text, s.counttime), s."timestamp", date_part('epoch'::text, rs."timestamp"), COALESCE(row_to_json((ROW(rs.settlement_id, rs."timestamp"))), '{}'::json)
  • Join Filter: (s.settlementtype_id = 8)
  • Buffers: shared hit=12,782
3. 2.595 96.440 ↓ 4.9 322 1

Nested Loop Left Join (cost=355.74..13,192.83 rows=66 width=241) (actual time=3.685..96.440 rows=322 loops=1)

  • Output: s.settlement_id, s.counttime, s.settlementnote, s.source_moneystorage_id, s."timestamp", s.settlementtype_id, u.firstname, u.lastname, (sum(prev.sum)), (sum(rs_1.sum)), (sum(cs.sum)), (sum(CASE WHEN (es.source_moneystorage_id IS NOT NULL) THEN (- es.sum) ELSE es.sum END)), (count(*) FILTER (WHERE (es.settlement_id IS NOT NULL)))
  • Buffers: shared hit=11,413
4. 2.355 19.141 ↓ 4.9 322 1

Nested Loop Left Join (cost=219.43..4,194.05 rows=66 width=105) (actual time=3.269..19.141 rows=322 loops=1)

  • Output: s.settlement_id, s.counttime, s.settlementnote, s.source_moneystorage_id, s."timestamp", s.settlementtype_id, u.firstname, u.lastname
  • Inner Unique: true
  • Buffers: shared hit=2,845
5. 12.700 14.532 ↓ 4.9 322 1

Bitmap Heap Scan on "company2de759bc-3fce-11e3-ac31-5b2986f46e71".settlement s (cost=219.15..4,094.58 rows=66 width=114) (actual time=3.237..14.532 rows=322 loops=1)

  • Output: s.settlement_id, s.counttime, s.settlementnote, s.source_moneystorage_id, s."timestamp", s.user_id, s.settlementtype_id
  • Recheck Cond: (s.parentsettlement_id IS NULL)
  • Filter: ((s.settlementtype_id = 8) AND (COALESCE(s.source_moneystorage_id, s.sink_moneystorage_id) = '4a5b7872-31c1-11e9-9fdd-0050568b70b8'::uuid))
  • Rows Removed by Filter: 14,484
  • Heap Blocks: exact=1,835
  • Buffers: shared hit=1,879
6. 1.832 1.832 ↓ 1.0 14,806 1

Bitmap Index Scan on "IX_settlement_parentsettlement_id" (cost=0.00..219.13 rows=14,762 width=0) (actual time=1.830..1.832 rows=14,806 loops=1)

  • Index Cond: (s.parentsettlement_id IS NULL)
  • Buffers: shared hit=44
7. 2.254 2.254 ↑ 1.0 1 322

Index Scan using pkey_user on main."user" u (cost=0.28..1.51 rows=1 width=23) (actual time=0.007..0.007 rows=1 loops=322)

  • Output: u.user_id, u.username, u.firstname, u.lastname, u.password, u.salt, u.disabledtime, u.language_id, u.log_id, u.pincode, u.lastlogin, u.avatar, u.usertype_id, u.introduction, u.external_id, u.presystem_id, u.client_id
  • Index Cond: (u.user_id = s.user_id)
  • Buffers: shared hit=966
8. 8.050 74.704 ↑ 1.0 1 322

Aggregate (cost=136.32..136.33 rows=1 width=136) (actual time=0.231..0.232 rows=1 loops=322)

  • Output: sum(prev.sum), sum(rs_1.sum), sum(cs.sum), sum(CASE WHEN (es.source_moneystorage_id IS NOT NULL) THEN (- es.sum) ELSE es.sum END), count(*) FILTER (WHERE (es.settlement_id IS NOT NULL))
  • Buffers: shared hit=8,568
9. 15.134 66.654 ↓ 1.2 6 322

Nested Loop Left Join (cost=53.77..136.23 rows=5 width=48) (actual time=0.067..0.207 rows=6 loops=322)

  • Output: prev.sum, rs_1.sum, cs.sum, es.source_moneystorage_id, es.sum, es.settlement_id
  • Buffers: shared hit=8,568
10. 10.948 30.268 ↓ 1.2 6 322

Nested Loop Left Join (cost=51.31..74.45 rows=5 width=28) (actual time=0.043..0.094 rows=6 loops=322)

  • Output: cs.sum, cs.settlement_id, prev.sum, rs_1.sum
  • Join Filter: ((prev.counttime < cs.counttime) AND (prev.paymenttype_id = cs.paymenttype_id) AND (prev.source_moneystorage_id = cs.source_moneystorage_id))
  • Buffers: shared hit=2,362
11. 7.728 15.456 ↓ 1.2 6 322

Bitmap Heap Scan on "company2de759bc-3fce-11e3-ac31-5b2986f46e71".settlement cs (cost=4.88..16.74 rows=5 width=60) (actual time=0.032..0.048 rows=6 loops=322)

  • Output: cs.sum, cs.paymenttype_id, cs.source_moneystorage_id, cs.counttime, cs.settlement_id
  • Recheck Cond: ((cs.parentsettlement_id = s.settlement_id) OR (cs.settlement_id = s.settlement_id))
  • Filter: ((cs.settlementtype_id = 8) AND ((cs.parentsettlement_id = s.settlement_id) OR ((cs.parentsettlement_id IS NULL) AND (cs.settlement_id = s.settlement_id))))
  • Rows Removed by Filter: 0
  • Heap Blocks: exact=414
  • Buffers: shared hit=2,356
12. 1.932 7.728 ↓ 0.0 0 322

BitmapOr (cost=4.88..4.88 rows=6 width=0) (actual time=0.024..0.024 rows=0 loops=322)

  • Buffers: shared hit=1,942
13. 3.220 3.220 ↑ 1.0 5 322

Bitmap Index Scan on "IX_settlement_parentsettlement_id" (cost=0.00..2.46 rows=5 width=0) (actual time=0.010..0.010 rows=5 loops=322)

  • Index Cond: (cs.parentsettlement_id = s.settlement_id)
  • Buffers: shared hit=973
14. 2.576 2.576 ↑ 1.0 1 322

Bitmap Index Scan on settlement_pkey (cost=0.00..2.42 rows=1 width=0) (actual time=0.008..0.008 rows=1 loops=322)

  • Index Cond: (cs.settlement_id = s.settlement_id)
  • Buffers: shared hit=969
15. 3.778 3.864 ↓ 0.0 0 1,932

Materialize (cost=46.43..57.61 rows=1 width=48) (actual time=0.002..0.002 rows=0 loops=1,932)

  • Output: prev.sum, prev.paymenttype_id, prev.source_moneystorage_id, prev.counttime, rs_1.sum
  • Buffers: shared hit=6
16. 0.004 0.086 ↓ 0.0 0 1

Nested Loop Left Join (cost=46.43..57.61 rows=1 width=48) (actual time=0.084..0.086 rows=0 loops=1)

  • Output: prev.sum, prev.paymenttype_id, prev.source_moneystorage_id, prev.counttime, rs_1.sum
  • Buffers: shared hit=6
17. 0.006 0.082 ↓ 0.0 0 1

Subquery Scan on prev (cost=0.43..1.79 rows=1 width=76) (actual time=0.081..0.082 rows=0 loops=1)

  • Output: prev.settlement_id, prev.settlementnote, prev.user_id, prev."timestamp", prev.settlementtype_id, prev.source_moneystorage_id, prev.sink_moneystorage_id, prev.sum, prev.sink_ledgeraccount_id, prev.source_ledgeraccount_id, prev.settlementnumber, prev.branch_id, prev.paymenttype_id, prev.sourcecontentbefore, prev.sourcecontentafter, prev.sinkcontentbefore, prev.sinkcontentafter, prev.settlementname, prev.counttime, prev.parentsettlement_id, prev.pickname, prev.pickvalues
  • Filter: (prev.settlementtype_id = 8)
  • Rows Removed by Filter: 1
  • Buffers: shared hit=6
18. 0.006 0.076 ↑ 1.0 1 1

Limit (cost=0.43..1.78 rows=1 width=717) (actual time=0.073..0.076 rows=1 loops=1)

  • Output: s_1.settlement_id, NULL::text, NULL::uuid, NULL::timestamp with time zone, s_1.settlementtype_id, s_1.source_moneystorage_id, NULL::uuid, s_1.sum, NULL::uuid, NULL::uuid, NULL::bigint, NULL::uuid, s_1.paymenttype_id, NULL::numeric(15,2), NULL::numeric(15,2), NULL::numeric(15,2), NULL::numeric(15,2), NULL::character varying(100), s_1.counttime, s_1.parentsettlement_id, NULL::character varying(100), NULL::boolean
  • Buffers: shared hit=6
19. 0.010 0.070 ↑ 22,242.0 1 1

Nested Loop (cost=0.43..30,077.50 rows=22,242 width=717) (actual time=0.068..0.070 rows=1 loops=1)

  • Output: s_1.settlement_id, NULL::text, NULL::uuid, NULL::timestamp with time zone, s_1.settlementtype_id, s_1.source_moneystorage_id, NULL::uuid, s_1.sum, NULL::uuid, NULL::uuid, NULL::bigint, NULL::uuid, s_1.paymenttype_id, NULL::numeric(15,2), NULL::numeric(15,2), NULL::numeric(15,2), NULL::numeric(15,2), NULL::character varying(100), s_1.counttime, s_1.parentsettlement_id, NULL::character varying(100), NULL::boolean
  • Inner Unique: true
  • Join Filter: (pt.mainpaymenttype_id = mpt.paymenttype_id)
  • Buffers: shared hit=6
20. 0.007 0.034 ↑ 66,725.0 1 1

Nested Loop (cost=0.43..15,354.85 rows=66,725 width=84) (actual time=0.032..0.034 rows=1 loops=1)

  • Output: s_1.settlement_id, s_1.settlementtype_id, s_1.source_moneystorage_id, s_1.sum, s_1.paymenttype_id, s_1.counttime, s_1.parentsettlement_id, pt.mainpaymenttype_id
  • Inner Unique: true
  • Buffers: shared hit=5
21. 0.017 0.017 ↑ 66,725.0 1 1

Index Scan Backward using "IX_settlement_counttime" on "company2de759bc-3fce-11e3-ac31-5b2986f46e71".settlement s_1 (cost=0.29..5,046.37 rows=66,725 width=80) (actual time=0.016..0.017 rows=1 loops=1)

  • Output: s_1.settlement_id, s_1.settlementtype_id, s_1.source_moneystorage_id, s_1.sum, s_1.paymenttype_id, s_1.counttime, s_1.parentsettlement_id
  • Buffers: shared hit=3
22. 0.010 0.010 ↑ 1.0 1 1

Index Scan using paymenttype_pkey on "company2de759bc-3fce-11e3-ac31-5b2986f46e71".paymenttype pt (cost=0.14..0.16 rows=1 width=20) (actual time=0.009..0.010 rows=1 loops=1)

  • Output: pt.paymenttype_id, pt.mainpaymenttype_id, pt.log_id, pt.currency_id, pt.disabledtime, pt.isbase, pt.name, pt.product_id, pt.ledgeraccount_id, pt.invoicecustomer_id
  • Index Cond: (pt.paymenttype_id = s_1.paymenttype_id)
  • Buffers: shared hit=2
23. 0.006 0.026 ↑ 15.0 1 1

Materialize (cost=0.00..1.52 rows=15 width=4) (actual time=0.025..0.026 rows=1 loops=1)

  • Output: mpt.paymenttype_id
  • Buffers: shared hit=1
24. 0.020 0.020 ↑ 15.0 1 1

Seq Scan on main.paymenttype mpt (cost=0.00..1.45 rows=15 width=4) (actual time=0.018..0.020 rows=1 loops=1)

  • Output: mpt.paymenttype_id
  • Filter: mpt.isphysical
  • Rows Removed by Filter: 30
  • Buffers: shared hit=1
25. 0.000 0.000 ↓ 0.0 0

Nested Loop (cost=46.00..55.80 rows=1 width=68) (never executed)

  • Output: rs_1.sum, rs_1.parentsettlement_id, rs_1.paymenttype_id, rs_1.source_moneystorage_id, ps.parentsettlement_id
  • Inner Unique: true
  • Join Filter: (COALESCE(ps.parentsettlement_id, rs_1.parentsettlement_id) = COALESCE(prev.parentsettlement_id, prev.settlement_id))
26. 0.000 0.000 ↓ 0.0 0

Bitmap Heap Scan on "company2de759bc-3fce-11e3-ac31-5b2986f46e71".settlement rs_1 (cost=45.58..53.52 rows=1 width=52) (never executed)

  • Output: rs_1.sum, rs_1.parentsettlement_id, rs_1.paymenttype_id, rs_1.source_moneystorage_id
  • Recheck Cond: ((rs_1.source_moneystorage_id = prev.source_moneystorage_id) AND (rs_1.settlementtype_id = 2))
  • Filter: (rs_1.paymenttype_id = prev.paymenttype_id)
27. 0.000 0.000 ↓ 0.0 0

BitmapAnd (cost=45.58..45.58 rows=4 width=0) (never executed)

28. 0.000 0.000 ↓ 0.0 0

Bitmap Index Scan on "IX_settlement_source_moneystorage_id_counttime" (cost=0.00..3.03 rows=82 width=0) (never executed)

  • Index Cond: (rs_1.source_moneystorage_id = prev.source_moneystorage_id)
29. 0.000 0.000 ↓ 0.0 0

Bitmap Index Scan on settlement_settlementtype_id_idx (cost=0.00..41.53 rows=3,098 width=0) (never executed)

  • Index Cond: (rs_1.settlementtype_id = 2)
30. 0.000 0.000 ↓ 0.0 0

Index Scan using settlement_pkey on "company2de759bc-3fce-11e3-ac31-5b2986f46e71".settlement ps (cost=0.42..2.27 rows=1 width=32) (never executed)

  • Output: ps.settlement_id, ps.parentsettlement_id
  • Index Cond: (ps.settlement_id = rs_1.parentsettlement_id)
31. 9.660 21.252 ↓ 0.0 0 1,932

Bitmap Heap Scan on "company2de759bc-3fce-11e3-ac31-5b2986f46e71".settlement es (cost=2.46..12.35 rows=1 width=52) (actual time=0.011..0.011 rows=0 loops=1,932)

  • Output: es.source_moneystorage_id, es.sum, es.settlement_id, es.parentsettlement_id
  • Recheck Cond: (es.parentsettlement_id = cs.settlement_id)
  • Filter: (es.settlementtype_id = 7)
  • Rows Removed by Filter: 1
  • Heap Blocks: exact=396
  • Buffers: shared hit=6,206
32. 11.592 11.592 ↑ 5.0 1 1,932

Bitmap Index Scan on "IX_settlement_parentsettlement_id" (cost=0.00..2.46 rows=5 width=0) (actual time=0.006..0.006 rows=1 loops=1,932)

  • Index Cond: (es.parentsettlement_id = cs.settlement_id)
  • Buffers: shared hit=5,810
33. 3.220 3.220 ↓ 0.0 0 322

Index Scan using "IX_settlement_parentsettlement_id" on "company2de759bc-3fce-11e3-ac31-5b2986f46e71".settlement rs (cost=0.42..11.88 rows=1 width=56) (actual time=0.010..0.010 rows=0 loops=322)

  • Output: rs."timestamp", rs.parentsettlement_id, ROW(rs.settlement_id, rs."timestamp")
  • Index Cond: (rs.parentsettlement_id = s.settlement_id)
  • Filter: (rs.settlementtype_id = 2)
  • Rows Removed by Filter: 5
  • Buffers: shared hit=1,369
Planning time : 20.514 ms
Execution time : 105.984 ms