使用clickhouse和mysql查询时间对比

业务场景,对于数据量过大的数据统计,跑脚本会很吃力

先建立一个clickhouse的mysql引擎表关联本地mysql数据表,以下这个表会自动同步mysql主表数据

CREATE TABLE test_table (
  id UInt32,
  message String,
  content String,
  remark String,
  order_id String,
  user_id UInt32,
  recharge_amount UInt32,
  bonus Decimal(10,2),
  create_time Datetime,
  update_time Datetime
)
ENGINE = MySQL('127.0.0.1:3306','you_database','you_table','you_user','you_password');

再在clickhouse建立一个mergetree引擎数据表:

CREATE TABLE my_test_table (
  id UInt32,
  message String,
  content String,
  remark String,
  order_id String,
  user_id UInt32,
  recharge_amount UInt32,
  bonus Decimal(10,2),
  create_time Datetime,
  update_time Datetime,
  PRIMARY KEY (id)
)
ENGINE = MergeTree()
ORDER BY (id,create_time) 
SETTINGS index_granularity = 8192;

将test_table 数据插入到my_test_table :
INSERT INTO my_test_table SELECT * FROM test_table;
或者使用mysql数据源插件
INSERT INTO my_test_table SELECT * FROM mysql('127.0.0.1:3306','you_database','you_table','you_user','you_password');

如图是mysql执行,需要耗时22s
select sum(recharge_amount) from test_table;

如图是clickhouse执行,耗时75ms,连一秒都不到:

对比下来,都知道用什么了吧

posted @ 2023-06-10 17:49  八戒vs  阅读(304)  评论(0编辑  收藏  举报