mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 16:12:01 +00:00
Merge pull request #63443 from ClickHouse/fix-index-analysis-datetime64
Fix index analysis for `DateTime64`
This commit is contained in:
commit
977783ea94
@ -4853,7 +4853,7 @@ FunctionBasePtr createFunctionBaseCast(
|
||||
DataTypeUInt8, DataTypeUInt16, DataTypeUInt32, DataTypeUInt64, DataTypeUInt128, DataTypeUInt256,
|
||||
DataTypeInt8, DataTypeInt16, DataTypeInt32, DataTypeInt64, DataTypeInt128, DataTypeInt256,
|
||||
DataTypeFloat32, DataTypeFloat64,
|
||||
DataTypeDate, DataTypeDate32, DataTypeDateTime,
|
||||
DataTypeDate, DataTypeDate32, DataTypeDateTime, DataTypeDateTime64,
|
||||
DataTypeString>(return_type.get(), [&](auto & type)
|
||||
{
|
||||
monotonicity = FunctionTo<std::decay_t<decltype(type)>>::Type::Monotonic::get;
|
||||
|
@ -1,57 +0,0 @@
|
||||
drop table if exists dt64_monot_test;
|
||||
drop table if exists dt64_monot_test_string;
|
||||
CREATE TABLE dt64_monot_test(`date_time` DateTime64(3, 'Europe/Berlin'), `id` String) ENGINE = MergeTree PARTITION BY toDate(date_time, 'Europe/Berlin') ORDER BY date_time;
|
||||
insert into dt64_monot_test select toDateTime64('2020-01-01 00:00:00.000',3)+number , '' from numbers(10);
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime(date_time) >= toDateTime('2020-01-01 00:00:00') SETTINGS force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time, 3) >= '2020-01-01 00:00:01.111' SETTINGS force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time, 3) >= '2020-01-01 00:00:00.000' SETTINGS force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,3) >= toDateTime64('2020-01-01 00:00:00.000001', 3) SETTINGS force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,3) >= toDateTime64('2020-01-01 00:00:00.000001', 3, 'Europe/Berlin') SETTINGS force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,3) >= toDateTime64('2020-01-01 00:00:00.000001',6) SETTINGS force_index_by_date = 1; -- { serverError 277}
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,3) >= toDateTime64('2020-01-01 00:00:00.000001',6, 'Europe/Berlin') SETTINGS force_primary_key = 1; -- { serverError 277}
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,3) >= toDateTime64('2020-01-01 00:00:00.000001',6) SETTINGS force_primary_key = 1; -- { serverError 277}
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,3) <= toDateTime64('2020-01-01 00:00:00.000001',3, 'Europe/Berlin') settings force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,3) <= toDateTime64('2020-01-01 00:00:00.000001',3) settings force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,3) = toDateTime64('2020-01-01 00:00:00.000000',6);
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,3) = toDateTime64('2020-01-01 00:00:00.000000',6, 'Europe/Berlin');
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,6) = toDateTime64('2020-01-01 00:00:00.000000',6) settings force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,6) = toDateTime64('2020-01-01 00:00:00.000001',6, 'Europe/Berlin') settings force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,6) > toDateTime64('2020-01-01 00:00:00.000001',6, 'Europe/Berlin') settings force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,6) >= toDateTime64('2020-01-01 00:00:00.000001',6, 'Europe/Berlin') settings force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,6) >= toDateTime64('2020-01-01 00:00:00.000001',6) settings force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,0) >= toDateTime64('2020-01-01 00:00:00.000001',0, 'Europe/Berlin') settings force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,0) >= toDateTime64('2020-01-01 00:00:00.000001',0) settings force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,0) >= '2020-01-01 00:00:00' settings force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
SELECT count() FROM dt64_monot_test WHERE toDateTime64(date_time,0) >= '2020-01-01 00:00:01.1' settings force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
create table dt64_monot_test_string(date_time String, x String) Engine=MergeTree order by date_time;
|
||||
insert into dt64_monot_test_string select '2020-01-01 00:00:00.000000001', '' from numbers(1);
|
||||
insert into dt64_monot_test_string select '2020-01-01 00:00:00.000', '' from numbers(10);
|
||||
|
||||
SELECT count() FROM dt64_monot_test_string WHERE toDateTime64(date_time,9) = '2020-01-01 00:00:00.000000000';
|
||||
SELECT count() FROM dt64_monot_test_string WHERE toDateTime64(date_time,3) = '2020-01-01 00:00:00.000000001';
|
||||
SELECT count() FROM dt64_monot_test_string WHERE toDateTime64(date_time,9) = '2020-01-01 00:00:00';
|
||||
|
||||
drop table dt64_monot_test;
|
||||
drop table dt64_monot_test_string;
|
@ -4,6 +4,9 @@ Asia/Tehran
|
||||
0
|
||||
10
|
||||
0
|
||||
9
|
||||
0
|
||||
9
|
||||
10
|
||||
1
|
||||
1
|
||||
@ -27,6 +30,9 @@ UTC
|
||||
10
|
||||
10
|
||||
10
|
||||
9
|
||||
10
|
||||
9
|
||||
0
|
||||
1
|
||||
1
|
||||
@ -50,6 +56,9 @@ Canada/Atlantic
|
||||
10
|
||||
10
|
||||
10
|
||||
9
|
||||
10
|
||||
9
|
||||
0
|
||||
1
|
||||
1
|
||||
@ -73,6 +82,9 @@ Europe/Berlin
|
||||
10
|
||||
10
|
||||
10
|
||||
9
|
||||
9
|
||||
9
|
||||
1
|
||||
1
|
||||
1
|
||||
|
@ -7,6 +7,44 @@ CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
for tz in Asia/Tehran UTC Canada/Atlantic Europe/Berlin
|
||||
do
|
||||
echo "$tz"
|
||||
TZ=$tz $CLICKHOUSE_LOCAL -mn < ${CUR_DIR}/02373_datetime64_monotonicity.queries
|
||||
TZ=$tz $CLICKHOUSE_LOCAL --multiline --multiquery "
|
||||
drop table if exists dt64_monotonicity_test;
|
||||
drop table if exists dt64_monotonicity_test_string;
|
||||
CREATE TABLE dt64_monotonicity_test (date_time DateTime64(3, 'Europe/Berlin'), id String) ENGINE = MergeTree PARTITION BY toDate(date_time, 'Europe/Berlin') ORDER BY date_time;
|
||||
insert into dt64_monotonicity_test select toDateTime64('2020-01-01 00:00:00.000', 3) + number, '' from numbers(10);
|
||||
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime(date_time) >= toDateTime('2020-01-01 00:00:00') SETTINGS force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 3) >= '2020-01-01 00:00:01.111' SETTINGS force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 3) >= '2020-01-01 00:00:00.000' SETTINGS force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 3) >= toDateTime64('2020-01-01 00:00:00.000001', 3) SETTINGS force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 3) >= toDateTime64('2020-01-01 00:00:00.000001', 3, 'Europe/Berlin') SETTINGS force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 3) >= toDateTime64('2020-01-01 00:00:00.000001', 6) SETTINGS force_index_by_date = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 3) >= toDateTime64('2020-01-01 00:00:00.000001', 6, 'Europe/Berlin') SETTINGS force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 3) >= toDateTime64('2020-01-01 00:00:00.000001', 6) SETTINGS force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 3) <= toDateTime64('2020-01-01 00:00:00.000001', 3, 'Europe/Berlin') settings force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 3) <= toDateTime64('2020-01-01 00:00:00.000001', 3) settings force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 3) = toDateTime64('2020-01-01 00:00:00.000000', 6);
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 3) = toDateTime64('2020-01-01 00:00:00.000000', 6, 'Europe/Berlin');
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 6) = toDateTime64('2020-01-01 00:00:00.000000', 6) settings force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 6) = toDateTime64('2020-01-01 00:00:00.000001', 6, 'Europe/Berlin') settings force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 6) > toDateTime64('2020-01-01 00:00:00.000001', 6, 'Europe/Berlin') settings force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 6) >= toDateTime64('2020-01-01 00:00:00.000001', 6, 'Europe/Berlin') settings force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 6) >= toDateTime64('2020-01-01 00:00:00.000001', 6) settings force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 0) >= toDateTime64('2020-01-01 00:00:00.000001', 0, 'Europe/Berlin') settings force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 0) >= toDateTime64('2020-01-01 00:00:00.000001', 0) settings force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 0) >= '2020-01-01 00:00:00' settings force_index_by_date = 1, force_primary_key = 1;
|
||||
SELECT count() FROM dt64_monotonicity_test WHERE toDateTime64(date_time, 0) >= '2020-01-01 00:00:01.1' settings force_index_by_date = 1, force_primary_key = 1;
|
||||
|
||||
create table dt64_monotonicity_test_string(date_time String, x String) Engine=MergeTree order by date_time;
|
||||
insert into dt64_monotonicity_test_string select '2020-01-01 00:00:00.000000001', '' from numbers(1);
|
||||
insert into dt64_monotonicity_test_string select '2020-01-01 00:00:00.000', '' from numbers(10);
|
||||
|
||||
SELECT count() FROM dt64_monotonicity_test_string WHERE toDateTime64(date_time,9) = '2020-01-01 00:00:00.000000000';
|
||||
SELECT count() FROM dt64_monotonicity_test_string WHERE toDateTime64(date_time,3) = '2020-01-01 00:00:00.000000001';
|
||||
SELECT count() FROM dt64_monotonicity_test_string WHERE toDateTime64(date_time,9) = '2020-01-01 00:00:00';
|
||||
|
||||
drop table dt64_monotonicity_test;
|
||||
drop table dt64_monotonicity_test_string;
|
||||
"
|
||||
echo ""
|
||||
done
|
||||
|
@ -0,0 +1,6 @@
|
||||
7385
|
||||
7385
|
||||
7385
|
||||
7385
|
||||
86401
|
||||
86401
|
@ -0,0 +1,12 @@
|
||||
DROP TABLE IF EXISTS test;
|
||||
CREATE TABLE test (d DateTime, PRIMARY KEY (d));
|
||||
INSERT INTO test SELECT toDateTime('2024-01-01') + number FROM numbers(1e6);
|
||||
SET max_rows_to_read = 10000;
|
||||
SELECT count() FROM test WHERE d <= '2024-01-01 02:03:04';
|
||||
SELECT count() FROM test WHERE d <= toDateTime('2024-01-01 02:03:04');
|
||||
SELECT count() FROM test WHERE d <= toDateTime64('2024-01-01 02:03:04', 0);
|
||||
SELECT count() FROM test WHERE d <= toDateTime64('2024-01-01 02:03:04', 3);
|
||||
SET max_rows_to_read = 100_000;
|
||||
SELECT count() FROM test WHERE d <= '2024-01-02';
|
||||
SELECT count() FROM test WHERE d <= toDate('2024-01-02');
|
||||
DROP TABLE test;
|
Loading…
Reference in New Issue
Block a user