Suppose someone wrote the following query
SELECT col1, col2 FROM tableWHERE CAST(col1 AS INTEGER) AND f(col2) = 2
such that f doesn't have a good inverse function that I could apply to 2. The transformed fields become non-SARGable, right? Thus, we should avoid transforming the right side of any WHERE/JOIN keys when we are able to do so. However, if we aren't able to do it, is the following query more efficient?
WITH table2 AS ( SELECT CAST(col1 AS INTEGER) AS col1, f(col2) AS col2 FROM table)SELECT col1, col2,FROM table2WHERE col1 = 3 AND col2 = 2