ClickHouse® is a real-time analytics DBMS
Go to file
Ivan Babrou d9d8d0242e Optimize PK lookup for queries that match exact PK range
Existing code that looks up marks that match the query has a pathological
case, when most of the part does in fact match the query.

The code works by recursively splitting a part into ranges and then discarding
the ranges that definitely do not match the query, based on primary key.

The problem is that it requires visiting every mark that matches the query,
making the complexity of this sort of look up O(n).

For queries that match exact range on the primary key, we can find
both left and right parts of the range with O(log 2) complexity.

This change implements exactly that.

To engage this optimization, the query must:

* Have a prefix list of the primary key.
* Have only range or single set element constraints for columns.
* Have only AND as a boolean operator.

Consider a table with `(service, timestamp)` as the primary key.

The following conditions will be optimized:

* `service = 'foo'`
* `service = 'foo' and timestamp >= now() - 3600`
* `service in ('foo')`
* `service in ('foo') and timestamp >= now() - 3600 and timestamp <= now`

The following will fall back to previous lookup algorithm:

* `timestamp >= now() - 3600`
* `service in ('foo', 'bar') and timestamp >= now() - 3600`
* `service = 'foo'`

Note that the optimization won't engage when PK has a range expression
followed by a point expression, since in that case the range is not continuous.

Trace query logging provides the following messages types of messages,
each representing a different kind of PK usage for a part:

```
Used optimized inclusion search over index for part 20200711_5710108_5710108_0 with 9 steps
Used generic exclusion search over index for part 20200711_5710118_5710228_5 with 1495 steps
Not using index on part 20200710_5710473_5710473_0
```

Number of steps translates to computational complexity.

Here's a comparison for before and after for a query over 24h of data:

```
Read 4562944 rows, 148.05 MiB in 45.19249672 sec.,   100966 rows/sec.,   3.28 MiB/sec.
Read 4183040 rows, 135.78 MiB in 0.196279627 sec., 21311636 rows/sec., 691.75 MiB/sec.
```

This is especially useful for queries that read data in order
and terminate early to return "last X things" matching a query.

See #11564 for more thoughts on this.
2020-07-11 12:26:54 -07:00
.github [anchore] more detailed Dockerfile scan reports (#12159) 2020-07-06 11:19:48 +03:00
base Log sanitizer trap messages from separate thread 2020-07-09 05:00:48 +03:00
benchmark Move all folders inside /dbms one level up (#9974) 2020-04-02 02:51:21 +03:00
cmake Merge pull request #12178 from azat/gcc10-build-fixes 2020-07-09 01:49:07 +03:00
contrib Update config.h for arrow 2020-07-09 10:19:44 +03:00
debian Auto version update to [20.6.1.1] [54436] 2020-06-22 20:40:26 +03:00
docker query fuzzer 2020-07-10 17:16:16 +03:00
docs [docs] split misc statements (#12403) 2020-07-11 14:05:49 +03:00
programs query fuzzer 2020-07-10 17:16:16 +03:00
src Optimize PK lookup for queries that match exact PK range 2020-07-11 12:26:54 -07:00
tests Merge pull request #12416 from vzakaznikov/fixing_flopping_live_view_tests 2020-07-11 19:38:39 +03:00
utils changelog fixes 2020-07-07 13:50:32 +03:00
website [docs] add syntax highlight (#12398) 2020-07-10 17:32:18 +03:00
.arcignore Added .arcignore 2020-05-21 09:17:03 +03:00
.clang-format Fixed wrong code around Memory Profiler 2020-03-03 03:24:44 +03:00
.clang-tidy Enable clang-tidy for programs and utils 2020-05-18 04:19:50 +03:00
.editorconfig Changed tabs to spaces in editor configs and in style guide [#CLICKHOUSE-3]. 2017-04-01 11:35:09 +03:00
.gitattributes Decreased warning threshold [#MOBMET-3248] 2016-06-07 11:23:15 +03:00
.gitignore Add integration test 2020-05-29 22:53:16 +03:00
.gitmodules Merge branch 'master' into add-storage-rabbitmq-read-only 2020-07-02 16:08:29 +03:00
.potato.yml Update comments in .potato.yml 2019-10-20 12:50:33 +08:00
.vimrc Changed tabs to spaces in editor configs and in style guide [#CLICKHOUSE-3]. 2017-04-01 11:35:09 +03:00
AUTHORS Update AUTHORS 2020-01-23 17:36:05 +03:00
CHANGELOG.md changelog fixes 2020-07-07 13:50:32 +03:00
CMakeLists.txt Warn if jemalloc is not enabled for non-linux too 2020-07-09 10:25:42 +03:00
CODE_OF_CONDUCT.md Add minimal code of conduct #9676 2020-03-16 12:44:28 +03:00
CONTRIBUTING.md Update CONTRIBUTING.md 2020-01-27 21:03:30 +03:00
docker-compose.yml Updated docker-compose.yml #1025 2017-07-26 20:05:32 +03:00
format_sources allow several <graphite> targets (#603) 2017-03-21 23:08:09 +04:00
LICENSE Update LICENSE 2020-01-23 17:38:30 +03:00
PreLoad.cmake Disable ninja for CLion 2019-09-11 10:23:20 +03:00
README.md Update README.md 2020-07-08 10:18:51 +03:00
release Added auto-generated machine-readable file with list of stable versions 2020-05-02 21:53:55 +03:00
SECURITY.md [security docs] actually, only admins can create advisories 2020-07-10 16:51:37 +03:00
uncrustify.cfg Better .clang-format and uncrustify.cfg 2018-11-29 15:45:34 +03:00
ya.make Changes required for auto-sync with Arcadia 2020-04-16 15:31:57 +03:00

ClickHouse — open source distributed column-oriented DBMS

ClickHouse is an open-source column-oriented database management system that allows generating analytical data reports in real time.

  • Official website has quick high-level overview of ClickHouse on main page.
  • Tutorial shows how to set up and query small ClickHouse cluster.
  • Documentation provides more in-depth information.
  • YouTube channel has a lot of content about ClickHouse in video format.
  • Slack and Telegram allow to chat with ClickHouse users in real-time.
  • Blog contains various ClickHouse-related articles, as well as announces and reports about events.
  • Yandex.Messenger channel shares announcements and useful links in Russian.
  • Contacts can help to get your questions answered if there are any.
  • You can also fill this form to meet Yandex ClickHouse team in person.

Upcoming Events