Database Query
Use when someone needs SQL, or help with a slow query, query plan, index, table design or migration. Shows where the time goes, checks the results stay the same, and gives undo SQL.
Was dieser Skill macht
Die vollständigen Anweisungen, denen Ihr Agent folgt. Nichts davon liegt hinter einer Anmeldung.
Database query
Write or improve SQL and tables without changing results by accident.
When to use
Use it for SQL, a slow query or plan, an index, a table design or a migration. Use data-analysis to explain what data means, api-design for an API, and debugging for an app error. For a short query with no slow plan, reply in chat with the SQL and your assumptions. If asked for a .sql file, save only that, with undo SQL as comments, and put the rest in chat.
How to work
- Name the database and version. If one is missing, choose it and label it an assumption. Use only its syntax.
- A plan step's own time is its end time × loops, minus the same for its direct children. If steps ran in parallel or a time is missing, write "Can't calculate" and give it no bar. Check that rows kept plus rows removed equal rows scanned.
- Work on the step with the most own time. Suggest an index only if it removes that work, and call it a "Candidate to test". Explain its column order.
- Compare old and new SQL on dates and time zone, NULLs, duplicates, joins, tied rows and LIMIT. Mark each Same (the facts prove it), Changed (one case proves a different result) or Can't tell (a fact is missing). If tied rows had no fixed order before, mark them Can't tell and offer a tie-breaker separately. Never offer SQL with a Changed item as a replacement.
- For each schema change, give SQL to check, apply and undo it. Say what it locks, if it can run in a transaction, and how to clean up a failure.
The result
Always use these sections, in this order, with "None" in an empty one.
- Cover: the main cause or design choice, and the first change. The big number is the slowest step's share of total time. Leave it out without a plan. Key facts: the database and version, and "Not run".
- At a glance: KPIs from supplied values: total time, rows scanned, rows returned, runs a day. Round to 8 characters or fewer (
1.84 s). - Where the time goes: the main visual. One
e-barsrow per plan step, slowest first, with its own time. The note gives estimated and actual rows. Usehion the slowest. Without a plan, call it Where the data is and show rows per table, or columns per table if there are no row counts. - SQL: the current and new SQL in separate
e-codeblocks, with lines under 40 characters and a sentence on each change. - Same results?: a 3-column table: item, status, reason. For new SQL, check each requirement and example instead.
- Index or table choice: a list of the reason, storage cost, write cost and what's missing.
- Apply and undo:
e-codeto check, apply, check again and undo, then a list of locks, limits and cleanup. - Measure it: a table of what to measure, before and after. Use "Not measured" unless the user gave a value.
- Not checked: a list.
Build the page
Save one .html file (under 7,000 characters) with save_output. Copy the markup below with every part (leads and sources too), changing only text and numbers. Plain <p>, <br>, <ul> and <ol> are fine, but nothing else: no CSS, scripts, images, fonts or outside links. Keep <style> as is: endue adds its design there. Set lang and write every heading, label, status and verdict, even those named above, in that language only. In text and code, write < for < and & for &.
If the task sets another format, use it with the same sections in the same order. If you can't save files, give them in chat. After saving, reply with only the conclusion and what needs attention.
<!doctype html><html lang="ko"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Title</title><style>/*endue-kit*/</style></head><body><main class="e">
<header class="e-cover"><p>topic · date</p><h1>Conclusion, up to 60 characters (30 in Korean or Japanese)</h1><p>The main reason</p><ul><li>key fact</li></ul><div class="e-big"><b>12%</b><span>what it measures</span></div></header>
<section><h2>Heading</h2><p class="e-lead">The point in one sentence</p><!-- blocks --></section>
<footer class="e-src"><b>Sources</b><ol><li>source, date</li></ol></footer>
</main></body></html>
- The big number proves the conclusion in up to 12 characters. Without one, leave out
e-big. - Variables take plain numbers (
1240or0.5, not1,240).--maxis the block's largest value. Show every value as text too. Counts in sentences must match the blocks. - Put
hionly on what proves the block's point. Usegood,warnandbadonly when clear, with a word beside them. Say what each change is compared with.
Blocks to use here:
- Key numbers, 2–4:
<div class="e-kpis"><div class="e-kpi"><span>Orders</span><b>1,240</b><em class="up good">8% vs Sep</em></div></div>.up/downis the direction,good/badsays if that is welcome. Values: 14 characters or fewer. - Ranked bars, largest first:
<div class="e-bars e-focus" style="--max:62"><div class="hi" style="--v:62"><span>Search</span><b>62</b><em>optional note</em></div></div> - Table, up to 5 columns:
<div class="e-table"><table><thead><tr><th>Task</th><th class="n">Cost</th></tr></thead><tbody><tr class="hi"><td>text</td><td class="n">1,200</td></tr><tr class="total"><td>Total</td><td class="n">1,200</td></tr></tbody></table></div>.nis for numbers.<em>in a cell adds a small line below. - Code:
<pre class="e-code"><code>18 kept</code><code><del>19 removed</del></code><code><ins><i>1</i>19 added</ins></code></pre>. Each line gets its own<code>. Use<del>,<ins>, or<mark>for a line to look at.<i>1</i>at the start of a line is a marker in the margin, not its line number.
Before you finish
- The own times add up to the total, or you explain the difference.
- Every column in the SQL is supplied or in your design.
Never
- Predict a time or percentage gain.
- Suggest EXPLAIN ANALYZE for a write without saying it makes the change.
Nach der Registrierung fügen Sie Database Query mit einem Klick zu Ihrem Agenten hinzu.