explain.depesz.com

PostgreSQL's explain analyze made readable

Result: S1lb

Settings
# exclusive inclusive rows x rows loops node
1. 126.078 392,388.815 ↓ 44,280.0 44,280 1

Sort (cost=233,949.75..233,949.76 rows=1 width=46) (actual time=392,378.151..392,388.815 rows=44,280 loops=1)

  • Sort Key: aml.date_maturity, aml.id
  • Sort Method: quicksort Memory: 7,398kB
2.          

CTE jnl_precision

3. 0.032 0.135 ↑ 1.0 24 1

Hash Right Join (cost=4.43..10.18 rows=24 width=8) (actual time=0.122..0.135 rows=24 loops=1)

  • Hash Cond: (currency.id = COALESCE(j.currency_id, c.currency_id))
4. 0.045 0.045 ↑ 1.0 170 1

Seq Scan on res_currency currency (cost=0.00..4.70 rows=170 width=8) (actual time=0.021..0.045 rows=170 loops=1)

5. 0.013 0.058 ↑ 1.0 24 1

Hash (cost=4.13..4.13 rows=24 width=12) (actual time=0.056..0.058 rows=24 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 9kB
6. 0.014 0.045 ↑ 1.0 24 1

Hash Left Join (cost=1.14..4.13 rows=24 width=12) (actual time=0.016..0.045 rows=24 loops=1)

  • Hash Cond: (j.company_id = c.id)
7. 0.023 0.023 ↑ 1.0 24 1

Seq Scan on account_journal j (cost=0.00..2.89 rows=24 width=12) (actual time=0.004..0.023 rows=24 loops=1)

  • Filter: ((type)::text = ANY ('{bank,cash}'::text[]))
  • Rows Removed by Filter: 47
8. 0.002 0.008 ↑ 1.0 6 1

Hash (cost=1.06..1.06 rows=6 width=8) (actual time=0.008..0.008 rows=6 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 9kB
9. 0.006 0.006 ↑ 1.0 6 1

Seq Scan on res_company c (cost=0.00..1.06 rows=6 width=8) (actual time=0.005..0.006 rows=6 loops=1)

10.          

CTE partners_table

11. 0.040 0.040 ↑ 1.0 131 1

Values Scan on "*VALUES*" (cost=0.00..1.64 rows=131 width=8) (actual time=0.002..0.040 rows=131 loops=1)

12. 18,464.539 392,262.737 ↓ 44,280.0 44,280 1

Nested Loop Left Join (cost=5.29..233,937.93 rows=1 width=46) (actual time=30.863..392,262.737 rows=44,280 loops=1)

  • Join Filter: (account.id = aml.account_id)
  • Rows Removed by Join Filter: 134,375,194
  • Filter: ((((aml.account_id = journal.default_credit_account_id) OR (aml.account_id = journal.default_debit_account_id)) AND (aml.statement_id IS NULL) AND ((company.account_bank_reconciliation_start IS NULL) OR (aml.date > company.account_bank_reconciliation_start))) OR ((account.reconcile IS TRUE) AND (aml.reconciled IS FALSE)))
  • Rows Removed by Filter: 681,804
13. 1,288.227 354,920.014 ↓ 726,084.0 726,084 1

Nested Loop Left Join (cost=5.29..233,851.84 rows=1 width=117) (actual time=0.558..354,920.014 rows=726,084 loops=1)

  • Filter: (((line_partner.partner_id <> 0) AND (aml.partner_id = line_partner.partner_id)) OR ((line_partner.partner_id = 0) AND (btrim(regexp_replace((st_line.name)::text, '[^0-9|^\s]'::text, ''::text, 'g'::text)) <> ''::text) AND ((regexp_split_to_array(btrim(regexp_replace((move.name)::text, '[^0-9|^\s]'::text, ''::text, 'g'::text)), '\s+'::text) && regexp_split_to_array(btrim(regexp_replace((st_line.name)::text, '[^0-9|^\s]'::text, ''::text, 'g'::text)), '\s+'::text)) OR ((move.ref IS NOT NULL) AND (regexp_split_to_array(btrim(regexp_replace((move.ref)::text, '[^0-9|^\s]'::text, ''::text, 'g'::text)), '\s+'::text) && regexp_split_to_array(btrim(regexp_replace((st_line.name)::text, '[^0-9|^\s]'::text, ''::text, 'g'::text)), '\s+'::text))))))
14. 1,420.205 349,275.283 ↓ 11,170.5 726,084 1

Nested Loop Left Join (cost=4.86..233,817.22 rows=65 width=92) (actual time=0.480..349,275.283 rows=726,084 loops=1)

  • Join Filter: (company.id = st_line.company_id)
  • Rows Removed by Join Filter: 726,084
  • Filter: (COALESCE(st_line.currency_id, journal.currency_id, company.currency_id) = COALESCE(aml.currency_id, company.currency_id))
15. 201,713.338 347,855.078 ↓ 55.5 726,084 1

Nested Loop (cost=4.86..232,605.93 rows=13,083 width=100) (actual time=0.472..347,855.078 rows=726,084 loops=1)

  • Join Filter: ((st_line.company_id = aml.company_id) AND ((line_partner.partner_id = 0) OR (aml.partner_id = line_partner.partner_id)) AND CASE WHEN (st_line.amount > 0.0) THEN (aml.balance > '0'::numeric) ELSE (aml.balance < '0'::numeric) END)
  • Rows Removed by Join Filter: 464,624,550
16. 0.814 8.200 ↓ 126.0 126 1

Nested Loop Left Join (cost=4.86..368.87 rows=1 width=58) (actual time=0.443..8.200 rows=126 loops=1)

  • Join Filter: (jnl_precision.journal_id = journal.id)
  • Rows Removed by Join Filter: 2,898
17. 1.498 6.252 ↓ 126.0 126 1

Nested Loop Left Join (cost=4.86..368.09 rows=1 width=62) (actual time=0.312..6.252 rows=126 loops=1)

  • Join Filter: (journal.id = st_line.journal_id)
  • Rows Removed by Join Filter: 2,268
18. 0.951 3.746 ↓ 126.0 126 1

Hash Join (cost=4.86..364.49 rows=1 width=50) (actual time=0.295..3.746 rows=126 loops=1)

  • Hash Cond: (st_line.id = line_partner.line_id)
19. 2.699 2.699 ↑ 1.0 131 1

Index Scan using account_bank_statement_line_pkey on account_bank_statement_line st_line (cost=0.29..359.42 rows=131 width=46) (actual time=0.186..2.699 rows=131 loops=1)

  • Index Cond: (id = ANY ('{23295,23294,23424,23423,23422,23421,23420,23419,23418,23417,23416,23415,23414,23413,23412,23411,23410,23409,23408,23407,23406,23405,23404,23403,23402,23401,23400,23399,23398,23397,23396,23395,23394,23393,23392,23391,23390,23389,23388,23387,23386,23385,23384,23383,23382,23381,23380,23379,23378,23377,23376,23375,23374,23373,23372,23371,23370,23369,23368,23367,23366,23365,23364,23363,23362,23361,23360,23359,23358,23357,23356,23355,23354,23353,23352,23351,23350,23349,23348,23347,23346,23345,23344,23343,23342,23341,23340,23339,23338,23337,23336,23335,23334,23333,23332,23331,23330,23329,23328,23327,23326,23325,23324,23323,23322,23321,23320,23319,23318,23317,23316,23315,23314,23313,23312,23311,23310,23309,23308,23307,23306,23305,23304,23303,23302,23301,23300,23299,23298,23297,23296}'::integer[]))
20. 0.016 0.096 ↑ 1.0 126 1

Hash (cost=2.95..2.95 rows=130 width=8) (actual time=0.095..0.096 rows=126 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 13kB
21. 0.080 0.080 ↑ 1.0 126 1

CTE Scan on partners_table line_partner (cost=0.00..2.95 rows=130 width=8) (actual time=0.007..0.080 rows=126 loops=1)

  • Filter: (partner_id <> 0)
  • Rows Removed by Filter: 5
22. 1.008 1.008 ↑ 3.7 19 126

Seq Scan on account_journal journal (cost=0.00..2.71 rows=71 width=16) (actual time=0.006..0.008 rows=19 loops=126)

23. 1.134 1.134 ↑ 1.0 24 126

CTE Scan on jnl_precision (cost=0.00..0.48 rows=24 width=4) (actual time=0.002..0.009 rows=24 loops=126)

24. 146,133.540 146,133.540 ↑ 1.0 3,693,259 126

Seq Scan on account_move_line aml (cost=0.00..139,905.59 rows=3,693,259 width=52) (actual time=0.011..1,159.790 rows=3,693,259 loops=126)

25. 0.000 0.000 ↑ 3.0 2 726,084

Materialize (cost=0.00..1.09 rows=6 width=12) (actual time=0.000..0.000 rows=2 loops=726,084)

26. 0.005 0.005 ↑ 3.0 2 1

Seq Scan on res_company company (cost=0.00..1.06 rows=6 width=12) (actual time=0.004..0.005 rows=2 loops=1)

27. 4,356.504 4,356.504 ↑ 1.0 1 726,084

Index Scan using account_move_pkey on account_move move (cost=0.43..0.47 rows=1 width=41) (actual time=0.006..0.006 rows=1 loops=726,084)

  • Index Cond: (id = aml.move_id)
28. 18,878.184 18,878.184 ↑ 9.3 186 726,084

Seq Scan on account_account account (cost=0.00..51.35 rows=1,735 width=11) (actual time=0.003..0.026 rows=186 loops=726,084)

Planning time : 15.897 ms
Execution time : 392,391.994 ms