ClickHouse/dbms
Marek Vavruša ff73394124 PKCondition: infer index use with pk subexpression
By default only constraints explicitly matching
primary key expression (or expression wrapped in
a monotonic function) are eligible for part and
range selection. So for example, if index is:

(toStartOfHour(dt), UserID)

Then a query such as this resorts to full scan:

SELECT count() FROM t WHERE dt = now()

Intuitively, only parts with toStartOfHour(now())
could be selected, but it is less trivial to prove.
The primary key currently can be wrapped in a chain
of monotonic functions, so following would work:

toStartOfHour(dt) = toStartOfHour(now()) AND dt = now()

It must be however explicitly stated, if we wanted
to infer that we’d have to know the inverse function,
and prove that the inverse function is monotonic
on given interval. This is not practical as
there is no inverse function that for example undos
rounding, it isn’t strictly monotonic.

There are however functions that don’t transform
output range and preserve monotonicity on the
complete input range, such as rounding or casts
to a same or wider numeric type. This eliminates
the need to find inverse function, as no check for monotonicity over arbitrary interval is needed,
and thus makes this optimisation possible.
2017-07-09 17:13:51 +03:00
..
benchmark Fool's day changed, continued [#CLICKHOUSE-3]. 2017-04-05 14:52:23 +03:00
cmake Auto version update to [54248] 2017-07-05 21:47:14 +03:00
scripts Fool's day changed, continued [#CLICKHOUSE-3]. 2017-04-05 14:52:23 +03:00
src PKCondition: infer index use with pk subexpression 2017-07-09 17:13:51 +03:00
tests Fixed multiIf in case of empty arguments. [#CLICKHOUSE-3119] 2017-07-07 17:42:37 +03:00
CMakeLists.txt Reorganize includes. part 1 (#921) 2017-06-23 23:22:35 +03:00