:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(skills): scope team-wide query optimization across frontend and backend (#62227)
Robbie63267d954179
diff --git a/.agents/skills/optimizing-clickhouse-and-hogql-queries/SKILL.md b/.agents/skills/optimizing-clickhouse-and-hogql-queries/SKILL.mdindex 428e4b114fb8..70195eb2da86 100644--- a/.agents/skills/optimizing-clickhouse-and-hogql-queries/SKILL.md+++ b/.agents/skills/optimizing-clickhouse-and-hogql-queries/SKILL.md@@ -11,6 +11,25 @@ The best way to optimize a HogQL query is to **start with the ClickHouse SQL itThis skill assumes you already know how to write HogQL. For writing new ClickHouse-backed queries from scratch, use `/writing-clickhouse-queries` first. For migration mechanics, use `/clickhouse-migrations`.+## Optimizing every query a team owns++Sometimes the job isn't one slow query — it's "optimize all the ClickHouse/HogQL queries owned by team X." Before diving into individual queries, build the full inventory first, or you'll optimize a subset and miss the rest.++**Find the team's code via `.github/CODEOWNERS` and `.github/CODEOWNERS-soft`.** Grep both for the team's handle (e.g. `@PostHog/team-surveys`) to get every path the team owns. `CODEOWNERS-soft` in particular carries the product-area ownership most teams rely on.++**The ownership paths drift out of date — verify each one exists before trusting it.** Products move (e.g. into `products/<name>/`), files get renamed, directories get restructured, but `CODEOWNERS-soft` often lags. After extracting the owned paths, check each actually exists on disk; for any that don't, find where the code moved (the product likely relocated under `products/`) and **flag the stale entries to the operator** so they can fix `CODEOWNERS-soft` — don't silently substitute and move on. A stale path you skip is a query you never optimized.++**Search both backend AND frontend — owned paths include both.** A team's ownership almost always spans `frontend/src/...` as well as backend Python. The majority of ClickHouse/HogQL queries are written in Python (query runners, `execute_hogql_query`, raw `sync_execute`), **but not all of them** — plenty of products still build HogQL client-side in kea logics / React / TypeScript and POST it to the `/query` endpoint. If you only search backend paths and backend idioms, you'll miss these entirely (this is a real, recurring miss). When scoping a team, either search every owned path — frontend included — with both backend and frontend query idioms, or tell the operator up front that you're covering backend only and ask whether they want frontend too. Don't let an unstated "queries live in the backend" assumption narrow the search silently.++Frontend HogQL doesn't look like the backend patterns in Step 0. Grep the team's `frontend/` paths for these too:++- `api.queryHogQL(...)`, `HogQLQueryString`, the `` hogql`...` `` tagged template+- `NodeKind.HogQLQuery` / `kind: 'HogQLQuery'` objects with a `query:` string+- structured query nodes that compile to ClickHouse: `DataTableNode`, `EventsQuery`, `TrendsQuery`/`InsightVizNode`, and `PropertyFilterType.HogQL` expressions inside them+- string literals with `SELECT ... FROM events`, or product-specific markers (event names like `'survey sent'`, property keys like `$survey_id`)++The same logical query is sometimes implemented **twice** — once in a backend query runner / endpoint and once as frontend-built HogQL (often a stalled frontend→backend migration). Treat both copies as in-scope, and note the duplication: a printer- or function-level fix on the backend won't reach a hand-built frontend string emitting the same SQL.+## Step 0: confirm you're at the right layerBefore walking through the workflow, check that the slow query in front of you actually goes to ClickHouse via HogQL. The fastest way is to look at how the query is built: