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

Function plan_explain_analyze_object

src/sql/src/plan/statement/dml.rs:879–1115  ·  view source on GitHub ↗
(
    scx: &StatementContext,
    statement: ExplainAnalyzeObjectStatement<Aug>,
    params: &Params,
)

Source from the content-addressed store, hash-verified

877}
878
879pub fn plan_explain_analyze_object(
880 scx: &StatementContext,
881 statement: ExplainAnalyzeObjectStatement<Aug>,
882 params: &Params,
883) -> Result<Plan, PlanError> {
884 let explainee_name = statement
885 .explainee
886 .name()
887 .ok_or_else(|| sql_err!("EXPLAIN ANALYZE on anonymous dataflows",))?
888 .full_name_str();
889 let explainee = plan_explainee(scx, statement.explainee, params)?;
890
891 let check_ownership = |item_id: &CatalogItemId, item_type: &str| -> Result<(), PlanError> {
892 if scx.catalog.restrict_to_user_objects() {
893 let item = scx.catalog.get_item(item_id);
894 if item.owner_id() != *scx.catalog.active_role_id() {
895 let full_name = scx.catalog.resolve_full_name(item.name());
896 return Err(sql_err!("must be owner of {item_type} {full_name}"));
897 }
898 }
899 Ok(())
900 };
901 match &explainee {
902 plan::Explainee::Index(item_id) => check_ownership(item_id, "INDEX")?,
903 plan::Explainee::MaterializedView(item_id) => {
904 check_ownership(item_id, "MATERIALIZED VIEW")?
905 }
906 _ => return Err(sql_err!("EXPLAIN ANALYZE queries for this explainee type",)),
907 };
908
909 // generate SQL query
910
911 /* WITH {CTEs}
912 SELECT REPEAT(' ', nesting * 2) || operator AS operator
913 {columns}
914 FROM mz_introspection.mz_lir_mapping mlm
915 JOIN {from} USING (lir_id)
916 JOIN mz_introspection.mz_mappable_objects mo
917 ON (mlm.global_id = mo.global_id)
918 WHERE mo.name = {escaped explainee_name}
919 AND {predicates}
920 ORDER BY lir_id DESC
921 */
922 let mut ctes = Vec::with_capacity(4); // max 2 per ExplainAnalyzeComputationProperty
923 let mut columns = vec!["REPEAT(' ', nesting * 2) || operator AS operator"];
924 let mut from = vec!["mz_introspection.mz_lir_mapping mlm"];
925 let mut predicates = vec![format!(
926 "mo.name = {}",
927 escaped_string_literal(&explainee_name)
928 )];
929 let mut order_by = vec!["mlm.lir_id DESC"];
930
931 match statement.properties {
932 ExplainAnalyzeProperty::Computation(ExplainAnalyzeComputationProperties {
933 properties,
934 skew,
935 }) => {
936 let mut worker_id = None;

Callers 1

planFunction · 0.85

Calls 15

plan_explaineeFunction · 0.85
SelectClass · 0.85
full_name_strMethod · 0.80
record_sql_impl_idsMethod · 0.80
planMethod · 0.80
separatedFunction · 0.50
nameMethod · 0.45
get_itemMethod · 0.45
owner_idMethod · 0.45
active_role_idMethod · 0.45
resolve_full_nameMethod · 0.45

Tested by

no test coverage detected