ClickHouse for Advanced Users in Questions and Answers

In April, Avito engineers gathered for online gatherings with ClickHouse chief developer Alexei Milovidov and Kirill Shvakov, a Golang developer from Integros. They discussed how we use the database management system and what difficulties we are having.


Based on the meeting, we collected an article with expert answers to our and audience questions about backups, data resharding, external dictionaries, the Golang driver and ClickHouse version updates. It may be useful to developers who are already actively working with Yandex DBMS and are interested in its present and future. The default answer is Alexey Milovidov, unless otherwise written.


Caution, under the cut a lot of text. We hope that the content with questions will help you navigate.



Content



,   -. β€”    .

ClickHouse ,  β€” .   ?


ClickHouse , , optimize final ,   .

,   - , . , , ,     ,     ClickHouse.   , ?

,       ,   , .  ,  ClickHouse . ,  , - . ,  , ClickHouse . .


     ClickHouse?


  ,   optimize final,  , , , ,   ,   ?

  : - - . , , ?

    .         Β«.Β», . , .


,    ClickHouse,   . , . , ,   .


    . β€” .


  , :


  1. , β€” show create table.
  2.   ClickHouse β€” select * from table  .     TabSeparated. β€”   Native.

, . ,   ClickHouse. ,    MySQL  .


 ClickHouse   .   alter table freeze partition. alter table freeze β€” .


    , .   ,   .   .  -  ,  .


.  β€”   .  Directory-Detached   attach partition.   .


-  β€”   ,     . ,    Β«.Β». β€” , .


  .   ClickHouse ,   .   , . .  β€” LVM ,  β€” ZFS  Linux.


, - . , ,   .   , .  , .


 ?


 ClickHouse.   ?       .

- roll back ? ,   ,   ,   ?

  ,     , ,   ,   ?

  .   , issue    : Β« - , , Β». , issue . , , ClickHouse. ,   20.3.


ClickHouse    β€” . ,   .   , ,     .


-,   , select, ,   . select   .


-,   β€”   .   .  :     ,   ,   .   ClickHouse   .


,  . ,   ClickHouse , .  - , , , alter drop column.   .


  20.3, , .  β€” , . ,  , .   , , , , - ,   .   , ,   .


. alter delete alter update, , . .


, ?


,   ?     . Btrfs ZFS  Linux LVM?

attach partition   , ClickHouse , . .  β€” MergeTree   ,   attach, alter. attach , alter table move partition.


 β€” Btrfs. ,   LVM, LVM , ext4, .  Btrts   . ,   ,     . ,   Btrfs  .


  ?


  . .    β€”  ClickHouse . , .   ,  ClickHouse .


   , .   ,   , . ,  ,  , .


, , β€”     alter table fetch partition. ,  , 2017    , β€”  - . , - .


  ,  .   , .  . , .   , .


  ,   ,   , .        β€”  .   select  Distributed ,   .


,   ,   . ,     , , .   ,   select  β€” , ,  β€” .


.     ,  - , ,  Distributed . ClickHouse optimize skip unused shards.     select   where , ,   .  ,     . , .


, . , , .


, lead system administrator : , , ,   . ,   ,   , . , ,   ,   -   .


: β€” , , . , .   ,   . , ,   .


, , , .   . ,   ,   .   ,  ,   .


    2019 . ,  2019 ,   2019  β€”   ,  - . .   , ad hoc , .


   .   , ,   . .


,   .   .  β€” .  β€” .  β€” ,  . , .


,      β€” .     ,  select.  select, ,   .


, CPU  - - . , ,   .   , ,   .   ,  . , .


:  , ,    .     , ClickHouse   .


,     , .     .     , ClickHouse: Β«   . -   - ,  Β».


,   ,   ,  . .


:  ,   , , ,   .


  Β«.Β».  β€” , .   -. Β«.Β», β€” avito.ru,  ,   .


 β€” , .   ,   «». , «»   .   ,   .


,   , ?  ,  ClickHouse   «» β€”  .   , ,   ClickHouse .


 β€”  - .   Distributed , ,   .   ,  , ,   , .


. ,  ,     .  ,   - .   . avito.ru. , ,  β€”    .   .


.   , .     . .


?  β€” , .     .    β€”    -, ,   ,  MySQL.  β€”   .   .


      .   , ,       . , -   ,   .  , .    Distributed ,     . .


, ,   .     clickhouse-copier.


     β€” . , ,   ,   , 120      β€” 360 . ,   .  Β«.Β»  avito.ru,  120 .   .  , . Distributed ,   120 .


 β€”   .   ,   .


ClickHouse clickhouse-copier.   ?


, .  , , .  , .     .


,   .   , , , , .


, , .   Distributed , clickhouse-copier,   , , .     , ,   ,     .  , , .


clickhouse-copier?       . , clickhouse-copier     , ,    β€” insert select. , , , , -, . .


, .  ?


 2017 , .  ClickHouse. , . , ? .

 ,      , .  , , , . ,     , β€” .


    ?


 TTL   move to slow disk   . ,  cron,       ?

 , -      β€” . ,   .  ,  ,   .


.  β€”   .   - ,   . ,  β€” .


β€”  .   .     , .


  ClickHouse, ?


 - ClickHouse   , .   19.11  19.16 , ,  19.16  20.3.   ,  ?

«» .  β€” changelog. ,   .     . ,   , , , .


 β€”  ,  ,  β€” . . , , , ,     , .   . - ,  β€” .


 β€”       .   ClickHouse, .


20.3.4. 20   β€” 2020.   , , ,   .  β€” 20.3.  β€” 3 β€” ,  - .  ClickHouse - , .   20.4 ClickHouse .  β€” 20.3.4.  4 β€” -,   , - . 4 , .


, - . ,  -    . ,  -   , , . . -, ClickHouse .


  ClickHouse  , ClickHouse   β€” , 20.4.1 β€” ,     . ? ClickHouse, , , , . ClickHouse ,    β€” .


:   . - , , ClickHouse,   . .


  .   , ClickHouse.   β€”  Hetzner   , . ,  Ansible,   , β€”    .


?   ClickHouse ,    β€”  Docker,  LXC, , Ansible playbook,   . .   ,  - . ,   ,  β€”  . , .   β€” .


, senior backend engineer :     .   ClickHouse,   ,  .     .  -,   .  β€”  ,  , ,  ,     .    . , ,    .


: ,  Β«.Β».  600  - ,  360, .    β€”    . ? . . , .


- -. , ,  .


. ClickHouse.   ,   Β«.Β»,    , . , CI. .


.  . ,     . .   :     , , . . .  β€”   , .


- . : Β« , . , .  , . Β». , , β€”  .   .


Kill query , . ?


, - , , ClickHouse. -  β€”    ,   . ,  CPU    , . ClickHouse   . : Β« , , process list, Β».

kill. , .  , ClickHouse - , , , .     ,    ClickHouse, kill query . ? , kill query , .

.  , kill query .


Kill query   Β« , Β».     . , . , , .   ,   . , .


 ,  - . , , , ,   , . ,     .   , . , , β€” ClickHouse.


?


,    item β€” .  β€” .   , 1K RPS  1K item’?

 ,   ,    β€” , , .


.  select 1 ClickHouse  ,   . ,  - key-value ,    .   , .  β€”  8192  .  64   1 .   . .


.  , .   , ,   . 1000 RPS ClickHouse ,   , .


ClickHouse   ,  β€”   .    , ,   .


, , ClickHouse   .   ?  β€” .    ,  ,    .   ,   64.


.   min compress block size, max compress block size. , , . ClickHouse β€” key-value .  β€” .


:  , . ,  ClickHouse - . ,  - , - , - . MySQL,  β€”  MySQL duplicate key, PostgreSQL conflict β€” . .


  , ClickHouse . ,   .


ClickHouse,  ?


 β€”   256  ,   ClickHouse 60β€”80 ,   β€”  130. ,   , ,  ?

, page cache   . , cached free β€” ,  β€” ,  .    ,  . , , .


, , ClickHouse   . uncompressed cache. config.xml uncompressed cache size  β€” ,  page cache.


, . β€” use uncompressed cache β€” .   , , . β€” -   . , .


storage_configuration ?


ClickHouse ,  data storage.    fast SSD.

,  volume hot memory. . select   , ,  ,  ? prewhere   ?

  , .
.


  . ,   β€” . tmpfs ,  -   .       , , .


-  , ,     -, . , . , . , . ClickHouse   ,   , , ZooKeeper . , , . .


     ,      page cache .   .   , ClickHouse fsync  insert.


    ,  . select , ,   , . prewhere ,  ,    .


Low Cardinality?


Low Cardinality . , . -,   , -,   .  β€” -,  β€” , .


 :   β€” ,   β€” -   Low Cardinality . fallback, , . , string, , , .


      ?


.  β€” , ClickHouse β€”   .   , Elasticsearch Sphinx. , , ,  Elasticsearch  ClickHouse.


? , Elasticsearch    ,  , . , ,  ClickHouse, ,    .   ,   -   , . ,      - .


 ClickHouse ,    .   . , , -   like. like  ClickHouse β€” like, .  β€” .


like β€” full scan. full scan  CPU,  .    ,   - , .   ,   ,    SSH .


.    β€” , . ClickHouse   -.   Arenadata , , .


, , :   - . ,    - , ,  .     , .


 ClickHouse   . , -,   ,     ,   ,   UTF-8  ASCII. , .


  . X like or X like . , .


β€” . -  ,   .


 ClickHouse   ?


,   . , max concurrent queries, ?

, ,  .   , , ,   .       .   ,   .


,     .   , .


 ,   .   Β«.Β» select count from hits, , . , , β€” ,     . .


,   , .  β€” force index by date. , . , .  β€” where event date between . , and or β€” or URL match. , URL .


, ClickHouse .  , . priority. priority β‰  0,  - ,    , , ,   , ,   .


,   ,   .   , ,   , .


OS thread priority.   nice   Linux. , - . nice β€” ,  β€”     -19, CPU   , .


 β€” , .  β€” . , , , ClickHouse , .


, : -   β€” . , . .   . min execution speed β€”    , timeout before checking min execution speed β€” . , , , β€” .


.  ClickHouse , . ,  , CPU, ,  β€” , . , ,    .


?  ClickHouse . .     , ,   .  ,   .   .


?


,     . ,   , - , , . , , , ?

 ,   . page cache ,   , ,  , , .


- , ,  - .   pull request, , in join β€” .


,   .  β€”  . ,   , limit 10. , limit 10,10. . , ? , .


,  ClickHouse β€” ClickHouse Proxy.


:  ClickHouse Proxy . , . Proxy ,  , ,   . , Proxy ,  ClickHouse .


Nginx , .  Nginx , , , , .  ClickHouse Proxy .  ClickHouse, , . .


  ?


,  -  β€” , .    - ,   . - , .  ?

 β€”     . - Β« Β»,   ?

 , . ,   ,  ,     .


  . ,   , . β€œOk”    insert, , .


 .     β€œOk”, .  ClickHouse, , .   , , .  β€” .   , , .   .


,   .     ,   .


  .   , . , ,   . ,   ,   ,     .  β€”  insert.     .


.   . ,   , , , . , . , .


:     . , , ,   β€” . , , , . ,  β€” . .


? ,  β€”   ,  .  - , . , , ,   .  - ,  , .


API β€”  ClickHouse . API :    , , ,     .     ,   , . , ClickHouse.


  API -  β€”  ,   β€”  , . , .    - .   , .


ClickHouse . , ,  ?


ClickHouse , .   -   ,    . , .   ,  , ,  - .

  ClickHouse,   , ,   ?   ,  ClickHouse β€” . ,   .   .

, .     - 60  ClickHouse, ,   , , - . Β«.Β». , .   .


 Β«Β»  Grafana,   .   . , .   , Graphite-web. .   , Grafana, , .


  .  : CPU, , , .  β€” , ,  ,   MergeTree, , ,  ,  . ,  ,  .


: , . Grafana.  Grafana datasource, ClickHouse.  Grafana  ClickHouse.  ClickHouse  ,   .    Grafana   , . .


.  β€” , Grafana ,  Β«Β» ?


:   datasource,  ClickHouse, Altinity. , .  , «» - ClickHouse, . Altinity β€” , ClickHouse. , .  ,   Grafana,  β€” .


:  ClickHouse   .     . , , . , , . - , .


, ,    β€” ,   .  -, , . . , , : Β«, - Grafana?Β», : Β«   Grafana, β€œβ€, ,  . , , Β».


,  OOM?


,   , ReplacingMergeTree.     .   - .

,     , OOM. , , ,  OOM. . .

,   , . , . - . ,  ,  ,    β€”   - ? ,   ,     , .

, «», , ,   . ,  . ,   ,  , , . ? , -  ,   - , - ,   ,   .  OOM  . , .

,    OOM,     .   .


: . , , , ,   , , , .     100  . 150 , 100 ,  50 ,  OOM .


  ,  OOM,  100  ?  ,   ?


: ,   .  , , - , ,   .  β€” , ,   . , , , , .


,  , Β« Β»  OOM. , ,  - , ,  β€”   .   .


Golang- ClickHouse?


Golang-, , ClickHouse. ClickHouse, .

. β€” Vertica. python-, Vertica. , , - . . , , «» β€” issue, .

. Golang- β€” Golang ClickHouse. - http , . ? - breaking changes ? issue?

:  β€” . , .


   issue, .  ,   .   , - .  - ClickHouse. , , ClickHouse . , .


  ClickHouse, - .  β€” , . , .


 Go, ,  Go.  β€” .  - , , - . CloudFlare   , -   , .  ClickHouse ,  .


- ,   ClickHouse   . issues .   , - . pull request - , .


. , , ClickHouse   . , , . ,  2   -  .


, . . - , , . «»   .


:     .  β€”   ,    Go. - , .


  .  β€” ,   ,   -, - .


  lazy_load. ?


lazy_load, . ,   .   . - ClickHouse , , ?

  ClickHouse, . ?

-,   system reload dictionaries. -,   β€” ,   , . ,   .


  . ,  MySQL. - select, select . .  β€” lazy_load.  β€” , ,   , system reload dictionary , . .   lazy_load, ClickHouse .


 β€” , .


 , system reload dictionaries   ,    ?


  system reload dictionaries.    β€” , . System reload dictionaries   ,   c  system reload dictionary.   ClickHouse?

. . , ClickHouse, . system reload dictionaries, , ,   .


  ClickHouse,  ?


 ,  , .   ClickHouse  ,    .

  ODBC. -   ClickHouse,  ?

 β€” credentials  odbc.ini,   ClickHouse ODBC Data Source Name.    β€”  MySQL,     .  ODBC β€” , .


:  


     .   ,         .



All Articles