postgresql - 为什么 Clickhouse 比 PostgreSQL 慢?

标签 postgresql olap clickhouse

我想使用 Clickhouse 作为 OLAP,使用 PostgreSQL 作为 OLTP 数据库。

问题是对 Clickhouse 的查询运行速度比在 Postgres 上慢。查询如下:

select count(id) from {table_name}

这是我的表结构:

CREATE TABLE IF NOT EXISTS {table_name} 
        (
            `id` UInt64,
            `label` Nullable(FixedString(50)),
            `query` Nullable(text),
            `creation_datetime` DateTime,
            `offset` UInt64,
            `user_is_first_search` UInt8,
            `user_date_of_start` Date,
            `usage_type` Nullable(FixedString(20)),
            `user_ip` Nullable(FixedString(200)),
            `who_searched_query` Nullable(FixedString(15)),
            `device_type` Nullable(FixedString(20)),
            `device_os` Nullable(FixedString(20)),
            `tab_type` Nullable(FixedString(20)),
            `response_api_type` Nullable(FixedString(20)),
            `total_response_time` Float64,
            `retrieved_instant_answer` Nullable(FixedString(100)),
            `is_relative_instant_answer` UInt8,
            `meta_search_instant_answer_type` Nullable(FixedString(50)),
            `settings_alignment` Nullable(FixedString(20)),
            `settings_safe_search` Nullable(FixedString(30)),
            `settings_search_results_number` Nullable(FixedString(30)),
            `settings_proxy_image_urls` Nullable(FixedString(30)),
            `cache_hit` Nullable(FixedString(20)),
            `net_status` Nullable(FixedString(20)),
            `is_transitional` UInt8
        )
        ENGINE = MergeTree() PARTITION BY creation_datetime ORDER BY (id)

我在两个数据库中的日期时间字段上创建了索引,然后对两个数据库运行optimize查询。谁能告诉我为什么 Clickhouse 比 Postgres 慢?

最佳答案

用Clickhouse有很多方法可以让你的脚发抖

create table test ( id Int64, d Date ) Engine=MergeTree Order by id;
insert into test select number, today() from numbers(1e9);

select count() from test;
┌───count()─┐
│ 100000000 │
└───────────┘
1 rows in set. Elapsed: 0.002 sec.

select count(id) from test;
┌─count(id)─┐
│ 100000000 │
└───────────┘
1 rows in set. Elapsed: 0.239 sec. Processed 100.00 million rows, 800.00 MB (418.46 million rows/s., 3.35 GB/s.)


drop table test;

create table test ( id Int64, d Int64 ) Engine=MergeTree partition by (intDiv(d, 10000)) Order by id;
set max_partitions_per_insert_block=0;
insert into test select number, number from numbers(1e8);

select count(id) from test;
┌─count(id)─┐
│ 100000000 │
└───────────┘
1 rows in set. Elapsed: 1.050 sec. Processed 100.00 million rows, 800.00 MB (95.20 million rows/s., 761.61 MB/s.)


select count(d) from test;
┌──count(d)─┐
│ 100000000 │
└───────────┘
1 rows in set. Elapsed: 0.004 sec.

关于postgresql - 为什么 Clickhouse 比 PostgreSQL 慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71192475/

相关文章:

mysql - 如何存储我的网络应用程序的指标?

sql - 如何在 CTE 或子查询中引用 DISTINCT 列名称?

postgresql - Postgres UNIQUE 约束是否意味着索引?

postgresql - 从 ST_MinimumBoundingRadius 选择半径

python - 异常 : Pulsar error: IncompatibleSchema

indexing - 为什么向我的 Clickhouse 表添加 tokenbf_v2 索引没有任何效果

database - Clickhouse 无法更改列抛出 DB::Exception: 副本上的元数据与 Zookeeper 中的常见元数据不同步

sql - 提交事务时自动设置 SERIAL 值

reporting - 在报告中为 icCube 事件分配值

olap - 立方体设计 - 带有附加列的多对多映射的桥接表