If value represents a query that can be optimized, returns the optimized query. Otherwise returns value.