Skip to content

refactor: de-normalize per-query method classification to a varchar column - #48

Merged
TheWitness merged 4 commits into
mainfrom
refactor/denormalize-methods
Oct 1, 2026
Merged

TheWitness merged 4 commits into
mainfrom
refactor/denormalize-methods

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

Follow-up to #47 (the import memory fix). Addresses the over-normalization you flagged: plugin_slowlog_details_methods stored a methodid foreign key into the plugin_slowlog_methods dictionary, so every read path (stats cache build, By Method chart, details list, method filter dropdown, chart-scope list) had to JOIN the dictionary, and import had to look method ids up.

Changes

  • Schema: plugin_slowlog_details_methods.methodid (int FK) → method varchar(45), stored directly. Primary key is now (logid, logentry, method).
  • Classification: the method→fragment dictionary moved from the plugin_slowlog_methods table into a PHP constant, SLOWLOG_METHOD_FRAGMENTS; import_post_process() and the OTHER TABLES / OTHERS bucketing write the method name directly.
  • Reads de-joined: slowlog_collect_stats_by_method(), slowlog_get_chart_object_live() (By Method), the details-list query in slowlog.php, the method filter dropdown, and slowlog_get_chart_scope_items() all now read plugin_slowlog_details_methods.method directly — no plugin_slowlog_methods join.
  • Dictionary tables left in place but unused: plugin_slowlog_methods and plugin_slowlog_tables are still created (so upgrades don't error); per your note, a clean install drops them.
  • Stats cache kept (plugin_slowlog_stats) — unchanged; it's already memory-safe (bounded reservoir + exact count/sum).

Tests

  • ImportPostProcessMethodsTest / OtherTablesClassificationTest updated to assert method names instead of ids, and the removed methodid-lookup guard's test was dropped.
  • ComputeStatsTest, SetupTableApiUsageTest, TableModeDispatchTest, PreparedStatementUsageTest pass unchanged.

php -l clean on all changed files. No version bump; CHANGELOG updated under 2.6.

Note: this branches off main (independent of #47); they touch different functions and merge cleanly.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 19:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Existing installations lack the migration needed by the new method-column inserts and queries.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Simplifies slowlog method classification by storing method names directly, complementing #47’s separate import-memory fix.

Changes:

  • Replaces method IDs with names and moves classifier fragments into PHP constants.
  • Removes method-dictionary joins from statistics, charts, and detail queries.
  • Updates classification tests and the changelog.
File Description
tests/​Unit/​OtherTablesClassificationTest.php Asserts named classification buckets.
tests/​Integration/​ImportPostProcessMethodsTest.php Verifies method-name inserts and classifications.
slowlog.php Filters and displays methods by name.
includes/​slowlog_functions.php Uses method constants and simplifies read queries.
includes/​database.php Changes the association table’s create-time schema.
CHANGELOG.md Documents the de-normalization.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread includes/database.php
plugin_slowlog_details_methods stored a methodid FK into the plugin_slowlog_methods dictionary, forcing a join on every stats/chart/details/scope read path and a dictionary lookup during import. Store the method name directly in a new method varchar column, drive classification from a PHP constant (SLOWLOG_METHOD_FRAGMENTS), and drop the plugin_slowlog_methods joins. The dictionary tables are left created-but-unused (a clean install drops them). Tests updated to assert method names; plugin_slowlog_stats cache is unchanged.
…ant details-list DISTINCT

plugin_slowlog_tables was written on import and cleared on remove/reprocess but never read - everything uses plugin_slowlog_details_tables - so remove its CREATE and all DML (the uninstall drop stays to clean up existing installs). Separately, the details list used SELECT DISTINCT sld.*; the association tables' composite PKs already make every join row unique, so the DISTINCT never removed a row and only forced a filesort/hash over the mediumtext query columns - dropped it.
@TheWitness
TheWitness force-pushed the refactor/denormalize-methods branch from c1e4842 to 6ccbad5 Compare October 1, 2026 22:00
@TheWitness
TheWitness merged commit a80fbcf into main Oct 1, 2026
5 checks passed
@TheWitness
TheWitness deleted the refactor/denormalize-methods branch October 1, 2026 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants