def METHOD_NAME(
    query_asts_pickled: bytes,
    data: list[list[bytes]],
    std_schema: s_schema.FlatSchema,
) -> bytes:
    if debug.flags.edgeql_explain:
        debug.header('Explain')
    ql: qlast.Base
    ir: irast.Statement
    pg: pgast.Base
    ql, ir, pg, explain_data = pickle.loads(query_asts_pickled)
    config_vals, args, modaliases = explain_data
    args = Arguments(**args)
    schema = ir.schema
    # We omit the std schema when serializing, so put it back
    if isinstance(schema, s_schema.ChainedSchema):
        schema = s_schema.ChainedSchema(
            top_schema=schema._top_schema,
            global_schema=schema._global_schema,
            base_schema=std_schema
        )
    assert len(data) == 1 and len(data[0]) == 1
    plan = json.loads(data[0][0])
    assert len(plan) == 1
    plan = debug_tree = plan[0]['Plan']
    info = None
    fg_tree = None
    cg_tree = None
    try:
        ctx = AnalyzeContext(
            schema=schema,
            modaliases=modaliases,
            # This has last alias wins strategy. Do we need reverse?
            reverse_mod_aliases={v: k for k, v in modaliases.items()},
        )
        info = ir_analyze.analyze_queries(ql, ir, pg, ctx)
        debug_tree = pg_tree.Plan.from_json(plan, ctx)
        fg_tree, index = fine_grained.build(debug_tree, info, args)
        if debug.flags.edgeql_explain:
            debug.dump(fg_tree)
            debug.dump(info)
        cg_tree = coarse_grained.build(fg_tree, info, index)
    except Exception as e:
        log.exception("Error building explain model", exc_info=e)
    config_vals = {
        k: v for k, v in config_vals.items() if k not in OMITTED_CONFIG_VALS
    }
    globals_used = sorted([str(k) for k in ir.globals])
    if info:
        buffers = info.buffers
    elif ql.context:
        buffers = [ql.context.buffer]
    else:
        buffers = []  # should never happen
    output = {
        'config_vals': config_vals,
        'globals_used': globals_used,
        'module_aliases': dict(modaliases),
        'arguments': args,
        'version': buildmeta.get_version_string(),
        'buffers': buffers,
        'debug_info': {
            'full_plan': debug_tree,
            'analysis_info': info,
        },
        'fine_grained': fg_tree,
        'coarse_grained': cg_tree,
    }
    return json.dumps(output, default=to_json.json_hook).encode('utf-8')