I've added another possibility recently: _partition_value. This
can be useful in real queries as partition keys are deterministic
and immutable.
https://github.com/ClickHouse/ClickHouse/pull/23673
Denis Zhuravlev <
denis.z...@gmail.com> writes:
>>And thanks for the tests I didn't even know I can select from
>>partition
> using *_partition_id*. Thank you! :-)
> I suggest to never use *_partition_id *in real queries, only for
> debug
> purposes.
> Use *and toYYYYMM(date) in (202001, 202002);*
>
>
> On Thursday, May 6, 2021 at 10:19:16 a.m. UTC-3
>
filip.p...@gmail.com wrote:
>
>> That's awesome! I'm using last stable version v21.4.6.55 so it
>> probably
>> will work.
>>
>> And thanks for the tests I didn't even know I can select from
>> partition
>> using *_partition_id*. Thank you! :-)
>>
>> Dne čtvrtek 6. května 2021 v 15:01:25 UTC+2 uživatel
>>
denis.z...@gmail.com
>> napsal:
>>
>>> CH version? It's important for answering your question.
>>>
>>> Partition pruner is quite sophisticated and can eliminate
>>> excessive
>>> partitions in various expressions on partitioned columns:
>>>
>>> CREATE TABLE t
>>>
>>> (
>>> `scheme` LowCardinality(String),
>>> `domain` String,
>>> `path` String,
>>> `date` Date,
>>> `estimate` UInt8
>>> )
>>> ENGINE = MergeTree
>>> PARTITION BY toYYYYMM(date)
>>> ORDER BY (domain, path)
>>>
>>> insert into t(date) select toDate('2020-01-01') +
>>> number/10000 from
>>> numbers(1000000);
>>>
>>> set send_logs_level='debug';
>>>
>>> select count() from t where domain = '' *and toYYYYMM(date) in
>>> (202001,
>>> 202002);*
>>>
>>> *Processed 600.00 thousand rows*
>>> ...
>>> *Selected 2/4 parts by partition key*
>>>
>>>
>>> select count() from t where domain = '' *and
>>> toStartOfMonth(date) in
>>> ('2020-01-01', '2020-02-01');*
>>> *Processed 600.00 thousand rows*
>>> ...
>>> *Selected 2/4 parts by partition key*
>>>
>>>
>>> select count() from t where domain = ''* and _partition_id in
>>> ('202001',
>>> '202002');*
>>> *Processed 600.00 thousand rows*
>>> *...*
>>> *Selected 2/4 parts by partition key*
>>> *toYYYYMM(toDateTime(intDiv(d,1000),'UTC'))+1* or *
>>> toDateTime(intDiv(d,1000),'UTC') *, before a query execution:
>>>
>>> CREATE TABLE sDD(d UInt64,a Int) ENGINE = MergeTree
>>> PARTITION BY *toYYYYMM(toDate(intDiv(d,1000)))*
>>> ORDER BY tuple() SETTINGS index_granularity = 8192;
>>>
>>> select uniqExact(_part), count() from sDD
>>> where *toYYYYMM(toDateTime(intDiv(d,1000),'UTC'))+1 > 202009
>>> and
>>> toDateTime(intDiv(d,1000),'UTC') < toDateTime('2020-10-01
>>> 00:00:00','UTC');*