Fix for subqueries
WIP: Write data to optimizer_cost_factors table