Skip to content

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']

_FORMATS module-attribute

_FORMATS = ('html', 'md')

_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

html_note(kind: str = 'sanity') -> str

The long note as an escaped, self-styled HTML block (works in light and dark pages).

md_note

md_note(kind: str = 'sanity') -> str

The long note as a Markdown quote.

_t

_t(v: Any) -> str

_d

_d(v: Any) -> dict

_l

_l(v: Any) -> list

_body

_body(sql: Any) -> str

The query of a view text: no REPLACE VIEW header, no wrapping, no trailing semicolon.

candidate_of

candidate_of(result: dict) -> str

The proposed SELECT of a result when the run found a better rewrite, else ''.

measure_verdict

measure_verdict(measure: Optional[dict]) -> str

One short phrase for a confirm line: 'same rows', 'N rows differ', 'not compared'.

_strategies

_strategies(result: dict) -> List[Dict[str, str]]

_notes

_notes(result: dict, key: str) -> Any

A key kept by the simplification (top level of the result, else one of its steps).

build_qopt_report_data

build_qopt_report_data(result: dict, measure: Optional[dict] = None) -> dict

A plain, JSON-able dict from a skill_optimize_query result (and a measured comparison, if any).

_html_body

_html_body(data: dict) -> str

_html_report

_html_report(data: dict) -> str

_md_report

_md_report(data: dict) -> str

render_qopt_report

render_qopt_report(data: dict, fmt: str = 'html') -> str

The report text from :func:build_qopt_report_data: fmt 'html' (standalone page, no script) or 'md'.

_safe

_safe(name: str) -> str

write_qopt_report

write_qopt_report(data: dict, out_path: Optional[str] = None, fmt: str = 'html') -> str

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>.

_names

_names(v: Any) -> List[str]

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.