byted-bytehouse-slow-query

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ByteHouse 慢查询分析 Skill

ByteHouse Slow Query Analysis Skill

🔵 ByteHouse 品牌标识

🔵 ByteHouse Brand Identity

「ByteHouse」—— 火山引擎云原生数据仓库,极速、稳定、安全、易用
本Skill基于ByteHouse MCP Server,提供完整的慢查询分析和性能优化能力

"ByteHouse" - Volcano Engine Cloud-Native Data Warehouse: Fast, Stable, Secure, Easy to Use
This Skill is based on ByteHouse MCP Server and provides comprehensive slow query analysis and performance optimization capabilities

描述

Description

ByteHouse慢查询分析和性能优化工具。
当以下情况时使用此 Skill: (1) 需要识别和分析慢查询 (2) 需要查询性能优化建议 (3) 需要查看查询执行计划 (4) 需要分析查询历史趋势 (5) 用户提到"慢查询"、"查询优化"、"性能分析"、"执行计划"
ByteHouse Slow Query Analysis and Performance Optimization Tool.
Use this Skill when: (1) You need to identify and analyze slow queries (2) You need query performance optimization suggestions (3) You need to view query execution plans (4) You need to analyze query historical trends (5) You mention terms like "slow query", "query optimization", "performance analysis", "execution plan"

前置条件

Prerequisites

  • Python 3.8+
  • uv (已安装在
    /root/.local/bin/uv
    )
  • ByteHouse MCP Server Skill - 本skill依赖
    bytehouse-mcp
    skill提供的ByteHouse访问能力
  • Python 3.8+
  • uv (installed at
    /root/.local/bin/uv
    )
  • ByteHouse MCP Server Skill - This skill depends on the ByteHouse access capability provided by the
    bytehouse-mcp
    skill

依赖关系

Dependencies

本skill依赖
bytehouse-mcp
skill,使用其提供的MCP Server访问ByteHouse。
确保
bytehouse-mcp
skill已正确配置并可以正常使用。
This skill depends on the
bytehouse-mcp
skill and uses its MCP Server to access ByteHouse.
Ensure the
bytehouse-mcp
skill is properly configured and functioning normally.

📁 文件说明

📁 File Description

  • SKILL.md - 本文件,技能主文档
  • slow_query_analyzer.py - 慢查询分析主程序
  • README.md - 快速入门指南
  • SKILL.md - This file, the main skill documentation
  • slow_query_analyzer.py - Main program for slow query analysis
  • README.md - Quick start guide

配置信息

Configuration Information

ByteHouse连接配置

ByteHouse Connection Configuration

本skill复用
bytehouse-mcp
skill的配置。请确保已在
bytehouse-mcp
skill中配置好:
bash
export BYTEHOUSE_HOST="<ByteHouse-host>"
export BYTEHOUSE_PORT="<ByteHouse-port>"
export BYTEHOUSE_USER="<ByteHouse-user>"
export BYTEHOUSE_PASSWORD="<ByteHouse-password>"
export BYTEHOUSE_SECURE="true"
export BYTEHOUSE_VERIFY="true"
This skill reuses the configuration of the
bytehouse-mcp
skill. Please ensure the following configurations are set in the
bytehouse-mcp
skill:
bash
export BYTEHOUSE_HOST="<ByteHouse-host>"
export BYTEHOUSE_PORT="<ByteHouse-port>"
export BYTEHOUSE_USER="<ByteHouse-user>"
export BYTEHOUSE_PASSWORD="<ByteHouse-password>"
export BYTEHOUSE_SECURE="true"
export BYTEHOUSE_VERIFY="true"

🎯 功能特性

🎯 Feature Highlights

1. 慢查询识别

1. Slow Query Identification

  • 从query_log表获取慢查询
  • 按执行时间排序
  • 识别Top N慢查询
  • 分析慢查询模式
  • Retrieve slow queries from the query_log table
  • Sort by execution time
  • Identify Top N slow queries
  • Analyze slow query patterns

2. 查询性能分析

2. Query Performance Analysis

  • 查询执行时间分布
  • 查询类型统计
  • 查询频率分析
  • 性能趋势分析
  • Query execution time distribution
  • Query type statistics
  • Query frequency analysis
  • Performance trend analysis

3. 执行计划分析

3. Execution Plan Analysis

  • 获取查询执行计划
  • 分析执行计划节点
  • 识别性能瓶颈
  • 提供优化建议
  • Retrieve query execution plans
  • Analyze execution plan nodes
  • Identify performance bottlenecks
  • Provide optimization suggestions

4. 优化建议生成

4. Optimization Suggestion Generation

  • 索引优化建议
  • 查询重写建议
  • 表引擎建议
  • 配置参数调优
  • Index optimization suggestions
  • Query rewrite suggestions
  • Table engine suggestions
  • Configuration parameter tuning

🚀 快速开始

🚀 Quick Start

方法1: 运行慢查询分析

Method 1: Run Slow Query Analysis

bash
cd /root/.openclaw/workspace/skills/bytehouse-slow-query
bash
cd /root/.openclaw/workspace/skills/bytehouse-slow-query

先设置环境变量(复用bytehouse-mcp的配置)

Set environment variables first (reuse bytehouse-mcp configuration)

export BYTEHOUSE_HOST="<ByteHouse-host>" export BYTEHOUSE_PORT="<ByteHouse-port>" export BYTEHOUSE_USER="<ByteHouse-user>" export BYTEHOUSE_PASSWORD="<ByteHouse-password>" export BYTEHOUSE_SECURE="true" export BYTEHOUSE_VERIFY="true"
export BYTEHOUSE_HOST="<ByteHouse-host>" export BYTEHOUSE_PORT="<ByteHouse-port>" export BYTEHOUSE_USER="<ByteHouse-user>" export BYTEHOUSE_PASSWORD="<ByteHouse-password>" export BYTEHOUSE_SECURE="true" export BYTEHOUSE_VERIFY="true"

运行慢查询分析

Run slow query analysis

uv run slow_query_analyzer.py

**分析内容包括:**
- Top 20慢查询
- 查询性能统计
- 执行时间分布
- 优化建议生成

**输出文件(保存在 `output/` 目录):**
1. **`slow_queries_{timestamp}.json`** - 慢查询列表
2. **`query_stats_{timestamp}.json`** - 查询统计报告
3. **`optimization_suggestions_{timestamp}.json`** - 优化建议
uv run slow_query_analyzer.py

**Analysis content includes:**
- Top 20 slow queries
- Query performance statistics
- Execution time distribution
- Optimization suggestion generation

**Output files (saved in `output/` directory):**
1. **`slow_queries_{timestamp}.json`** - Slow query list
2. **`query_stats_{timestamp}.json`** - Query statistics report
3. **`optimization_suggestions_{timestamp}.json`** - Optimization suggestions

💻 慢查询分析维度

💻 Slow Query Analysis Dimensions

时间维度分析

Time Dimension Analysis

  • 按小时: 每小时慢查询数量
  • 按天: 每天慢查询趋势
  • 按周: 每周慢查询模式
  • 按月: 每月慢查询统计
  • By Hour: Number of slow queries per hour
  • By Day: Daily slow query trend
  • By Week: Weekly slow query pattern
  • By Month: Monthly slow query statistics

查询类型分析

Query Type Analysis

  • SELECT查询: 查询语句分析
  • INSERT查询: 写入性能分析
  • UPDATE查询: 更新性能分析
  • DELETE查询: 删除性能分析
  • DDL查询: 建表/改表性能分析
  • SELECT Queries: Query statement analysis
  • INSERT Queries: Write performance analysis
  • UPDATE Queries: Update performance analysis
  • DELETE Queries: Delete performance analysis
  • DDL Queries: Table creation/alteration performance analysis

性能指标

Performance Metrics

  • 平均执行时间: 所有查询平均耗时
  • P50执行时间: 中位数执行时间
  • P95执行时间: 95分位执行时间
  • P99执行时间: 99分位执行时间
  • 最大执行时间: 最慢查询耗时

  • Average Execution Time: Average time taken by all queries
  • P50 Execution Time: Median execution time
  • P95 Execution Time: 95th percentile execution time
  • P99 Execution Time: 99th percentile execution time
  • Maximum Execution Time: Time taken by the slowest query

📊 慢查询报告示例

📊 Slow Query Report Example

慢查询列表

Slow Query List

json
{
  "analysis_time": "2026-03-12T21:00:00",
  "total_queries": 10000,
  "slow_queries": 150,
  "top_slow_queries": [
    {
      "query_id": "query-12345",
      "query_text": "SELECT * FROM large_table WHERE ...",
      "duration_ms": 15000,
      "start_time": "2026-03-12T20:55:00",
      "read_rows": 1000000,
      "read_bytes": 104857600
    }
  ]
}

json
{
  "analysis_time": "2026-03-12T21:00:00",
  "total_queries": 10000,
  "slow_queries": 150,
  "top_slow_queries": [
    {
      "query_id": "query-12345",
      "query_text": "SELECT * FROM large_table WHERE ...",
      "duration_ms": 15000,
      "start_time": "2026-03-12T20:55:00",
      "read_rows": 1000000,
      "read_bytes": 104857600
    }
  ]
}

📚 更多信息

📚 More Information

详细使用说明请参考 bytehouse-mcp skill

最后更新: 2026-03-12
For detailed usage instructions, please refer to bytehouse-mcp skill

Last Updated: 2026-03-12