tdfs4ds.agent.qopt_report¶
tdfs4ds.agent.qopt_report
¶
Query optimizer report: the result of skill_optimize_query as a shareable file, and the optional
measured comparison of the current and the optimized SELECT.
Pure functions for the report (no database, no language model, no JavaScript in the HTML);
write_qopt_report and run_measurement are the only I/O. The HTML reuses the impact report's page
CSS, SQL side-by-side panes and measured-comparison tables, so both reports read alike.
Public: :func:build_qopt_report_data, :func:render_qopt_report, :func:write_qopt_report,
:func:run_measurement, :func:candidate_of.
__all__
module-attribute
¶
__all__ = ['build_qopt_report_data', 'render_qopt_report', 'write_qopt_report', 'run_measurement', 'candidate_of', 'measure_verdict']
_STEP_KINDS
module-attribute
¶
_STEP_KINDS = ('strategy_generation_failure', 'strategy_invariant_violation', 'strategy_near_duplicate')
_STEP_LABELS
module-attribute
¶
_STEP_LABELS = {'strategy_generation_failure': 'no candidate generated', 'strategy_invariant_violation': 'rejected: the rewrite lost business logic', 'strategy_near_duplicate': 'rejected: same as an earlier candidate'}
_MEASURE_NOTE
module-attribute
¶
_MEASURE_NOTE = 'Both SELECTs computed in full into volatile tables of one session, compared on the entity key, then dropped. Nothing was stored.'
html_note
¶
The long note as an escaped, self-styled HTML block (works in light and dark pages).
_body
¶
The query of a view text: no REPLACE VIEW header, no wrapping, no trailing semicolon.
candidate_of
¶
The proposed SELECT of a result when the run found a better rewrite, else ''.
measure_verdict
¶
One short phrase for a confirm line: 'same rows', 'N rows differ', 'not compared'.
_notes
¶
A key kept by the simplification (top level of the result, else one of its steps).
build_qopt_report_data
¶
A plain, JSON-able dict from a skill_optimize_query result (and a measured comparison, if any).
render_qopt_report
¶
The report text from :func:build_qopt_report_data: fmt 'html' (standalone page, no script) or 'md'.
write_qopt_report
¶
Render and write the report; returns the absolute path. Without out_path the file goes under
tdfs4ds.QUERY_OPTIMIZER_REPORT_DIR / data domain, named tdfs4ds_optim_<view>_<pid>.<ext>.
run_measurement
¶
run_measurement(result: dict, *, force: bool = False, progress=None, cancel_event=None, wait_resources: bool = False, wait_minutes: float = 15.0, conn=None) -> dict
Measure the optimized SELECT of result against the current one with tdfs4ds.impact_measure.measure
(the impact study's measurement, unchanged: same gate, two volatile tables in the job's own session,
both computed in full). Returns the measure dict. Raises ValueError when there is nothing to
measure (no candidate, no entity key). With wait_resources it then waits for DBQL (query-banded
session) to add CPU, I/O and spool; cancelling stops the wait only.