单表简单的聚合查询耗时1min+,领导要求在10s以内查询聚合出结果。
EXPLAIN ANALYZE
SELECT
COUNT(s.id) pv,
COUNT(DISTINCT IFNULL(s.user_id,s.uuid)) uv,
ROUND(COUNT(s.id)/COUNT(DISTINCT IFNULL(s.user_id,s.uuid)),2) avgPv,
ROUND(SUM(IFNULL(s.page_duration,0))/1000,2) duration,
ROUND(SUM(IFNULL(s.page_duration,0))/COUNT(s.id)/1000,2) avgDuration
FROM track.ods_online_log s
WHERE s.data_time BETWEEN 20190318 and 20190326
AND s.page_id= 'Product'
AND JSON_UNQUOTE(JSON_EXTRACT(business,"$.ProductState")) = 2 ;
添加索引
添加组合索引:
查看统计信息等:
将信息接入到clickhouse:
查询1s以内.
Variable_name VALUE
---------------------------------- --------
tidb_hashagg_partial_concurrency 4
tidb_distsql_scan_concurrency 15
tidb_index_lookup_join_concurrency 4
tidb_projection_concurrency 4
tidb_hashagg_final_concurrency 4
tidb_index_lookup_concurrency 4
tidb_hash_join_concurrency 5
tidb_checksum_table_concurrency 4
tidb_index_serial_scan_concurrency 1
tidb_build_stats_concurrency 4
我们目前存储流量埋点信息 近三个月的数据量 5亿 现在查询速度达不到目标,看可否优化达到要求 或者看最大能优化到什么程度?
我们把同等量级的数据导入Hadoop中做比对看看看看查询性能如何。
TiDB的优化:
0.我们的硬件配置
1.我们的部署结构
2.参数设置
3.SQL优化:索引、分区、并行、统计信息、SQL编写