QUERY PLAN
Limit (cost=341.05..341.10 rows=20 width=21)
-> Sort (cost=341.05..341.55 rows=200 width=21)
Sort Key: s.created_at DESC
-> Subquery Scan on s (cost=331.73..335.73 rows=200 width=21)
-> HashAggregate (cost=331.73..333.73 rows=200 width=21)
Group Key: "*SELECT* 1".title
-> Append (cost=194.76..326.85 rows=977 width=21)
-> Subquery Scan on "*SELECT* 1" (cost=194.76..209.06 rows=715 width=21)
-> HashAggregate (cost=194.76..201.91 rows=715 width=34)
Group Key: pip.title
-> Hash Left Join (cost=92.83..190.03 rows=945 width=21)
Hash Cond: (pip.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_purchase_invoice_products pip (cost=0.00..94.72 rows=945 width=17)
Filter: ((title)::text ~~* '%2%'::text)
-> Hash (cost=60.70..60.70 rows=2570 width=12)
-> Seq Scan on tbl_purchase_contract_invoices pci (cost=0.00..60.70 rows=2570 width=12)
-> Subquery Scan on "*SELECT* 2" (cost=112.55..117.79 rows=262 width=20)
-> HashAggregate (cost=112.55..115.17 rows=262 width=32)
Group Key: pip_1.title
-> Hash Left Join (cost=71.99..110.82 rows=347 width=20)
Hash Cond: (pip_1.sales_invoice_id = pci_1.id)
-> Seq Scan on tbl_sales_invoice_products pip_1 (cost=0.00..37.91 rows=347 width=16)
Filter: ((title)::text ~~* '%2%'::text)
-> Hash (cost=45.33..45.33 rows=2133 width=12)
-> Seq Scan on tbl_sales_contract_invoices pci_1 (cost=0.00..45.33 rows=2133 width=12)