MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / explain

Function explain

misc/python/materialize/mzexplore/extract.py:453–482  ·  view source on GitHub ↗
(
    db: sql.Database,
    explain_stage: ExplainStage,
    explainee: str,
    explain_options: list[ExplainOption],
    explain_format: ExplainFormat,
)

Source from the content-addressed store, hash-verified

451
452
453def explain(
454 db: sql.Database,
455 explain_stage: ExplainStage,
456 explainee: str,
457 explain_options: list[ExplainOption],
458 explain_format: ExplainFormat,
459) -> str:
460 explain_query = "\n".join(
461 line
462 for line in [
463 f"EXPLAIN {explain_stage}",
464 f"WITH({', '.join(map(str, explain_options))})" if explain_options else "",
465 f"AS {explain_format} FOR",
466 explainee,
467 ]
468 if line != ""
469 )
470 if explain_stage == ExplainStage.OPTIMIZER_TRACE:
471 return json.dumps(
472 {
473 "explainee": {"query": explainee},
474 "list": [
475 {"id": id, **entry}
476 for (id, entry) in enumerate(db.query_all(explain_query))
477 ],
478 },
479 indent=4,
480 )
481 else:
482 return next(iter(db.query_one(explain_query).values()))
483
484
485def explain_item(item_type: ItemType, fqname: str, replan: bool) -> str | None:

Callers 6

explain_dataflowFunction · 0.85
collect_allMethod · 0.85
create_targetFunction · 0.85
build_index_sqlFunction · 0.85
build_view_sqlFunction · 0.85
plansFunction · 0.85

Calls 5

iterFunction · 0.85
joinMethod · 0.45
query_allMethod · 0.45
valuesMethod · 0.45
query_oneMethod · 0.45

Tested by

no test coverage detected