Let me explain how ClickHouse can utilize an index in this case, despite the expression intDiv(X, 10) = ?
appearing non-sargable at first glance.
The key lies in ClickHouse's ability to perform monotonic function analysis. Here's how it works:
First, let's understand what makes intDiv(X, 10)
special. The integer division function is monotonic - as X increases, intDiv(X, 10)
either increases or stays the same, never decreases. For example:
X = 45 -> intDiv(X, 10) = 4
X = 46 -> intDiv(X, 10) = 4
X = 50 -> intDiv(X, 10) = 5