[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7AMABDV55CMNQYKBY84C8QF":3,"skill-same:01M7AMABDV55CMNQYKBY84C8QF":47},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":31,"updatedAt":32,"install":33,"resources":46},"01M7AMABDV55CMNQYKBY84C8QF","clickhouse-io",null,"ClickHouse database patterns, query optimization, analytics, and data engineering best practices for high-performance analytical workloads.","Cyrilthetecchieee\u002Fcyril-code-","Cyrilthetecchieee","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F219787998?v=4","01M7AF0MMMKRAA0H61XMJPV92H","Julian Cyril D ","01M7AF0MQ10AVG6QJQ1C2BC0F5",2,"MIT","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fclickhouse-io\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: clickhouse-io\ndescription: ClickHouse database patterns, query optimization, analytics, and data engineering best practices for high-performance analytical workloads.\n---\n\n# ClickHouse 分析模式\n\n用於高效能分析和資料工程的 ClickHouse 特定模式。\n\n## 概述\n\nClickHouse 是一個列式資料庫管理系統（DBMS），用於線上分析處理（OLAP）。它針對大型資料集的快速分析查詢進行了優化。\n\n**關鍵特性：**\n- 列式儲存\n- 資料壓縮\n- 平行查詢執行\n- 分散式查詢\n- 即時分析\n\n## 表格設計模式\n\n### MergeTree 引擎（最常見）\n\n```sql\nCREATE TABLE markets_analytics (\n    date Date,\n    market_id String,\n    market_name String,\n    volume UInt64,\n    trades UInt32,\n    unique_traders UInt32,\n    avg_trade_size Float64,\n    created_at DateTime\n) ENGINE = MergeTree()\nPARTITION BY toYYYYMM(date)\nORDER BY (date, market_id)\nSETTINGS index_granularity = 8192;\n```\n\n### ReplacingMergeTree（去重）\n\n```sql\n-- 用於可能有重複的資料（例如來自多個來源）\nCREATE TABLE user_events (\n    event_id String,\n    user_id String,\n    event_type String,\n    timestamp DateTime,\n    properties String\n) ENGINE = ReplacingMergeTree()\nPARTITION BY toYYYYMM(timestamp)\nORDER BY (user_id, event_id, timestamp)\nPRIMARY KEY (user_id, event_id);\n```\n\n### AggregatingMergeTree（預聚合）\n\n```sql\n-- 用於維護聚合指標\nCREATE TABLE market_stats_hourly (\n    hour DateTime,\n    market_id String,\n    total_volume AggregateFunction(sum, UInt64),\n    total_trades AggregateFunction(count, UInt32),\n    unique_users AggregateFunction(uniq, String)\n) ENGINE = AggregatingMergeTree()\nPARTITION BY toYYYYMM(hour)\nORDER BY (hour, market_id);\n\n-- 查詢聚合資料\nSELECT\n    hour,\n    market_id,\n    sumMerge(total_volume) AS volume,\n    countMerge(total_trades) AS trades,\n    uniqMerge(unique_users) AS users\nFROM market_stats_hourly\nWHERE hour >= toStartOfHour(now() - INTERVAL 24 HOUR)\nGROUP BY hour, market_id\nORDER BY hour DESC;\n```\n\n## 查詢優化模式\n\n### 高效過濾\n\n```sql\n-- PASS: 良好：先使用索引欄位\nSELECT *\nFROM markets_analytics\nWHERE date >= '2025-01-01'\n  AND market_id = 'market-123'\n  AND volume > 1000\nORDER BY date DESC\nLIMIT 100;\n\n-- FAIL: 不良：先過濾非索引欄位\nSELECT *\nFROM markets_analytics\nWHERE volume > 1000\n  AND market_name LIKE '%election%'\n  AND date >= '2025-01-01';\n```\n\n### 聚合\n\n```sql\n-- PASS: 良好：使用 ClickHouse 特定聚合函式\nSELECT\n    toStartOfDay(created_at) AS day,\n    market_id,\n    sum(volume) AS total_volume,\n    count() AS total_trades,\n    uniq(trader_id) AS unique_traders,\n    avg(trade_size) AS avg_size\nFROM trades\nWHERE created_at >= today() - INTERVAL 7 DAY\nGROUP BY day, market_id\nORDER BY day DESC, total_volume DESC;\n\n-- PASS: 使用 quantile 計算百分位數（比 percentile 更高效）\nSELECT\n    quantile(0.50)(trade_size) AS median,\n    quantile(0.95)(trade_size) AS p95,\n    quantile(0.99)(trade_size) AS p99\nFROM trades\nWHERE created_at >= now() - INTERVAL 1 HOUR;\n```\n\n### 視窗函式\n\n```sql\n-- 計算累計總和\nSELECT\n    date,\n    market_id,\n    volume,\n    sum(volume) OVER (\n        PARTITION BY market_id\n        ORDER BY date\n        ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW\n    ) AS cumulative_volume\nFROM markets_analytics\nWHERE date >= today() - INTERVAL 30 DAY\nORDER BY market_id, date;\n```\n\n## 資料插入模式\n\n### 批量插入（推薦）\n\n```typescript\nimport { createClient } from '@clickhouse\u002Fclient'\n\nconst clickhouse = createClient({\n  url: process.env.CLICKHOUSE_URL ?? 'http:\u002F\u002Flocalhost:8123',\n  username: process.env.CLICKHOUSE_USER,\n  password: process.env.CLICKHOUSE_PASSWORD\n})\n\n\u002F\u002F PASS: 批量插入（高效）\nasync function bulkInsertTrades(trades: Trade[]) {\n  await clickhouse.insert({\n    table: 'trades',\n    values: trades.map(trade => ({\n      id: trade.id,\n      market_id: trade.market_id,\n      user_id: trade.user_id,\n      amount: trade.amount,\n      timestamp: trade.timestamp.toISOString()\n    })),\n    format: 'JSONEachRow'\n  })\n}\n\n\u002F\u002F FAIL: 個別插入（慢）\nasync function insertTrade(trade: Trade) {\n  \u002F\u002F 不要在迴圈中這樣做！\n  await clickhouse.insert({\n    table: 'trades',\n    values: [{\n      id: trade.id,\n      market_id: trade.market_id,\n      user_id: trade.user_id,\n      amount: trade.amount,\n      timestamp: trade.timestamp.toISOString()\n    }],\n    format: 'JSONEachRow'\n  })\n}\n```\n\n### 串流插入\n\n```typescript\n\u002F\u002F 用於持續資料攝取\nimport { Readable } from 'node:stream'\n\nasync function streamInserts(dataSource: AsyncIterable\u003CRecord\u003Cstring, unknown>>) {\n  await clickhouse.insert({\n    table: 'trades',\n    values: Readable.from(dataSource, { objectMode: true }),\n    format: 'JSONEachRow'\n  })\n}\n```\n\n## 物化視圖\n\n### 即時聚合\n\n```sql\n-- 建立每小時統計的物化視圖\nCREATE MATERIALIZED VIEW market_stats_hourly_mv\nTO market_stats_hourly\nAS SELECT\n    toStartOfHour(timestamp) AS hour,\n    market_id,\n    sumState(amount) AS total_volume,\n    countState() AS total_trades,\n    uniqState(user_id) AS unique_users\nFROM trades\nGROUP BY hour, market_id;\n\n-- 查詢物化視圖\nSELECT\n    hour,\n    market_id,\n    sumMerge(total_volume) AS volume,\n    countMerge(total_trades) AS trades,\n    uniqMerge(unique_users) AS users\nFROM market_stats_hourly\nWHERE hour >= now() - INTERVAL 24 HOUR\nGROUP BY hour, market_id;\n```\n\n## 效能監控\n\n### 查詢效能\n\n```sql\n-- 檢查慢查詢\nSELECT\n    query_id,\n    user,\n    query,\n    query_duration_ms,\n    read_rows,\n    read_bytes,\n    memory_usage\nFROM system.query_log\nWHERE type = 'QueryFinish'\n  AND query_duration_ms > 1000\n  AND event_time >= now() - INTERVAL 1 HOUR\nORDER BY query_duration_ms DESC\nLIMIT 10;\n```\n\n### 表格統計\n\n```sql\n-- 檢查表格大小\nSELECT\n    database,\n    table,\n    formatReadableSize(sum(bytes)) AS size,\n    sum(rows) AS rows,\n    max(modification_time) AS latest_modification\nFROM system.parts\nWHERE active\nGROUP BY database, table\nORDER BY sum(bytes) DESC;\n```\n\n## 常見分析查詢\n\n### 時間序列分析\n\n```sql\n-- 每日活躍使用者\nSELECT\n    toDate(timestamp) AS date,\n    uniq(user_id) AS daily_active_users\nFROM events\nWHERE timestamp >= today() - INTERVAL 30 DAY\nGROUP BY date\nORDER BY date;\n\n-- 留存分析\nSELECT\n    signup_date,\n    countIf(days_since_signup = 0) AS day_0,\n    countIf(days_since_signup = 1) AS day_1,\n    countIf(days_since_signup = 7) AS day_7,\n    countIf(days_since_signup = 30) AS day_30\nFROM (\n    SELECT\n        user_id,\n        min(toDate(timestamp)) AS signup_date,\n        toDate(timestamp) AS activity_date,\n        dateDiff('day', signup_date, activity_date) AS days_since_signup\n    FROM events\n    GROUP BY user_id, activity_date\n)\nGROUP BY signup_date\nORDER BY signup_date DESC;\n```\n\n### 漏斗分析\n\n```sql\n-- 轉換漏斗\nSELECT\n    countIf(step = 'viewed_market') AS viewed,\n    countIf(step = 'clicked_trade') AS clicked,\n    countIf(step = 'completed_trade') AS completed,\n    round(clicked \u002F viewed * 100, 2) AS view_to_click_rate,\n    round(completed \u002F clicked * 100, 2) AS click_to_completion_rate\nFROM (\n    SELECT\n        user_id,\n        session_id,\n        event_type AS step\n    FROM events\n    WHERE event_date = today()\n)\nGROUP BY session_id;\n```\n\n### 世代分析\n\n```sql\n-- 按註冊月份的使用者世代\nSELECT\n    toStartOfMonth(signup_date) AS cohort,\n    toStartOfMonth(activity_date) AS month,\n    dateDiff('month', cohort, month) AS months_since_signup,\n    count(DISTINCT user_id) AS active_users\nFROM (\n    SELECT\n        user_id,\n        min(toDate(timestamp)) OVER (PARTITION BY user_id) AS signup_date,\n        toDate(timestamp) AS activity_date\n    FROM events\n)\nGROUP BY cohort, month, months_since_signup\nORDER BY cohort, months_since_signup;\n```\n\n## 資料管線模式\n\n### ETL 模式\n\n```typescript\n\u002F\u002F 提取、轉換、載入\nasync function etlPipeline() {\n  \u002F\u002F 1. 從來源提取\n  const rawData = await extractFromPostgres()\n\n  \u002F\u002F 2. 轉換\n  const transformed = rawData.map(row => ({\n    date: new Date(row.created_at).toISOString().split('T')[0],\n    market_id: row.market_slug,\n    volume: parseFloat(row.total_volume),\n    trades: parseInt(row.trade_count)\n  }))\n\n  \u002F\u002F 3. 載入到 ClickHouse\n  await bulkInsertToClickHouse(transformed)\n}\n\n\u002F\u002F 定期執行\nsetInterval(etlPipeline, 60 * 60 * 1000)  \u002F\u002F 每小時\n```\n\n### 變更資料捕獲（CDC）\n\n```typescript\n\u002F\u002F 監聽 PostgreSQL 變更並同步到 ClickHouse\nimport { Client } from 'pg'\n\nconst pgClient = new Client({ connectionString: process.env.DATABASE_URL })\n\npgClient.query('LISTEN market_updates')\n\npgClient.on('notification', async (msg) => {\n  const update = JSON.parse(msg.payload)\n\n  await clickhouse.insert({\n    table: 'market_updates',\n    values: [\n      {\n        market_id: update.id,\n        event_type: update.operation,  \u002F\u002F INSERT, UPDATE, DELETE\n        timestamp: new Date(),\n        data: JSON.stringify(update.new_data)\n      }\n    ],\n    format: 'JSONEachRow'\n  })\n})\n```\n\n## 最佳實務\n\n### 1. 分區策略\n- 按時間分區（通常按月或日）\n- 避免太多分區（效能影響）\n- 分區鍵使用 DATE 類型\n\n### 2. 排序鍵\n- 最常過濾的欄位放在最前面\n- 考慮基數（高基數優先）\n- 排序影響壓縮\n\n### 3. 資料類型\n- 使用最小的適當類型（UInt32 vs UInt64）\n- 重複字串使用 LowCardinality\n- 分類資料使用 Enum\n\n### 4. 避免\n- SELECT *（指定欄位）\n- FINAL（改為在查詢前合併資料）\n- 太多 JOINs（為分析反正規化）\n- 小量頻繁插入（改用批量）\n\n### 5. 監控\n- 追蹤查詢效能\n- 監控磁碟使用\n- 檢查合併操作\n- 審查慢查詢日誌\n\n**記住**：ClickHouse 擅長分析工作負載。為你的查詢模式設計表格，批量插入，並利用物化視圖進行即時聚合。\n","# ClickHouse 分析模式\n\n用於高效能分析和資料工程的 ClickHouse 特定模式。\n\n## 概述\n\nClickHouse 是一個列式資料庫管理系統（DBMS），用於線上分析處理（OLAP）。它針對大型資料集的快速分析查詢進行了優化。\n\n**關鍵特性：**\n- 列式儲存\n- 資料壓縮\n- 平行查詢執行\n- 分散式查詢\n- 即時分析\n\n## 表格設計模式\n\n### MergeTree 引擎（最常見）\n\n```sql\nCREATE TABLE markets_analytics (\n    date Date,\n    market_id String,\n    market_name String,\n    volume UInt64,\n    trades UInt32,\n    unique_traders UInt32,\n    avg_trade_size Float64,\n    created_at DateTime\n) ENGINE = MergeTree()\nPARTITION BY toYYYYMM(date)\nORDER BY (date, market_id)\nSETTINGS index_granularity = 8192;\n```\n\n### ReplacingMergeTree（去重）\n\n```sql\n-- 用於可能有重複的資料（例如來自多個來源）\nCREATE TABLE user_events (\n    event_id String,\n    user_id String,\n    event_type String,\n    timestamp DateTime,\n    properties String\n) ENGINE = ReplacingMergeTree()\nPARTITION BY toYYYYMM(timestamp)\nORDER BY (user_id, event_id, timestamp)\nPRIMARY KEY (user_id, event_id);\n```\n\n### AggregatingMergeTree（預聚合）\n\n```sql\n-- 用於維護聚合指標\nCREATE TABLE market_stats_hourly (\n    hour DateTime,\n    market_id String,\n    total_volume AggregateFunction(sum, UInt64),\n    total_trades AggregateFunction(count, UInt32),\n    unique_users AggregateFunction(uniq, String)\n) ENGINE = AggregatingMergeTree()\nPARTITION BY toYYYYMM(hour)\nORDER BY (hour, market_id);\n\n-- 查詢聚合資料\nSELECT\n    hour,\n    market_id,\n    sumMerge(total_volume) AS volume,\n    countMerge(total_trades) AS trades,\n    uniqMerge(unique_users) AS users\nFROM market_stats_hourly\nWHERE hour >= toStartOfHour(now() - INTERVAL 24 HOUR)\nGROUP BY hour, market_id\nORDER BY hour DESC;\n```\n\n## 查詢優化模式\n\n### 高效過濾\n\n```sql\n-- PASS: 良好：先使用索引欄位\nSELECT *\nFROM markets_analytics\nWHERE date >= '2025-01-01'\n  AND market_id = 'market-123'\n  AND volume > 1000\nORDER BY date DESC\nLIMIT 100;\n\n-- FAIL: 不良：先過濾非索引欄位\nSELECT *\nFROM markets_analytics\nWHERE volume > 1000\n  AND market_name LIKE '%election%'\n  AND date >= '2025-01-01';\n```\n\n### 聚合\n\n```sql\n-- PASS: 良好：使用 ClickHouse 特定聚合函式\nSELECT\n    toStartOfDay(created_at) AS day,\n    market_id,\n    sum(volume) AS total_volume,\n    count() AS total_trades,\n    uniq(trader_id) AS unique_traders,\n    avg(trade_size) AS avg_size\nFROM trades\nWHERE created_at >= today() - INTERVAL 7 DAY\nGROUP BY day, market_id\nORDER BY day DESC, total_volume DESC;\n\n-- PASS: 使用 quantile 計算百分位數（比 percentile 更高效）\nSELECT\n    quantile(0.50)(trade_size) AS median,\n    quantile(0.95)(trade_size) AS p95,\n    quantile(0.99)(trade_size) AS p99\nFROM trades\nWHERE created_at >= now() - INTERVAL 1 HOUR;\n```\n\n### 視窗函式\n\n```sql\n-- 計算累計總和\nSELECT\n    date,\n    market_id,\n    volume,\n    sum(volume) OVER (\n        PARTITION BY market_id\n        ORDER BY date\n        ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW\n    ) AS cumulative_volume\nFROM markets_analytics\nWHERE date >= today() - INTERVAL 30 DAY\nORDER BY market_id, date;\n```\n\n## 資料插入模式\n\n### 批量插入（推薦）\n\n```typescript\nimport { createClient } from '@clickhouse\u002Fclient'\n\nconst clickhouse = createClient({\n  url: process.env.CLICKHOUSE_URL ?? 'http:\u002F\u002Flocalhost:8123',\n  username: process.env.CLICKHOUSE_USER,\n  password: process.env.CLICKHOUSE_PASSWORD\n})\n\n\u002F\u002F PASS: 批量插入（高效）\nasync function bulkInsertTrades(trades: Trade[]) {\n  await clickhouse.insert({\n    table: 'trades',\n    values: trades.map(trade => ({\n      id: trade.id,\n      market_id: trade.market_id,\n      user_id: trade.user_id,\n      amount: trade.amount,\n      timestamp: trade.timestamp.toISOString()\n    })),\n    format: 'JSONEachRow'\n  })\n}\n\n\u002F\u002F FAIL: 個別插入（慢）\nasync function insertTrade(trade: Trade) {\n  \u002F\u002F 不要在迴圈中這樣做！\n  await clickhouse.insert({\n    table: 'trades',\n    values: [{\n      id: trade.id,\n      market_id: trade.market_id,\n      user_id: trade.user_id,\n      amount: trade.amount,\n      timestamp: trade.timestamp.toISOString()\n    }],\n    format: 'JSONEachRow'\n  })\n}\n```\n\n### 串流插入\n\n```typescript\n\u002F\u002F 用於持續資料攝取\nimport { Readable } from 'node:stream'\n\nasync function streamInserts(dataSource: AsyncIterable\u003CRecord\u003Cstring, unknown>>) {\n  await clickhouse.insert({\n    table: 'trades',\n    values: Readable.from(dataSource, { objectMode: true }),\n    format: 'JSONEachRow'\n  })\n}\n```\n\n## 物化視圖\n\n### 即時聚合\n\n```sql\n-- 建立每小時統計的物化視圖\nCREATE MATERIALIZED VIEW market_stats_hourly_mv\nTO market_stats_hourly\nAS SELECT\n    toStartOfHour(timestamp) AS hour,\n    market_id,\n    sumState(amount) AS total_volume,\n    countState() AS total_trades,\n    uniqState(user_id) AS unique_users\nFROM trades\nGROUP BY hour, market_id;\n\n-- 查詢物化視圖\nSELECT\n    hour,\n    market_id,\n    sumMerge(total_volume) AS volume,\n    countMerge(total_trades) AS trades,\n    uniqMerge(unique_users) AS users\nFROM market_stats_hourly\nWHERE hour >= now() - INTERVAL 24 HOUR\nGROUP BY hour, market_id;\n```\n\n## 效能監控\n\n### 查詢效能\n\n```sql\n-- 檢查慢查詢\nSELECT\n    query_id,\n    user,\n    query,\n    query_duration_ms,\n    read_rows,\n    read_bytes,\n    memory_usage\nFROM system.query_log\nWHERE type = 'QueryFinish'\n  AND query_duration_ms > 1000\n  AND event_time >= now() - INTERVAL 1 HOUR\nORDER BY query_duration_ms DESC\nLIMIT 10;\n```\n\n### 表格統計\n\n```sql\n-- 檢查表格大小\nSELECT\n    database,\n    table,\n    formatReadableSize(sum(bytes)) AS size,\n    sum(rows) AS rows,\n    max(modification_time) AS latest_modification\nFROM system.parts\nWHERE active\nGROUP BY database, table\nORDER BY sum(bytes) DESC;\n```\n\n## 常見分析查詢\n\n### 時間序列分析\n\n```sql\n-- 每日活躍使用者\nSELECT\n    toDate(timestamp) AS date,\n    uniq(user_id) AS daily_active_users\nFROM events\nWHERE timestamp >= today() - INTERVAL 30 DAY\nGROUP BY date\nORDER BY date;\n\n-- 留存分析\nSELECT\n    signup_date,\n    countIf(days_since_signup = 0) AS day_0,\n    countIf(days_since_signup = 1) AS day_1,\n    countIf(days_since_signup = 7) AS day_7,\n    countIf(days_since_signup = 30) AS day_30\nFROM (\n    SELECT\n        user_id,\n        min(toDate(timestamp)) AS signup_date,\n        toDate(timestamp) AS activity_date,\n        dateDiff('day', signup_date, activity_date) AS days_since_signup\n    FROM events\n    GROUP BY user_id, activity_date\n)\nGROUP BY signup_date\nORDER BY signup_date DESC;\n```\n\n### 漏斗分析\n\n```sql\n-- 轉換漏斗\nSELECT\n    countIf(step = 'viewed_market') AS viewed,\n    countIf(step = 'clicked_trade') AS clicked,\n    countIf(step = 'completed_trade') AS completed,\n    round(clicked \u002F viewed * 100, 2) AS view_to_click_rate,\n    round(completed \u002F clicked * 100, 2) AS click_to_completion_rate\nFROM (\n    SELECT\n        user_id,\n        session_id,\n        event_type AS step\n    FROM events\n    WHERE event_date = today()\n)\nGROUP BY session_id;\n```\n\n### 世代分析\n\n```sql\n-- 按註冊月份的使用者世代\nSELECT\n    toStartOfMonth(signup_date) AS cohort,\n    toStartOfMonth(activity_date) AS month,\n    dateDiff('month', cohort, month) AS months_since_signup,\n    count(DISTINCT user_id) AS active_users\nFROM (\n    SELECT\n        user_id,\n        min(toDate(timestamp)) OVER (PARTITION BY user_id) AS signup_date,\n        toDate(timestamp) AS activity_date\n    FROM events\n)\nGROUP BY cohort, month, months_since_signup\nORDER BY cohort, months_since_signup;\n```\n\n## 資料管線模式\n\n### ETL 模式\n\n```typescript\n\u002F\u002F 提取、轉換、載入\nasync function etlPipeline() {\n  \u002F\u002F 1. 從來源提取\n  const rawData = await extractFromPostgres()\n\n  \u002F\u002F 2. 轉換\n  const transformed = rawData.map(row => ({\n    date: new Date(row.created_at).toISOString().split('T')[0],\n    market_id: row.market_slug,\n    volume: parseFloat(row.total_volume),\n    trades: parseInt(row.trade_count)\n  }))\n\n  \u002F\u002F 3. 載入到 ClickHouse\n  await bulkInsertToClickHouse(transformed)\n}\n\n\u002F\u002F 定期執行\nsetInterval(etlPipeline, 60 * 60 * 1000)  \u002F\u002F 每小時\n```\n\n### 變更資料捕獲（CDC）\n\n```typescript\n\u002F\u002F 監聽 PostgreSQL 變更並同步到 ClickHouse\nimport { Client } from 'pg'\n\nconst pgClient = new Client({ connectionString: process.env.DATABASE_URL })\n\npgClient.query('LISTEN market_updates')\n\npgClient.on('notification', async (msg) => {\n  const update = JSON.parse(msg.payload)\n\n  await clickhouse.insert({\n    table: 'market_updates',\n    values: [\n      {\n        market_id: update.id,\n        event_type: update.operation,  \u002F\u002F INSERT, UPDATE, DELETE\n        timestamp: new Date(),\n        data: JSON.stringify(update.new_data)\n      }\n    ],\n    format: 'JSONEachRow'\n  })\n})\n```\n\n## 最佳實務\n\n### 1. 分區策略\n- 按時間分區（通常按月或日）\n- 避免太多分區（效能影響）\n- 分區鍵使用 DATE 類型\n\n### 2. 排序鍵\n- 最常過濾的欄位放在最前面\n- 考慮基數（高基數優先）\n- 排序影響壓縮\n\n### 3. 資料類型\n- 使用最小的適當類型（UInt32 vs UInt64）\n- 重複字串使用 LowCardinality\n- 分類資料使用 Enum\n\n### 4. 避免\n- SELECT *（指定欄位）\n- FINAL（改為在查詢前合併資料）\n- 太多 JOINs（為分析反正規化）\n- 小量頻繁插入（改用批量）\n\n### 5. 監控\n- 追蹤查詢效能\n- 監控磁碟使用\n- 檢查合併操作\n- 審查慢查詢日誌\n\n**記住**：ClickHouse 擅長分析工作負載。為你的查詢模式設計表格，批量插入，並利用物化視圖進行即時聚合。\n",{"name":5,"description":7},"main","57e7aa6b6e03bce1a7d7862ba9c2ec312f7f19b5","src\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fclickhouse-io",0,"https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee","https:\u002F\u002Fwithcyril.me\u002F","Hi, I’m Julian Cyril D, a Computer Science and Business Systems student at PSNACET.\r\nI’m passionate about full-stack development, UI\u002FUX design, and building sma","2026-11-04 23:28:50",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add Cyrilthetecchieee\u002Fcyril-code- --skill clickhouse-io",{"tool":39,"command":40},"bunx","bunx skills add Cyrilthetecchieee\u002Fcyril-code- --skill clickhouse-io",{"tool":42,"command":43},"pnpm","pnpm dlx skills add Cyrilthetecchieee\u002Fcyril-code- --skill clickhouse-io","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fclickhouse-io\u002FSKILL.md",true,[],[48,57,64,72,79,86],{"skillNo":49,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":52,"licenseFileUrl":53,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":19},"01M7AQV6CYX8RMC78420V9WZ62","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","Apache-2.0","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fwebapp-testing\u002FSKILL.md",[],[],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":19},"01M7AQV2895N3S1MEX6K76G6G2","youtube-downloader","Download YouTube videos with customizable quality and format options. Use this skill when the user asks to download, save, or grab YouTube videos. Supports various quality settings (best, 1080p, 720p, 480p, 360p), multiple formats (mp4, webm, mkv), and audio-only downloads as MP3.","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fvideo-downloader\u002FSKILL.md",[],[],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":52,"licenseFileUrl":68,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":19},"01M7AQTRNX62DNKVZ5GXEHRBKB","theme-factory","Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors\u002Ffonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Ftheme-factory\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Ftheme-factory\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":19},"01M7AQTNNVHAAN9H6DA8T6ZVE0","template-skill","Replace with description of the skill and when Claude should use it.","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Ftemplate-skill\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":19},"01M7AQTJ3MQ6AKX152MEX2MYCC","tailored-resume-generator","Analyzes job descriptions and generates tailored resumes that highlight relevant experience, skills, and achievements to maximize interview chances","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Ftailored-resume-generator\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":52,"licenseFileUrl":90,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":19},"01M7AQTD7D5MYET2YWG7HG9WM3","slack-gif-creator","Toolkit for creating animated GIFs optimized for Slack, with validators for size constraints and composable animation primitives. This skill applies when users request animated GIFs or emoji animations for Slack from descriptions like \"make me a GIF for Slack of X doing Y\".","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fslack-gif-creator\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FCyrilthetecchieee\u002Fcyril-code-\u002Fblob\u002Fmain\u002Fsrc\u002Fcyril_code\u002Fassets\u002F.skills_repo\u002Fslack-gif-creator\u002FSKILL.md",[],[]]