In SQL databases (I use Python+Sqlite), how to make sure that, if we have 1 million rows, the query
SELECT * FROM mytable WHERE myfunction(description) <
One way that you can force the order of execution is using a case expression. In general, SQL optimizers can re-arrange operations, the one exception is case.
SELECT *
FROM mytable
WHERE (CASE WHEN column2 >= 1000 OR column2 IS NULL THEN 0
WHEN myfunction(description) < 500 THEN 1
END) = 1;
Generally, case expressions are discouraged in WHERE clauses . . . one major reason is that they impede optimization. In this case, that is a good thing.