04-query-insights-and-tags
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "04-query-insights-and-tags":https://skillpi.com/zh/skills/deepskill-d368e75e281cd9e0a9044078bbb91e55749f49e38bab00bc5575a52ab27ab221。安装前核对上游来源和版本:https://github.com/planetscale/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
使用 PlanetScale Insights 和 SQLCommenter 风格的查询标签对数据库负载进行归因,识别高风险查询,并提出安全的流量控制或模式建议。
介绍来源: third_party · planetscale · 1.0.0 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 适合谁
- 来源文档未说明。
- 输入和输出
- 翻译待完成,请参阅来源文档。
- 软件、账号及付费要求
- 来源文档未说明。
- 限制与区别
- 来源文档未说明。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: planetscale-query-insights-and-tags
description: Use PlanetScale Insights and SQLCommenter-style query tags to attribute database load, identify risky queries, and prepare safe Traffic Control or schema recommendations.Query Insights and tags
Purpose
Use PlanetScale Insights to understand query behavior, then recommend SQLCommenter-compatible tags that make future diagnosis and Traffic Control possible. Do not change database settings or repository code without approval.
What to inspect
Query behavior
For the selected database and branch, inspect:
- Top queries by total time.
- Top queries by time per execution.
- Top queries by rows read.
- Top queries by execution count.
- For Postgres, top queries by CPU usage (
sort=cpuTimeorsort=percentCpuTimeon the Insights API). - Queries with errors.
- Notable queries and active anomalies.
- Query patterns affected by recent deploys.
- Query patterns attached to schema recommendations.
- For sharded Vitess databases, vindex usage for each query pattern: the
percentage of traffic using relevant vindexes and the vindex-usage trend
over time. The API exposes per-pattern
index_usagesandrouting_index_usages; get the trend from the dashboard Vindexes tab or by comparing API windows. Treat missing or declining relevant-vindex usage as an indexing or routing investigation input, not as proof that a new index is required.
Insights API surface
Query Insights is public API: read-only GET endpoints under
organizations/{org}/databases/{db}/branches/{branch}, authorized by a
service token or OAuth token with read_databases/read_database.
/insights— aggregated statistics per query pattern over the requested window. Set the window withfrom/to(ISO 8601) orperiod(for example1h,24h); search SQL patterns withq; sort server-side withsortanddir— sort keys includecount,errorCount,rowsRead,totalTime,cpuTime,ioTime,percentTime,percentCpuTime,p50Latency,p99Latency,maxLatency,egressBytes, and thetrafficControlWarnings/trafficControlThrottledfamily. Filter withtablet_type(primary,replica,rdonly) andtype(SELECT,INSERT,UPDATE,DELETE); trim responses withfields; paginate withpage/per_page./insights/{fingerprint}— individual collected executions for a pattern (timestamps, duration, rows, username, client address, error message). Available regardless of raw query collection; raw collection adds literal parameter values to these records./insights/{fingerprint}/summaryreturns the single-pattern aggregate;/insights/queries/{id}fetches one execution./insights/errors— error fingerprints with counts and messages (qsearches the error message; sort bycount,lastRun,totalTime, ortimePerQuery)./insights/errors/{fingerprint}lists the failing executions behind one error fingerprint./insights/anomaliesand/insights/anomalies/{id}— anomaly windows with per-query correlation coefficients identifying which patterns moved with the anomaly./insights/tags— tag keys with observed values (values_limit,literal_values_only, andfingerprint/keyspacefilters);/insights/tags/{tag}for a single key./insights/tags/summariesgroups the full statistics schema by one or more tag keys via thetagsparameter — use it to attribute load to routes, jobs, or features without client-side aggregation./insights/{fingerprint}/traffic/budgets— the Traffic Control budgets and rules that affect a fingerprint (Postgres).
Aggregates cover the requested window. Duration fields use names like
sum_total_duration_millis, with explicit share-of-window percent fields
(sum_total_duration_percent); both totals and percentages are reliable
for the window requested.
The response schema is shared across engines, but some fields are
engine-specific: CPU/IO durations and block-cache statistics
(sum_cpu_duration_millis, blocks_read, block_cache_hit_ratio, …) are
populated for Postgres; shard queries, keyspaces, tablet_type, and
routing-index (vindex) usage are populated for Vitess.
Tag coverage
For each expensive or anomalous query, determine:
- Is it tagged?
- Which service produced it?
- Which route, job, controller, or action produced it?
- Which deployment SHA produced it?
- Is the tag cardinality safe?
- Are tags consistent across frameworks and languages?
- Use the tags API to answer these questions:
/insights/tagsshows which keys and values are present, and/insights/tags/summaries?tags=...attributes load per tag value. In the Vitess dashboard, filter the query table withtag:key:valueand drill into query details to see tags on individual executions. Built-in query metadata and SQLCommenter tags are both valid attribution sources.
Raw query collection
Check whether raw query / complete query collection is enabled. On
Postgres the effective state is the pginsights.raw_queries cluster
parameter (per branch, dashboard Extensions tab, default false); the
database API object's insights_raw_queries field is a separate surface.
When the two differ, report the cluster parameter as the effective state
and do not describe the difference as an inconsistency. On Vitess there
is no cluster parameter; the database API's insights_raw_queries field
is the effective state.
Report it as a capability state, not a risk posture. Raw query collection
records literal parameter values per execution, which pattern-level Insights
data does not provide. It is the mechanism for isolating which specific
invocation of a pattern is pathological. Execution-level records are
retrievable from /insights/{fingerprint} with or without raw collection;
raw collection adds the literal parameter values to those records.
When it is disabled, the finding is a capability gap: identify the query patterns in this assessment where pattern-level data is insufficient (unexplained latency variance within a fingerprint, tenant- or parameter-dependent behavior) and state that raw collection would resolve them. State the operational property once, as fact: literal values become visible to the observability pipeline. Where the customer's data-handling requirements constrain this, scoped enablement (incident windows, defined retention) and leaving collection disabled are both valid outcomes — record the rationale rather than a default judgment in either direction.
Tags and raw collection are complementary instruments: tags attribute a pattern to a code path; raw collection identifies the specific invocation. Assessments should evaluate both.
SQLCommenter tag schema
Recommend this baseline tag set:
application: stable app name.service: service or process name.environment: production, staging, development.route: normalized route template, for example/accounts/:id/orders, not/accounts/123/orders.controller: framework controller name where applicable.action: framework action name where applicable.job: background job class or worker name.queue: background queue.feature: bounded feature name for traffic classes like export, report, search, billing, checkout.release_sha: short git SHA or deploy identifier.source: app, worker, script, agent, mcp, bi, integration.tenant_tier: free, pro, enterprise, internal, only if bounded.
Do not recommend these tags by default:
user_idrequest_idtenant_idemailsession_id- raw URL
- unbounded GraphQL operation text
- access token
- secret
If the customer needs tenant-level isolation, recommend a bounded abstraction first, such as tenant tier, cell, shard, or customer class. Tenant ID is only acceptable with explicit approval after cardinality and privacy review.
Cardinality rules
Flag a tag as unsafe when:
- Values are unbounded.
- Values include IDs, UUIDs, emails, slugs, or raw paths.
- The same query pattern emits many unique tag combinations.
- The tag would make Insights or Traffic Control aggregation noisy.
Recommend normalizing at the application boundary.
Analysis output
For each top query pattern, produce:
- Fingerprint or normalized query.
- Current metrics.
- Current tags.
- Missing tags.
- Likely source in application code.
- Whether it is a schema recommendation candidate.
- Whether it is a Traffic Control candidate.
- Whether it is an application optimization candidate.
Recommendation classes
Add tags
Recommend SQLCommenter instrumentation when query attribution is weak.
Improve tag normalization
Recommend replacing high-cardinality tags with bounded values.
Add Traffic Control warning budget
For Postgres only, recommend warn mode budgets for expensive but important routes, jobs, analytics, exports, or third-party integrations.
Add schema recommendation workflow
For Vitess, recommend turning open schema recommendations into branch/deploy-request work. For Postgres, recommend turning them into reviewed migrations against a non-production branch.
Fix code path
Recommend a repository PR when the expensive query is caused by N+1, missing pagination, accidental eager load, unbounded export, broad search, or polling.
Safety rules
Do not:
- Enable raw query collection.
- Add tags to code.
- Change Traffic Control budgets.
- Apply schema recommendations.
- Run production EXPLAIN ANALYZE on expensive queries.
Without explicit approval.
Output
Return:
- Query risk table.
- Tag coverage table.
- Bad/high-cardinality tag table.
- Recommended tag schema for this application.
- Candidate Traffic Control slices.
- Candidate schema and code changes.
- Proposed changes requiring approval.
End with:
“No Insights, tag, repository, or Traffic Control changes have been applied.”
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 PlanetScale 数据库查询负载归因与风险识别能力
- 支持 SQLCommenter 标签体系实现精细化流量控制
- 适用于 DBA、后端开发与 SRE 等广泛角色
亮点
- 触发描述精准覆盖数据库洞察与标签归因核心场景
- 边界清晰,无歧义或重叠风险
亮点
- 文档结构完整,涵盖从检查项到输出建议的全流程
- API 参数与安全规则说明详尽,便于执行
待提升项
-
description写错位置 原报告严重程度:轻微
description 内容位于 skill_body 内部而非顶层 frontmatter
改进建议:建议将 description 移至顶层 frontmatter 以符合规范
亮点
- 工具来源明确,参数说明完整
- 关键操作(如 raw query collection)设有审批机制,保障安全
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
账号、密钥或授权
使用专用、最小权限账号,不把密钥粘贴到公开内容或命令日志;核对接收数据的服务与租户。
主文档提及 · 第 40, 160 行
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
来源文档未说明。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。