lealone / Lealone-Docs

与 Lealone 相关的所有文档
Other
82 stars 24 forks source link

如何将列存储表的查询从600毫秒优化到100毫秒以内 #11

Closed wangzihaogithub closed 2 years ago

wangzihaogithub commented 2 years ago

有110w条记录, 查询要600毫秒, 期望优化到100毫秒以内。

        SELECT
            count(DISTINCT ( `biz_object_id` )) count,
        t1.creator_p_user_id
        FROM
            `biz_remark` t1 
        WHERE t1.`create_time` >= '2020-01-01'
        AND t1.`create_time` <= '2022-10-05'
        AND t1.biz_type_enum = 3
        AND t1.type = 2
        GROUP BY t1.creator_p_user_id
        order by count desc

表结构如下

      CREATE TABLE biz_remark (
                      id int(10)  PRIMARY key AUTO_INCREMENT,
                      biz_object_id int(11) ,
                      biz_type_enum tinyint(4) ,
                      type tinyint(3)  ,
                      latest_status int(11) ,
                      create_time datetime ,
                      update_time datetime ,
                      delete_flag tinyint(1) ,
                      creator_p_user_id int(11) ,
                      creator_p_user_name varchar(32)  ,
                      updator_p_user_id int(11) ,
                      updator_p_user_name varchar(32)  ,
                      biz_feed_back_task_id int(11) ,
                      biz_object_name varchar(512) ,
                      no_touch_flag tinyint(1),
                      creator_dept_id int(11))
          PARAMETERS (pageStorageMode='COLUMN_STORAGE')
codefollower commented 2 years ago

你这条 sql 用 COLUMN_STORAGE 意义不大,还不如给 create_time 建索引。

wangzihaogithub commented 2 years ago

create_time 这个一年80w条记录, 查2年在mysql上加联合索引要查4.4秒。

wangzihaogithub commented 2 years ago

是机器配置的原因, 这个表现和mysql差不多,初始化buff_pool的时间比mysql慢400多毫秒。