QUERY PLAN
GroupAggregate (cost=117.78..118.01 rows=10 width=44)
Group Key: sub.status
-> Sort (cost=117.78..117.81 rows=10 width=10)
Sort Key: sub.status
-> Subquery Scan on sub (cost=117.39..117.62 rows=10 width=10)
-> Group (cost=117.39..117.52 rows=10 width=14)
Group Key: r.id
-> Sort (cost=117.39..117.42 rows=10 width=13)
Sort Key: r.id
-> Hash Right Join (cost=94.98..117.23 rows=10 width=13)
Hash Cond: (rvr.erp_payment_ticket_id = r.id)
Filter: ((r.created_by = 1004) OR (rvr.user_id = 1004) OR (r.created_by = 1004))
-> Seq Scan on tbl_erp_payment_ticket_verify_rels rvr (cost=0.00..19.70 rows=970 width=8)
-> Hash (cost=69.16..69.16 rows=2066 width=17)
-> Seq Scan on tbl_erp_payment_tickets r (cost=0.00..69.16 rows=2066 width=17)
Filter: ((status <> 0) OR ((status = 0) AND (created_by = 1004)))