@@ -68,7 +68,6 @@ planner_hook_typepathman_planner_hook_next= NULL;
6868post_parse_analyze_hook_type pathman_post_parse_analyze_hook_next = NULL ;
6969shmem_startup_hook_type pathman_shmem_startup_hook_next = NULL ;
7070ProcessUtility_hook_type pathman_process_utility_hook_next = NULL ;
71- ExecutorRun_hook_type pathman_executor_run_hook_next = NULL ;
7271
7372
7473/* Take care of joins */
@@ -616,6 +615,29 @@ pathman_enable_assign_hook(bool newval, void *extra)
616615newval ?"enabled" :"disabled" );
617616}
618617
618+ static void
619+ execute_for_plantree (PlannedStmt * planned_stmt ,
620+ Plan * (* proc ) (List * rtable ,Plan * plan ))
621+ {
622+ List * subplans = NIL ;
623+ ListCell * lc ;
624+ Plan * resplan = proc (planned_stmt -> rtable ,planned_stmt -> planTree );
625+
626+ if (resplan )
627+ planned_stmt -> planTree = resplan ;
628+
629+ foreach (lc ,planned_stmt -> subplans )
630+ {
631+ Plan * subplan = lfirst (lc );
632+ resplan = proc (planned_stmt -> rtable , (Plan * )lfirst (lc ));
633+ if (resplan )
634+ subplans = lappend (subplans ,resplan );
635+ else
636+ subplans = lappend (subplans ,subplan );
637+ }
638+ planned_stmt -> subplans = subplans ;
639+ }
640+
619641/*
620642 * Planner hook. It disables inheritance for tables that have been partitioned
621643 * by pathman to prevent standart PostgreSQL partitioning mechanism from
@@ -624,14 +646,6 @@ pathman_enable_assign_hook(bool newval, void *extra)
624646PlannedStmt *
625647pathman_planner_hook (Query * parse ,int cursorOptions ,ParamListInfo boundParams )
626648{
627- #define ExecuteForPlanTree (planned_stmt ,proc ) \
628- do { \
629- ListCell *lc; \
630- proc((planned_stmt)->rtable, (planned_stmt)->planTree); \
631- foreach (lc, (planned_stmt)->subplans) \
632- proc((planned_stmt)->rtable, (Plan *) lfirst(lc)); \
633- } while (0)
634-
635649PlannedStmt * result ;
636650uint32 query_id = parse -> queryId ;
637651
@@ -658,10 +672,10 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
658672if (pathman_ready )
659673{
660674/* Add PartitionFilter node for INSERT queries */
661- ExecuteForPlanTree (result ,add_partition_filters );
675+ execute_for_plantree (result ,add_partition_filters );
662676
663677/* Add PartitionRouter node for UPDATE queries */
664- ExecuteForPlanTree (result ,add_partition_routers );
678+ execute_for_plantree (result ,add_partition_routers );
665679
666680/* Decrement planner() calls count */
667681decr_planner_calls_count ();
@@ -686,7 +700,6 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
686700
687701/* Finally return the Plan */
688702return result ;
689- #undef ExecuteForPlanTree
690703}
691704
692705/*
@@ -950,40 +963,3 @@ pathman_process_utility_hook(Node *first_arg,
950963context ,params ,queryEnv ,
951964dest ,completionTag );
952965}
953-
954- /*
955- * Executor hook (for PartitionRouter).
956- */
957- #if PG_VERSION_NUM >=100000
958- void
959- pathman_executor_hook (QueryDesc * queryDesc ,
960- ScanDirection direction ,
961- ExecutorRun_CountArgType count ,
962- bool execute_once )
963- #else
964- void
965- pathman_executor_hook (QueryDesc * queryDesc ,
966- ScanDirection direction ,
967- ExecutorRun_CountArgType count )
968- #endif
969- {
970- #define EXECUTOR_HOOK pathman_executor_run_hook_next
971- #if PG_VERSION_NUM >=100000
972- #define EXECUTOR_HOOK_NEXT (q ,d ,c )EXECUTOR_HOOK((q),(d),(c), execute_once)
973- #define EXECUTOR_RUN (q ,d ,c )standard_ExecutorRun((q),(d),(c), execute_once)
974- #else
975- #define EXECUTOR_HOOK_NEXT (q ,d ,c )EXECUTOR_HOOK((q),(d),(c))
976- #define EXECUTOR_RUN (q ,d ,c )standard_ExecutorRun((q),(d),(c))
977- #endif
978-
979- /* Prepare ModifyTable nodes for PartitionRouter hackery */
980- state_tree_visitor ((PlanState * )queryDesc -> planstate ,
981- prepare_modify_table_for_partition_router ,
982- NULL );
983-
984- /* Call hooks set by other extensions if needed */
985- if (EXECUTOR_HOOK )
986- EXECUTOR_HOOK_NEXT (queryDesc ,direction ,count );
987- /* Else call internal implementation */
988- else EXECUTOR_RUN (queryDesc ,direction ,count );
989- }