diff --git a/.github/ISSUE_TEMPLATE/40_bug-report.md b/.github/ISSUE_TEMPLATE/40_bug-report.md
index 4dfd19266d0..97137366189 100644
--- a/.github/ISSUE_TEMPLATE/40_bug-report.md
+++ b/.github/ISSUE_TEMPLATE/40_bug-report.md
@@ -7,7 +7,7 @@ assignees: ''
---
-(you don't have to strictly follow this form)
+You have to provide the following information whenever possible.
**Describe the bug**
A clear and concise description of what works not as it is supposed to.
diff --git a/.gitignore b/.gitignore
index d33dbf0600d..1db6e0a78c9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,6 +27,7 @@
/docs/zh/single.md
/docs/ja/single.md
/docs/fa/single.md
+/docs/en/development/cmake-in-clickhouse.md
# callgrind files
callgrind.out.*
diff --git a/.gitmodules b/.gitmodules
index de7250166b8..66a2370f0da 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -17,6 +17,7 @@
[submodule "contrib/zlib-ng"]
path = contrib/zlib-ng
url = https://github.com/ClickHouse-Extras/zlib-ng.git
+ branch = clickhouse-new
[submodule "contrib/googletest"]
path = contrib/googletest
url = https://github.com/google/googletest.git
@@ -133,7 +134,7 @@
url = https://github.com/unicode-org/icu.git
[submodule "contrib/flatbuffers"]
path = contrib/flatbuffers
- url = https://github.com/google/flatbuffers.git
+ url = https://github.com/ClickHouse-Extras/flatbuffers.git
[submodule "contrib/libc-headers"]
path = contrib/libc-headers
url = https://github.com/ClickHouse-Extras/libc-headers.git
@@ -221,6 +222,9 @@
[submodule "contrib/NuRaft"]
path = contrib/NuRaft
url = https://github.com/ClickHouse-Extras/NuRaft.git
+[submodule "contrib/nanodbc"]
+ path = contrib/nanodbc
+ url = https://github.com/ClickHouse-Extras/nanodbc.git
[submodule "contrib/datasketches-cpp"]
path = contrib/datasketches-cpp
url = https://github.com/ClickHouse-Extras/datasketches-cpp.git
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8590fefa66d..cc1ec835a7b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,156 @@
+## ClickHouse release 21.4
+
+### ClickHouse release 21.4.1 2021-04-12
+
+#### Backward Incompatible Change
+
+* The `toStartOfIntervalFunction` will align hour intervals to the midnight (in previous versions they were aligned to the start of unix epoch). For example, `toStartOfInterval(x, INTERVAL 11 HOUR)` will split every day into three intervals: `00:00:00..10:59:59`, `11:00:00..21:59:59` and `22:00:00..23:59:59`. This behaviour is more suited for practical needs. This closes [#9510](https://github.com/ClickHouse/ClickHouse/issues/9510). [#22060](https://github.com/ClickHouse/ClickHouse/pull/22060) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* `Age` and `Precision` in graphite rollup configs should increase from retention to retention. Now it's checked and the wrong config raises an exception. [#21496](https://github.com/ClickHouse/ClickHouse/pull/21496) ([Mikhail f. Shiryaev](https://github.com/Felixoid)).
+* Fix `cutToFirstSignificantSubdomainCustom()`/`firstSignificantSubdomainCustom()` returning wrong result for 3+ level domains present in custom top-level domain list. For input domains matching these custom top-level domains, the third-level domain was considered to be the first significant one. This is now fixed. This change may introduce incompatibility if the function is used in e.g. the sharding key. [#21946](https://github.com/ClickHouse/ClickHouse/pull/21946) ([Azat Khuzhin](https://github.com/azat)).
+* Column `keys` in table `system.dictionaries` was replaced to columns `key.names` and `key.types`. Columns `key.names`, `key.types`, `attribute.names`, `attribute.types` from `system.dictionaries` table does not require dictionary to be loaded. [#21884](https://github.com/ClickHouse/ClickHouse/pull/21884) ([Maksim Kita](https://github.com/kitaisreal)).
+* Now replicas that are processing the `ALTER TABLE ATTACH PART[ITION]` command search in their `detached/` folders before fetching the data from other replicas. As an implementation detail, a new command `ATTACH_PART` is introduced in the replicated log. Parts are searched and compared by their checksums. [#18978](https://github.com/ClickHouse/ClickHouse/pull/18978) ([Mike Kot](https://github.com/myrrc)). **Note**:
+ * `ATTACH PART[ITION]` queries may not work during cluster upgrade.
+ * It's not possible to rollback to older ClickHouse version after executing `ALTER ... ATTACH` query in new version as the old servers would fail to pass the `ATTACH_PART` entry in the replicated log.
+* In this version, empty `` will block all access to remote hosts while in previous versions it did nothing. If you want to keep old behaviour and you have empty `remote_url_allow_hosts` element in configuration file, remove it. [#20058](https://github.com/ClickHouse/ClickHouse/pull/20058) ([Vladimir Chebotarev](https://github.com/excitoon)).
+
+
+#### New Feature
+
+* Extended range of `DateTime64` to support dates from year 1925 to 2283. Improved support of `DateTime` around zero date (`1970-01-01`). [#9404](https://github.com/ClickHouse/ClickHouse/pull/9404) ([alexey-milovidov](https://github.com/alexey-milovidov), [Vasily Nemkov](https://github.com/Enmk)). Not every time and date functions are working for extended range of dates.
+* Added support of Kerberos authentication for preconfigured users and HTTP requests (GSS-SPNEGO). [#14995](https://github.com/ClickHouse/ClickHouse/pull/14995) ([Denis Glazachev](https://github.com/traceon)).
+* Add `prefer_column_name_to_alias` setting to use original column names instead of aliases. it is needed to be more compatible with common databases' aliasing rules. This is for [#9715](https://github.com/ClickHouse/ClickHouse/issues/9715) and [#9887](https://github.com/ClickHouse/ClickHouse/issues/9887). [#22044](https://github.com/ClickHouse/ClickHouse/pull/22044) ([Amos Bird](https://github.com/amosbird)).
+* Added functions `dictGetChildren(dictionary, key)`, `dictGetDescendants(dictionary, key, level)`. Function `dictGetChildren` return all children as an array if indexes. It is a inverse transformation for `dictGetHierarchy`. Function `dictGetDescendants` return all descendants as if `dictGetChildren` was applied `level` times recursively. Zero `level` value is equivalent to infinity. Closes [#14656](https://github.com/ClickHouse/ClickHouse/issues/14656). [#22096](https://github.com/ClickHouse/ClickHouse/pull/22096) ([Maksim Kita](https://github.com/kitaisreal)).
+* Added `executable_pool` dictionary source. Close [#14528](https://github.com/ClickHouse/ClickHouse/issues/14528). [#21321](https://github.com/ClickHouse/ClickHouse/pull/21321) ([Maksim Kita](https://github.com/kitaisreal)).
+* Added table function `dictionary`. It works the same way as `Dictionary` engine. Closes [#21560](https://github.com/ClickHouse/ClickHouse/issues/21560). [#21910](https://github.com/ClickHouse/ClickHouse/pull/21910) ([Maksim Kita](https://github.com/kitaisreal)).
+* Support `Nullable` type for `PolygonDictionary` attribute. [#21890](https://github.com/ClickHouse/ClickHouse/pull/21890) ([Maksim Kita](https://github.com/kitaisreal)).
+* Functions `dictGet`, `dictHas` use current database name if it is not specified for dictionaries created with DDL. Closes [#21632](https://github.com/ClickHouse/ClickHouse/issues/21632). [#21859](https://github.com/ClickHouse/ClickHouse/pull/21859) ([Maksim Kita](https://github.com/kitaisreal)).
+* Added function `dictGetOrNull`. It works like `dictGet`, but return `Null` in case key was not found in dictionary. Closes [#22375](https://github.com/ClickHouse/ClickHouse/issues/22375). [#22413](https://github.com/ClickHouse/ClickHouse/pull/22413) ([Maksim Kita](https://github.com/kitaisreal)).
+* Added async update in `ComplexKeyCache`, `SSDCache`, `SSDComplexKeyCache` dictionaries. Added support for `Nullable` type in `Cache`, `ComplexKeyCache`, `SSDCache`, `SSDComplexKeyCache` dictionaries. Added support for multiple attributes fetch with `dictGet`, `dictGetOrDefault` functions. Fixes [#21517](https://github.com/ClickHouse/ClickHouse/issues/21517). [#20595](https://github.com/ClickHouse/ClickHouse/pull/20595) ([Maksim Kita](https://github.com/kitaisreal)).
+* Support `dictHas` function for `RangeHashedDictionary`. Fixes [#6680](https://github.com/ClickHouse/ClickHouse/issues/6680). [#19816](https://github.com/ClickHouse/ClickHouse/pull/19816) ([Maksim Kita](https://github.com/kitaisreal)).
+* Add function `timezoneOf` that returns the timezone name of `DateTime` or `DateTime64` data types. This does not close [#9959](https://github.com/ClickHouse/ClickHouse/issues/9959). Fix inconsistencies in function names: add aliases `timezone` and `timeZone` as well as `toTimezone` and `toTimeZone` and `timezoneOf` and `timeZoneOf`. [#22001](https://github.com/ClickHouse/ClickHouse/pull/22001) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Add new optional clause `GRANTEES` for `CREATE/ALTER USER` commands. It specifies users or roles which are allowed to receive grants from this user on condition this user has also all required access granted with grant option. By default `GRANTEES ANY` is used which means a user with grant option can grant to anyone. Syntax: `CREATE USER ... GRANTEES {user | role | ANY | NONE} [,...] [EXCEPT {user | role} [,...]]`. [#21641](https://github.com/ClickHouse/ClickHouse/pull/21641) ([Vitaly Baranov](https://github.com/vitlibar)).
+* Add new column `slowdowns_count` to `system.clusters`. When using hedged requests, it shows how many times we switched to another replica because this replica was responding slowly. Also show actual value of `errors_count` in `system.clusters`. [#21480](https://github.com/ClickHouse/ClickHouse/pull/21480) ([Kruglov Pavel](https://github.com/Avogar)).
+* Add `_partition_id` virtual column for `MergeTree*` engines. Allow to prune partitions by `_partition_id`. Add `partitionID()` function to calculate partition id string. [#21401](https://github.com/ClickHouse/ClickHouse/pull/21401) ([Amos Bird](https://github.com/amosbird)).
+* Add function `isIPAddressInRange` to test if an IPv4 or IPv6 address is contained in a given CIDR network prefix. [#21329](https://github.com/ClickHouse/ClickHouse/pull/21329) ([PHO](https://github.com/depressed-pho)).
+* Added new SQL command `ALTER TABLE 'table_name' UNFREEZE [PARTITION 'part_expr'] WITH NAME 'backup_name'`. This command is needed to properly remove 'freezed' partitions from all disks. [#21142](https://github.com/ClickHouse/ClickHouse/pull/21142) ([Pavel Kovalenko](https://github.com/Jokser)).
+* Supports implicit key type conversion for JOIN. [#19885](https://github.com/ClickHouse/ClickHouse/pull/19885) ([Vladimir](https://github.com/vdimir)).
+
+#### Experimental Feature
+
+* Support `RANGE OFFSET` frame (for window functions) for floating point types. Implement `lagInFrame`/`leadInFrame` window functions, which are analogous to `lag`/`lead`, but respect the window frame. They are identical when the frame is `between unbounded preceding and unbounded following`. This closes [#5485](https://github.com/ClickHouse/ClickHouse/issues/5485). [#21895](https://github.com/ClickHouse/ClickHouse/pull/21895) ([Alexander Kuzmenkov](https://github.com/akuzm)).
+* Zero-copy replication for `ReplicatedMergeTree` over S3 storage. [#16240](https://github.com/ClickHouse/ClickHouse/pull/16240) ([ianton-ru](https://github.com/ianton-ru)).
+* Added possibility to migrate existing S3 disk to the schema with backup-restore capabilities. [#22070](https://github.com/ClickHouse/ClickHouse/pull/22070) ([Pavel Kovalenko](https://github.com/Jokser)).
+
+#### Performance Improvement
+
+* Supported parallel formatting in `clickhouse-local` and everywhere else. [#21630](https://github.com/ClickHouse/ClickHouse/pull/21630) ([Nikita Mikhaylov](https://github.com/nikitamikhaylov)).
+* Support parallel parsing for `CSVWithNames` and `TSVWithNames` formats. This closes [#21085](https://github.com/ClickHouse/ClickHouse/issues/21085). [#21149](https://github.com/ClickHouse/ClickHouse/pull/21149) ([Nikita Mikhaylov](https://github.com/nikitamikhaylov)).
+* Enable read with mmap IO for file ranges from 64 MiB (the settings `min_bytes_to_use_mmap_io`). It may lead to moderate performance improvement. [#22326](https://github.com/ClickHouse/ClickHouse/pull/22326) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Add cache for files read with `min_bytes_to_use_mmap_io` setting. It makes significant (2x and more) performance improvement when the value of the setting is small by avoiding frequent mmap/munmap calls and the consequent page faults. Note that mmap IO has major drawbacks that makes it less reliable in production (e.g. hung or SIGBUS on faulty disks; less controllable memory usage). Nevertheless it is good in benchmarks. [#22206](https://github.com/ClickHouse/ClickHouse/pull/22206) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Avoid unnecessary data copy when using codec `NONE`. Please note that codec `NONE` is mostly useless - it's recommended to always use compression (`LZ4` is by default). Despite the common belief, disabling compression may not improve performance (the opposite effect is possible). The `NONE` codec is useful in some cases: - when data is uncompressable; - for synthetic benchmarks. [#22145](https://github.com/ClickHouse/ClickHouse/pull/22145) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Faster `GROUP BY` with small `max_rows_to_group_by` and `group_by_overflow_mode='any'`. [#21856](https://github.com/ClickHouse/ClickHouse/pull/21856) ([Nikolai Kochetov](https://github.com/KochetovNicolai)).
+* Optimize performance of queries like `SELECT ... FINAL ... WHERE`. Now in queries with `FINAL` it's allowed to move to `PREWHERE` columns, which are in sorting key. [#21830](https://github.com/ClickHouse/ClickHouse/pull/21830) ([foolchi](https://github.com/foolchi)).
+* Improved performance by replacing `memcpy` to another implementation. This closes [#18583](https://github.com/ClickHouse/ClickHouse/issues/18583). [#21520](https://github.com/ClickHouse/ClickHouse/pull/21520) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Improve performance of aggregation in order of sorting key (with enabled setting `optimize_aggregation_in_order`). [#19401](https://github.com/ClickHouse/ClickHouse/pull/19401) ([Anton Popov](https://github.com/CurtizJ)).
+
+#### Improvement
+
+* Add connection pool for PostgreSQL table/database engine and dictionary source. Should fix [#21444](https://github.com/ClickHouse/ClickHouse/issues/21444). [#21839](https://github.com/ClickHouse/ClickHouse/pull/21839) ([Kseniia Sumarokova](https://github.com/kssenii)).
+* Support non-default table schema for postgres storage/table-function. Closes [#21701](https://github.com/ClickHouse/ClickHouse/issues/21701). [#21711](https://github.com/ClickHouse/ClickHouse/pull/21711) ([Kseniia Sumarokova](https://github.com/kssenii)).
+* Support replicas priority for postgres dictionary source. [#21710](https://github.com/ClickHouse/ClickHouse/pull/21710) ([Kseniia Sumarokova](https://github.com/kssenii)).
+* Introduce a new merge tree setting `min_bytes_to_rebalance_partition_over_jbod` which allows assigning new parts to different disks of a JBOD volume in a balanced way. [#16481](https://github.com/ClickHouse/ClickHouse/pull/16481) ([Amos Bird](https://github.com/amosbird)).
+* Added `Grant`, `Revoke` and `System` values of `query_kind` column for corresponding queries in `system.query_log`. [#21102](https://github.com/ClickHouse/ClickHouse/pull/21102) ([Vasily Nemkov](https://github.com/Enmk)).
+* Allow customizing timeouts for HTTP connections used for replication independently from other HTTP timeouts. [#20088](https://github.com/ClickHouse/ClickHouse/pull/20088) ([nvartolomei](https://github.com/nvartolomei)).
+* Better exception message in client in case of exception while server is writing blocks. In previous versions client may get misleading message like `Data compressed with different methods`. [#22427](https://github.com/ClickHouse/ClickHouse/pull/22427) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Fix error `Directory tmp_fetch_XXX already exists` which could happen after failed fetch part. Delete temporary fetch directory if it already exists. Fixes [#14197](https://github.com/ClickHouse/ClickHouse/issues/14197). [#22411](https://github.com/ClickHouse/ClickHouse/pull/22411) ([nvartolomei](https://github.com/nvartolomei)).
+* Fix MSan report for function `range` with `UInt256` argument (support for large integers is experimental). This closes [#22157](https://github.com/ClickHouse/ClickHouse/issues/22157). [#22387](https://github.com/ClickHouse/ClickHouse/pull/22387) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Add `current_database` column to `system.processes` table. It contains the current database of the query. [#22365](https://github.com/ClickHouse/ClickHouse/pull/22365) ([Alexander Kuzmenkov](https://github.com/akuzm)).
+* Add case-insensitive history search/navigation and subword movement features to `clickhouse-client`. [#22105](https://github.com/ClickHouse/ClickHouse/pull/22105) ([Amos Bird](https://github.com/amosbird)).
+* If tuple of NULLs, e.g. `(NULL, NULL)` is on the left hand side of `IN` operator with tuples of non-NULLs on the right hand side, e.g. `SELECT (NULL, NULL) IN ((0, 0), (3, 1))` return 0 instead of throwing an exception about incompatible types. The expression may also appear due to optimization of something like `SELECT (NULL, NULL) = (8, 0) OR (NULL, NULL) = (3, 2) OR (NULL, NULL) = (0, 0) OR (NULL, NULL) = (3, 1)`. This closes [#22017](https://github.com/ClickHouse/ClickHouse/issues/22017). [#22063](https://github.com/ClickHouse/ClickHouse/pull/22063) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Update used version of simdjson to 0.9.1. This fixes [#21984](https://github.com/ClickHouse/ClickHouse/issues/21984). [#22057](https://github.com/ClickHouse/ClickHouse/pull/22057) ([Vitaly Baranov](https://github.com/vitlibar)).
+* Added case insensitive aliases for `CONNECTION_ID()` and `VERSION()` functions. This fixes [#22028](https://github.com/ClickHouse/ClickHouse/issues/22028). [#22042](https://github.com/ClickHouse/ClickHouse/pull/22042) ([Eugene Klimov](https://github.com/Slach)).
+* Add option `strict_increase` to `windowFunnel` function to calculate each event once (resolve [#21835](https://github.com/ClickHouse/ClickHouse/issues/21835)). [#22025](https://github.com/ClickHouse/ClickHouse/pull/22025) ([Vladimir](https://github.com/vdimir)).
+* If partition key of a `MergeTree` table does not include `Date` or `DateTime` columns but includes exactly one `DateTime64` column, expose its values in the `min_time` and `max_time` columns in `system.parts` and `system.parts_columns` tables. Add `min_time` and `max_time` columns to `system.parts_columns` table (these was inconsistency to the `system.parts` table). This closes [#18244](https://github.com/ClickHouse/ClickHouse/issues/18244). [#22011](https://github.com/ClickHouse/ClickHouse/pull/22011) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Supported `replication_alter_partitions_sync=1` setting in `clickhouse-copier` for moving partitions from helping table to destination. Decreased default timeouts. Fixes [#21911](https://github.com/ClickHouse/ClickHouse/issues/21911). [#21912](https://github.com/ClickHouse/ClickHouse/pull/21912) ([turbo jason](https://github.com/songenjie)).
+* Show path to data directory of `EmbeddedRocksDB` tables in system tables. [#21903](https://github.com/ClickHouse/ClickHouse/pull/21903) ([tavplubix](https://github.com/tavplubix)).
+* Add profile event `HedgedRequestsChangeReplica`, change read data timeout from sec to ms. [#21886](https://github.com/ClickHouse/ClickHouse/pull/21886) ([Kruglov Pavel](https://github.com/Avogar)).
+* DiskS3 (experimental feature under development). Fixed bug with the impossibility to move directory if the destination is not empty and cache disk is used. [#21837](https://github.com/ClickHouse/ClickHouse/pull/21837) ([Pavel Kovalenko](https://github.com/Jokser)).
+* Better formatting for `Array` and `Map` data types in Web UI. [#21798](https://github.com/ClickHouse/ClickHouse/pull/21798) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Update clusters only if their configurations were updated. [#21685](https://github.com/ClickHouse/ClickHouse/pull/21685) ([Kruglov Pavel](https://github.com/Avogar)).
+* Propagate query and session settings for distributed DDL queries. Set `distributed_ddl_entry_format_version` to 2 to enable this. Added `distributed_ddl_output_mode` setting. Supported modes: `none`, `throw` (default), `null_status_on_timeout` and `never_throw`. Miscellaneous fixes and improvements for `Replicated` database engine. [#21535](https://github.com/ClickHouse/ClickHouse/pull/21535) ([tavplubix](https://github.com/tavplubix)).
+* If `PODArray` was instantiated with element size that is neither a fraction or a multiple of 16, buffer overflow was possible. No bugs in current releases exist. [#21533](https://github.com/ClickHouse/ClickHouse/pull/21533) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Add `last_error_time`/`last_error_message`/`last_error_stacktrace`/`remote` columns for `system.errors`. [#21529](https://github.com/ClickHouse/ClickHouse/pull/21529) ([Azat Khuzhin](https://github.com/azat)).
+* Add aliases `simpleJSONExtract/simpleJSONHas` to `visitParam/visitParamExtract{UInt, Int, Bool, Float, Raw, String}`. Fixes #21383. [#21519](https://github.com/ClickHouse/ClickHouse/pull/21519) ([fastio](https://github.com/fastio)).
+* Add setting `optimize_skip_unused_shards_limit` to limit the number of sharding key values for `optimize_skip_unused_shards`. [#21512](https://github.com/ClickHouse/ClickHouse/pull/21512) ([Azat Khuzhin](https://github.com/azat)).
+* Improve `clickhouse-format` to not throw exception when there are extra spaces or comment after the last query, and throw exception early with readable message when format `ASTInsertQuery` with data . [#21311](https://github.com/ClickHouse/ClickHouse/pull/21311) ([flynn](https://github.com/ucasFL)).
+* Improve support of integer keys in data type `Map`. [#21157](https://github.com/ClickHouse/ClickHouse/pull/21157) ([Anton Popov](https://github.com/CurtizJ)).
+* MaterializeMySQL: attempt to reconnect to MySQL if the connection is lost. [#20961](https://github.com/ClickHouse/ClickHouse/pull/20961) ([Håvard Kvålen](https://github.com/havardk)).
+* Support more cases to rewrite `CROSS JOIN` to `INNER JOIN`. [#20392](https://github.com/ClickHouse/ClickHouse/pull/20392) ([Vladimir](https://github.com/vdimir)).
+* Do not create empty parts on INSERT when `optimize_on_insert` setting enabled. Fixes [#20304](https://github.com/ClickHouse/ClickHouse/issues/20304). [#20387](https://github.com/ClickHouse/ClickHouse/pull/20387) ([Kruglov Pavel](https://github.com/Avogar)).
+* `MaterializeMySQL`: add minmax skipping index for `_version` column. [#20382](https://github.com/ClickHouse/ClickHouse/pull/20382) ([Stig Bakken](https://github.com/stigsb)).
+* Add option `--backslash` for `clickhouse-format`, which can add a backslash at the end of each line of the formatted query. [#21494](https://github.com/ClickHouse/ClickHouse/pull/21494) ([flynn](https://github.com/ucasFL)).
+* Now clickhouse will not throw `LOGICAL_ERROR` exception when we try to mutate the already covered part. Fixes [#22013](https://github.com/ClickHouse/ClickHouse/issues/22013). [#22291](https://github.com/ClickHouse/ClickHouse/pull/22291) ([alesapin](https://github.com/alesapin)).
+
+#### Bug Fix
+
+* Remove socket from epoll before cancelling packet receiver in `HedgedConnections` to prevent possible race. Fixes [#22161](https://github.com/ClickHouse/ClickHouse/issues/22161). [#22443](https://github.com/ClickHouse/ClickHouse/pull/22443) ([Kruglov Pavel](https://github.com/Avogar)).
+* Add (missing) memory accounting in parallel parsing routines. In previous versions OOM was possible when the resultset contains very large blocks of data. This closes [#22008](https://github.com/ClickHouse/ClickHouse/issues/22008). [#22425](https://github.com/ClickHouse/ClickHouse/pull/22425) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Fix exception which may happen when `SELECT` has constant `WHERE` condition and source table has columns which names are digits. [#22270](https://github.com/ClickHouse/ClickHouse/pull/22270) ([LiuNeng](https://github.com/liuneng1994)).
+* Fix query cancellation with `use_hedged_requests=0` and `async_socket_for_remote=1`. [#22183](https://github.com/ClickHouse/ClickHouse/pull/22183) ([Azat Khuzhin](https://github.com/azat)).
+* Fix uncaught exception in `InterserverIOHTTPHandler`. [#22146](https://github.com/ClickHouse/ClickHouse/pull/22146) ([Azat Khuzhin](https://github.com/azat)).
+* Fix docker entrypoint in case `http_port` is not in the config. [#22132](https://github.com/ClickHouse/ClickHouse/pull/22132) ([Ewout](https://github.com/devwout)).
+* Fix error `Invalid number of rows in Chunk` in `JOIN` with `TOTALS` and `arrayJoin`. Closes [#19303](https://github.com/ClickHouse/ClickHouse/issues/19303). [#22129](https://github.com/ClickHouse/ClickHouse/pull/22129) ([Vladimir](https://github.com/vdimir)).
+* Fix the background thread pool name which used to poll message from Kafka. The Kafka engine with the broken thread pool will not consume the message from message queue. [#22122](https://github.com/ClickHouse/ClickHouse/pull/22122) ([fastio](https://github.com/fastio)).
+* Fix waiting for `OPTIMIZE` and `ALTER` queries for `ReplicatedMergeTree` table engines. Now the query will not hang when the table was detached or restarted. [#22118](https://github.com/ClickHouse/ClickHouse/pull/22118) ([alesapin](https://github.com/alesapin)).
+* Disable `async_socket_for_remote`/`use_hedged_requests` for buggy Linux kernels. [#22109](https://github.com/ClickHouse/ClickHouse/pull/22109) ([Azat Khuzhin](https://github.com/azat)).
+* Docker entrypoint: avoid chown of `.` in case when `LOG_PATH` is empty. Closes [#22100](https://github.com/ClickHouse/ClickHouse/issues/22100). [#22102](https://github.com/ClickHouse/ClickHouse/pull/22102) ([filimonov](https://github.com/filimonov)).
+* The function `decrypt` was lacking a check for the minimal size of data encrypted in `AEAD` mode. This closes [#21897](https://github.com/ClickHouse/ClickHouse/issues/21897). [#22064](https://github.com/ClickHouse/ClickHouse/pull/22064) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* In rare case, merge for `CollapsingMergeTree` may create granule with `index_granularity + 1` rows. Because of this, internal check, added in [#18928](https://github.com/ClickHouse/ClickHouse/issues/18928) (affects 21.2 and 21.3), may fail with error `Incomplete granules are not allowed while blocks are granules size`. This error did not allow parts to merge. [#21976](https://github.com/ClickHouse/ClickHouse/pull/21976) ([Nikolai Kochetov](https://github.com/KochetovNicolai)).
+* Reverted [#15454](https://github.com/ClickHouse/ClickHouse/issues/15454) that may cause significant increase in memory usage while loading external dictionaries of hashed type. This closes [#21935](https://github.com/ClickHouse/ClickHouse/issues/21935). [#21948](https://github.com/ClickHouse/ClickHouse/pull/21948) ([Maksim Kita](https://github.com/kitaisreal)).
+* Prevent hedged connections overlaps (`Unknown packet 9 from server` error). [#21941](https://github.com/ClickHouse/ClickHouse/pull/21941) ([Azat Khuzhin](https://github.com/azat)).
+* Fix reading the HTTP POST request with "multipart/form-data" content type in some cases. [#21936](https://github.com/ClickHouse/ClickHouse/pull/21936) ([Ivan](https://github.com/abyss7)).
+* Fix wrong `ORDER BY` results when a query contains window functions, and optimization for reading in primary key order is applied. Fixes [#21828](https://github.com/ClickHouse/ClickHouse/issues/21828). [#21915](https://github.com/ClickHouse/ClickHouse/pull/21915) ([Alexander Kuzmenkov](https://github.com/akuzm)).
+* Fix deadlock in first catboost model execution. Closes [#13832](https://github.com/ClickHouse/ClickHouse/issues/13832). [#21844](https://github.com/ClickHouse/ClickHouse/pull/21844) ([Kruglov Pavel](https://github.com/Avogar)).
+* Fix incorrect query result (and possible crash) which could happen when `WHERE` or `HAVING` condition is pushed before `GROUP BY`. Fixes [#21773](https://github.com/ClickHouse/ClickHouse/issues/21773). [#21841](https://github.com/ClickHouse/ClickHouse/pull/21841) ([Nikolai Kochetov](https://github.com/KochetovNicolai)).
+* Better error handling and logging in `WriteBufferFromS3`. [#21836](https://github.com/ClickHouse/ClickHouse/pull/21836) ([Pavel Kovalenko](https://github.com/Jokser)).
+* Fix possible crashes in aggregate functions with combinator `Distinct`, while using two-level aggregation. This is a follow-up fix of [#18365](https://github.com/ClickHouse/ClickHouse/pull/18365) . Can only reproduced in production env. [#21818](https://github.com/ClickHouse/ClickHouse/pull/21818) ([Amos Bird](https://github.com/amosbird)).
+* Fix scalar subquery index analysis. This fixes [#21717](https://github.com/ClickHouse/ClickHouse/issues/21717) , which was introduced in [#18896](https://github.com/ClickHouse/ClickHouse/pull/18896). [#21766](https://github.com/ClickHouse/ClickHouse/pull/21766) ([Amos Bird](https://github.com/amosbird)).
+* Fix bug for `ReplicatedMerge` table engines when `ALTER MODIFY COLUMN` query doesn't change the type of `Decimal` column if its size (32 bit or 64 bit) doesn't change. [#21728](https://github.com/ClickHouse/ClickHouse/pull/21728) ([alesapin](https://github.com/alesapin)).
+* Fix possible infinite waiting when concurrent `OPTIMIZE` and `DROP` are run for `ReplicatedMergeTree`. [#21716](https://github.com/ClickHouse/ClickHouse/pull/21716) ([Azat Khuzhin](https://github.com/azat)).
+* Fix function `arrayElement` with type `Map` for constant integer arguments. [#21699](https://github.com/ClickHouse/ClickHouse/pull/21699) ([Anton Popov](https://github.com/CurtizJ)).
+* Fix SIGSEGV on not existing attributes from `ip_trie` with `access_to_key_from_attributes`. [#21692](https://github.com/ClickHouse/ClickHouse/pull/21692) ([Azat Khuzhin](https://github.com/azat)).
+* Server now start accepting connections only after `DDLWorker` and dictionaries initialization. [#21676](https://github.com/ClickHouse/ClickHouse/pull/21676) ([Azat Khuzhin](https://github.com/azat)).
+* Add type conversion for keys of tables of type `Join` (previously led to SIGSEGV). [#21646](https://github.com/ClickHouse/ClickHouse/pull/21646) ([Azat Khuzhin](https://github.com/azat)).
+* Fix distributed requests cancellation (for example simple select from multiple shards with limit, i.e. `select * from remote('127.{2,3}', system.numbers) limit 100`) with `async_socket_for_remote=1`. [#21643](https://github.com/ClickHouse/ClickHouse/pull/21643) ([Azat Khuzhin](https://github.com/azat)).
+* Fix `fsync_part_directory` for horizontal merge. [#21642](https://github.com/ClickHouse/ClickHouse/pull/21642) ([Azat Khuzhin](https://github.com/azat)).
+* Remove unknown columns from joined table in `WHERE` for queries to external database engines (MySQL, PostgreSQL). close [#14614](https://github.com/ClickHouse/ClickHouse/issues/14614), close [#19288](https://github.com/ClickHouse/ClickHouse/issues/19288) (dup), close [#19645](https://github.com/ClickHouse/ClickHouse/issues/19645) (dup). [#21640](https://github.com/ClickHouse/ClickHouse/pull/21640) ([Vladimir](https://github.com/vdimir)).
+* `std::terminate` was called if there is an error writing data into s3. [#21624](https://github.com/ClickHouse/ClickHouse/pull/21624) ([Vladimir](https://github.com/vdimir)).
+* Fix possible error `Cannot find column` when `optimize_skip_unused_shards` is enabled and zero shards are used. [#21579](https://github.com/ClickHouse/ClickHouse/pull/21579) ([Azat Khuzhin](https://github.com/azat)).
+* In case if query has constant `WHERE` condition, and setting `optimize_skip_unused_shards` enabled, all shards may be skipped and query could return incorrect empty result. [#21550](https://github.com/ClickHouse/ClickHouse/pull/21550) ([Amos Bird](https://github.com/amosbird)).
+* Fix table function `clusterAllReplicas` returns wrong `_shard_num`. close [#21481](https://github.com/ClickHouse/ClickHouse/issues/21481). [#21498](https://github.com/ClickHouse/ClickHouse/pull/21498) ([flynn](https://github.com/ucasFL)).
+* Fix that S3 table holds old credentials after config update. [#21457](https://github.com/ClickHouse/ClickHouse/pull/21457) ([Grigory Pervakov](https://github.com/GrigoryPervakov)).
+* Fixed race on SSL object inside `SecureSocket` in Poco. [#21456](https://github.com/ClickHouse/ClickHouse/pull/21456) ([Nikita Mikhaylov](https://github.com/nikitamikhaylov)).
+* Fix `Avro` format parsing for `Kafka`. Fixes [#21437](https://github.com/ClickHouse/ClickHouse/issues/21437). [#21438](https://github.com/ClickHouse/ClickHouse/pull/21438) ([Ilya Golshtein](https://github.com/ilejn)).
+* Fix receive and send timeouts and non-blocking read in secure socket. [#21429](https://github.com/ClickHouse/ClickHouse/pull/21429) ([Kruglov Pavel](https://github.com/Avogar)).
+* `force_drop_table` flag didn't work for `MATERIALIZED VIEW`, it's fixed. Fixes [#18943](https://github.com/ClickHouse/ClickHouse/issues/18943). [#20626](https://github.com/ClickHouse/ClickHouse/pull/20626) ([tavplubix](https://github.com/tavplubix)).
+* Fix name clashes in `PredicateRewriteVisitor`. It caused incorrect `WHERE` filtration after full join. Close [#20497](https://github.com/ClickHouse/ClickHouse/issues/20497). [#20622](https://github.com/ClickHouse/ClickHouse/pull/20622) ([Vladimir](https://github.com/vdimir)).
+
+#### Build/Testing/Packaging Improvement
+
+* Add [Jepsen](https://github.com/jepsen-io/jepsen) tests for ClickHouse Keeper. [#21677](https://github.com/ClickHouse/ClickHouse/pull/21677) ([alesapin](https://github.com/alesapin)).
+* Run stateless tests in parallel in CI. Depends on [#22181](https://github.com/ClickHouse/ClickHouse/issues/22181). [#22300](https://github.com/ClickHouse/ClickHouse/pull/22300) ([alesapin](https://github.com/alesapin)).
+* Enable status check for [SQLancer](https://github.com/sqlancer/sqlancer) CI run. [#22015](https://github.com/ClickHouse/ClickHouse/pull/22015) ([Ilya Yatsishin](https://github.com/qoega)).
+* Multiple preparations for PowerPC builds: Enable the bundled openldap on `ppc64le`. [#22487](https://github.com/ClickHouse/ClickHouse/pull/22487) ([Kfir Itzhak](https://github.com/mastertheknife)). Enable compiling on `ppc64le` with Clang. [#22476](https://github.com/ClickHouse/ClickHouse/pull/22476) ([Kfir Itzhak](https://github.com/mastertheknife)). Fix compiling boost on `ppc64le`. [#22474](https://github.com/ClickHouse/ClickHouse/pull/22474) ([Kfir Itzhak](https://github.com/mastertheknife)). Fix CMake error about internal CMake variable `CMAKE_ASM_COMPILE_OBJECT` not set on `ppc64le`. [#22469](https://github.com/ClickHouse/ClickHouse/pull/22469) ([Kfir Itzhak](https://github.com/mastertheknife)). Fix Fedora/RHEL/CentOS not finding `libclang_rt.builtins` on `ppc64le`. [#22458](https://github.com/ClickHouse/ClickHouse/pull/22458) ([Kfir Itzhak](https://github.com/mastertheknife)). Enable building with `jemalloc` on `ppc64le`. [#22447](https://github.com/ClickHouse/ClickHouse/pull/22447) ([Kfir Itzhak](https://github.com/mastertheknife)). Fix ClickHouse's config embedding and cctz's timezone embedding on `ppc64le`. [#22445](https://github.com/ClickHouse/ClickHouse/pull/22445) ([Kfir Itzhak](https://github.com/mastertheknife)). Fixed compiling on `ppc64le` and use the correct instruction pointer register on `ppc64le`. [#22430](https://github.com/ClickHouse/ClickHouse/pull/22430) ([Kfir Itzhak](https://github.com/mastertheknife)).
+* Re-enable the S3 (AWS) library on `aarch64`. [#22484](https://github.com/ClickHouse/ClickHouse/pull/22484) ([Kfir Itzhak](https://github.com/mastertheknife)).
+* Add `tzdata` to Docker containers because reading `ORC` formats requires it. This closes [#14156](https://github.com/ClickHouse/ClickHouse/issues/14156). [#22000](https://github.com/ClickHouse/ClickHouse/pull/22000) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Introduce 2 arguments for `clickhouse-server` image Dockerfile: `deb_location` & `single_binary_location`. [#21977](https://github.com/ClickHouse/ClickHouse/pull/21977) ([filimonov](https://github.com/filimonov)).
+* Allow to use clang-tidy with release builds by enabling assertions if it is used. [#21914](https://github.com/ClickHouse/ClickHouse/pull/21914) ([alexey-milovidov](https://github.com/alexey-milovidov)).
+* Add llvm-12 binaries name to search in cmake scripts. Implicit constants conversions to mute clang warnings. Updated submodules to build with CMake 3.19. Mute recursion in macro expansion in `readpassphrase` library. Deprecated `-fuse-ld` changed to `--ld-path` for clang. [#21597](https://github.com/ClickHouse/ClickHouse/pull/21597) ([Ilya Yatsishin](https://github.com/qoega)).
+* Updating `docker/test/testflows/runner/dockerd-entrypoint.sh` to use Yandex dockerhub-proxy, because Docker Hub has enabled very restrictive rate limits [#21551](https://github.com/ClickHouse/ClickHouse/pull/21551) ([vzakaznikov](https://github.com/vzakaznikov)).
+* Fix macOS shared lib build. [#20184](https://github.com/ClickHouse/ClickHouse/pull/20184) ([nvartolomei](https://github.com/nvartolomei)).
+* Add `ctime` option to `zookeeper-dump-tree`. It allows to dump node creation time. [#21842](https://github.com/ClickHouse/ClickHouse/pull/21842) ([Ilya](https://github.com/HumanUser)).
+
+
## ClickHouse release 21.3 (LTS)
### ClickHouse release v21.3, 2021-03-12
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c4d429c565f..2c3fa088995 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -68,17 +68,30 @@ endif ()
include (cmake/find/ccache.cmake)
-option(ENABLE_CHECK_HEAVY_BUILDS "Don't allow C++ translation units to compile too long or to take too much memory while compiling" OFF)
+# Take care to add prlimit in command line before ccache, or else ccache thinks that
+# prlimit is compiler, and clang++ is its input file, and refuses to work with
+# multiple inputs, e.g in ccache log:
+# [2021-03-31T18:06:32.655327 36900] Command line: /usr/bin/ccache prlimit --as=10000000000 --data=5000000000 --cpu=600 /usr/bin/clang++-11 - ...... std=gnu++2a -MD -MT src/CMakeFiles/dbms.dir/Storages/MergeTree/IMergeTreeDataPart.cpp.o -MF src/CMakeFiles/dbms.dir/Storages/MergeTree/IMergeTreeDataPart.cpp.o.d -o src/CMakeFiles/dbms.dir/Storages/MergeTree/IMergeTreeDataPart.cpp.o -c ../src/Storages/MergeTree/IMergeTreeDataPart.cpp
+#
+# [2021-03-31T18:06:32.656704 36900] Multiple input files: /usr/bin/clang++-11 and ../src/Storages/MergeTree/IMergeTreeDataPart.cpp
+#
+# Another way would be to use --ccache-skip option before clang++-11 to make
+# ccache ignore it.
+option(ENABLE_CHECK_HEAVY_BUILDS "Don't allow C++ translation units to compile too long or to take too much memory while compiling." OFF)
if (ENABLE_CHECK_HEAVY_BUILDS)
# set DATA (since RSS does not work since 2.6.x+) to 2G
set (RLIMIT_DATA 5000000000)
# set VIRT (RLIMIT_AS) to 10G (DATA*10)
set (RLIMIT_AS 10000000000)
+ # set CPU time limit to 600 seconds
+ set (RLIMIT_CPU 600)
+
# gcc10/gcc10/clang -fsanitize=memory is too heavy
if (SANITIZE STREQUAL "memory" OR COMPILER_GCC)
set (RLIMIT_DATA 10000000000)
endif()
- set (CMAKE_CXX_COMPILER_LAUNCHER prlimit --as=${RLIMIT_AS} --data=${RLIMIT_DATA} --cpu=600)
+
+ set (CMAKE_CXX_COMPILER_LAUNCHER prlimit --as=${RLIMIT_AS} --data=${RLIMIT_DATA} --cpu=${RLIMIT_CPU} ${CMAKE_CXX_COMPILER_LAUNCHER})
endif ()
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "None")
@@ -154,9 +167,10 @@ endif ()
# If turned `ON`, assumes the user has either the system GTest library or the bundled one.
option(ENABLE_TESTS "Provide unit_test_dbms target with Google.Test unit tests" ON)
+option(ENABLE_EXAMPLES "Build all example programs in 'examples' subdirectories" OFF)
-if (OS_LINUX AND NOT UNBUNDLED AND MAKE_STATIC_LIBRARIES AND NOT SPLIT_SHARED_LIBRARIES AND CMAKE_VERSION VERSION_GREATER "3.9.0")
- # Only for Linux, x86_64.
+if (OS_LINUX AND (ARCH_AMD64 OR ARCH_AARCH64) AND NOT UNBUNDLED AND MAKE_STATIC_LIBRARIES AND NOT SPLIT_SHARED_LIBRARIES AND CMAKE_VERSION VERSION_GREATER "3.9.0")
+ # Only for Linux, x86_64 or aarch64.
option(GLIBC_COMPATIBILITY "Enable compatibility with older glibc libraries." ON)
elseif(GLIBC_COMPATIBILITY)
message (${RECONFIGURE_MESSAGE_LEVEL} "Glibc compatibility cannot be enabled in current configuration")
@@ -244,12 +258,17 @@ endif()
include(cmake/cpu_features.cmake)
-option(ARCH_NATIVE "Add -march=native compiler flag")
+option(ARCH_NATIVE "Add -march=native compiler flag. This makes your binaries non-portable but more performant code may be generated.")
if (ARCH_NATIVE)
set (COMPILER_FLAGS "${COMPILER_FLAGS} -march=native")
endif ()
+# Asynchronous unwind tables are needed for Query Profiler.
+# They are already by default on some platforms but possibly not on all platforms.
+# Enable it explicitly.
+set (COMPILER_FLAGS "${COMPILER_FLAGS} -fasynchronous-unwind-tables")
+
if (${CMAKE_VERSION} VERSION_LESS "3.12.4")
# CMake < 3.12 doesn't support setting 20 as a C++ standard version.
# We will add C++ standard controlling flag in CMAKE_CXX_FLAGS manually for now.
@@ -277,6 +296,12 @@ if (COMPILER_GCC OR COMPILER_CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsized-deallocation")
endif ()
+# falign-functions=32 prevents from random performance regressions with the code change. Thus, providing more stable
+# benchmarks.
+if (COMPILER_GCC OR COMPILER_CLANG)
+ set(COMPILER_FLAGS "${COMPILER_FLAGS} -falign-functions=32")
+endif ()
+
# Compiler-specific coverage flags e.g. -fcoverage-mapping for gcc
option(WITH_COVERAGE "Profile the resulting binary/binaries" OFF)
@@ -475,6 +500,7 @@ include (cmake/find/krb5.cmake)
include (cmake/find/libgsasl.cmake)
include (cmake/find/cyrus-sasl.cmake)
include (cmake/find/rdkafka.cmake)
+include (cmake/find/libuv.cmake) # for amqpcpp and cassandra
include (cmake/find/amqpcpp.cmake)
include (cmake/find/capnp.cmake)
include (cmake/find/llvm.cmake)
@@ -497,6 +523,7 @@ include (cmake/find/fast_float.cmake)
include (cmake/find/rapidjson.cmake)
include (cmake/find/fastops.cmake)
include (cmake/find/odbc.cmake)
+include (cmake/find/nanodbc.cmake)
include (cmake/find/rocksdb.cmake)
include (cmake/find/libpqxx.cmake)
include (cmake/find/nuraft.cmake)
@@ -566,6 +593,9 @@ include_directories(${ConfigIncludePath})
# Add as many warnings as possible for our own code.
include (cmake/warnings.cmake)
+# Check if needed compiler flags are supported
+include (cmake/check_flags.cmake)
+
add_subdirectory (base)
add_subdirectory (src)
add_subdirectory (programs)
diff --git a/base/bridge/IBridge.cpp b/base/bridge/IBridge.cpp
index 348b0fd7190..b2ec53158b1 100644
--- a/base/bridge/IBridge.cpp
+++ b/base/bridge/IBridge.cpp
@@ -159,17 +159,12 @@ void IBridge::initialize(Application & self)
if (port > 0xFFFF)
throw Exception("Out of range 'http-port': " + std::to_string(port), ErrorCodes::ARGUMENT_OUT_OF_BOUND);
- http_timeout = config().getUInt("http-timeout", DEFAULT_HTTP_READ_BUFFER_TIMEOUT);
+ http_timeout = config().getUInt64("http-timeout", DEFAULT_HTTP_READ_BUFFER_TIMEOUT);
max_server_connections = config().getUInt("max-server-connections", 1024);
- keep_alive_timeout = config().getUInt("keep-alive-timeout", 10);
+ keep_alive_timeout = config().getUInt64("keep-alive-timeout", 10);
initializeTerminationAndSignalProcessing();
-#if USE_ODBC
- if (bridgeName() == "ODBCBridge")
- Poco::Data::ODBC::Connector::registerConnector();
-#endif
-
ServerApplication::initialize(self); // NOLINT
}
@@ -200,8 +195,8 @@ int IBridge::main(const std::vector & /*args*/)
http_params->setKeepAliveTimeout(keep_alive_timeout);
auto shared_context = Context::createShared();
- Context context(Context::createGlobal(shared_context.get()));
- context.makeGlobalContext();
+ auto context = Context::createGlobal(shared_context.get());
+ context->makeGlobalContext();
if (config().has("query_masking_rules"))
SensitiveDataMasker::setInstance(std::make_unique(config(), "query_masking_rules"));
diff --git a/base/bridge/IBridge.h b/base/bridge/IBridge.h
index f9bb00f9e48..c64003d9959 100644
--- a/base/bridge/IBridge.h
+++ b/base/bridge/IBridge.h
@@ -2,10 +2,11 @@
#include
#include
-#include
-#include
#include
+#include
+#include
+
namespace DB
{
@@ -29,9 +30,9 @@ protected:
int main(const std::vector & args) override;
- virtual const std::string bridgeName() const = 0;
+ virtual std::string bridgeName() const = 0;
- virtual HandlerFactoryPtr getHandlerFactoryPtr(Context & context) const = 0;
+ virtual HandlerFactoryPtr getHandlerFactoryPtr(ContextPtr context) const = 0;
size_t keep_alive_timeout;
diff --git a/src/Common/BorrowedObjectPool.h b/base/common/BorrowedObjectPool.h
similarity index 99%
rename from src/Common/BorrowedObjectPool.h
rename to base/common/BorrowedObjectPool.h
index d5263cf92a8..6a90a7e7122 100644
--- a/src/Common/BorrowedObjectPool.h
+++ b/base/common/BorrowedObjectPool.h
@@ -7,8 +7,7 @@
#include
#include
-
-#include
+#include
/** Pool for limited size objects that cannot be used from different threads simultaneously.
* The main use case is to have fixed size of objects that can be reused in difference threads during their lifetime
diff --git a/base/common/CMakeLists.txt b/base/common/CMakeLists.txt
index 7dfb9bc10c0..e5e18669ebe 100644
--- a/base/common/CMakeLists.txt
+++ b/base/common/CMakeLists.txt
@@ -29,7 +29,7 @@ elseif (ENABLE_READLINE)
endif ()
if (USE_DEBUG_HELPERS)
- set (INCLUDE_DEBUG_HELPERS "-include ${ClickHouse_SOURCE_DIR}/base/common/iostream_debug_helpers.h")
+ set (INCLUDE_DEBUG_HELPERS "-include \"${ClickHouse_SOURCE_DIR}/base/common/iostream_debug_helpers.h\"")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${INCLUDE_DEBUG_HELPERS}")
endif ()
@@ -45,7 +45,7 @@ if (USE_INTERNAL_CCTZ)
set_source_files_properties(DateLUTImpl.cpp PROPERTIES COMPILE_DEFINITIONS USE_INTERNAL_CCTZ)
endif()
-target_include_directories(common PUBLIC .. ${CMAKE_CURRENT_BINARY_DIR}/..)
+target_include_directories(common PUBLIC .. "${CMAKE_CURRENT_BINARY_DIR}/..")
if (OS_DARWIN AND NOT MAKE_STATIC_LIBRARIES)
target_link_libraries(common PUBLIC -Wl,-U,_inside_main)
diff --git a/base/common/DateLUTImpl.h b/base/common/DateLUTImpl.h
index 363f281584e..9e60181e802 100644
--- a/base/common/DateLUTImpl.h
+++ b/base/common/DateLUTImpl.h
@@ -25,7 +25,7 @@
#if defined(__PPC__)
-#if !__clang__
+#if !defined(__clang__)
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
#endif
@@ -1266,7 +1266,7 @@ public:
};
#if defined(__PPC__)
-#if !__clang__
+#if !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#endif
diff --git a/base/common/DecomposedFloat.h b/base/common/DecomposedFloat.h
new file mode 100644
index 00000000000..078ba823c15
--- /dev/null
+++ b/base/common/DecomposedFloat.h
@@ -0,0 +1,216 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+
+
+/// Allows to check the internals of IEEE-754 floating point number.
+
+template struct FloatTraits;
+
+template <>
+struct FloatTraits
+{
+ using UInt = uint32_t;
+ static constexpr size_t bits = 32;
+ static constexpr size_t exponent_bits = 8;
+ static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+template <>
+struct FloatTraits
+{
+ using UInt = uint64_t;
+ static constexpr size_t bits = 64;
+ static constexpr size_t exponent_bits = 11;
+ static constexpr size_t mantissa_bits = bits - exponent_bits - 1;
+};
+
+
+/// x = sign * (2 ^ normalized_exponent) * (1 + mantissa * 2 ^ -mantissa_bits)
+/// x = sign * (2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent - mantissa_bits))
+template
+struct DecomposedFloat
+{
+ using Traits = FloatTraits;
+
+ DecomposedFloat(T x)
+ {
+ memcpy(&x_uint, &x, sizeof(x));
+ }
+
+ typename Traits::UInt x_uint;
+
+ bool is_negative() const
+ {
+ return x_uint >> (Traits::bits - 1);
+ }
+
+ /// Returns 0 for both +0. and -0.
+ int sign() const
+ {
+ return (exponent() == 0 && mantissa() == 0)
+ ? 0
+ : (is_negative()
+ ? -1
+ : 1);
+ }
+
+ uint16_t exponent() const
+ {
+ return (x_uint >> (Traits::mantissa_bits)) & (((1ull << (Traits::exponent_bits + 1)) - 1) >> 1);
+ }
+
+ int16_t normalized_exponent() const
+ {
+ return int16_t(exponent()) - ((1ull << (Traits::exponent_bits - 1)) - 1);
+ }
+
+ uint64_t mantissa() const
+ {
+ return x_uint & ((1ull << Traits::mantissa_bits) - 1);
+ }
+
+ int64_t mantissa_with_sign() const
+ {
+ return is_negative() ? -mantissa() : mantissa();
+ }
+
+ /// NOTE Probably floating point instructions can be better.
+ bool is_integer_in_representable_range() const
+ {
+ return x_uint == 0
+ || (normalized_exponent() >= 0 /// The number is not less than one
+ /// The number is inside the range where every integer has exact representation in float
+ && normalized_exponent() <= static_cast(Traits::mantissa_bits)
+ /// After multiplying by 2^exp, the fractional part becomes zero, means the number is integer
+ && ((mantissa() & ((1ULL << (Traits::mantissa_bits - normalized_exponent())) - 1)) == 0));
+ }
+
+
+ /// Compare float with integer of arbitrary width (both signed and unsigned are supported). Assuming two's complement arithmetic.
+ /// Infinities are compared correctly. NaNs are treat similarly to infinities, so they can be less than all numbers.
+ /// (note that we need total order)
+ template
+ int compare(Int rhs)
+ {
+ if (rhs == 0)
+ return sign();
+
+ /// Different signs
+ if (is_negative() && rhs > 0)
+ return -1;
+ if (!is_negative() && rhs < 0)
+ return 1;
+
+ /// Fractional number with magnitude less than one
+ if (normalized_exponent() < 0)
+ {
+ if (!is_negative())
+ return rhs > 0 ? -1 : 1;
+ else
+ return rhs >= 0 ? -1 : 1;
+ }
+
+ /// The case of the most negative integer
+ if constexpr (is_signed_v)
+ {
+ if (rhs == std::numeric_limits::lowest())
+ {
+ assert(is_negative());
+
+ if (normalized_exponent() < static_cast(8 * sizeof(Int) - is_signed_v))
+ return 1;
+ if (normalized_exponent() > static_cast(8 * sizeof(Int) - is_signed_v))
+ return -1;
+
+ if (mantissa() == 0)
+ return 0;
+ else
+ return -1;
+ }
+ }
+
+ /// Too large number: abs(float) > abs(rhs). Also the case with infinities and NaN.
+ if (normalized_exponent() >= static_cast(8 * sizeof(Int) - is_signed_v))
+ return is_negative() ? -1 : 1;
+
+ using UInt = make_unsigned_t;
+ UInt uint_rhs = rhs < 0 ? -rhs : rhs;
+
+ /// Smaller octave: abs(rhs) < abs(float)
+ if (uint_rhs < (static_cast(1) << normalized_exponent()))
+ return is_negative() ? -1 : 1;
+
+ /// Larger octave: abs(rhs) > abs(float)
+ if (normalized_exponent() + 1 < static_cast(8 * sizeof(Int) - is_signed_v)
+ && uint_rhs >= (static_cast(1) << (normalized_exponent() + 1)))
+ return is_negative() ? 1 : -1;
+
+ /// The same octave
+ /// uint_rhs == 2 ^ normalized_exponent + mantissa * 2 ^ (normalized_exponent - mantissa_bits)
+
+ bool large_and_always_integer = normalized_exponent() >= static_cast(Traits::mantissa_bits);
+
+ typename Traits::UInt a = large_and_always_integer
+ ? mantissa() << (normalized_exponent() - Traits::mantissa_bits)
+ : mantissa() >> (Traits::mantissa_bits - normalized_exponent());
+
+ typename Traits::UInt b = uint_rhs - (static_cast(1) << normalized_exponent());
+
+ if (a < b)
+ return is_negative() ? 1 : -1;
+ if (a > b)
+ return is_negative() ? -1 : 1;
+
+ /// Float has no fractional part means that the numbers are equal.
+ if (large_and_always_integer || (mantissa() & ((1ULL << (Traits::mantissa_bits - normalized_exponent())) - 1)) == 0)
+ return 0;
+ else
+ /// Float has fractional part means its abs value is larger.
+ return is_negative() ? -1 : 1;
+ }
+
+
+ template
+ bool equals(Int rhs)
+ {
+ return compare(rhs) == 0;
+ }
+
+ template
+ bool notEquals(Int rhs)
+ {
+ return compare(rhs) != 0;
+ }
+
+ template
+ bool less(Int rhs)
+ {
+ return compare(rhs) < 0;
+ }
+
+ template
+ bool greater(Int rhs)
+ {
+ return compare(rhs) > 0;
+ }
+
+ template
+ bool lessOrEquals(Int rhs)
+ {
+ return compare(rhs) <= 0;
+ }
+
+ template
+ bool greaterOrEquals(Int rhs)
+ {
+ return compare(rhs) >= 0;
+ }
+};
+
+
+using DecomposedFloat64 = DecomposedFloat;
+using DecomposedFloat32 = DecomposedFloat;
diff --git a/src/Common/MoveOrCopyIfThrow.h b/base/common/MoveOrCopyIfThrow.h
similarity index 100%
rename from src/Common/MoveOrCopyIfThrow.h
rename to base/common/MoveOrCopyIfThrow.h
diff --git a/base/common/ReplxxLineReader.cpp b/base/common/ReplxxLineReader.cpp
index fcd1610e589..7893e56d751 100644
--- a/base/common/ReplxxLineReader.cpp
+++ b/base/common/ReplxxLineReader.cpp
@@ -91,6 +91,10 @@ ReplxxLineReader::ReplxxLineReader(
/// it also binded to M-p/M-n).
rx.bind_key(Replxx::KEY::meta('N'), [this](char32_t code) { return rx.invoke(Replxx::ACTION::COMPLETE_NEXT, code); });
rx.bind_key(Replxx::KEY::meta('P'), [this](char32_t code) { return rx.invoke(Replxx::ACTION::COMPLETE_PREVIOUS, code); });
+ /// By default M-BACKSPACE is KILL_TO_WHITESPACE_ON_LEFT, while in readline it is backward-kill-word
+ rx.bind_key(Replxx::KEY::meta(Replxx::KEY::BACKSPACE), [this](char32_t code) { return rx.invoke(Replxx::ACTION::KILL_TO_BEGINING_OF_WORD, code); });
+ /// By default C-w is KILL_TO_BEGINING_OF_WORD, while in readline it is unix-word-rubout
+ rx.bind_key(Replxx::KEY::control('W'), [this](char32_t code) { return rx.invoke(Replxx::ACTION::KILL_TO_WHITESPACE_ON_LEFT, code); });
rx.bind_key(Replxx::KEY::meta('E'), [this](char32_t) { openEditor(); return Replxx::ACTION_RESULT::CONTINUE; });
}
diff --git a/base/common/arithmeticOverflow.h b/base/common/arithmeticOverflow.h
index c170d214636..175e75a62f4 100644
--- a/base/common/arithmeticOverflow.h
+++ b/base/common/arithmeticOverflow.h
@@ -56,27 +56,33 @@ namespace common
}
template <>
- inline bool addOverflow(__int128 x, __int128 y, __int128 & res)
+ inline bool addOverflow(Int128 x, Int128 y, Int128 & res)
{
- static constexpr __int128 min_int128 = minInt128();
- static constexpr __int128 max_int128 = maxInt128();
res = addIgnoreOverflow(x, y);
- return (y > 0 && x > max_int128 - y) || (y < 0 && x < min_int128 - y);
+ return (y > 0 && x > std::numeric_limits::max() - y) ||
+ (y < 0 && x < std::numeric_limits::min() - y);
}
template <>
- inline bool addOverflow(wInt256 x, wInt256 y, wInt256 & res)
+ inline bool addOverflow(UInt128 x, UInt128 y, UInt128 & res)
{
res = addIgnoreOverflow(x, y);
- return (y > 0 && x > std::numeric_limits::max() - y) ||
- (y < 0 && x < std::numeric_limits::min() - y);
+ return x > std::numeric_limits::max() - y;
}
template <>
- inline bool addOverflow(wUInt256 x, wUInt256 y, wUInt256 & res)
+ inline bool addOverflow(Int256 x, Int256 y, Int256 & res)
{
res = addIgnoreOverflow(x, y);
- return x > std::numeric_limits::max() - y;
+ return (y > 0 && x > std::numeric_limits::max() - y) ||
+ (y < 0 && x < std::numeric_limits::min() - y);
+ }
+
+ template <>
+ inline bool addOverflow(UInt256 x, UInt256 y, UInt256 & res)
+ {
+ res = addIgnoreOverflow(x, y);
+ return x > std::numeric_limits::max() - y;
}
template
@@ -104,24 +110,30 @@ namespace common
}
template <>
- inline bool subOverflow(__int128 x, __int128 y, __int128 & res)
+ inline bool subOverflow(Int128 x, Int128 y, Int128 & res)
{
- static constexpr __int128 min_int128 = minInt128();
- static constexpr __int128 max_int128 = maxInt128();
res = subIgnoreOverflow(x, y);
- return (y < 0 && x > max_int128 + y) || (y > 0 && x < min_int128 + y);
+ return (y < 0 && x > std::numeric_limits::max() + y) ||
+ (y > 0 && x < std::numeric_limits::min() + y);
}
template <>
- inline bool subOverflow(wInt256 x, wInt256 y, wInt256 & res)
+ inline bool subOverflow(UInt128 x, UInt128 y, UInt128 & res)
{
res = subIgnoreOverflow(x, y);
- return (y < 0 && x > std::numeric_limits::max() + y) ||
- (y > 0 && x < std::numeric_limits::min() + y);
+ return x < y;
}
template <>
- inline bool subOverflow(wUInt256 x, wUInt256 y, wUInt256 & res)
+ inline bool subOverflow(Int256 x, Int256 y, Int256 & res)
+ {
+ res = subIgnoreOverflow(x, y);
+ return (y < 0 && x > std::numeric_limits::max() + y) ||
+ (y > 0 && x < std::numeric_limits::min() + y);
+ }
+
+ template <>
+ inline bool subOverflow(UInt256 x, UInt256 y, UInt256 & res)
{
res = subIgnoreOverflow(x, y);
return x < y;
@@ -151,36 +163,33 @@ namespace common
return __builtin_smulll_overflow(x, y, &res);
}
+ /// Overflow check is not implemented for big integers.
+
template <>
- inline bool mulOverflow(__int128 x, __int128 y, __int128 & res)
+ inline bool mulOverflow(Int128 x, Int128 y, Int128 & res)
{
res = mulIgnoreOverflow(x, y);
- if (!x || !y)
- return false;
-
- unsigned __int128 a = (x > 0) ? x : -x;
- unsigned __int128 b = (y > 0) ? y : -y;
- return mulIgnoreOverflow(a, b) / b != a;
+ return false;
}
template <>
- inline bool mulOverflow(wInt256 x, wInt256 y, wInt256 & res)
+ inline bool mulOverflow(Int256 x, Int256 y, Int256 & res)
{
res = mulIgnoreOverflow(x, y);
- if (!x || !y)
- return false;
-
- wInt256 a = (x > 0) ? x : -x;
- wInt256 b = (y > 0) ? y : -y;
- return mulIgnoreOverflow(a, b) / b != a;
+ return false;
}
template <>
- inline bool mulOverflow(wUInt256 x, wUInt256 y, wUInt256 & res)
+ inline bool mulOverflow(UInt128 x, UInt128 y, UInt128 & res)
{
res = mulIgnoreOverflow(x, y);
- if (!x || !y)
- return false;
- return res / y != x;
+ return false;
+ }
+
+ template <>
+ inline bool mulOverflow(UInt256 x, UInt256 y, UInt256 & res)
+ {
+ res = mulIgnoreOverflow(x, y);
+ return false;
}
}
diff --git a/base/common/extended_types.h b/base/common/extended_types.h
index 2ae70c0f432..79209568ef5 100644
--- a/base/common/extended_types.h
+++ b/base/common/extended_types.h
@@ -5,16 +5,14 @@
#include
#include
-using Int128 = __int128;
-using wInt256 = wide::integer<256, signed>;
-using wUInt256 = wide::integer<256, unsigned>;
+using Int128 = wide::integer<128, signed>;
+using UInt128 = wide::integer<128, unsigned>;
+using Int256 = wide::integer<256, signed>;
+using UInt256 = wide::integer<256, unsigned>;
-static_assert(sizeof(wInt256) == 32);
-static_assert(sizeof(wUInt256) == 32);
-
-static constexpr __int128 minInt128() { return static_cast(1) << 127; }
-static constexpr __int128 maxInt128() { return (static_cast(1) << 127) - 1; }
+static_assert(sizeof(Int256) == 32);
+static_assert(sizeof(UInt256) == 32);
/// The standard library type traits, such as std::is_arithmetic, with one exception
/// (std::common_type), are "set in stone". Attempting to specialize them causes undefined behavior.
@@ -26,7 +24,7 @@ struct is_signed
};
template <> struct is_signed { static constexpr bool value = true; };
-template <> struct is_signed { static constexpr bool value = true; };
+template <> struct is_signed { static constexpr bool value = true; };
template
inline constexpr bool is_signed_v = is_signed::value;
@@ -37,7 +35,8 @@ struct is_unsigned
static constexpr bool value = std::is_unsigned_v;
};
-template <> struct is_unsigned { static constexpr bool value = true; };
+template <> struct is_unsigned { static constexpr bool value = true; };
+template <> struct is_unsigned { static constexpr bool value = true; };
template
inline constexpr bool is_unsigned_v = is_unsigned::value;
@@ -51,8 +50,9 @@ struct is_integer
};
template <> struct is_integer { static constexpr bool value = true; };
-template <> struct is_integer { static constexpr bool value = true; };
-template <> struct is_integer { static constexpr bool value = true; };
+template <> struct is_integer { static constexpr bool value = true; };
+template <> struct is_integer { static constexpr bool value = true; };
+template <> struct is_integer { static constexpr bool value = true; };
template
inline constexpr bool is_integer_v = is_integer::value;
@@ -64,7 +64,11 @@ struct is_arithmetic
static constexpr bool value = std::is_arithmetic_v;
};
-template <> struct is_arithmetic<__int128> { static constexpr bool value = true; };
+template <> struct is_arithmetic { static constexpr bool value = true; };
+template <> struct is_arithmetic { static constexpr bool value = true; };
+template <> struct is_arithmetic { static constexpr bool value = true; };
+template <> struct is_arithmetic { static constexpr bool value = true; };
+
template
inline constexpr bool is_arithmetic_v = is_arithmetic::value;
@@ -75,9 +79,10 @@ struct make_unsigned
typedef std::make_unsigned_t type;
};
-template <> struct make_unsigned { using type = unsigned __int128; };
-template <> struct make_unsigned { using type = wUInt256; };
-template <> struct make_unsigned { using type = wUInt256; };
+template <> struct make_unsigned { using type = UInt128; };
+template <> struct make_unsigned { using type = UInt128; };
+template <> struct make_unsigned { using type = UInt256; };
+template <> struct make_unsigned { using type = UInt256; };
template using make_unsigned_t = typename make_unsigned::type;
@@ -87,8 +92,10 @@ struct make_signed
typedef std::make_signed_t type;
};
-template <> struct make_signed { using type = wInt256; };
-template <> struct make_signed { using type = wInt256; };
+template <> struct make_signed { using type = Int128; };
+template <> struct make_signed { using type = Int128; };
+template <> struct make_signed { using type = Int256; };
+template <> struct make_signed { using type = Int256; };
template using make_signed_t = typename make_signed::type;
@@ -98,8 +105,10 @@ struct is_big_int
static constexpr bool value = false;
};
-template <> struct is_big_int { static constexpr bool value = true; };
-template <> struct is_big_int { static constexpr bool value = true; };
+template <> struct is_big_int { static constexpr bool value = true; };
+template <> struct is_big_int { static constexpr bool value = true; };
+template <> struct is_big_int { static constexpr bool value = true; };
+template <> struct is_big_int { static constexpr bool value = true; };
template
inline constexpr bool is_big_int_v = is_big_int::value;
diff --git a/base/common/getThreadId.cpp b/base/common/getThreadId.cpp
index 700c51f21fc..054e9be9074 100644
--- a/base/common/getThreadId.cpp
+++ b/base/common/getThreadId.cpp
@@ -25,6 +25,10 @@ uint64_t getThreadId()
current_tid = syscall(SYS_gettid); /// This call is always successful. - man gettid
#elif defined(OS_FREEBSD)
current_tid = pthread_getthreadid_np();
+#elif defined(OS_SUNOS)
+ // On Solaris-derived systems, this returns the ID of the LWP, analogous
+ // to a thread.
+ current_tid = static_cast(pthread_self());
#else
if (0 != pthread_threadid_np(nullptr, ¤t_tid))
throw std::logic_error("pthread_threadid_np returned error");
diff --git a/base/common/itoa.h b/base/common/itoa.h
index a02e7b68c05..4c86239de36 100644
--- a/base/common/itoa.h
+++ b/base/common/itoa.h
@@ -30,9 +30,8 @@
#include
#include
#include
+#include
-using int128_t = __int128;
-using uint128_t = unsigned __int128;
namespace impl
{
@@ -106,7 +105,7 @@ using UnsignedOfSize = typename SelectType
uint16_t,
uint32_t,
uint64_t,
- uint128_t
+ __uint128_t
>::Result;
/// Holds the result of dividing an unsigned N-byte variable by 10^N resulting in
@@ -313,7 +312,8 @@ namespace convert
}
}
-static inline int digits10(uint128_t x)
+template
+static inline int digits10(T x)
{
if (x < 10ULL)
return 1;
@@ -346,8 +346,11 @@ static inline int digits10(uint128_t x)
return 12 + digits10(x / 1000000000000ULL);
}
-static inline char * writeUIntText(uint128_t x, char * p)
+template
+static inline char * writeUIntText(T x, char * p)
{
+ static_assert(is_unsigned_v);
+
int len = digits10(x);
auto pp = p + len;
while (x >= 100)
@@ -370,14 +373,28 @@ static inline char * writeLeadingMinus(char * pos)
return pos + 1;
}
-static inline char * writeSIntText(int128_t x, char * pos)
+template
+static inline char * writeSIntText(T x, char * pos)
{
- static constexpr int128_t min_int128 = uint128_t(1) << 127;
+ static_assert(std::is_same_v || std::is_same_v);
- if (unlikely(x == min_int128))
+ using UnsignedT = make_unsigned_t;
+ static constexpr T min_int = UnsignedT(1) << (sizeof(T) * 8 - 1);
+
+ if (unlikely(x == min_int))
{
- memcpy(pos, "-170141183460469231731687303715884105728", 40);
- return pos + 40;
+ if constexpr (std::is_same_v)
+ {
+ const char * res = "-170141183460469231731687303715884105728";
+ memcpy(pos, res, strlen(res));
+ return pos + strlen(res);
+ }
+ else if constexpr (std::is_same_v)
+ {
+ const char * res = "-57896044618658097711785492504343953926634992332820282019728792003956564819968";
+ memcpy(pos, res, strlen(res));
+ return pos + strlen(res);
+ }
}
if (x < 0)
@@ -385,7 +402,7 @@ static inline char * writeSIntText(int128_t x, char * pos)
x = -x;
pos = writeLeadingMinus(pos);
}
- return writeUIntText(static_cast(x), pos);
+ return writeUIntText(UnsignedT(x), pos);
}
}
@@ -403,13 +420,25 @@ inline char * itoa(char8_t i, char * p)
}
template <>
-inline char * itoa(uint128_t i, char * p)
+inline char * itoa(UInt128 i, char * p)
{
return impl::writeUIntText(i, p);
}
template <>
-inline char * itoa(int128_t i, char * p)
+inline char * itoa(Int128 i, char * p)
+{
+ return impl::writeSIntText(i, p);
+}
+
+template <>
+inline char * itoa(UInt256 i, char * p)
+{
+ return impl::writeUIntText(i, p);
+}
+
+template <>
+inline char * itoa(Int256 i, char * p)
{
return impl::writeSIntText(i, p);
}
diff --git a/base/common/strong_typedef.h b/base/common/strong_typedef.h
index 77b83bfa6e5..a1e2b253aa7 100644
--- a/base/common/strong_typedef.h
+++ b/base/common/strong_typedef.h
@@ -4,7 +4,8 @@
#include
#include
-template
+
+template
struct StrongTypedef
{
private:
@@ -38,14 +39,16 @@ public:
bool operator==(const Self & rhs) const { return t == rhs.t; }
bool operator<(const Self & rhs) const { return t < rhs.t; }
+ bool operator>(const Self & rhs) const { return t > rhs.t; }
T & toUnderType() { return t; }
const T & toUnderType() const { return t; }
};
+
namespace std
{
- template
+ template
struct hash>
{
size_t operator()(const StrongTypedef & x) const
diff --git a/base/common/throwError.h b/base/common/throwError.h
index b495a0fbc7a..dd352913e78 100644
--- a/base/common/throwError.h
+++ b/base/common/throwError.h
@@ -1,13 +1,15 @@
#pragma once
+
#include
+
/// Throw DB::Exception-like exception before its definition.
/// DB::Exception derived from Poco::Exception derived from std::exception.
-/// DB::Exception generally cought as Poco::Exception. std::exception generally has other catch blocks and could lead to other outcomes.
+/// DB::Exception generally caught as Poco::Exception. std::exception generally has other catch blocks and could lead to other outcomes.
/// DB::Exception is not defined yet. It'd better to throw Poco::Exception but we do not want to include any big header here, even .
/// So we throw some std::exception instead in the hope its catch block is the same as DB::Exception one.
template
-inline void throwError(const T & err)
+[[noreturn]] inline void throwError(const T & err)
{
throw std::runtime_error(err);
}
diff --git a/base/common/time.h b/base/common/time.h
index 1bf588b7cb3..d0b8e94a9a5 100644
--- a/base/common/time.h
+++ b/base/common/time.h
@@ -2,7 +2,7 @@
#include
-#if defined (OS_DARWIN)
+#if defined (OS_DARWIN) || defined (OS_SUNOS)
# define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
#elif defined (OS_FREEBSD)
# define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_FAST
diff --git a/base/common/types.h b/base/common/types.h
index bd5c28fe73b..e178653f7c6 100644
--- a/base/common/types.h
+++ b/base/common/types.h
@@ -13,7 +13,12 @@ using char8_t = unsigned char;
#endif
/// This is needed for more strict aliasing. https://godbolt.org/z/xpJBSb https://stackoverflow.com/a/57453713
+#if !defined(PVS_STUDIO) /// But PVS-Studio does not treat it correctly.
using UInt8 = char8_t;
+#else
+using UInt8 = uint8_t;
+#endif
+
using UInt16 = uint16_t;
using UInt32 = uint32_t;
using UInt64 = uint64_t;
diff --git a/base/common/wide_integer.h b/base/common/wide_integer.h
index c9d1eaa32aa..419b4e4558c 100644
--- a/base/common/wide_integer.h
+++ b/base/common/wide_integer.h
@@ -58,9 +58,11 @@ public:
using signed_base_type = int64_t;
// ctors
- constexpr integer() noexcept;
+ constexpr integer() noexcept = default;
+
template
constexpr integer(T rhs) noexcept;
+
template
constexpr integer(std::initializer_list il) noexcept;
@@ -108,9 +110,9 @@ public:
constexpr explicit operator bool() const noexcept;
template
- using __integral_not_wide_integer_class = typename std::enable_if::value, T>::type;
+ using _integral_not_wide_integer_class = typename std::enable_if::value, T>::type;
- template >
+ template >
constexpr operator T() const noexcept;
constexpr operator long double() const noexcept;
@@ -119,25 +121,27 @@ public:
struct _impl;
+ base_type items[_impl::item_count];
+
private:
template
friend class integer;
friend class std::numeric_limits>;
friend class std::numeric_limits>;
-
- base_type items[_impl::item_count];
};
template
static constexpr bool ArithmeticConcept() noexcept;
+
template
-using __only_arithmetic = typename std::enable_if() && ArithmeticConcept()>::type;
+using _only_arithmetic = typename std::enable_if() && ArithmeticConcept()>::type;
template
static constexpr bool IntegralConcept() noexcept;
+
template
-using __only_integer = typename std::enable_if() && IntegralConcept()>::type;
+using _only_integer = typename std::enable_if() && IntegralConcept()>::type;
// Unary operators
template
@@ -153,54 +157,55 @@ constexpr integer operator+(const integer & lhs) noe
template
std::common_type_t, integer> constexpr
operator*(const integer & lhs, const integer & rhs);
-template >
+template >
std::common_type_t constexpr operator*(const Arithmetic & rhs, const Arithmetic2 & lhs);
template
std::common_type_t, integer> constexpr
operator/(const integer & lhs, const integer & rhs);
-template >
+template >
std::common_type_t constexpr operator/(const Arithmetic & rhs, const Arithmetic2 & lhs);
template
std::common_type_t, integer> constexpr
operator+(const integer & lhs, const integer & rhs);
-template >
+template >
std::common_type_t constexpr operator+(const Arithmetic & rhs, const Arithmetic2 & lhs);
template
std::common_type_t, integer> constexpr
operator-(const integer & lhs, const integer & rhs);
-template >
+template >
std::common_type_t constexpr operator-(const Arithmetic & rhs, const Arithmetic2 & lhs);
template
std::common_type_t, integer> constexpr
operator%(const integer & lhs, const integer & rhs);
-template >
+template >
std::common_type_t constexpr operator%(const Integral & rhs, const Integral2 & lhs);
template
std::common_type_t, integer> constexpr
operator&(const integer & lhs, const integer & rhs);
-template >
+template >
std::common_type_t constexpr operator&(const Integral & rhs, const Integral2 & lhs);
template
std::common_type_t, integer> constexpr
operator|(const integer & lhs, const integer & rhs);
-template >
+template >
std::common_type_t constexpr operator|(const Integral & rhs, const Integral2 & lhs);
template
std::common_type_t, integer> constexpr
operator^(const integer & lhs, const integer & rhs);
-template >
+template >
std::common_type_t constexpr operator^(const Integral & rhs, const Integral2 & lhs);
// TODO: Integral
template
constexpr integer operator<<(const integer & lhs, int n) noexcept;
+
template
constexpr integer operator>>(const integer & lhs, int n) noexcept;
@@ -217,32 +222,32 @@ constexpr integer operator>>(const integer & lhs, In
template
constexpr bool operator<(const integer & lhs, const integer & rhs);
-template >
+template >
constexpr bool operator<(const Arithmetic & rhs, const Arithmetic2 & lhs);
template
constexpr bool operator>(const integer