CDB-2649 Changed the CTE by another wrapped query that doesn't hits so much the DB