{"id":308064,"date":"2020-08-06T09:00:12","date_gmt":"2020-08-06T09:00:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308064"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308064","title":{"rendered":"\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u0432 ClickHouse"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/rebrainme\/blog\/513972\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/hd\/m1\/sa\/hdm1saopaqfgg2-u1bapnqxy80s.png\"><\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043e\u0442\u043a\u0440\u044b\u043b\u0438 \u044d\u0442\u0443 <del>\u0434\u0432\u0435\u0440\u044c<\/del> \u0441\u0442\u0430\u0442\u044c\u044e, \u0442\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430, \u0432\u044b \u0443\u0436\u0435 \u0438\u043c\u0435\u043b\u0438 \u0434\u0435\u043b\u043e \u0441 ClickHouse \u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043e\u0431 \u0435\u0433\u043e \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0435 \u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438, \u0430 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0441\u0440\u0430\u0437\u0443 \u043a \u0434\u0435\u043b\u0443 \u2013 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043a \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0438\u043c\u0438 \u0432 ClickHouse.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"chto-takoe-slovari-v-clickhouse\">\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u0432 ClickHouse?<\/h2>\n<p>  <\/p>\n<p><strong>\u0421\u043b\u043e\u0432\u0430\u0440\u044c \u2014 \u044d\u0442\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0432\u0438\u0434\u0435 <code>key<\/code> \u2192 <code>value<\/code>.<\/strong> \u041f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u043e\u0447\u0435\u043d\u044c \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 ClickHouse, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0432 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 ETL-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u0443\u044e \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0444\u043e\u0440\u043c\u0443.<br \/>  \u0418\u0437 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0432 ClickHouse \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0443\u043d\u043a\u0442\u043e\u0432:<\/p>\n<p>  <\/p>\n<ul>\n<li>ClickHouse \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.<\/li>\n<li>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 <code>TTL<\/code> \u2013 ClickHouse \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u0438 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/li>\n<li>ClickHouse \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u2014 XML-\u0444\u0430\u0439\u043b\u044b \u0438 DDL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"podklyuchenie-slovarey\">\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439<\/h2>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445: \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e\/\u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, HTTP(s) \u0440\u0435\u0441\u0443\u0440\u0441\u0430, \u0434\u0440\u0443\u0433\u043e\u0439 \u0421\u0423\u0411\u0414 \u0438 \u0442.\u0434.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u044d\u0442\u0438\u0445 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 xml-\u0444\u0430\u0439\u043b\u0430\u0445, \u043f\u0443\u0442\u044c \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 <code>dictionaries_config<\/code> \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 ClickHouse.<\/p>\n<p>  <\/p>\n<p>\u0421\u043b\u043e\u0432\u0430\u0440\u0438 \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0441\u0442\u0430\u0440\u0442\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438\u043b\u0438 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 <code>dictionaries_lazy_load<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 (\u043a\u0440\u043e\u043c\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438) \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u2014 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0441\u0442\u0430\u0440\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u0445, \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <code>system.dictionaries<\/code>, \u0432 \u043d\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0441\u0442\u0430\u0442\u0443\u0441 \u0441\u043b\u043e\u0432\u0430\u0440\u044f;<\/li>\n<li>\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b;<\/li>\n<li>\u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u043d\u0430\u043f\u043e\u0434\u043e\u0431\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043d\u044f\u0442\u043e\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u043c RAM \u0438\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0441\u043b\u043e\u0432\u0430\u0440\u044e \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0435\u0433\u043e \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"konfiguraciya-slovarey\">\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439<\/h2>\n<p>  <\/p>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0435\u0441\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0447\u0435\u0440\u0435\u0437 xml \u0444\u0430\u0439\u043b\u044b \u0438 \u0447\u0435\u0440\u0435\u0437 DDL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0434\u043b\u044f \u0432\u0430\u0441 \u0441\u043f\u043e\u0441\u043e\u0431, \u043d\u043e \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u2014 \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f DDL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0431\u0449\u0438\u0439 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0432\u0438\u0434 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 xml \u0441\u043b\u043e\u0432\u0430\u0440\u044f:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;yandex&gt;     &lt;!--\u041d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043a \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c--&gt;     &lt;comment&gt;Some comments&lt;\/comment&gt;      &lt;!--\u041d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430 \u0441 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430\u043c\u0438--&gt;     &lt;include_from&gt;\/etc\/metrika.xml&lt;\/include_from&gt;      &lt;dictionary&gt;         &lt;!-- \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044f --&gt;     &lt;\/dictionary&gt;      ...      &lt;dictionary&gt;         &lt;!-- \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044f --&gt;     &lt;\/dictionary&gt; &lt;\/yandex&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0432\u044b\u0431\u0440\u0430\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0447\u0435\u0440\u0435\u0437 DDL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0442\u043e \u043d\u0435 \u0437\u0430\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u044f:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;dictionary&gt;     &lt;name&gt;clients&lt;\/name&gt;     &lt;s\u043eurce&gt;         &lt;clickhouse&gt;             &lt;host&gt;myHostName&lt;\/host&gt;             &lt;port&gt;9000&lt;\/port&gt;             &lt;user&gt;admin&lt;\/user&gt;             &lt;password&gt;secret_password&lt;\/password&gt;             &lt;db&gt;clients&lt;\/db&gt;             &lt;table&gt;users&lt;\/table&gt;             &lt;where&gt;id&lt;=10&lt;\/where&gt;         &lt;\/clickhouse&gt;     &lt;\/s\u043eurce&gt;     &lt;lifetime&gt;         &lt;min&gt;3600&lt;\/min&gt;         &lt;max&gt;5400&lt;\/max&gt;     &lt;\/lifetime&gt;     &lt;layout&gt;         &lt;flat\/&gt;     &lt;\/layout&gt;     &lt;structure&gt;         &lt;id&gt;user_id&lt;\/id&gt;         &lt;attribute&gt;             &lt;name&gt;username&lt;\/name&gt;             &lt;type&gt;string&lt;\/type&gt;         &lt;\/attribute&gt;         &lt;attribute&gt;             &lt;name&gt;age&lt;\/name&gt;             &lt;type&gt;Int8&lt;\/type&gt;         &lt;\/attribute&gt;     &lt;\/structure&gt; &lt;\/dictionary&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>name<\/code>\u00a0\u2014 \u0438\u043c\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044f;<\/li>\n<li><code>source<\/code>\u00a0\u2014 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0441\u043b\u043e\u0432\u0430\u0440\u044f;<\/li>\n<li><code>lifetime<\/code>\u00a0\u2014 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439;<\/li>\n<li><code>layout<\/code> \u2014 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u041e\u0442 \u044d\u0442\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u044f;<\/li>\n<li><code>structure<\/code> \u2014 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u044f. \u041a\u043b\u044e\u0447 \u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e \u043a\u043b\u044e\u0447\u0443.<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0447\u0435\u0440\u0435\u0437 DDL-\u0437\u0430\u043f\u0440\u043e\u0441:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE DICTIONARY dict_users_id (     id UInt64,     username String,     email String,     status UInt16,     hash String ) PRIMARY KEY id SOURCE(MYSQL(     port 3306     user clickhouse     password secret_password     replica(host 'mysql1.fevlake.com' priority 1)     db fevlake_dicts     table users )) LAYOUT(HASHED()) LIFETIME(MIN 3600 MAX 5400);<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"istochniki-vneshnih-slovarey\">\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439<\/h2>\n<p>  <\/p>\n<p>\u0412\u043d\u0435\u0448\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u2014 \u044d\u0442\u043e:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b<\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u0444\u0430\u0439\u043b<\/li>\n<li>HTTP(s)<\/li>\n<li>\u0421\u0423\u0411\u0414<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u2014 \u0447\u0435\u0440\u0435\u0437 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043b\u0438\u0431\u043e \u0421\u0423\u0411\u0414, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u0438\u0445 \u043c\u044b \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0430\u043b\u0435\u0435.<\/p>\n<p>  <\/p>\n<h3 id=\"lokalnyy-fayl\">\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b<\/h3>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0447\u0435\u0440\u0435\u0437 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;s\u043eurce&gt;     &lt;file&gt;       &lt;path&gt;\/opt\/dictionaries\/clients.csv&lt;\/path&gt;       &lt;format&gt;CSV&lt;\/format&gt;     &lt;\/file&gt; &lt;\/s\u043eurce&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>path<\/code>\u00a0\u2014 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443.<\/li>\n<li><code>format<\/code>\u00a0\u2014 \u0444\u043e\u0440\u043c\u0430\u0442 \u0444\u0430\u0439\u043b\u0430. \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b ClickHouse.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0418\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 DDL-\u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">SOURCE(FILE(path '\/opt\/dictionaries\/clients.csv' format 'CSV')) SETTINGS(format_csv_allow_single_quotes = 0)<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"subd\">\u0421\u0423\u0411\u0414<\/h3>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0421\u0423\u0411\u0414 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 MySQL \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;s\u043eurce&gt;     &lt;mysql&gt;         &lt;port&gt;3306&lt;\/port&gt;         &lt;user&gt;clickhouse&lt;\/user&gt;         &lt;password&gt;secret_password&lt;\/password&gt;         &lt;replica&gt;             &lt;host&gt;example01-1&lt;\/host&gt;             &lt;priority&gt;1&lt;\/priority&gt;         &lt;\/replica&gt;         &lt;replica&gt;             &lt;host&gt;example01-2&lt;\/host&gt;             &lt;priority&gt;1&lt;\/priority&gt;         &lt;\/replica&gt;         &lt;db&gt;db_name&lt;\/db&gt;         &lt;table&gt;table_name&lt;\/table&gt;         &lt;where&gt;id=10&lt;\/where&gt;         &lt;invalidate_query&gt;SQL_QUERY&lt;\/invalidate_query&gt;     &lt;\/mysql&gt; &lt;\/s\u043eurce&gt;<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><code>port<\/code>\u00a0\u2014 \u043f\u043e\u0440\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 MySQL. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u0433\u0430 <code>&lt;replica&gt;<\/code>.<\/li>\n<li><code>user<\/code>\u00a0\u2014 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f MySQL. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u0433\u0430 <code>&lt;replica&gt;<\/code>.<\/li>\n<li><code>password<\/code>\u00a0\u2014 \u043f\u0430\u0440\u043e\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f MySQL. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u0433\u0430 <code>&lt;replica&gt;<\/code>.<\/li>\n<li><code>replica<\/code>\u00a0\u2014 \u0431\u043b\u043e\u043a \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0440\u0435\u043f\u043b\u0438\u043a\u0438. \u0411\u043b\u043e\u043a\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e.<\/li>\n<li><code>db<\/code>\u00a0\u2014 \u0438\u043c\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/li>\n<li><code>table<\/code>\u00a0\u2014 \u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/li>\n<li><code>where<\/code>\u00a0\u2014 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u044b\u0431\u043e\u0440\u0430. \u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u043e\u043c \u0441\u0435\u043a\u0446\u0438\u0438\u00a0<code>WHERE<\/code>\u00a0\u0432 MySQL, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443,\u00a0<code>id &gt;= 3 AND id &lt; 10<\/code> (\u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440).<\/li>\n<li><code>invalidate_query<\/code>\u00a0\u2014 \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u044f (\u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440).<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0418\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 DDL-\u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">SOURCE(MYSQL(     port 3306     user clickhouse     password secret_password     replica(host 'mysql1.fevlake.com' priority 1)     db fevlake_dicts     table users ))<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"hranenie-slovarey-v-pamyati\">\u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438<\/h2>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 ClickHouse:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>flat<\/code><\/li>\n<li><code>hashed<\/code><\/li>\n<li><code>sparse_hashed<\/code><\/li>\n<li><code>cache<\/code><\/li>\n<li><code>direct<\/code><\/li>\n<li><code>range_hashed<\/code><\/li>\n<li><code>complex_key_hashed<\/code><\/li>\n<li><code>complex_key_cache<\/code><\/li>\n<li><code>complex_key_direct<\/code><\/li>\n<li><code>ip_trie<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u044b\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u0432\u0441\u0435\u0433\u043e 3, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430, \u2014 \u044d\u0442\u043e <code>flat<\/code>, <code>hashed<\/code> \u0438 <code>complex_key_hashed<\/code>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u044d\u0442\u0438\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<h3 id=\"flat\">Flat<\/h3>\n<p>  <\/p>\n<p>\u0421\u043b\u043e\u0432\u0430\u0440\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0432\u0438\u0434\u0435 \u043f\u043b\u043e\u0441\u043a\u0438\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0431\u044a\u0435\u043c \u0437\u0430\u043d\u044f\u0442\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u043e\u043d\u0430\u043b\u0435\u043d \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u0441\u0430\u043c\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043f\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u043a\u043b\u044e\u0447\u0430 \u0441\u043b\u043e\u0432\u0430\u0440\u044f. \u041a\u043b\u044e\u0447 \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0442\u0438\u043f <code>UInt64<\/code> \u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0434\u043b\u0438\u043d\u043d\u0435\u0435 500 000, \u0438\u043d\u0430\u0447\u0435 ClickHouse \u0431\u0440\u043e\u0441\u0438\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044f.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;layout&gt;     &lt;flat\/&gt; &lt;\/layout&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438\u043b\u0438<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">LAYOUT(FLAT())<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"hashed\">Hashed<\/h3>\n<p>  <\/p>\n<p>\u0421\u043b\u043e\u0432\u0430\u0440\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0432\u0438\u0434\u0435 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u043c\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430\u043c\u0438. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u044e\u0447\u0435\u0439 \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0442\u044c \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;layout&gt;     &lt;hashed\/&gt; &lt;\/layout&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438\u043b\u0438<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">LAYOUT(HASHED())<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"somplex_key_hashed\">\u0421omplex_key_hashed<\/h3>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u0442\u0438\u043f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u043c\u0438\u00a0\u043a\u043b\u044e\u0447\u0430\u043c\u0438. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d\u00a0<code>hashed<\/code> \u0441\u043f\u043e\u0441\u043e\u0431\u0443.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;layout&gt;     &lt;hashed\/&gt; &lt;\/layout&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438\u043b\u0438<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">LAYOUT(COMPLEX_KEY_HASHED())<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"klyuch-i-polya-slovarya\">\u041a\u043b\u044e\u0447 \u0438 \u043f\u043e\u043b\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u044f<\/h2>\n<p>  <\/p>\n<p>\u0421\u0435\u043a\u0446\u0438\u044f\u00a0<code>&lt;structure&gt;<\/code>\u00a0\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043a\u043b\u044e\u0447 \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0438 \u043f\u043e\u043b\u044f, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 XML:<\/p>\n<p>  <\/p>\n<pre><code class=\"xml\">&lt;structure&gt;     &lt;id&gt;user_id&lt;\/id&gt;     &lt;attribute&gt;         &lt;name&gt;username&lt;\/name&gt;         &lt;type&gt;string&lt;\/type&gt;     &lt;\/attribute&gt;     &lt;attribute&gt;         &lt;name&gt;age&lt;\/name&gt;         &lt;type&gt;Int8&lt;\/type&gt;     &lt;\/attribute&gt; &lt;\/structure&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>&lt;id&gt;<\/code>\u00a0\u2014\u00a0\u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u043a\u043b\u044e\u0447\u043e\u043c;<\/li>\n<li><code>&lt;attribute&gt;<\/code>\u00a0\u2014\u00a0\u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432.<\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"klyuchi\">\u041a\u043b\u044e\u0447\u0438<\/h3>\n<p>  <\/p>\n<p>ClickHouse \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0438\u0434\u044b \u043a\u043b\u044e\u0447\u0435\u0439:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0427\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043a\u043b\u044e\u0447.\u00a0<code>UInt64<\/code>. \u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u0435\u0433\u0435\u00a0<code>&lt;id&gt;<\/code>\u00a0\u0438\u043b\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c\u00a0<code>PRIMARY KEY<\/code>.<\/li>\n<li>\u0421\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u043a\u043b\u044e\u0447. \u041d\u0430\u0431\u043e\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u0435\u0433\u0435\u00a0<code>&lt;key&gt;<\/code>\u00a0\u0438\u043b\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c\u00a0<code>PRIMARY KEY<\/code>.<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u0427\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043a\u043b\u044e\u0447<\/strong><\/p>\n<p>  <\/p>\n<p>\u0422\u0438\u043f:\u00a0<code>UInt64<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;id&gt;     &lt;name&gt;user_id&lt;\/name&gt; &lt;\/id&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438\u043b\u0438<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">CREATE DICTIONARY (     user_id UInt64,     ... ) PRIMARY KEY user_id ...<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><code>PRIMARY KEY<\/code> \u2013 \u0438\u043c\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438.<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u0421\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u0439 \u043a\u043b\u044e\u0447<\/strong><\/p>\n<p>  <\/p>\n<p>\u041a\u043b\u044e\u0447\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u043e\u0440\u0442\u0435\u0436 (<code>tuple<\/code>) \u0438\u0437 \u043f\u043e\u043b\u0435\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u00a0<code>layout<\/code>\u00a0\u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c\u00a0<code>complex_key_hashed<\/code>\u00a0\u0438\u043b\u0438\u00a0<code>complex_key_cache<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043b\u044e\u0447\u0430 \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435\u00a0<code>&lt;key&gt;<\/code>. \u041f\u043e\u043b\u044f \u043a\u043b\u044e\u0447\u0430 \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u0442\u043e\u043c \u0436\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0447\u0442\u043e \u0438\u00a0\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b\u00a0\u0441\u043b\u043e\u0432\u0430\u0440\u044f. \u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;key&gt;     &lt;attribute&gt;         &lt;name&gt;field1&lt;\/name&gt;         &lt;type&gt;String&lt;\/type&gt;     &lt;\/attribute&gt;     &lt;attrbute&gt;         &lt;name&gt;field2&lt;\/name&gt;         &lt;type&gt;UInt32&lt;\/type&gt;     &lt;\/attribute&gt;     ... &lt;\/key&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438\u043b\u0438<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">CREATE DICTIONARY ( field1 String, field2 String ... ) PRIMARY KEY field1, field2 ...<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"atributy\">\u0410\u0442\u0440\u0438\u0431\u0443\u0442\u044b<\/h3>\n<p>  <\/p>\n<pre><code class=\"plaintext\">&lt;structure&gt;     ...     &lt;attribute&gt;         &lt;name&gt;Name&lt;\/name&gt;         &lt;type&gt;ClickHouseDataType&lt;\/type&gt;         &lt;null_value&gt;&lt;\/null_value&gt;         &lt;expression&gt;rand64()&lt;\/expression&gt;         &lt;hierarchical&gt;true&lt;\/hierarchical&gt;         &lt;injective&gt;true&lt;\/injective&gt;         &lt;is_object_id&gt;true&lt;\/is_object_id&gt;     &lt;\/attribute&gt; &lt;\/structure&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438\u043b\u0438<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">CREATE DICTIONARY somename (     Name ClickHouseDataType DEFAULT '' EXPRESSION rand64() HIERARCHICAL INJECTIVE IS_OBJECT_ID )<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"kak-mozhno-ispolzovat-slovari-v-clickhouse\">\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u0432 ClickHouse<\/h1>\n<p>  <\/p>\n<p>\u041e\u0434\u0438\u043d \u0438\u0437 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u043a\u0435\u0439\u0441\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u0432 ClickHouse \u2014 \u044d\u0442\u043e <strong>\u0430\u0433\u0440\u0435\u0433\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0441\u0442\u0440\u0430\u043d\u0430\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 IP (v4) \u0430\u0434\u0440\u0435\u0441\u043e\u0432<\/strong>. <\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u0437\u0430\u0434\u0430\u0447\u0430: \u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0441 <code>ip String<\/code> \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0443 \u0441 <code>country String<\/code>. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043c\u044b \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0431\u0430\u0437\u044b <strong>GeoIP2<\/strong> \u043e\u0442 MaxMind.<\/p>\n<p>  <\/p>\n<p>MaxMind \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e \u0441\u0432\u043e\u0438\u043c\u0438 <strong>.mmdb<\/strong> \u0431\u0430\u0437\u0430\u043c\u0438 API \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0412 ClickHouse \u043d\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0444\u043e\u0440\u043c\u0430\u0442 <strong>.mmdb<\/strong>, \u043d\u043e \u043d\u0430\u043c \u044d\u0442\u043e \u0438 \u043d\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u2013 MaxMind \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0431\u0430\u0437\u044b \u0432 \u0432\u0438\u0434\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 CSV, \u0447\u0435\u043c \u043c\u044b \u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u0432\u044f\u0437\u0430\u0442\u044c IP \u0441\u043e \u0441\u0442\u0440\u0430\u043d\u043e\u0439, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0444\u0430\u0439\u043b\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>GeoIP2-Country-Blocks-IPv4.csv<\/code> \u2013 \u0437\u0434\u0435\u0441\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0441\u0432\u044f\u0437\u0438 IP \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043e\u0432 \u0438 ID \u0441\u0442\u0440\u0430\u043d;<\/li>\n<li><code>GeoIP2-Country-Locations-en.csv<\/code> \u2013 \u0430 \u0437\u0434\u0435\u0441\u044c \u0443\u0436\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u0430\u043d \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0437\u0430\u0432\u0435\u0434\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e DDL:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE DICTIONARY dicts.geoip_country_blocks_ipv4 (     network String DEFAULT '',     geoname_id UInt64 DEFAULT 0,     registered_country_geoname_id UInt64 DEFAULT 0,     represented_country_geoname_id UInt64 DEFAULT 0,     is_anonymous_proxy UInt8 DEFAULT 0,     is_satellite_provider UInt8 DEFAULT 0 )  PRIMARY KEY network SOURCE(FILE(     path '\/var\/lib\/clickhouse\/user_files\/GeoIP2-Country-Blocks-IPv4.csv'     format 'CSVWithNames' )) LAYOUT(IP_TRIE()) LIFETIME(300);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 <code>geoip_country_blocks_ipv4<\/code> \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>network<\/code> \u2013 IP \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0441\u0435\u0442\u0438, \u043e\u043d \u0436\u0435 \u0438 \u0431\u0443\u0434\u0435\u0442 \u043a\u043b\u044e\u0447\u043e\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044f.<\/li>\n<li><code>geoname_id<\/code> \u2013 ID \u0441\u0442\u0440\u0430\u043d\u044b.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u2013 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c \u0432 CSV.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b ClickHouse \u043c\u043e\u0433 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0441\u0435\u0442\u0438 \u0438 ID, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f <code>ip_trie<\/code>. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c IP \u0430\u0434\u0440\u0435\u0441 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c <code>geoip_country_locations_en<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">CREATE DICTIONARY dicts.geoip_country_locations_en (     geoname_id UInt64 DEFAULT 0,     locale_code String DEFAULT '',     continent_code String DEFAULT '',     continent_name String DEFAULT '',     country_iso_code String DEFAULT '',     country_name String DEFAULT '',     is_in_european_union UInt8 DEFAULT 0 ) PRIMARY KEY geoname_id SOURCE(FILE(     path '\/var\/lib\/clickhouse\/user_files\/GeoIP2-Country-Locations-en.csv'     format 'CSVWithNames' )) LAYOUT(HASHED()) LIFETIME(300);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c ID \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u044b. \u0412 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u0445 <code>GeoIP2-Country-Locations-en.csv<\/code> \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>geoname_id<\/code> \u2013 ID \u0441\u0442\u0440\u0430\u043d\u044b, \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u0435, \u043d\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430.<\/li>\n<li><code>country_name<\/code> \u2013 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u044b.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0438\u043f\u0430 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 <code>hashed<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0442\u0438 \u043a \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c CSV \u0444\u0430\u0439\u043b\u0430\u043c.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0438\u043c\u0435\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>user_visits (user_ip String, user_id UUID)<\/code>, \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u043e \u0441\u0442\u0440\u0430\u043d\u0430\u043c. \u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u2013 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c\u0438 <code>dictGet*<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">SELECT      dictGetString('dicts.geoip_city_locations_en', 'country_name', users_country_id) AS users_country,      uniqs FROM (     SELECT          dictGetUInt64('dicts.geoip_country_blocks_ipv4', 'geoname_id', tuple(IPv4StringToNum(user_ip))) AS users_country_id,          uniq(user_id) AS uniqs     FROM user_visits     GROUP BY users_country_id );<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <code>user_ip<\/code> \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0435 \u0438 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0432 \u043a\u043e\u0440\u0442\u0435\u0436, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u043e\u043c\u0443 \u043a\u043b\u044e\u0447\u0443 <code>ip_trie<\/code>-\u0441\u043b\u043e\u0432\u0430\u0440\u044f: <code>tuple(IPv4StringToNum(user_ip))<\/code>;<\/li>\n<li>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u043a\u043b\u044e\u0447, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0431\u0440\u0430\u0442\u044c ID \u0441\u0442\u0440\u0430\u043d\u044b \u043a\u0430\u043a <code>users_country_id<\/code>: <code>dictGetUInt64('geoip_country_blocks_ipv4', 'geoname_id', ...) as users_country_id<\/code>;<\/li>\n<li>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u0430\u043c\u0443 \u043c\u0435\u0442\u0440\u0438\u043a\u0443: <code>uniq(user_id) as uniq_users<\/code>;<\/li>\n<li>\u0430\u0433\u0440\u0435\u0433\u0438\u0440\u0443\u0435\u043c \u043f\u043e ID \u0441\u0442\u0440\u0430\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0437\u044f\u043b\u0438 \u0438\u0437 \u0441\u043b\u043e\u0432\u0430\u0440\u044f: <code>GROUP BY users_country_id<\/code>;<\/li>\n<li>\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 ID \u0441\u0442\u0440\u0430\u043d, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f\u043c\u0438: <code>dictGetString('geoip_city_locations_en', 'country_name', users_country_id) AS users_country<\/code>.<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u0430\u043d. \u0412 \u0442\u0435\u0445 \u0436\u0435 GeoIP2 \u0431\u0430\u0437\u0430\u0445 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043d\u0435 \u0431\u043e\u0439\u0442\u0435\u0441\u044c \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \ud83d\ude42<\/p>\n<p>  <\/p>\n<h1 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u0441\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f\u043c\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u043e. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442 \u0432\u0430\u0448\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f ClickHouse \u0438 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/rebrainme\/blog\/513972\/\"> https:\/\/habr.com\/ru\/company\/rebrainme\/blog\/513972\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/rebrainme\/blog\/513972\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/hd\/m1\/sa\/hdm1saopaqfgg2-u1bapnqxy80s.png\"><\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u043e\u0442\u043a\u0440\u044b\u043b\u0438 \u044d\u0442\u0443 <del>\u0434\u0432\u0435\u0440\u044c<\/del> \u0441\u0442\u0430\u0442\u044c\u044e, \u0442\u043e \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430, \u0432\u044b \u0443\u0436\u0435 \u0438\u043c\u0435\u043b\u0438 \u0434\u0435\u043b\u043e \u0441 ClickHouse \u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043e\u0431 \u0435\u0433\u043e \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0435 \u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438, \u0430 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0441\u0440\u0430\u0437\u0443 \u043a \u0434\u0435\u043b\u0443 \u2013 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043a \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u0438 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0438\u043c\u0438 \u0432 ClickHouse.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-308064","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=308064"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308064\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}