当前位置 :首页 >> 网红

openGaussAPI分析(六)执行计划生成

2023-05-01   来源 : 网红

n_queries->pg_plan_query->planner算子命令行。standard_planner将Query(查看树根)聚合规划设计好的语义,可用作分派器具体分派。

PlannedStmt* standard_planner(Query* parse, int cursorOptions, ParamListInfo boundParams)

{

PlannedStmt* result = NULL;//调回结果

PlannerGlobal* glob = NULL;

double tuple_fraction;

PlannerInfo* root = NULL;

Plan* top_plan = NULL;

glob = makeNode(PlannerGlobal);

/* primary planning entry point (may recurse for subqueries) */

top_plan = subquery_planner(glob, parse, NULL, false, tuple_fraction, &root); //;大规划设计过程大门

/* build the PlannedStmt result */

result = makeNode(PlannedStmt);//构造PlannedStmt

result->commandType = parse->commandType;

result->queryId = parse->queryId;

result->uniqueSQLId = parse->uniqueSQLId;

result->hasReturning = (parse->returningList != NIL);

result->hasModifyingCTE = parse->hasModifyingCTE;

result->canSetTag = parse->canSetTag;

result->transientPlan = glob->transientPlan;

result->dependsOnRole = glob->dependsOnRole;

result->planTree = top_plan;//分派计划书

result->rtable = glob->finalrtable;

result->resultRelations = glob->resultRelations;

return result;

}

仍然那时候文的join列子来所述

SELECT * FROM t1 inner JOIN t2 ON t1.c1 = t2.c1;

在planner算子分心点,用gdb查看standard_planner调回的PlannedStmt

(gdb) bt

#0 planner (parse=0x7fd93a410288, cursorOptions=0, boundParams=0x0) at planner.cpp:389

#1 0x0000000001936fbd in pg_plan_query (querytree=0x7fd93a410288, cursorOptions=0, boundParams=0x0, underExplain=false) at postgres.cpp:1197

#2 0x0000000001937381 in pg_plan_queries (querytrees=0x7fd939b81090, cursorOptions=0, boundParams=0x0) at postgres.cpp:1315

#3 0x000000000193a6b8 in exec_simple_query (query_string=0x7fd966ad2060 "SELECT * FROM t1 inner JOIN t2 ON t1.c1 = t2.c1;", messageType=QUERY_MESSAGE, msg=0x7fd931056210)

at postgres.cpp:2560

#4 0x0000000001947104 in PostgresMain (argc=1, argv=0x7fd93a2cf1c0, dbname=0x7fd93a2ce1f8 "postgres", username=0x7fd93a2ce1b0 "test") at postgres.cpp:8403

#5 0x0000000001890740 in BackendRun (port=0x7fd931056720) at postmaster.cpp:8053

#6 0x00000000018a00b1 in GaussDbThreadMain (arg=0x7fd97c55c5f0) at postmaster.cpp:12181

#7 0x000000000189c0de in InternalThreadFunc (args=0x7fd97c55c5f0) at postmaster.cpp:12755

#8 0x00000000024bf7d8 in ThreadStarterFunc (arg=0x7fd97c55c5e0) at gs_thread.cpp:382

#9 0x00007fd9a60cfdd5 in start_thread () from /lib64/libpthread.so.0

#10 0x00007fd9a5df8ead in clone () from /lib64/libc.so.6

(gdb) p *result

$14 = {type = T_PlannedStmt, commandType = CMD_SELECT, queryId = 0, hasReturning = false, hasModifyingCTE = false, canSetTag = true, transientPlan = false, dependsOnRole = false,

planTree = 0x7fd93a409d58, rtable = 0x7fd939b81660, …}

(gdb) p *result->planTree->lefttree

$46 = {type = T_SeqScan, plan_node_id = 2, parent_node_id = 1, exec_type = EXEC_ON_DATANODES, startup_cost = 0, total_cost = 1.03, plan_rows = 3, multiple = 1, plan_width = 8,…}

将Query规划设计后得到PlannedStmt

可以看着,Plannedstmt与explain分派计划书是保持一致的

南京肛肠医院专家预约挂号
成都妇科医院
关节僵硬吃什么药好
艾得辛和甲氨蝶呤一样吗
济南男科医院哪家好
“硬核”知识在较短视频平台上乘风破浪

真人版“小剧场”让人忍俊不禁;遇到缺少图像资料的历史文化英雄人物时,符合英雄人物特征的同人志跃然纸上;讲出解当中,英雄人物的卡通形像小游戏也不时登场,使得画面来得加生动活泼……亲手绘制同人志、剪辑小游...

友情链接