QUERY PLAN
Sort (cost=295.73..295.80 rows=29 width=136)
Sort Key: "*SELECT* 1".id DESC
-> Result (cost=82.85..295.03 rows=29 width=136)
-> Append (cost=82.85..294.74 rows=29 width=96)
-> Subquery Scan on "*SELECT* 1" (cost=82.85..150.34 rows=27 width=94)
-> Hash Join (cost=82.85..150.07 rows=27 width=98)
Hash Cond: (t.id = r.erp_collect_ticket_id)
-> Seq Scan on tbl_erp_collect_tickets t (cost=0.00..59.31 rows=1986 width=48)
Filter: (status = ANY ('{2,5,1}'::integer[]))
-> Hash (cost=82.51..82.51 rows=27 width=18)
-> Seq Scan on tbl_erp_collect_ticket_settles r (cost=0.00..82.51 rows=27 width=18)
Filter: ((sales_contract_id IS NOT NULL) AND (sales_contract_id = ANY ('{4075,4055,3997,3978,3967,3935,3916,3900,3857,3803,3763,3755,3746,3725,3724,3703,3661,3620,3525,3598}'::integer[])))
-> Subquery Scan on "*SELECT* 2" (cost=12.65..50.17 rows=1 width=120)
-> Hash Join (cost=12.65..50.16 rows=1 width=124)
Hash Cond: (r_1.erp_cash_cost_ticket_id = t_1.id)
-> Seq Scan on tbl_erp_cash_cost_ticket_sales_contract_settles r_1 (cost=0.00..37.30 rows=78 width=44)
Filter: ((sales_contract_id IS NOT NULL) AND (sales_contract_id = ANY ('{4075,4055,3997,3978,3967,3935,3916,3900,3857,3803,3763,3755,3746,3725,3724,3703,3661,3620,3525,3598}'::integer[])))
-> Hash (cost=12.61..12.61 rows=3 width=48)
-> Seq Scan on tbl_erp_cash_cost_tickets t_1 (cost=0.00..12.61 rows=3 width=48)
Filter: (status = ANY ('{2,5,1}'::integer[]))
-> Subquery Scan on "*SELECT* 3" (cost=0.28..94.22 rows=1 width=120)
-> Nested Loop (cost=0.28..94.21 rows=1 width=124)
-> Seq Scan on tbl_erp_payment_ticket_settles r_2 (cost=0.00..85.89 rows=1 width=18)
Filter: ((sales_contract_id IS NOT NULL) AND (sales_contract_id = ANY ('{4075,4055,3997,3978,3967,3935,3916,3900,3857,3803,3763,3755,3746,3725,3724,3703,3661,3620,3525,3598}'::integer[])))
-> Index Scan using tbl_erp_payment_tickets_pkey on tbl_erp_payment_tickets t_2 (cost=0.28..8.30 rows=1 width=48)
Index Cond: (id = r_2.erp_payment_ticket_id)
Filter: (status = ANY ('{2,5,1}'::integer[]))