Clickhouse: Slow query response by using date time field instead of date

Created on 17 Apr 2019  路  3Comments  路  Source: ClickHouse/ClickHouse

Hello,

I have created a table in CH using date and request_time as fields as shown below:

date Date DEFAULT toDate(request_time),
request_time DateTime DEFAULT now(),

I can see a huge difference in the response time when I run the following queries:

SELECT COUNT() FROM table WHERE field_name_1 ='sth' AND field_name_2 IN('sth') AND date >= '2019-04-16' AND date < '2019-04-17'

SELECT COUNT() FROM table WHERE field_name_1 ='sth' AND field_name_2 IN('sth') AND request_time >= '2019-04-16 00:00:00' AND request_time <= '2019-04-16 23:59:59'

The results respectively are shown below:

  1. 0.55 sec.| 11,954,689 rows | response 143164
  2. 2.25 sec.| 43,731,625 rows | response 143164

Could someone tell me why there is such a huge difference in the response time? I need to use the second query with the request time apparently.

question

Most helpful comment

Just use request_time in a partitioning expression and primary key expression.

create table (
....)
partition by toYYYYMM(request_time)
order by field_name_1, request_time

CH able to eliminate partitions and uses a table order (index organized table) for locating rows.

All 3 comments

Just use request_time in a partitioning expression and primary key expression.

create table (
....)
partition by toYYYYMM(request_time)
order by field_name_1, request_time

CH able to eliminate partitions and uses a table order (index organized table) for locating rows.

@den-crane can you still modify these table settings after table creation?

@bzon of course not (it has no sense it requires to remerge everything).
I am using https://clickhouse.yandex/docs/en/operations/table_engines/merge/ (Example 2:)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

opavader picture opavader  路  3Comments

jangorecki picture jangorecki  路  3Comments

atk91 picture atk91  路  3Comments

bseng picture bseng  路  3Comments

fizerkhan picture fizerkhan  路  3Comments