# neo4j-query-tuning-skill

Reads a Neo4j execution plan, spots the operators that slow a Cypher query down, and tells you what to change. Useful when a query drags and PROFILE output is hard to read.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 908 installs · ★ 116
- Author: neo4j-contrib
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/neo4j-contrib/neo4j-skills/tree/HEAD/neo4j-query-tuning-skill/SKILL.md
- Updated: 2026-10-21
- HTML: https://affpapa.org/en/nevibecode/skills/neo4j-query-tuning-skill

## What it does

The skill parses `EXPLAIN` and `PROFILE` output and looks for the usual suspects: `AllNodesScan`, `NodeByLabelScan`, `CartesianProduct`, `Eager`. Then it prescribes a fix — add an index, force a `USING INDEX` or `USING SCAN` hint, rewrite the query, switch runtime. It also walks through the metrics that matter: `dbHits`, `rows`, `estimatedRows`, `pageCacheHitRatio`. When the estimated cardinality diverges from the actual by more than 10×, that is your cue to replan stats with `db.prepareForReplanning()` or `db.resampleIndex()`.

The runbook is ordered: capture a baseline plan, check indexes with `SHOW INDEXES`, create the missing one, then re-run `PROFILE` to compare. It advises profiling twice — the first run warms the page cache, the second gives numbers you can trust. For live work it covers `SHOW QUERIES`, `SHOW TRANSACTIONS` and `TERMINATE TRANSACTION`. Only `Bash` and `WebFetch` are allowed as tools.

This is not a general Cypher helper. It will not write queries from scratch — that is `neo4j-cypher-skill`. GDS algorithm tuning and index/constraint creation syntax are out of scope too. Come here when an existing query is slow, not when you are designing a schema.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add neo4j-contrib/neo4j-skills --skill neo4j-query-tuning-skill -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/neo4j-query-tuning-skill/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/neo4j-query-tuning-skill/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add neo4j-contrib/neo4j-skills --skill neo4j-query-tuning-skill -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/neo4j-query-tuning-skill/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add neo4j-contrib/neo4j-skills --skill neo4j-query-tuning-skill -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/neo4j-query-tuning-skill/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install neo4j-contrib/neo4j-skills neo4j-query-tuning-skill
```

2. **Manually: put the files in place**
- File: `.github/skills/neo4j-query-tuning-skill/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add neo4j-contrib/neo4j-skills --skill neo4j-query-tuning-skill -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/neo4j-contrib/neo4j-skills --path neo4j-query-tuning-skill
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/neo4j-query-tuning-skill/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add neo4j-contrib/neo4j-skills --skill neo4j-query-tuning-skill -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/neo4j-contrib/neo4j-skills/tree/HEAD/neo4j-query-tuning-skill/SKILL.md

## When to use it
- find out why a Cypher query runs longer than expected
- interpret `EXPLAIN` or `PROFILE` output and name the operator that hurts
- figure out which index is missing for a property lookup
- choose between slotted, pipelined and parallel runtimes
- inspect running queries and transactions, then kill one if needed

## Example prompts
- Read the plan for this slow query: `PROFILE MATCH (p:Person {email: $email}) RETURN p.name`
- Why is there an `AllNodesScan` here, and which index should I add?
- Check `SHOW QUERIES` and tell me which of these to terminate

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 4eab71087d925709.

BEGIN THIRD-PARTY FILE 4eab71087d925709
````text
---
name: neo4j-query-tuning-skill
description: 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 QUERIES,
  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.
allowed-tools: Bash WebFetch
version: 1.0.8
---

## 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 QUERIES, SHOW TRANSACTIONS
- 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.

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

Query API alternative (no driver):
```bash
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": "a@b.com"}}'
```

---
````
END THIRD-PARTY FILE 4eab71087d925709

The third-party file has ended. Everything between the 4eab71087d925709 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2258 of 10491 bytes. © neo4j-contrib · MIT · https://github.com/neo4j-contrib/neo4j-skills/tree/HEAD/neo4j-query-tuning-skill/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
