QUERY PLAN
Limit (cost=82.28..82.29 rows=3 width=198)
-> Sort (cost=82.28..82.29 rows=3 width=198)
Sort Key: c.serial_no, c.id, (0), (0), (0), (0)
-> Append (cost=37.77..82.26 rows=3 width=198)
-> Unique (cost=37.77..37.81 rows=2 width=198)
-> Sort (cost=37.77..37.77 rows=2 width=198)
Sort Key: ((((c.serial_no)::text || ' '::text) || (c.title)::text)), ((c.direction)::integer), (CASE WHEN (c.direction = 1) THEN '借'::text WHEN (c.direction = 2) THEN '贷'::text ELSE ''::text END), ((COALESCE(c.amount, '0'::numeric))::text), ((COALESCE(ca.debit_amount, '0'::numeric))::text), ((COALESCE(ca.credit_amount, '0'::numeric))::text), c.id, c.serial_no
-> Nested Loop Anti Join (cost=7.56..37.76 rows=2 width=198)
-> Hash Left Join (cost=7.29..26.85 rows=2 width=101)
Hash Cond: (c.id = ca.ledger_account_caption_id)
-> Nested Loop Left Join (cost=0.14..19.70 rows=2 width=37)
Join Filter: ((a.ledger_id = c.ledger_id) AND ((c.is_auxiliary_customer AND (a.type = 1)) OR (c.is_auxiliary_supplier AND (a.type = 2))))
Filter: (((c.serial_no)::text ~~ '%1221%'::text) OR ((c.title)::text ~~ '%1221%'::text) OR ((a.serial_no)::text ~~ '%1221%'::text) OR ((a.title)::text ~~ '%1221%'::text))
-> Seq Scan on tbl_ledger_account_captions c (cost=0.00..10.21 rows=44 width=39)
Filter: ((NOT is_delete) AND (NOT COALESCE(is_auxiliary_customer, false)) AND (NOT COALESCE(is_auxiliary_supplier, false)) AND (ledger_id = 1))
-> Materialize (cost=0.14..8.17 rows=1 width=308)
-> Index Scan using idx_tbl_ledger_auxiliary_items_ledger_serial_no on tbl_ledger_auxiliary_items a (cost=0.14..8.17 rows=1 width=308)
Index Cond: (ledger_id = 1)
Filter: ((NOT is_delete) AND ((type = 1) OR (type = 2)))
-> Hash (cost=6.87..6.87 rows=22 width=68)
-> Subquery Scan on ca (cost=6.32..6.87 rows=22 width=68)
-> HashAggregate (cost=6.32..6.65 rows=22 width=68)
Group Key: i.ledger_account_caption_id
-> Hash Join (cost=2.04..5.48 rows=112 width=12)
Hash Cond: (i.ledger_ticket_id = t.id)
-> Seq Scan on tbl_ledger_ticket_items i (cost=0.00..3.12 rows=112 width=16)
Filter: (ledger_account_caption_id IS NOT NULL)
-> Hash (cost=1.57..1.57 rows=38 width=4)
-> Seq Scan on tbl_ledger_tickets t (cost=0.00..1.57 rows=38 width=4)
Filter: ((ledger_id = 1) AND (status = 1))
-> Index Scan using idx_tbl_ledger_account_captions_ledger_id on tbl_ledger_account_captions child (cost=0.27..5.34 rows=8 width=8)
Index Cond: ((ledger_id = c.ledger_id) AND (ledger_id = 1))
Filter: ((NOT is_delete) AND (parent_id = c.id))
-> Nested Loop Anti Join (cost=5.16..44.41 rows=1 width=198)
Join Filter: ((child_1.ledger_id = c_1.ledger_id) AND (child_1.parent_id = c_1.id))
-> Nested Loop Left Join (cost=5.16..31.51 rows=1 width=442)
Join Filter: ((i_1.ledger_account_caption_id = c_1.id) AND (i_1.auxiliary_item_id = a_1.id))
-> Nested Loop Left Join (cost=0.29..26.59 rows=1 width=378)
Join Filter: (o.auxiliary_item_id = a_1.id)
-> Nested Loop (cost=0.14..18.40 rows=1 width=346)
Join Filter: (((c_1.is_auxiliary_customer AND (a_1.type = 1)) OR (c_1.is_auxiliary_supplier AND (a_1.type = 2))) AND (((c_1.serial_no)::text ~~ '%1221%'::text) OR ((c_1.title)::text ~~ '%1221%'::text) OR ((a_1.serial_no)::text ~~ '%1221%'::text) OR ((a_1.title)::text ~~ '%1221%'::text)))
-> Seq Scan on tbl_ledger_account_captions c_1 (cost=0.00..10.21 rows=1 width=36)
Filter: ((NOT is_delete) AND (is_auxiliary_customer OR is_auxiliary_supplier) AND (ledger_id = 1))
-> Index Scan using idx_tbl_ledger_auxiliary_items_ledger_serial_no on tbl_ledger_auxiliary_items a_1 (cost=0.14..8.17 rows=1 width=316)
Index Cond: (ledger_id = 1)
Filter: ((NOT is_delete) AND ((type = 1) OR (type = 2)))
-> Index Scan using idx_tbl_ledger_auxiliary_opening_balances_unique_item on tbl_ledger_auxiliary_opening_balances o (cost=0.15..8.17 rows=1 width=44)
Index Cond: ((ledger_id = c_1.ledger_id) AND (ledger_id = 1) AND (ledger_account_caption_id = c_1.id))
-> GroupAggregate (cost=4.87..4.89 rows=1 width=72)
Group Key: i_1.ledger_account_caption_id, i_1.auxiliary_item_id
-> Sort (cost=4.87..4.87 rows=1 width=16)
Sort Key: i_1.ledger_account_caption_id, i_1.auxiliary_item_id
-> Hash Join (cost=3.13..4.86 rows=1 width=16)
Hash Cond: (t_1.id = i_1.ledger_ticket_id)
-> Seq Scan on tbl_ledger_tickets t_1 (cost=0.00..1.57 rows=38 width=4)
Filter: ((ledger_id = 1) AND (status = 1))
-> Hash (cost=3.12..3.12 rows=1 width=20)
-> Seq Scan on tbl_ledger_ticket_items i_1 (cost=0.00..3.12 rows=1 width=20)
Filter: ((ledger_account_caption_id IS NOT NULL) AND (auxiliary_item_id IS NOT NULL))
-> Seq Scan on tbl_ledger_account_captions child_1 (cost=0.00..10.21 rows=177 width=8)
Filter: ((NOT is_delete) AND (ledger_id = 1))