ClickHouse/docs/zh/sql-reference/dictionaries/external-dictionaries/external-dicts-dict-lifetime.md
Ivan Blinkov cd14f9ebcb
SQL reference refactoring (#10857)
* split up select.md

* array-join.md basic refactoring

* distinct.md basic refactoring

* format.md basic refactoring

* from.md basic refactoring

* group-by.md basic refactoring

* having.md basic refactoring

* additional index.md refactoring

* into-outfile.md basic refactoring

* join.md basic refactoring

* limit.md basic refactoring

* limit-by.md basic refactoring

* order-by.md basic refactoring

* prewhere.md basic refactoring

* adjust operators/index.md links

* adjust sample.md links

* adjust more links

* adjust operatots links

* fix some links

* adjust aggregate function article titles

* basic refactor of remaining select clauses

* absolute paths in make_links.sh

* run make_links.sh

* remove old select.md locations

* translate docs/es

* translate docs/fr

* translate docs/fa

* remove old operators.md location

* change operators.md links

* adjust links in docs/es

* adjust links in docs/es

* minor texts adjustments

* wip

* update machine translations to use new links

* fix changelog

* es build fixes

* get rid of some select.md links

* temporary adjust ru links

* temporary adjust more ru links

* improve curly brace handling

* adjust ru as well

* fa build fix

* ru link fixes

* zh link fixes

* temporary disable part of anchor checks
2020-05-15 07:34:54 +03:00

92 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
machine_translated: true
machine_translated_rev: 72537a2d527c63c07aa5d2361a8829f3895cf2bd
toc_priority: 42
toc_title: "\u5B57\u5178\u66F4\u65B0"
---
# 字典更新 {#dictionary-updates}
ClickHouse定期更新字典。 完全下载字典的更新间隔和缓存字典的无效间隔在 `<lifetime>` 在几秒钟内标记。
字典更新(除首次使用的加载之外)不会阻止查询。 在更新期间,将使用旧版本的字典。 如果在更新过程中发生错误,则将错误写入服务器日志,并使用旧版本的字典继续查询。
设置示例:
``` xml
<dictionary>
...
<lifetime>300</lifetime>
...
</dictionary>
```
``` sql
CREATE DICTIONARY (...)
...
LIFETIME(300)
...
```
设置 `<lifetime>0</lifetime>` (`LIFETIME(0)`)防止字典更新。
您可以设置升级的时间间隔ClickHouse将在此范围内选择一个统一的随机时间。 为了在大量服务器上升级时分配字典源上的负载,这是必要的。
设置示例:
``` xml
<dictionary>
...
<lifetime>
<min>300</min>
<max>360</max>
</lifetime>
...
</dictionary>
```
``` sql
LIFETIME(MIN 300 MAX 360)
```
如果 `<min>0</min>``<max>0</max>`ClickHouse不会按超时重新加载字典。
在这种情况下如果字典配置文件已更改ClickHouse可以更早地重新加载字典 `SYSTEM RELOAD DICTIONARY` 命令被执行。
升级字典时ClickHouse服务器根据字典的类型应用不同的逻辑 [来源](external-dicts-dict-sources.md):
升级字典时ClickHouse服务器根据字典的类型应用不同的逻辑 [来源](external-dicts-dict-sources.md):
- 对于文本文件,它检查修改的时间。 如果时间与先前记录的时间不同,则更新字典。
- 对于MyISAM表修改的时间使用检查 `SHOW TABLE STATUS` 查询。
- 默认情况下,每次都会更新来自其他来源的字典。
对于MySQLInnoDBODBC和ClickHouse源代码您可以设置一个查询只有在字典真正改变时才会更新字典而不是每次都更新。 为此,请按照下列步骤操作:
- 字典表必须具有在源数据更新时始终更改的字段。
- 源的设置必须指定检索更改字段的查询。 ClickHouse服务器将查询结果解释为一行如果此行相对于其以前的状态发生了更改则更新字典。 指定查询 `<invalidate_query>` 字段中的设置 [来源](external-dicts-dict-sources.md).
设置示例:
``` xml
<dictionary>
...
<odbc>
...
<invalidate_query>SELECT update_time FROM dictionary_source where id = 1</invalidate_query>
</odbc>
...
</dictionary>
```
``` sql
...
SOURCE(ODBC(... invalidate_query 'SELECT update_time FROM dictionary_source where id = 1'))
...
```
[原始文章](https://clickhouse.tech/docs/en/query_language/dicts/external_dicts_dict_lifetime/) <!--hide-->