PostgreSQL Source Code interpretation (37)-query statement # 22 (query Optimization-grouping_plan...
After the main function subquery_planner completes the outer join elimination, the grouping_planner function is then called, and this section briefly introduces the body logic of this function.
I. Source code interpretation
Grouping_planner function source code:
/ *-* grouping_planner * Perform planning steps related to grouping, aggregation, etc. * * generate the "planning steps" * * This function adds all required top-level processing to the scan/join * Path (s) produced by query_planner related to grouping / aggregation. * * this function also handles all scan / connection paths that need to be processed at the top level (generated by the query_planner function) * * If inheritance_update is true, we're being called from inheritance_planner * and should not include a ModifyTable step in the resulting Path (s). * (inheritance_planner will create a single ModifyTable node covering all the * target tables.) * * if the flag inheritance_update is true, the caller of this function is inheritance_planner, and the ModifyTable step should not be included in the result path (inheritance_planner creates a separate ModifyTable node that covers all target tables). * * tuple_fraction is the fraction of tuples we expect will be retrieved. * tuple_fraction is interpreted as follows: * 0: expect all tuples to be retrieved (normal case) * 0
< tuple_fraction < 1: expect the given fraction of tuples available * from the plan to be retrieved * tuple_fraction >