explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 3eIC

Settings
# exclusive inclusive rows x rows loops node
1. 30.738 140,428.830 ↓ 44,279.0 44,279 1

Sort (cost=233,995.84..233,995.84 rows=1 width=46) (actual time=140,426.026..140,428.830 rows=44,279 loops=1)

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

CTE jnl_precision

3. 0.050 0.161 ↑ 1.0 24 1

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

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

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

5. 0.009 0.076 ↑ 1.0 24 1

Hash (cost=4.13..4.13 rows=24 width=12) (actual time=0.075..0.076 rows=24 loops=1)

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

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

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

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

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

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

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

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

10.          

CTE partners_table

11. 0.062 0.062 ↑ 1.0 126 1

Values Scan on "*VALUES*" (cost=0.00..1.58 rows=126 width=8) (actual time=0.011..0.062 rows=126 loops=1)

12. 7,935.215 140,398.092 ↓ 44,279.0 44,279 1

Nested Loop Left Join (cost=5.11..233,984.07 rows=1 width=46) (actual time=18.472..140,398.092 rows=44,279 loops=1)

  • Join Filter: (account.id = aml.account_id)
  • Rows Removed by Join Filter: 134,341,101
  • 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,654
13. 554.327 125,203.547 ↓ 725,933.0 725,933 1

Nested Loop Left Join (cost=5.11..233,897.99 rows=1 width=117) (actual time=0.563..125,203.547 rows=725,933 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. 344.691 123,923.287 ↓ 10,675.5 725,933 1

Nested Loop Left Join (cost=4.69..233,861.77 rows=68 width=92) (actual time=0.518..123,923.287 rows=725,933 loops=1)

  • Join Filter: (company.id = st_line.company_id)
  • Rows Removed by Join Filter: 725,933
  • Filter: (COALESCE(st_line.currency_id, journal.currency_id, company.currency_id) = COALESCE(aml.currency_id, company.currency_id))
15. 79,218.648 123,578.596 ↓ 53.1 725,933 1

Nested Loop (cost=4.69..232,596.75 rows=13,664 width=100) (actual time=0.492..123,578.596 rows=725,933 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: 453,544,924
16. 0.257 2.827 ↓ 123.0 123 1

Nested Loop Left Join (cost=4.69..359.68 rows=1 width=58) (actual time=0.449..2.827 rows=123 loops=1)

  • Join Filter: (jnl_precision.journal_id = journal.id)
  • Rows Removed by Join Filter: 2,829
17. 0.427 2.078 ↓ 123.0 123 1

Nested Loop Left Join (cost=4.69..358.90 rows=1 width=62) (actual time=0.288..2.078 rows=123 loops=1)

  • Join Filter: (journal.id = st_line.journal_id)
  • Rows Removed by Join Filter: 2,214
18. 0.355 1.282 ↓ 123.0 123 1

Hash Join (cost=4.69..355.31 rows=1 width=50) (actual time=0.269..1.282 rows=123 loops=1)

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

Index Scan using account_bank_statement_line_pkey on account_bank_statement_line st_line (cost=0.29..350.43 rows=126 width=46) (actual time=0.092..0.776 rows=126 loops=1)

  • Index Cond: (id = ANY ('{23121,23120,23250,23249,23248,23247,23246,23245,23244,23241,23240,23239,23238,23237,23236,23235,23234,23233,23232,23231,23230,23229,23228,23227,23224,23223,23221,23220,23219,23218,23217,23216,23215,23214,23213,23212,23211,23210,23209,23208,23207,23206,23205,23204,23203,23202,23201,23200,23199,23198,23197,23195,23194,23193,23192,23191,23190,23189,23188,23187,23186,23185,23184,23183,23182,23181,23180,23179,23178,23177,23176,23175,23174,23173,23172,23171,23170,23169,23168,23167,23166,23165,23164,23163,23162,23161,23160,23159,23158,23157,23156,23155,23154,23153,23152,23151,23150,23149,23148,23147,23146,23145,23144,23143,23142,23141,23140,23139,23138,23137,23136,23135,23134,23133,23132,23131,23130,23129,23128,23127,23126,23125,23124,23123,23122,23196}'::integer[]))
20. 0.030 0.151 ↑ 1.0 123 1

Hash (cost=2.83..2.83 rows=125 width=8) (actual time=0.151..0.151 rows=123 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 13kB
21. 0.121 0.121 ↑ 1.0 123 1

CTE Scan on partners_table line_partner (cost=0.00..2.83 rows=125 width=8) (actual time=0.017..0.121 rows=123 loops=1)

  • Filter: (partner_id <> 0)
  • Rows Removed by Filter: 3
22. 0.369 0.369 ↑ 3.7 19 123

Seq Scan on account_journal journal (cost=0.00..2.71 rows=71 width=16) (actual time=0.002..0.003 rows=19 loops=123)

23. 0.492 0.492 ↑ 1.0 24 123

CTE Scan on jnl_precision (cost=0.00..0.48 rows=24 width=4) (actual time=0.001..0.004 rows=24 loops=123)

24. 44,357.121 44,357.121 ↑ 1.0 3,693,259 123

Seq Scan on account_move_line aml (cost=0.00..139,905.59 rows=3,693,259 width=52) (actual time=0.004..360.627 rows=3,693,259 loops=123)

25. 0.000 0.000 ↑ 3.0 2 725,933

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

26. 0.006 0.006 ↑ 3.0 2 1

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

27. 725.933 725.933 ↑ 1.0 1 725,933

Index Scan using account_move_pkey on account_move move (cost=0.43..0.47 rows=1 width=41) (actual time=0.001..0.001 rows=1 loops=725,933)

  • Index Cond: (id = aml.move_id)
28. 7,259.330 7,259.330 ↑ 9.3 186 725,933

Seq Scan on account_account account (cost=0.00..51.35 rows=1,735 width=11) (actual time=0.001..0.010 rows=186 loops=725,933)

Planning time : 21.693 ms
Execution time : 140,430.679 ms