mysql_genius-core 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/lib/mysql_genius/core/ai/config.rb +5 -2
  4. data/lib/mysql_genius/core/ai/describe_query.rb +41 -0
  5. data/lib/mysql_genius/core/ai/index_advisor.rb +43 -0
  6. data/lib/mysql_genius/core/ai/migration_risk.rb +51 -0
  7. data/lib/mysql_genius/core/ai/rewrite_query.rb +51 -0
  8. data/lib/mysql_genius/core/ai/schema_context_builder.rb +82 -0
  9. data/lib/mysql_genius/core/ai/schema_review.rb +46 -0
  10. data/lib/mysql_genius/core/analysis/columns.rb +64 -0
  11. data/lib/mysql_genius/core/version.rb +1 -1
  12. data/lib/mysql_genius/core/views/mysql_genius/queries/_shared_results.html.erb +56 -0
  13. data/lib/mysql_genius/core/views/mysql_genius/queries/_tab_ai_tools.html.erb +43 -0
  14. data/lib/mysql_genius/core/views/mysql_genius/queries/_tab_dashboard.html.erb +95 -0
  15. data/lib/mysql_genius/core/views/mysql_genius/queries/_tab_duplicate_indexes.html.erb +35 -0
  16. data/lib/mysql_genius/core/views/mysql_genius/queries/_tab_query_explorer.html.erb +110 -0
  17. data/lib/mysql_genius/core/views/mysql_genius/queries/_tab_query_stats.html.erb +26 -0
  18. data/lib/mysql_genius/core/views/mysql_genius/queries/_tab_server.html.erb +54 -0
  19. data/lib/mysql_genius/core/views/mysql_genius/queries/_tab_slow_queries.html.erb +17 -0
  20. data/lib/mysql_genius/core/views/mysql_genius/queries/_tab_table_sizes.html.erb +33 -0
  21. data/lib/mysql_genius/core/views/mysql_genius/queries/_tab_unused_indexes.html.erb +36 -0
  22. data/lib/mysql_genius/core/views/mysql_genius/queries/dashboard.html.erb +1565 -0
  23. data/lib/mysql_genius/core.rb +18 -0
  24. data/mysql_genius-core.gemspec +1 -1
  25. metadata +20 -2
@@ -0,0 +1,35 @@
1
+ <!-- Duplicate Indexes Tab -->
2
+ <div class="mg-tab-content" id="tab-indexes">
3
+ <div class="mg-row" style="justify-content:space-between;align-items:center;margin-bottom:12px;">
4
+ <div class="mg-text-muted">Indexes whose columns are a left-prefix of another index on the same table. These are redundant and can safely be dropped. <span id="dup-count" class="mg-badge mg-badge-secondary"></span></div>
5
+ <button id="dup-refresh" class="mg-btn mg-btn-outline-secondary mg-btn-sm">&#8635; Refresh</button>
6
+ </div>
7
+ <div id="dup-loading" class="mg-text-center mg-hidden"><span class="mg-spinner"></span> Scanning indexes...</div>
8
+ <div id="dup-empty" class="mg-text-center mg-text-muted mg-hidden">No duplicate indexes found.</div>
9
+ <div id="dup-table-wrapper" class="mg-table-wrap mg-hidden">
10
+ <table class="mg-table">
11
+ <thead>
12
+ <tr>
13
+ <th>Table</th>
14
+ <th>Duplicate Index</th>
15
+ <th>Columns</th>
16
+ <th>Covered By</th>
17
+ <th>Covered Columns</th>
18
+ <th>DROP Statement</th>
19
+ </tr>
20
+ </thead>
21
+ <tbody id="dup-tbody"></tbody>
22
+ </table>
23
+ </div>
24
+ <div id="dup-migration" class="mg-hidden" style="margin-top:16px;">
25
+ <div class="mg-card">
26
+ <div class="mg-card-header" style="display:flex;justify-content:space-between;align-items:center;">
27
+ <strong>Suggested Migration</strong>
28
+ <button id="dup-copy-migration" class="mg-btn mg-btn-outline-secondary mg-btn-sm">&#128203; Copy</button>
29
+ </div>
30
+ <div class="mg-card-body">
31
+ <pre id="dup-migration-code" style="font-size:12px;margin:0;white-space:pre-wrap;user-select:all;"></pre>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ </div>
@@ -0,0 +1,110 @@
1
+ <!-- Query Explorer Tab -->
2
+ <div class="mg-tab-content" id="tab-explorer">
3
+ <div style="margin-bottom:12px;">
4
+ <button class="mg-btn mg-btn-sm qe-mode active" data-mode="visual">Visual Builder</button>
5
+ <button class="mg-btn mg-btn-sm mg-btn-outline qe-mode" data-mode="sql">SQL Editor</button>
6
+ </div>
7
+
8
+ <!-- Visual Builder Mode -->
9
+ <div id="qe-visual">
10
+ <div class="mg-row mg-mb">
11
+ <div class="mg-col-4 mg-field">
12
+ <label for="vb-table">Table</label>
13
+ <select id="vb-table">
14
+ <option value="">-- Select a table --</option>
15
+ <% if @featured_tables != @all_tables %>
16
+ <optgroup label="Featured">
17
+ <% @featured_tables.each do |table| %>
18
+ <option value="<%= table %>"><%= table %></option>
19
+ <% end %>
20
+ </optgroup>
21
+ <optgroup label="All Tables">
22
+ <% (@all_tables - @featured_tables).each do |table| %>
23
+ <option value="<%= table %>"><%= table %></option>
24
+ <% end %>
25
+ </optgroup>
26
+ <% else %>
27
+ <% @all_tables.each do |table| %>
28
+ <option value="<%= table %>"><%= table %></option>
29
+ <% end %>
30
+ <% end %>
31
+ </select>
32
+ </div>
33
+ <div class="mg-col-2 mg-field">
34
+ <label for="vb-row-limit">Row Limit</label>
35
+ <input type="number" id="vb-row-limit" value="25" min="1" max="<%= MysqlGenius.configuration.max_row_limit %>">
36
+ </div>
37
+ <div class="mg-field">
38
+ <label>&nbsp;</label>
39
+ <button id="vb-run" class="mg-btn mg-btn-primary" disabled>&#9654; Run Query</button>
40
+ <button id="vb-explain" class="mg-btn mg-btn-outline" disabled>&#128270; Explain</button>
41
+ </div>
42
+ </div>
43
+
44
+ <div id="vb-columns-section" class="mg-mb mg-hidden">
45
+ <label>Columns
46
+ <span id="vb-toggle-all" class="mg-link">Toggle All</span>
47
+ <span id="vb-show-defaults" class="mg-link">Reset Defaults</span>
48
+ </label>
49
+ <div id="vb-columns" class="mg-checks"></div>
50
+ </div>
51
+
52
+ <div id="vb-filters-section" class="mg-mb mg-hidden">
53
+ <label>Filters</label>
54
+ <div id="vb-filters"></div>
55
+ <button id="vb-add-filter" class="mg-btn mg-btn-outline-secondary mg-btn-sm" style="margin-top:4px;">+ Add Filter</button>
56
+ </div>
57
+
58
+ <div id="vb-order-section" class="mg-mb mg-hidden">
59
+ <label>Order By</label>
60
+ <div id="vb-orders"></div>
61
+ <button id="vb-add-order" class="mg-btn mg-btn-outline-secondary mg-btn-sm" style="margin-top:4px;">+ Add Sort</button>
62
+ </div>
63
+
64
+ <div id="vb-generated-sql" class="mg-mb mg-hidden">
65
+ <label>Generated SQL</label>
66
+ <textarea id="vb-sql-preview" rows="2" readonly></textarea>
67
+ </div>
68
+ </div>
69
+
70
+ <!-- SQL Editor Mode -->
71
+ <div id="qe-sql" class="mg-hidden">
72
+ <% if @ai_enabled %>
73
+ <div class="mg-card mg-mb">
74
+ <div class="mg-card-header">
75
+ <span class="mg-card-toggle" id="ai-toggle">&#9889; AI Assistant <span class="mg-text-muted">- Describe what you want in plain English</span></span>
76
+ </div>
77
+ <div class="mg-card-body mg-hidden" id="ai-panel">
78
+ <div class="mg-field">
79
+ <textarea id="ai-prompt" rows="2" placeholder="e.g. Show me all users created in the last 30 days"></textarea>
80
+ <div class="mg-text-muted" style="margin-top:2px;">Only table names and column names are sent to the AI. No row data leaves the system.</div>
81
+ </div>
82
+ <button id="ai-suggest" class="mg-btn mg-btn-primary mg-btn-sm mg-mb">&#9889; Suggest Query</button>
83
+ <div id="ai-result" class="mg-hidden">
84
+ <div id="ai-explanation" class="mg-alert mg-alert-info"></div>
85
+ </div>
86
+ </div>
87
+ </div>
88
+ <% end %>
89
+
90
+ <div class="mg-field">
91
+ <label for="sql-input">SQL Query</label>
92
+ <textarea id="sql-input" rows="5" placeholder="SELECT * FROM users LIMIT 10"></textarea>
93
+ </div>
94
+ <div class="mg-row">
95
+ <div class="mg-col-2 mg-field">
96
+ <label for="sql-row-limit">Row Limit</label>
97
+ <input type="number" id="sql-row-limit" value="25" min="1" max="<%= MysqlGenius.configuration.max_row_limit %>">
98
+ </div>
99
+ <div class="mg-field">
100
+ <label>&nbsp;</label>
101
+ <button id="sql-run" class="mg-btn mg-btn-primary">&#9654; Run Query</button>
102
+ <button id="sql-explain" class="mg-btn mg-btn-outline">&#128270; Explain</button>
103
+ <% if @ai_enabled %>
104
+ <button id="sql-describe" class="mg-btn mg-btn-outline mg-btn-sm" style="margin-left:8px;">&#9889; Describe</button>
105
+ <button id="sql-rewrite" class="mg-btn mg-btn-outline mg-btn-sm">&#9889; Rewrite</button>
106
+ <% end %>
107
+ </div>
108
+ </div>
109
+ </div>
110
+ </div>
@@ -0,0 +1,26 @@
1
+ <!-- Query Stats Tab -->
2
+ <div class="mg-tab-content" id="tab-qstats">
3
+ <div class="mg-row" style="justify-content:space-between;align-items:center;margin-bottom:12px;">
4
+ <div class="mg-text-muted">Top queries from <code>performance_schema.events_statements_summary_by_digest</code>. <span id="qstats-count" class="mg-badge mg-badge-secondary"></span></div>
5
+ </div>
6
+ <div id="qstats-loading" class="mg-text-center mg-hidden"><span class="mg-spinner"></span> Loading...</div>
7
+ <div id="qstats-error" class="mg-hidden"></div>
8
+ <div id="qstats-empty" class="mg-text-center mg-text-muted mg-hidden">No query statistics available.</div>
9
+ <div id="qstats-table-wrapper" class="mg-table-wrap mg-hidden">
10
+ <table class="mg-table">
11
+ <thead>
12
+ <tr>
13
+ <th>Query</th>
14
+ <th style="text-align:right">Calls</th>
15
+ <th style="text-align:right">Total Time</th>
16
+ <th style="text-align:right">Avg Time</th>
17
+ <th style="text-align:right">Max Time</th>
18
+ <th style="text-align:right">Rows Examined</th>
19
+ <th style="text-align:right">Rows Sent</th>
20
+ <th style="text-align:right">Exam/Sent</th>
21
+ </tr>
22
+ </thead>
23
+ <tbody id="qstats-tbody"></tbody>
24
+ </table>
25
+ </div>
26
+ </div>
@@ -0,0 +1,54 @@
1
+ <!-- Server Tab -->
2
+ <div class="mg-tab-content" id="tab-server">
3
+ <div class="mg-row" style="justify-content:flex-end;margin-bottom:12px;">
4
+ <% if @ai_enabled %>
5
+ <button id="server-root-cause" class="mg-btn mg-btn-primary mg-btn-sm">&#9889; Why is it slow?</button>
6
+ <button id="server-anomaly" class="mg-btn mg-btn-outline mg-btn-sm">&#9889; Anomaly Detection</button>
7
+ <% end %>
8
+ <button id="server-refresh" class="mg-btn mg-btn-outline-secondary mg-btn-sm">&#8635; Refresh</button>
9
+ </div>
10
+ <div id="server-loading" class="mg-text-center mg-hidden"><span class="mg-spinner"></span> Loading...</div>
11
+ <div id="server-error" class="mg-hidden"></div>
12
+ <div id="server-content" class="mg-hidden">
13
+ <!-- Server Info -->
14
+ <div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:12px;margin-bottom:16px;">
15
+ <div class="mg-card">
16
+ <div class="mg-card-header"><strong>Server</strong></div>
17
+ <div class="mg-card-body">
18
+ <div class="mg-stat-grid" id="server-info"></div>
19
+ </div>
20
+ </div>
21
+ <div class="mg-card">
22
+ <div class="mg-card-header"><strong>Connections</strong></div>
23
+ <div class="mg-card-body">
24
+ <div id="conn-bar" style="margin-bottom:8px;"></div>
25
+ <div class="mg-stat-grid" id="conn-info"></div>
26
+ </div>
27
+ </div>
28
+ <div class="mg-card">
29
+ <div class="mg-card-header"><strong>InnoDB Buffer Pool</strong></div>
30
+ <div class="mg-card-body">
31
+ <div id="innodb-bar" style="margin-bottom:8px;"></div>
32
+ <div class="mg-stat-grid" id="innodb-info"></div>
33
+ </div>
34
+ </div>
35
+ <div class="mg-card">
36
+ <div class="mg-card-header"><strong>Query Activity</strong></div>
37
+ <div class="mg-card-body">
38
+ <div class="mg-stat-grid" id="query-info"></div>
39
+ </div>
40
+ </div>
41
+ </div>
42
+ <div id="server-ai-result" class="mg-mt mg-hidden">
43
+ <div class="mg-card">
44
+ <div class="mg-card-header">
45
+ <span id="server-ai-title"><strong>&#9889; AI Analysis</strong></span>
46
+ <button id="server-ai-close" class="mg-btn mg-btn-outline-secondary mg-btn-sm">&#10005;</button>
47
+ </div>
48
+ <div class="mg-card-body">
49
+ <div id="server-ai-content" style="font-size:13px;"></div>
50
+ </div>
51
+ </div>
52
+ </div>
53
+ </div>
54
+ </div>
@@ -0,0 +1,17 @@
1
+ <!-- Slow Queries Tab -->
2
+ <div class="mg-tab-content" id="tab-slow">
3
+ <div class="mg-row" style="justify-content:space-between;align-items:center;margin-bottom:12px;">
4
+ <div class="mg-text-muted">SELECT queries exceeding <%= MysqlGenius.configuration.slow_query_threshold_ms %>ms. <span id="slow-count" class="mg-badge mg-badge-secondary"></span></div>
5
+ <button id="slow-refresh" class="mg-btn mg-btn-outline-secondary mg-btn-sm">&#8635; Refresh</button>
6
+ </div>
7
+ <div id="slow-loading" class="mg-text-center mg-hidden"><span class="mg-spinner"></span> Loading...</div>
8
+ <div id="slow-empty" class="mg-text-center mg-text-muted mg-hidden">No slow queries recorded.</div>
9
+ <div id="slow-table-wrapper" class="mg-table-wrap mg-hidden">
10
+ <table class="mg-table">
11
+ <thead>
12
+ <tr><th style="width:100px">Duration</th><th style="width:160px">Time</th><th>SQL</th><th style="width:150px">Actions</th></tr>
13
+ </thead>
14
+ <tbody id="slow-tbody"></tbody>
15
+ </table>
16
+ </div>
17
+ </div>
@@ -0,0 +1,33 @@
1
+ <!-- Tables Tab -->
2
+ <div class="mg-tab-content" id="tab-tables">
3
+ <div class="mg-row" style="justify-content:space-between;align-items:center;margin-bottom:12px;">
4
+ <div class="mg-text-muted">Table details from <code>information_schema</code>, sorted by total size. <span id="sizes-total" class="mg-badge mg-badge-secondary"></span></div>
5
+ <button id="sizes-refresh" class="mg-btn mg-btn-outline-secondary mg-btn-sm">&#8635; Refresh</button>
6
+ </div>
7
+ <div id="sizes-loading" class="mg-text-center mg-hidden"><span class="mg-spinner"></span> Loading...</div>
8
+ <div id="sizes-chart-wrapper" class="mg-hidden" style="margin-bottom:16px;">
9
+ <div style="display:flex;align-items:center;gap:24px;flex-wrap:wrap;">
10
+ <canvas id="sizes-pie" width="280" height="280" style="flex-shrink:0;"></canvas>
11
+ <div id="sizes-legend" style="font-size:12px;line-height:1.8;"></div>
12
+ </div>
13
+ </div>
14
+ <div id="sizes-table-wrapper" class="mg-table-wrap mg-hidden">
15
+ <table class="mg-table">
16
+ <thead>
17
+ <tr>
18
+ <th>Table</th>
19
+ <th style="text-align:right">Rows</th>
20
+ <th>Engine</th>
21
+ <th style="text-align:right">Data</th>
22
+ <th style="text-align:right">Indexes</th>
23
+ <th style="text-align:right">Total</th>
24
+ <th style="text-align:right">Fragmented</th>
25
+ <th>Updated</th>
26
+ <th style="width:200px" data-no-sort></th>
27
+ </tr>
28
+ </thead>
29
+ <tbody id="sizes-tbody"></tbody>
30
+ </table>
31
+ </div>
32
+
33
+ </div>
@@ -0,0 +1,36 @@
1
+ <!-- Unused Indexes Tab -->
2
+ <div class="mg-tab-content" id="tab-unused">
3
+ <div class="mg-row" style="justify-content:space-between;align-items:center;margin-bottom:12px;">
4
+ <div class="mg-text-muted">Indexes with zero reads since last server restart, from <code>performance_schema</code>. <span id="unused-count" class="mg-badge mg-badge-secondary"></span></div>
5
+ <button id="unused-refresh" class="mg-btn mg-btn-outline-secondary mg-btn-sm">&#8635; Refresh</button>
6
+ </div>
7
+ <div id="unused-loading" class="mg-text-center mg-hidden"><span class="mg-spinner"></span> Scanning...</div>
8
+ <div id="unused-error" class="mg-hidden"></div>
9
+ <div id="unused-empty" class="mg-text-center mg-text-muted mg-hidden">No unused indexes found.</div>
10
+ <div id="unused-table-wrapper" class="mg-table-wrap mg-hidden">
11
+ <table class="mg-table">
12
+ <thead>
13
+ <tr>
14
+ <th>Table</th>
15
+ <th>Index</th>
16
+ <th style="text-align:right">Reads</th>
17
+ <th style="text-align:right">Writes</th>
18
+ <th style="text-align:right">Table Rows</th>
19
+ <th>DROP Statement</th>
20
+ </tr>
21
+ </thead>
22
+ <tbody id="unused-tbody"></tbody>
23
+ </table>
24
+ </div>
25
+ <div id="unused-migration" class="mg-hidden" style="margin-top:16px;">
26
+ <div class="mg-card">
27
+ <div class="mg-card-header" style="display:flex;justify-content:space-between;align-items:center;">
28
+ <strong>Suggested Migration</strong>
29
+ <button id="unused-copy-migration" class="mg-btn mg-btn-outline-secondary mg-btn-sm">&#128203; Copy</button>
30
+ </div>
31
+ <div class="mg-card-body">
32
+ <pre id="unused-migration-code" style="font-size:12px;margin:0;white-space:pre-wrap;user-select:all;"></pre>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ </div>