SELECT id, id as market_id FROM ( SELECT DISTINCT on (q.id) id, row FROM ( SELECT market.id, row_number() OVER(ORDER BY market.iorder) as row FROM market LEFT JOIN venue on market.id = venue.market_id and venue.active = 1 LEFT JOIN ct_event on venue.id = ct_event.venue_id and ct_event.active = 1 LEFT JOIN ct_contract on ( ct_event.ct_contract_id = ct_contract.id or ct_contract.market_id = market.id ) and ct_contract.active = 1 LEFT JOIN ct_contract_date on ct_contract.id = ct_contract_date.ct_contract_id and ct_contract_date.active = 1 LEFT JOIN ct_contract_category on ct_contract.id = ct_contract_category.ct_contract_id and ct_contract_category.active = 1 LEFT JOIN ct_subpromoter on ct_contract.ct_promoter_id = ct_subpromoter.producer__ct_promoter_id and ct_subpromoter.seller__ct_promoter_id = 1 and ct_subpromoter.active = 1 LEFT JOIN ct_contract_partner on ct_contract.id = ct_contract_partner.ct_contract_id and ct_contract_partner.ct_promoter_id = 1 and ct_contract_partner.active = 1 WHERE market.active = 1 AND market.id > 0 AND ( ct_subpromoter.id is not null or ct_contract_partner.id is not null or ct_contract.ct_promoter_id = 1 ) AND ct_contract_date.start_date >= now() - interval '1 day' AND ct_event.status in ('S', 'H', 'A', 'B') ORDER BY market.iorder ) as q ) as fin ORDER BY row
ERROR: canceling statement due to conflict with recovery DETAIL: User was holding a relation lock for too long.