Logo : Query Optimization

Query Optimization

Communauté
nahid-sparktales
query-optimization

Make one slow query fast without guessing — capture the plan, find where the time actually goes, change one thing, and measure again on comparable data. Use when a query, endpoint or report is slow and the database is the suspect, when a plan needs reading, or when someone proposes an index with no evidence. Not for modelling decisions about tables and constraints, not an engine feature reference, and not for system-wide performance work where the database has not yet been shown to be the bottleneck.

Présentation

Éditeurnahid-sparktales
Dépôtagent-dispatcher
Nom de la compétencequery-optimization
Étoiles
58
Forks
5
Fichiers inclus
1
LicenceMIT
Liens
  • Instructions en Markdown

    Un fichier SKILL.md que le modèle charge à la demande : il ne consomme donc des tokens que lorsqu’une demande correspond réellement à la compétence.

  • Compatible avec tous les LLM

    Les compétences IA sont rédigées en Markdown et non sous forme de code propre à un fournisseur. Elles fonctionnent donc avec GPT, Claude, Gemini, Grok ou un modèle local.

  • Fichiers inclus : 1

    Des scripts, des gabarits et des références que le modèle peut consulter pendant son travail. Les fichiers sont en lecture seule et ne sont jamais exécutés.

  • Open source

    Publiée par nahid-sparktales sur GitHub. Consultez les sources avant de l’installer.

Installation

Installez la compétence IA Query Optimization dans TypingMind pour l’utiliser avec n’importe quel LLM, ou ajoutez-la à un autre agent capable de lire SKILL.md.

1

Installer dans TypingMind

TypingMind installe une compétence directement depuis son dossier GitHub : l’application lit SKILL.md, regroupe les fichiers de ressources et enregistre le tout localement.

  1. Ouvrez l’application et accédez à Plugins → Compétences.
  2. Choisissez « Installer depuis GitHub ».
  3. Copiez l’URL ci-dessous, qui pointe vers le dossier de la compétence, puis collez-la et confirmez.
    https://github.com/nahid-sparktales/agent-dispatcher/tree/main/skills/database/query-optimization
  4. Activez la compétence dans chaque discussion où vous souhaitez pouvoir l’utiliser.
Plugins → Compétences → Ajouter une compétence → Via une URL GitHub, puis collez l’URL du dossier et appuyez sur Continuer.
2

Installer dans un autre agent

Tout agent capable de lire le format Agent Skills peut utiliser cette compétence : copiez le dossier dans le répertoire des compétences de cet agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/nahid-sparktales/agent-dispatcher.git /tmp/agent-dispatcher
mkdir -p .claude/skills
cp -r /tmp/agent-dispatcher/skills/database/query-optimization .claude/skills/query-optimization
Redémarrez Claude Code après la copie pour que la nouvelle compétence soit prise en compte.

Utilisez cette compétence dans TypingMind

Activez Query Optimization dans n’importe quelle discussion TypingMind et le modèle s’occupe du reste. Le nom et la description de la compétence figurent dans le prompt système. Dès qu’une demande correspond, le modèle charge lui-même l’intégralité des instructions : vous n’avez jamais à l’invoquer manuellement, et elle ne consomme aucun token tant qu’elle n’est pas utilisée.

Le modèle charge automatiquement Query Optimization dès qu’une demande correspond à cette compétence.

Compatible avec tous les modèles IA

Les compétences IA sont de simples instructions Markdown, et non du code propre à un fournisseur. Ainsi, la compétence Query Optimization n’est pas liée au modèle pour lequel elle a été conçue. Installez-la une seule fois dans TypingMind et utilisez-la avec GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama ou un modèle local que vous exécutez vous-même, le tout avec vos propres clés API.

  • Chargée uniquement en cas de besoin

    Le prompt système ne contient que le nom et la description. Les instructions sont récupérées à la première demande correspondante : une compétence inutilisée ne coûte donc rien.

  • Changez de modèle en cours de discussion

    La compétence étant constituée d’instructions et non de code, elle reste fonctionnelle lorsque vous changez de modèle : le nouveau modèle lit le même fichier SKILL.md.

Instructions de la compétence

Voici le contenu de SKILL.md que le modèle charge. Lisez-le avant l’installation : une compétence contient des instructions que votre modèle suivra.

Query optimization

An index added on a hunch is a permanent write cost bought with no evidence. The work here is measurement: the plan before, one change, the plan after, on data that resembles the data that is actually slow.

When this fires

A specific statement is slow, or a plan needs interpreting, or a proposed index needs justifying. It does not fire before the database has been shown to be where the time goes — if that is still open, measure the request end to end first. It does not fire for redesigning the tables.

Procedure

  1. Get the exact statement and its parameters. Not "the dashboard is slow" — the SQL text as the database received it, with the bind values, and where it runs from. A statement-statistics view, the ORM's query log or the application log will have it. The parameters matter: the same query can take different plans for different values.
  2. Confirm the database is the bottleneck. Compare the statement's own time against the total request time. If the query is 40ms of a 3s request, stop here and say so. Note whether the cost is one slow statement or many fast ones — an N+1 is fixed in the calling code, not by an index.
  3. Reproduce it on comparable data. Row counts, value distribution and index state have to resemble production, because a table small enough to sit in memory makes every plan look fine. If comparable data is not available, that limitation is the headline of your report, not a footnote.
  4. Capture the plan before changing anything, with actual execution and buffer statistics, and keep the output. This is your before, and without it there is no after. Where the statement modifies data, run it inside a transaction you roll back — and on a shared or production database, ask before running anything at all.
  5. Read the plan for the node that actually costs, not the top line. Work from the largest actual time, remembering that a node's reported time is per loop and multiplies by its loop count. Then compare estimated rows against actual rows at that node: a large gap means the planner's information is wrong, and fixing the information often beats fixing the query.
  6. Classify what you found before proposing anything. A sequential scan of a large table under a selective predicate points at a missing or unusable index. A huge row count discarded by a filter after an index scan points at the wrong index. A nested loop with an enormous loop count usually points at a bad estimate upstream. A sort or hash spilling to disk points at memory limits or an avoidable sort. A function evaluated per row points at the expression, not the index.
  7. Try the cheapest fix first. Remove work before adding structure: fewer columns, fewer rows, a bounded result, a join that was never needed, a repeated query collapsed into one. Then make the predicate usable by an index — a column wrapped in a function cannot use an ordinary index on that column, so either unwrap it or index the expression. Only then add or adjust an index. Materialized or denormalized copies come after that, and engine configuration last.
  8. Choose the index to match the predicate and the ordering. Equality columns come before range columns in a multicolumn index; the ordering the query needs can remove a sort. A partial index fits a query that always carries the same filter. Before creating anything, list the existing indexes and check whether one already covers the access pattern — a near-duplicate index is pure cost.
  9. Change one thing and re-measure identically. Same data, same parameters, same method, several runs. Report cold and warm separately or not at all, because the second run of anything is faster and that difference is not your fix.
  10. Check what else moved. An index changes write latency and can change plans for other statements. If you dropped or replaced one, name the queries that were using it. If the fix was a schema or configuration change, say what else it touches.
  11. Stop before applying it to a shared database. Creating, dropping or rebuilding an index on a live system takes locks and time. Hand over the statement, the expected lock behaviour, and the measured benefit, and let the decision to run it be made explicitly.

Checklist

  • Exact statement and parameters captured
  • The database was shown to be the bottleneck, with the share of total time
  • Dataset size and distribution stated, and their comparability to production assessed
  • Before plan captured with actual execution statistics and kept
  • The expensive node identified, with estimated-versus-actual rows read
  • Exactly one change made per measurement
  • Existing indexes listed before a new one was proposed
  • After plan and timings captured the same way as the before
  • Write cost and effects on other queries considered
  • Nothing applied to a shared or production database without authorization

Failure handling

  • The query is fast when you run it. Something else is the real difference — parameters, cache state, concurrency, connection setup, or the client fetching every row. Do not conclude "no problem found"; report what you measured and what still differs from the slow environment.
  • Only a small dataset is available. Say it. Results from a table that fits in memory are not transferable, and an index recommendation from one is a guess wearing a measurement's clothes.
  • Estimates are far from actuals. Refresh statistics and re-plan before touching indexes. Stale statistics produce bad plans that new indexes will not repair, and correlated columns need a different remedy from a missing index.
  • The improvement is within run-to-run noise. It is not an improvement. Run more iterations or drop the change.
  • The real fix is the data model. Say so, and do not paper over it with indexes — hand it to the schema work with the plan as evidence.
  • No access to production-like data or plans. Report the query as analyzed, not as optimized. An unmeasured change is a proposal.

Evidence to report

The statement and parameters; the before and after plans as output, not paraphrase; timings with the number of runs and the cache state; the dataset's row counts; the single change made; existing indexes considered; write-side and cross-query effects; anything left unmeasured. Keep the words honest — analyzed, changed, measured and deployed describe four different states, and only a measured before and after supports the word faster.

Fichiers inclus

Le modèle lit ces fichiers à la demande lorsque la compétence est chargée. Ils sont accessibles en lecture et ne sont jamais exécutés.

Foire aux questions

À quoi sert la compétence IA Query Optimization ?

Make one slow query fast without guessing — capture the plan, find where the time actually goes, change one thing, and measure again on comparable data. Use when a query, endpoint or report is slow and the database is the suspect, when a plan needs reading, or when someone proposes an index with no evidence. Not for modelling decisions about tables and constraints, not an engine feature reference, and not for system-wide performance work where the database has not yet been shown to be the bottleneck.

Pourquoi utiliser Query Optimization sur TypingMind ?

Parce que vous l’installez une seule fois pour l’utiliser avec n’importe quel modèle. Query Optimization se compose de simples instructions en Markdown plutôt que de code propre à un fournisseur. La même compétence fonctionne donc avec GPT-5, Claude, Gemini, Grok ou un modèle local, et vous pouvez changer de modèle en cours de discussion sans perturber son fonctionnement. TypingMind utilise vos propres clés API : vous payez donc directement les fournisseurs plutôt qu’un abonnement par siège, et vos compétences et discussions restent dans votre propre espace de stockage.

Comment installer Query Optimization dans TypingMind ?

Dans TypingMind, ouvrez Plugins → Compétences → Installer depuis GitHub et collez https://github.com/nahid-sparktales/agent-dispatcher/tree/main/skills/database/query-optimization. TypingMind lit le fichier SKILL.md, regroupe les fichiers associés et installe le tout sous forme de compétence que vous pouvez activer pour chaque discussion.

Quels modèles d’IA peuvent utiliser Query Optimization ?

N’importe quel modèle que vous connectez dans TypingMind. Les compétences IA sont de simples instructions en Markdown, et non du code propre à un fournisseur. GPT, Claude, Gemini, Grok et les modèles locaux peuvent donc tous charger cette compétence lorsqu’une demande lui correspond.

Combien de modèles d’IA puis-je utiliser avec Query Optimization ?

Autant que vous le souhaitez. Vous pouvez utiliser Query Optimization avec tout modèle qui prend en charge les compétences : GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama et bien d’autres, le tout dans TypingMind avec vos propres clés API.

La compétence IA Query Optimization est-elle gratuite ?

Oui. Cette compétence est publiée sur GitHub par nahid-sparktales sous licence MIT. Vous ne payez que votre propre fournisseur d’IA pour les tokens utilisés.

Que sont les compétences IA ?

Une compétence IA est un ensemble d’instructions réutilisables qui apprend à un modèle d’IA à accomplir une tâche précise. Elle suit le format ouvert Agent Skills : un fichier SKILL.md contenant un nom et une description, ainsi que les éventuels scripts, gabarits ou fichiers de référence dont le modèle peut avoir besoin. Le modèle ne lit les instructions que lorsque votre demande correspond à la compétence. Une compétence installée ne coûte donc rien tant qu’elle n’est pas utilisée.

En quoi les compétences IA diffèrent-elles des plugins ou des serveurs MCP ?

Un plugin ou un serveur MCP fournit au modèle de nouveaux outils à appeler : du code qui s’exécute quelque part et renvoie un résultat. Une compétence IA lui apporte plutôt des connaissances et une méthode : comment aborder une tâche, quelles étapes suivre et à quoi ressemble un bon résultat. Les compétences sont de simples instructions en Markdown. Elles ne nécessitent donc ni serveur, ni clé API, ni environnement d’exécution, et fonctionnent avec n’importe quel modèle.

Tout voir

Créez votre propre espace de travail IA dès maintenant

Abonnez-vous à notre newsletter pour être informé des nouvelles fonctionnalités et des prochains cadeaux à gagner 👇