Skip to content

DateTime64 (Decimal64) comparsion much slower than UInt64 or DateTime #28192

Closed

Description

@UnamedRus

Describe the situation
Equality, non-equality conditions over DateTime64 column.
Not sure about how decimal values being stored on disk / in memory, but when we do compare column and literal, we can convert literal value to the same precise as decimal column and just compare bit's like in UInt64, so decimal datatype shouldn't have any impact for performance.

How to reproduce
Clickhouse version 21.8

SELECT count()
FROM numbers_mt(10000000000)
WHERE materialize(toDateTime64(1000000, 3)) = toDateTime64(1000000, 3)

┌─────count()─┐
│ 10000000000 │
└─────────────┘

1 rows in set. Elapsed: 1.679 sec. Processed 10.00 billion rows, 80.00 GB (5.95 billion rows/s., 47.64 GB/s.)

SELECT count()
FROM numbers_mt(10000000000)
WHERE materialize(toDecimal64(toDateTime64(1000000, 3), 3)) = toDecimal64(toDateTime64(1000000, 3), 3)

Query id: 98b50c04-9067-4d6c-9ae2-346f9a64d8d6

┌─────count()─┐
│ 10000000000 │
└─────────────┘

1 rows in set. Elapsed: 1.812 sec. Processed 10.00 billion rows, 80.00 GB (5.52 billion rows/s., 44.16 GB/s.)


SELECT count()
FROM numbers_mt(10000000000)
WHERE materialize(toUInt64(toDateTime64(1000000, 3))) = toUInt64(toDateTime64(1000000, 3))

┌─────count()─┐
│ 10000000000 │
└─────────────┘

1 rows in set. Elapsed: 0.975 sec. Processed 10.00 billion rows, 80.00 GB (10.26 billion rows/s., 82.06 GB/s.)


SELECT count()
FROM numbers_mt(10000000000)
WHERE materialize(toDateTime(1000000)) = toDateTime(1000000)

┌─────count()─┐
│ 10000000000 │
└─────────────┘

1 rows in set. Elapsed: 0.508 sec. Processed 10.00 billion rows, 80.00 GB (19.70 billion rows/s., 157.57 GB/s.)

Expected performance
DateTime64 compare with literal would have at least half of DateTime performance or the same as UInt64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions