QUERY PLAN
Sort (cost=94.04..94.05 rows=3 width=184)
Sort Key: sub.id DESC
-> Subquery Scan on sub (cost=0.00..94.02 rows=3 width=184)
-> Append (cost=0.00..93.99 rows=3 width=124)
-> Subquery Scan on "*SELECT* 1" (cost=0.00..31.12 rows=1 width=124)
-> Nested Loop (cost=0.00..31.10 rows=1 width=120)
Join Filter: (r.erp_collect_ticket_id = t.id)
-> Seq Scan on tbl_erp_collect_ticket_settles r (cost=0.00..18.75 rows=3 width=44)
Filter: ((sales_contract_id IS NOT NULL) AND (sales_contract_id = 8))
-> Materialize (cost=0.00..12.26 rows=2 width=52)
-> Seq Scan on tbl_erp_collect_tickets t (cost=0.00..12.25 rows=2 width=52)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Nested Loop (cost=0.00..31.81 rows=1 width=124)
Join Filter: (r_1.erp_cash_cost_ticket_id = t_1.id)
-> Seq Scan on tbl_erp_cash_cost_tickets t_1 (cost=0.00..12.38 rows=1 width=48)
Filter: (is_payment_settle AND (status = ANY ('{2,5}'::integer[])))
-> Seq Scan on tbl_erp_cash_cost_ticket_sales_contract_settles r_1 (cost=0.00..19.38 rows=4 width=44)
Filter: ((sales_contract_id IS NOT NULL) AND (sales_contract_id = 8))
-> Nested Loop (cost=0.00..31.05 rows=1 width=124)
Join Filter: (r_2.erp_payment_ticket_id = t_2.id)
-> Seq Scan on tbl_erp_payment_tickets t_2 (cost=0.00..12.25 rows=1 width=48)
Filter: (is_payment_settle AND (status = ANY ('{2,5}'::integer[])))
-> Seq Scan on tbl_erp_payment_ticket_settles r_2 (cost=0.00..18.75 rows=3 width=44)
Filter: ((sales_contract_id IS NOT NULL) AND (sales_contract_id = 8))