Skip site navigation (1) Skip section navigation (2)

Re: Optimizer hook

From: Julius Stroffek <Julius(dot)Stroffek(at)Sun(dot)COM>
To: pgsql-patches(at)postgresql(dot)org
Subject: Re: Optimizer hook
Date: 2007-08-24 23:50:46
Message-ID: 46CF6ED6.4020101@sun.com (view raw or flat)
Thread:
Lists: pgsql-patches
I rewrote a patch a bit.

I made function make_one_rel_by_joins also non-static,
so that the optimizer in plugin can reuse the dynamic
optimizer.

I also reorganized the code and put all the changes
to paths.h and allpaths.c files only. It seems to me more
appropriate that the hook should belong to this place only.

Thanks

Julo

Julius Stroffek wrote:
> Attached is the patch for the optimizer hook as discussed in
> http://archives.postgresql.org/pgsql-hackers/2007-08/msg00362.php
>
> The hook declaration and definition to the same places as the planner_hook
> is located since the optimizer_hook relates to the part of the planner and
> I find it good to have the planner related hooks on one place.
>
> The optimizer_hook is called in make_one_rel and the plugin replaces
> the function 'make_rel_from_joinlist'. I have created a macro
> standard_optimizer just for better readability of the code in plugins
> and I did not want to change function names.
>
> I also tried to dig out the dynamic programming optimizer and to compile
> it and use it as a plugin just to be sure that all the functions necessary
> to write the optimizer as a plugin are non-static. I placed all the code
> in joinrels.c, make_one_rel_by_joins and make_rel_from_joinlist functions.
> Of cause, I renamed all non-static symbols.
>
> Sure, I ran 'make check' without failures.
>
> Is there anything else I should take care? Thanks.
>
> Regards
>
> Julo Stroffek
>
> ------------------------------------------------------------------------
>
> *** ./src/backend/optimizer/path/allpaths.c.orig	Sat May 26 20:23:01 2007
> --- ./src/backend/optimizer/path/allpaths.c	Tue Aug 14 17:26:39 2007
> ***************
> *** 52,58 ****
>   					  RangeTblEntry *rte);
>   static void set_values_pathlist(PlannerInfo *root, RelOptInfo *rel,
>   					RangeTblEntry *rte);
> ! static RelOptInfo *make_rel_from_joinlist(PlannerInfo *root, List *joinlist);
>   static RelOptInfo *make_one_rel_by_joins(PlannerInfo *root, int levels_needed,
>   					  List *initial_rels);
>   static bool subquery_is_pushdown_safe(Query *subquery, Query *topquery,
> --- 52,58 ----
>   					  RangeTblEntry *rte);
>   static void set_values_pathlist(PlannerInfo *root, RelOptInfo *rel,
>   					RangeTblEntry *rte);
> ! RelOptInfo *make_rel_from_joinlist(PlannerInfo *root, List *joinlist);
>   static RelOptInfo *make_one_rel_by_joins(PlannerInfo *root, int levels_needed,
>   					  List *initial_rels);
>   static bool subquery_is_pushdown_safe(Query *subquery, Query *topquery,
> ***************
> *** 87,93 ****
>   	/*
>   	 * Generate access paths for the entire join tree.
>   	 */
> ! 	rel = make_rel_from_joinlist(root, joinlist);
>   
>   	/*
>   	 * The result should join all and only the query's base rels.
> --- 87,96 ----
>   	/*
>   	 * Generate access paths for the entire join tree.
>   	 */
> ! 	if (optimizer_hook)
> ! 		rel = optimizer_hook(root, joinlist);
> ! 	else
> ! 		rel = make_rel_from_joinlist(root, joinlist);
>   
>   	/*
>   	 * The result should join all and only the query's base rels.
> ***************
> *** 612,618 ****
>    * See comments for deconstruct_jointree() for definition of the joinlist
>    * data structure.
>    */
> ! static RelOptInfo *
>   make_rel_from_joinlist(PlannerInfo *root, List *joinlist)
>   {
>   	int			levels_needed;
> --- 615,621 ----
>    * See comments for deconstruct_jointree() for definition of the joinlist
>    * data structure.
>    */
> ! RelOptInfo *
>   make_rel_from_joinlist(PlannerInfo *root, List *joinlist)
>   {
>   	int			levels_needed;
> *** ./src/backend/optimizer/plan/planner.c.orig	Sat May 26 20:23:01 2007
> --- ./src/backend/optimizer/plan/planner.c	Wed Aug 15 15:31:21 2007
> ***************
> *** 45,50 ****
> --- 45,52 ----
>   /* Hook for plugins to get control in planner() */
>   planner_hook_type planner_hook = NULL;
>   
> + /* Hook for plugins to get control in make_one_rel() */
> + optimizer_hook_type optimizer_hook = NULL;
>   
>   /* Expression kind codes for preprocess_expression */
>   #define EXPRKIND_QUAL		0
> *** ./src/include/optimizer/planner.h.orig	Wed Jul 25 14:22:53 2007
> --- ./src/include/optimizer/planner.h	Wed Aug 15 11:17:00 2007
> ***************
> *** 17,22 ****
> --- 17,24 ----
>   #include "nodes/plannodes.h"
>   #include "nodes/relation.h"
>   
> + /* A macro pointing to the standard optimizer function. */
> + #define standard_optimizer make_rel_from_joinlist
>   
>   /* Hook for plugins to get control in planner() */
>   typedef PlannedStmt * (*planner_hook_type) (Query *parse,
> ***************
> *** 24,29 ****
> --- 26,35 ----
>   											ParamListInfo boundParams);
>   extern PGDLLIMPORT planner_hook_type planner_hook;
>   
> + /* Hook for plugins to get control in make_one_rel() */
> + typedef RelOptInfo * (*optimizer_hook_type) (PlannerInfo * root,
> + 											 List * joinlist);
> + extern PGDLLIMPORT optimizer_hook_type optimizer_hook;
>   
>   extern PlannedStmt *planner(Query *parse, int cursorOptions,
>   		ParamListInfo boundParams);
>
>   
> ------------------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>                http://archives.postgresql.org
>   

Attachment: optimizer_hookV2.patch
Description: text/x-patch (3.8 KB)

In response to

Responses

pgsql-patches by date

Next:From: Tom LaneDate: 2007-08-25 00:05:43
Subject: Re: Bunch of tsearch fixes and cleanup
Previous:From: Tom LaneDate: 2007-08-24 15:36:31
Subject: Re: Bunch of tsearch fixes and cleanup

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group