Initial commit: local SQL expert AI (Ollama + CLI + prompts + systemd timer)
This commit is contained in:
25
prompts/indexing_checklist.md
Normal file
25
prompts/indexing_checklist.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Indexing Checklist (SQL Server 2022)
|
||||
|
||||
## Vor dem Index
|
||||
- Welche Query/Workload? (Top N Abfragen)
|
||||
- Welche Filter/Join-Spalten?
|
||||
- Sort/Group By/Distinct? (ORDER BY, GROUP BY)
|
||||
- Häufige Lookups? (Key Lookup / RID Lookup)
|
||||
- Schreiblast hoch? (Index-Overhead)
|
||||
|
||||
## Plausible Index-Regeln
|
||||
- Key Columns: erst Equality predicates, dann Range, dann Join keys
|
||||
- Include Columns: nur für benötigte SELECT-Spalten (Covering)
|
||||
- Filtered Index: wenn Predicate stabil/selektiv (z.B. Status='Active')
|
||||
- Datentypen sauber (keine impliziten Konvertierungen)
|
||||
- Stats: nach großen Loads/Änderungen aktualisieren (gezielt)
|
||||
|
||||
## Validierung
|
||||
- Plan vorher/nachher
|
||||
- Reads/CPU/Duration
|
||||
- Index usage (DMVs) nur als Hinweis, nicht alleinige Wahrheit
|
||||
- Regression Tests / Parameter Sets
|
||||
|
||||
---BEGIN INPUT---
|
||||
<PASTE HERE>
|
||||
---END INPUT---
|
||||
27
prompts/plan_review.md
Normal file
27
prompts/plan_review.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Execution Plan Review Template (Showplan XML/Text)
|
||||
|
||||
## Kontext (optional)
|
||||
- Query text (falls verfügbar)
|
||||
- Parameterwerte bei Capture
|
||||
- CPU/Duration/Reads/Rowcount bei Capture
|
||||
- Server settings: MAXDOP, Cost Threshold for Parallelism (falls bekannt)
|
||||
|
||||
## Aufgabe
|
||||
1) Kurzfazit
|
||||
2) Hotspots:
|
||||
- Top Operatoren nach Kosten
|
||||
- Spills (Sort/Hash), Warnings
|
||||
- Memory Grant: zu hoch/zu niedrig
|
||||
- Parallelism (CXPACKET/CXCONSUMER Kontext)
|
||||
3) Kardinalität:
|
||||
- wo weicht Estimated vs Actual ab? (wenn Actual vorhanden)
|
||||
- Stats/Histogramm Hinweise
|
||||
4) Fixes:
|
||||
- Query Rewrite
|
||||
- Index/Stats Empfehlungen
|
||||
- Parameter Sniffing Mitigation
|
||||
5) Checkliste für Validierung
|
||||
|
||||
---BEGIN PLAN---
|
||||
<PASTE HERE>
|
||||
---END PLAN---
|
||||
22
prompts/proc_refactor_template.md
Normal file
22
prompts/proc_refactor_template.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Stored Procedure Review / Refactor Template
|
||||
|
||||
## Kontext (optional)
|
||||
- Aufrufmuster (Parameter, typische Werte):
|
||||
- Isolation Level / Transactions:
|
||||
- Deadlocks/Blocking bekannt? (ja/nein + Hinweise)
|
||||
- Ziel: Latenz, Throughput, Stabilität, Plan-Stabilität
|
||||
|
||||
## Aufgabe
|
||||
1) Kurzfazit
|
||||
2) Detailanalyse
|
||||
- Parameter Sniffing
|
||||
- Temp tables vs table variables
|
||||
- Row-by-row (Cursor, WHILE), UDFs, RBAR
|
||||
- TRY/CATCH + Fehlerbehandlung
|
||||
- Transaktionsumfang (zu groß?), Lock Escalation, Timeouts
|
||||
3) Konkrete Refactorings (mit T-SQL)
|
||||
4) Risiken/Checks/Next steps
|
||||
|
||||
---BEGIN PROC---
|
||||
<PASTE HERE>
|
||||
---END PROC---
|
||||
30
prompts/sniffing_stats_playbook.md
Normal file
30
prompts/sniffing_stats_playbook.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Parameter Sniffing & Statistics Playbook
|
||||
|
||||
## Symptome
|
||||
- Laufzeit stark schwankend je nach Parameter
|
||||
- Plan ist "gut" für einen Wert, "schlecht" für andere
|
||||
- Große Estimated vs Actual Abweichungen
|
||||
- Memory grants/spills je nach Parameter
|
||||
|
||||
## Diagnose (ohne DB-Zugriff: theoretisch/plan-basiert)
|
||||
- Welche Prädikate sind parameterabhängig?
|
||||
- Gibt es Skew (ein Wert sehr häufig/selten)?
|
||||
- OR-Logik / optional filters (@p IS NULL OR col=@p)?
|
||||
- Implizite Konvertierungen?
|
||||
|
||||
## Gegenmaßnahmen (geordnet von "leicht" zu "hart")
|
||||
1) Query rewrite (SARGability, Splitting optional filters)
|
||||
2) OPTION(RECOMPILE) selektiv
|
||||
3) OPTIMIZE FOR (oder OPTIMIZE FOR UNKNOWN) bewusst
|
||||
4) Zwei Queries / IF branches für stark unterschiedliche Pfade
|
||||
5) Plan guides / forced plan (nur in Ausnahmefällen)
|
||||
6) Stats: update + ggf. filtered stats (wenn passend)
|
||||
|
||||
## Checkliste
|
||||
- Welche Parameter-Sets testen (min/max/typisch)
|
||||
- Regression: CPU/Reads/Duration
|
||||
- Concurrency/Blocking beachten
|
||||
|
||||
---BEGIN INPUT---
|
||||
<PASTE HERE>
|
||||
---END INPUT---
|
||||
29
prompts/tsql_review.md
Normal file
29
prompts/tsql_review.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# T-SQL Review Template (Copy & Paste)
|
||||
|
||||
> Zweck: schnelle, präzise Analyse einer Abfrage.
|
||||
> Eingabe: T-SQL + (optional) Parameterwerte + (optional) Tabelleninfos.
|
||||
|
||||
## Kontext (optional)
|
||||
- SQL Server Version: 2022
|
||||
- DB Kompatibilitätslevel: ?
|
||||
- Tabellenvolumen grob (Rows): ?
|
||||
- Häufigkeit/Latency Ziel: ?
|
||||
- Parameterwerte (typisch & worst-case): ?
|
||||
|
||||
## Aufgabe
|
||||
Analysiere das T-SQL und liefere:
|
||||
1) **Kurzfazit** (3–6 Bulletpoints)
|
||||
2) **Detailanalyse**:
|
||||
- SARGability (LIKE, Funktionen auf Spalten, CAST/CONVERT, Datentyp-Mismatches)
|
||||
- Joins/Predicates (Reihenfolge, Join Typen)
|
||||
- Kardinalität/Stats (wo schätzt der Optimizer falsch)
|
||||
- Parameter Sniffing Risiko + konkrete Mitigation (z.B. OPTION(RECOMPILE) gezielt, OPTIMIZE FOR, plan guides nur wenn nötig)
|
||||
3) **Konkrete Verbesserungen**:
|
||||
- rewrite (mit kommentiertem SQL)
|
||||
- Index-Vorschläge (nur wenn plausibel; include columns; Filtered Index falls geeignet)
|
||||
4) **Checks**:
|
||||
- welche Messwerte/Plan-Indikatoren prüfen
|
||||
|
||||
---BEGIN T-SQL---
|
||||
<PASTE HERE>
|
||||
---END T-SQL---
|
||||
27
prompts/utf8_migration_runbook.md
Normal file
27
prompts/utf8_migration_runbook.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# UTF-8 Migration Runbook (SQL Server 2022)
|
||||
|
||||
## Ziel
|
||||
Tabellen/Spalten auf UTF-8 umstellen durch Verwendung von UTF-8-enabled Collations (`*_UTF8`).
|
||||
|
||||
## Input (paste)
|
||||
- Aktuelles Schema (CREATE TABLE oder relevante Spalten)
|
||||
- Aktuelle Collations
|
||||
- Abhängigkeiten (FKs, Indexes, Computed Columns, Triggers)
|
||||
- App assumptions (Sortierung, Vergleiche, Case sensitivity)
|
||||
|
||||
---BEGIN INPUT---
|
||||
<PASTE HERE>
|
||||
---END INPUT---
|
||||
|
||||
## Erwartete Ausgabe
|
||||
1) Kurzfazit
|
||||
2) Schritt-für-Schritt Plan (staging -> validate -> cutover -> rollback)
|
||||
3) DDL Snippets:
|
||||
- neue Collation setzen
|
||||
- Rebuild Indizes/Constraints
|
||||
4) Risiken:
|
||||
- Sort-/Compare-Verhalten kann sich ändern
|
||||
- mögliche Indexgrößenänderung
|
||||
- computed columns / persisted computed columns
|
||||
5) Teststrategie:
|
||||
- Vergleichssuites, Known tricky strings, roundtrip tests
|
||||
23
prompts/view_analysis_template.md
Normal file
23
prompts/view_analysis_template.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# View Analysis Template
|
||||
|
||||
## Kontext (optional)
|
||||
- Wird die View häufig gejoint/weitergefiltert?
|
||||
- Erwartete Selectivity / typische Filter?
|
||||
- Indexed view überhaupt erlaubt/gewünscht? (Schema binding etc.)
|
||||
|
||||
## Aufgabe
|
||||
1) Kurzfazit
|
||||
2) Detailanalyse:
|
||||
- Expand/Inlining Effekte
|
||||
- SARGability und Pushdown von Predicates
|
||||
- Aggregationen/Distinct/Union
|
||||
- Risiken bei Scalar UDFs / Non-deterministic Funktionen
|
||||
3) Verbesserungen:
|
||||
- alternative Definition
|
||||
- Hinweise zu Indizes auf Basistabellen
|
||||
- falls relevant: indexed view Voraussetzungen (nur als Option)
|
||||
4) Risiken/Checks
|
||||
|
||||
---BEGIN VIEW---
|
||||
<PASTE HERE>
|
||||
---END VIEW---
|
||||
Reference in New Issue
Block a user