tdfs4ds.impact_reference¶
tdfs4ds.impact_reference
¶
The original process's execution log as the cost reference of an impact study. Read only.
An EXPLAIN estimate and a measured SELECT say little on their own: is 9 seconds a lot for this process?
The process's own history answers it. :func:read_execution_reference reads, for one process:
- its follow-up rows (
FS_V_FOLLOW_UP): the durations of its last :data:REFERENCE_RUNSCOMPLETED runs (a run groups the segments / dates of one call, :func:tdfs4ds.process_store.process_followup.execution_run_ids); - when the optional history table
FS_EXECUTION_RESOURCESholds them, the CPU seconds, I/O and largest spool of the same runs (DBQL figures harvested by :mod:tdfs4ds.utils.execution_resources).
:func:reference_from_log (pure) turns the rows into {process_id, n_runs, duration_s: {median, max, last},
cpu_s, io, spool_gb, source: follow_up | resources | none, note}.
A logged duration covers the WHOLE run: computing the view, staging, the MERGE into the feature tables,
statistics. It is a reference for the order of magnitude, never the time of the SELECT alone (see
:data:REFERENCE_NOTE).
The reference is used by the efficiency comparison (the proposed plan's estimate is stated against it,
:func:compare_with_reference), by the gate of the measured comparison (the limits grow to
:data:REFERENCE_FACTOR times the logged median when that is above the generic limits,
:func:effective_limits), and after a measurement (:func:measured_reference).
READ ONLY: the only statements sent are SELECTs, checked before they are sent. Fail-open: a failed read
gives source: 'none' with the reason, never an exception.
REFERENCE_NOTE
module-attribute
¶
REFERENCE_NOTE = 'Logged durations cover the whole run of the process (computing the view, staging, the MERGE into the feature tables, statistics): a reference for the order of magnitude, not the time of the SELECT alone.'
NO_LOG_NOTE
module-attribute
¶
NO_LOG_NOTE = 'no COMPLETED run of the process is logged: the generic limits apply (SAMPLE_MAX_SECONDS / SAMPLE_MAX_SPOOL_GB)'
NOT_A_PROCESS_NOTE
module-attribute
¶
NOT_A_PROCESS_NOTE = 'not a registered process: no execution log, the generic limits apply (SAMPLE_MAX_SECONDS / SAMPLE_MAX_SPOOL_GB)'
empty_reference
¶
A reference with nothing logged.
_completed_runs
¶
[(start, end, row_index_list)] of the last n_runs runs whose every row COMPLETED, newest first.
reference_from_log
¶
The cost reference of a process from its follow-up rows (rows: dicts or a frame with RUN_ID,
PROCESS_ID, START_DATETIME, END_DATETIME, STATUS) and, when given, its FS_EXECUTION_RESOURCES rows
(resources: the same columns plus AMP_CPU_SEC, TOTAL_IO, MAX_SPOOL_BYTES). Pure.
Only runs whose every row COMPLETED count (a run that failed part-way says nothing about the cost); the most recent n_runs are kept. Durations: one per COMPLETED follow-up row (one execution of the process: a date or a segment), newest first, in seconds.
reference_line
¶
One sentence on the logged runs, or '' when nothing is logged. Pure.
compare_with_reference
¶
compare_with_reference(reference: Optional[dict], est_seconds=None, est_spool_gb=None) -> Optional[str]
The proposed plan's estimate stated against the logged history, or None when nothing is logged. Pure.
e.g. "the original process takes about 6 s per run (median of 10 logged run(s), ...); the proposed plan is estimated at 9.3 s (1.5 times the logged median)".
effective_limits
¶
effective_limits(max_seconds: float, max_spool_gb: float, reference: Optional[dict] = None, factor: float = REFERENCE_FACTOR) -> dict
The limits of the measured comparison: max(generic, factor x logged median) for the time and the
spool. {seconds, spool_gb, note}; with no log the generic limits and a note saying so. Pure.
measured_reference
¶
{logged, measured_old_s, measured_new_s, text, note}: the measured seconds of both SELECTs beside
the logged runs. Pure.
followup_sql
¶
The follow-up rows of one process, the most recent first. Pure.
resources_sql
¶
The stored resource rows of one process (FS_EXECUTION_RESOURCES), the most recent first. Pure.
read_execution_reference
¶
The cost reference of process process_id from its execution log. Never raises for a database
error: a failed follow-up read gives source: 'none' with the reason; an unreadable
FS_EXECUTION_RESOURCES (optional table) is skipped. run_sql (default teradataml.execute_sql)
gets each SELECT and returns a cursor (description + fetchall).