Command Palette

Search for a command to run...

Назад к скиллам
скилл № 82784

neo4j-query-tuning-skill

Diagnoses and fixes slow Neo4j Cypher queries by reading execution plans, identifying bad operators (AllNodesScan, CartesianProduct, Eager, NodeByLabelScan)…

БесплатноБез исполняемых скриптов
neo4jот neo4j★ 126 звёзд на GitHub

Установить neo4j-query-tuning-skill в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

When to Use

  • Query takes unexpectedly long; need root-cause analysis
  • EXPLAIN/PROFILE output in hand — needs interpretation
  • Identifying which index is missing or unused
  • Deciding between slotted / pipelined / parallel runtimes
  • Monitoring live queries: SHOW TRANSACTIONS (SHOW QUERIES does not exist)
  • Cardinality estimates wrong (plan replanning needed)

When NOT to Use

  • Writing Cypher from scratch → neo4j-cypher-skill
  • GDS algorithm performance → neo4j-gds-skill
  • Schema design / data modelling → neo4j-modeling-skill

EXPLAIN vs PROFILE

EXPLAIN PROFILE
Executes query? No Yes
Returns data? No Yes
Shows rows (actual) No Yes
Shows dbHits (actual) No Yes
Shows estimatedRows Yes Yes
Cost Zero Full query cost

Run PROFILE twice — first run warms page cache; second gives representative metrics.

EXPLAIN MATCH (p:Person {email: $email}) RETURN p.name
PROFILE MATCH (p:Person {email: $email}) RETURN p.name

Query API alternative (no driver):

curl -X POST https://<host>/db/<db>/query/v2 \
  -u <user>:<pass> -H "Content-Type: application/json" \
  -d '{"statement": "EXPLAIN MATCH (p:Person {email: $email}) RETURN p.name", "parameters": {"email": "[email protected]"}}'

Key Plan Metrics

Metric Good Investigate if
dbHits Low; drops after index added High relative to rows
rows Shrinks early in plan Large until final operator
estimatedRows Close to rows >10× divergence from actual
pageCacheHitRatio >0.99 <0.90 (disk I/O bottleneck)
pageCacheHits High —
pageCacheMisses Near 0 Rising (page cache too small)

Read plans bottom-up — leaf operators at bottom initiate data retrieval.


Operator Reference

Operator Good/Bad Meaning Fix
NodeIndexSeek ✓ Exact match via RANGE/LOOKUP index —
NodeUniqueIndexSeek ✓ Unique constraint index hit —
NodeIndexContainsScan ✓ TEXT index CONTAINS —
NodeIndexEndsWithScan ✓ TEXT index ENDS WITH —
NodeIndexSeekByRange ✓ RANGE index range predicate, or STARTS WITH via RANGE/TEXT index —
NodeIndexScan ~ Full index scan (no predicate) Add WHERE predicate or composite index
NodeByLabelScan ✗ Scans all nodes of label Add RANGE index on lookup property
AllNodesScan ✗✗ Scans entire node store Add label + index to MATCH
Expand(All) ~ Traverse relationships from node Normal; limit with LIMIT or WHERE
Expand(Into) ~ Find rels between two matched nodes Normal for known-endpoint joins
Filter ~ Predicate applied after scan Move predicate into WHERE with index
CartesianProduct ✗ No join predicate between two MATCH Bad only when both inputs are large. Add a join predicate or a path (only if the relationship is a real requirement); harmless for two single-row seeks. WITH between MATCHes changes nothing
NodeHashJoin ~ Hash join on node IDs Normal; planner chose hash join
ValueHashJoin ~ Hash join on values Normal; watch memory for large inputs
EagerAggregation ~ Full aggregation (ORDER BY, count(*)) Normal for aggregates
Aggregation ✓ Streaming aggregation —
Eager ✗ Read/write conflict; materialises all rows See Eager fix strategies below
Sort ~ Full sort — O(n log n) ORDER BY … LIMIT → Top; index-backed order. Never move LIMIT before Sort (changes results)
Top ✓ Sort+Limit combined — O(n log k) Preferred over Sort+Limit
Limit ✓ Truncates rows early Push early only where it can't change which rows win
Skip ~ Offset pagination Use keyset pagination on large graphs
ProduceResults — Final output operator Root of tree
UndirectedRelationshipByIdSeekPipe ~ Lookup by relationship ID Avoid id(r) — use elementId(r)

Full operator reference → references/plan-operators.md


Diagnostic Workflow (Agent Runbook)

Step 1 — Baseline Plan

EXPLAIN <query>

Scan output for AllNodesScan, NodeByLabelScan, CartesianProduct, Eager.

Step 2 — Check Indexes

SHOW INDEXES YIELD name, type, labelsOrTypes, properties, state
WHERE state = 'ONLINE'

Find whether the label/property from the bad operator has an index.

Step 3 — Create Missing Index

// RANGE index for equality/range predicates:
CREATE INDEX person_email IF NOT EXISTS FOR (n:Person) ON (n.email)
// TEXT index for CONTAINS/ENDS WITH:
CREATE TEXT INDEX person_bio IF NOT EXISTS FOR (n:Person) ON (n.bio)
// Composite for multi-property lookup:
CREATE INDEX order_status_date IF NOT EXISTS FOR (n:Order) ON (n.status, n.createdAt)

Wait for state = 'ONLINE' before measuring.

Step 4 — Profile After Fix

PROFILE <query>
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

  1. 01Bash
  2. 02WebFetch

Вложенные файлы

  • README.md
  • references/plan-operators.md
  • references/stats-and-monitoring.md

FAQ

Что делает скилл neo4j-query-tuning-skill?

Diagnoses and fixes slow Neo4j Cypher queries by reading execution plans, identifying bad operators (AllNodesScan, CartesianProduct, Eager, NodeByLabelScan), and prescribing fixes (indexes, hints, query rewrites, runtime selection). Use when a query is slow, when EXPLAIN or PROFILE output needs interpretation, when dbHits or pageCacheHitRatio are poor, when cardinality estimation diverges from actuals, or when deciding between slotted/pipelined/parallel runtimes. Covers USING INDEX / USING SCAN / USING JOIN hints, db.stats.retrieve, SHOW TRANSACTIONS, TERMINATE TRANSACTION. Does NOT write new Cypher from scratch — use neo4j-cypher-skill. Does NOT cover GDS algorithm tuning — use neo4j-gds-skill. Does NOT cover index/constraint creation syntax details — use neo4j-cypher-skill references/indexes.md.

Как установить скилл neo4j-query-tuning-skill?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл neo4j-query-tuning-skill запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить neo4j-query-tuning-skill с