explain.depesz.com

PostgreSQL's explain analyze made readable

Result: LkCI

Settings

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 1.364 812.713 ↓ 4.9 322 1

Sort (cost=47,712.29..47,712.46 rows=66 width=310) (actual time=812.421..812.713 rows=322 loops=1)

  • Output: s.settlement_id, ((COALESCE((sum(s_1.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(s_1.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=81,885
2. 2.683 811.349 ↓ 4.9 322 1

Nested Loop Left Join (cost=867.24..47,710.30 rows=66 width=310) (actual time=7.411..811.349 rows=322 loops=1)

  • Output: s.settlement_id, (COALESCE((sum(s_1.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(s_1.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=81,885
3. 1.899 806.090 ↓ 4.9 322 1

Nested Loop Left Join (cost=866.82..46,923.87 rows=66 width=241) (actual time=7.369..806.090 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(s_1.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=80,516
4. 1.649 15.291 ↓ 4.9 322 1

Nested Loop Left Join (cost=219.43..4,194.05 rows=66 width=105) (actual time=3.301..15.291 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. 9.880 11.710 ↓ 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.269..11.710 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.830 1.830 ↓ 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.829..1.830 rows=14,806 loops=1)

  • Index Cond: (s.parentsettlement_id IS NULL)
  • Buffers: shared hit=44
7. 1.932 1.932 ↑ 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.006..0.006 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. 6.762 788.900 ↑ 1.0 1 322

Aggregate (cost=647.39..647.40 rows=1 width=136) (actual time=2.449..2.450 rows=1 loops=322)

  • Output: sum(s_1.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=77,671
9. 11.592 782.138 ↓ 1.2 6 322

Nested Loop Left Join (cost=111.26..647.31 rows=5 width=48) (actual time=1.966..2.429 rows=6 loops=322)

  • Output: s_1.sum, rs_1.sum, cs.sum, es.source_moneystorage_id, es.sum, es.settlement_id
  • Buffers: shared hit=77,671
10. 9.660 753.158 ↓ 1.2 6 322

Nested Loop Left Join (cost=108.80..585.53 rows=5 width=28) (actual time=1.944..2.339 rows=6 loops=322)

  • Output: cs.sum, cs.settlement_id, s_1.sum, rs_1.sum
  • Buffers: shared hit=71,465
11. 5.474 11.270 ↓ 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.024..0.035 rows=6 loops=322)

  • Output: cs.sum, cs.counttime, cs.paymenttype_id, cs.source_moneystorage_id, 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.610 5.796 ↓ 0.0 0 322

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

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

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

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

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

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

Nested Loop Left Join (cost=103.92..113.75 rows=1 width=8) (actual time=0.379..0.379 rows=0 loops=1,932)

  • Output: s_1.sum, rs_1.sum
  • Buffers: shared hit=69,109
16. 5.796 521.640 ↓ 0.0 0 1,932

Limit (cost=57.92..57.93 rows=1 width=717) (actual time=0.269..0.270 rows=0 loops=1,932)

  • Output: s_1.settlement_id, NULL::text, NULL::uuid, NULL::timestamp with time zone, NULL::integer, 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=62,047
17. 79.212 515.844 ↓ 0.0 0 1,932

Sort (cost=57.92..57.93 rows=1 width=717) (actual time=0.267..0.267 rows=0 loops=1,932)

  • Output: s_1.settlement_id, NULL::text, NULL::uuid, NULL::timestamp with time zone, NULL::integer, 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
  • Sort Key: s_1.counttime DESC
  • Sort Method: quicksort Memory: 25kB
  • Buffers: shared hit=62,047
18. 111.090 436.632 ↓ 27.0 27 1,932

Nested Loop (cost=2.69..57.91 rows=1 width=717) (actual time=0.071..0.226 rows=27 loops=1,932)

  • Output: s_1.settlement_id, NULL::text, NULL::uuid, NULL::timestamp with time zone, NULL::integer, 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=62,047
19. 40.572 94.668 ↓ 0.0 0 1,932

Nested Loop (cost=0.00..2.96 rows=1 width=16) (actual time=0.048..0.049 rows=0 loops=1,932)

  • Output: pt.paymenttype_id
  • Inner Unique: true
  • Join Filter: (pt.mainpaymenttype_id = mpt.paymenttype_id)
  • Rows Removed by Join Filter: 12
  • Buffers: shared hit=3,864
20. 13.524 13.524 ↑ 1.0 1 1,932

Seq Scan on "company2de759bc-3fce-11e3-ac31-5b2986f46e71".paymenttype pt (cost=0.00..1.32 rows=1 width=20) (actual time=0.006..0.007 rows=1 loops=1,932)

  • 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
  • Filter: (pt.paymenttype_id = cs.paymenttype_id)
  • Rows Removed by Filter: 25
  • Buffers: shared hit=1,932
21. 40.572 40.572 ↑ 1.2 13 1,932

Seq Scan on main.paymenttype mpt (cost=0.00..1.45 rows=15 width=4) (actual time=0.007..0.021 rows=13 loops=1,932)

  • Output: mpt.paymenttype_id, mpt.namekey, mpt.bank, mpt.cardprogram_id, mpt.log_id, mpt.iscashreturn, mpt.isphysical, mpt.isactual, mpt.isreturnable, mpt.iscustom, mpt.currency_id, mpt.superpaymenttype_id, mpt.ispurchase, mpt.allownegativepayment, mpt.allowinvoicecustomer, mpt.iscountable
  • Filter: mpt.isphysical
  • Rows Removed by Filter: 30
  • Buffers: shared hit=1,932
22. 201.894 230.874 ↓ 40.0 160 322

Bitmap Heap Scan on "company2de759bc-3fce-11e3-ac31-5b2986f46e71".settlement s_1 (cost=2.69..54.91 rows=4 width=76) (actual time=0.118..0.717 rows=160 loops=322)

  • Output: s_1.settlement_id, s_1.source_moneystorage_id, s_1.sum, s_1.paymenttype_id, s_1.counttime, s_1.parentsettlement_id
  • Recheck Cond: ((s_1.source_moneystorage_id = cs.source_moneystorage_id) AND (s_1.counttime < cs.counttime))
  • Filter: ((s_1.paymenttype_id = cs.paymenttype_id) AND (s_1.settlementtype_id = 8))
  • Rows Removed by Filter: 802
  • Heap Blocks: exact=55,762
  • Buffers: shared hit=58,183
23. 28.980 28.980 ↓ 35.7 963 322

Bitmap Index Scan on "IX_settlement_source_moneystorage_id_counttime" (cost=0.00..2.69 rows=27 width=0) (actual time=0.090..0.090 rows=963 loops=322)

  • Index Cond: ((s_1.source_moneystorage_id = cs.source_moneystorage_id) AND (s_1.counttime < cs.counttime))
  • Buffers: shared hit=2,421
24. 1.605 205.440 ↓ 0.0 0 321

Nested Loop (cost=46.00..55.80 rows=1 width=68) (actual time=0.640..0.640 rows=0 loops=321)

  • 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(s_1.parentsettlement_id, s_1.settlement_id))
  • Buffers: shared hit=7,062
25. 1.926 203.835 ↓ 0.0 0 321

Bitmap Heap Scan on "company2de759bc-3fce-11e3-ac31-5b2986f46e71".settlement rs_1 (cost=45.58..53.52 rows=1 width=52) (actual time=0.635..0.635 rows=0 loops=321)

  • Output: rs_1.sum, rs_1.parentsettlement_id, rs_1.paymenttype_id, rs_1.source_moneystorage_id
  • Recheck Cond: ((rs_1.source_moneystorage_id = s_1.source_moneystorage_id) AND (rs_1.settlementtype_id = 2))
  • Filter: (rs_1.paymenttype_id = s_1.paymenttype_id)
  • Buffers: shared hit=7,062
26. 12.519 201.909 ↓ 0.0 0 321

BitmapAnd (cost=45.58..45.58 rows=4 width=0) (actual time=0.629..0.629 rows=0 loops=321)

  • Buffers: shared hit=7,062
27. 58.101 58.101 ↓ 23.6 1,935 321

Bitmap Index Scan on "IX_settlement_source_moneystorage_id_counttime" (cost=0.00..3.03 rows=82 width=0) (actual time=0.181..0.181 rows=1,935 loops=321)

  • Index Cond: (rs_1.source_moneystorage_id = s_1.source_moneystorage_id)
  • Buffers: shared hit=3,852
28. 131.289 131.289 ↓ 1.0 3,147 321

Bitmap Index Scan on settlement_settlementtype_id_idx (cost=0.00..41.53 rows=3,098 width=0) (actual time=0.409..0.409 rows=3,147 loops=321)

  • Index Cond: (rs_1.settlementtype_id = 2)
  • Buffers: shared hit=3,210
29. 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)
30. 7.728 17.388 ↓ 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.009..0.009 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
31. 9.660 9.660 ↑ 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.005..0.005 rows=1 loops=1,932)

  • Index Cond: (es.parentsettlement_id = cs.settlement_id)
  • Buffers: shared hit=5,810
32. 2.576 2.576 ↓ 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.008..0.008 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 : 4.510 ms
Execution time : 813.351 ms