*** ./src/backend/optimizer/path/allpaths.c.orig	Sat May 26 20:23:01 2007
--- ./src/backend/optimizer/path/allpaths.c	Thu Aug 23 15:29:28 2007
***************
*** 37,43 ****
--- 37,45 ----
  bool		enable_geqo = false;	/* just in case GUC doesn't set it */
  int			geqo_threshold;
  
+ optimizer_hook_type optimizer_hook = NULL;
  
+ 
  static void set_base_rel_pathlists(PlannerInfo *root);
  static void set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
  							 Index rti, RangeTblEntry *rte);
***************
*** 52,60 ****
  					  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,
  						  bool *differentTypes);
  static bool recurse_pushdown_safe(Node *setOp, Query *topquery,
--- 54,59 ----
***************
*** 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.
--- 86,95 ----
  	/*
  	 * 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;
--- 614,620 ----
   * See comments for deconstruct_jointree() for definition of the joinlist
   * data structure.
   */
! RelOptInfo *
  make_rel_from_joinlist(PlannerInfo *root, List *joinlist)
  {
  	int			levels_needed;
***************
*** 695,701 ****
   * Returns the final level of join relations, i.e., the relation that is
   * the result of joining all the original relations together.
   */
! static RelOptInfo *
  make_one_rel_by_joins(PlannerInfo *root, int levels_needed, List *initial_rels)
  {
  	List	  **joinitems;
--- 697,703 ----
   * Returns the final level of join relations, i.e., the relation that is
   * the result of joining all the original relations together.
   */
! RelOptInfo *
  make_one_rel_by_joins(PlannerInfo *root, int levels_needed, List *initial_rels)
  {
  	List	  **joinitems;
*** ./src/include/optimizer/paths.h.orig	Tue May 22 03:40:33 2007
--- ./src/include/optimizer/paths.h	Thu Aug 23 15:20:56 2007
***************
*** 23,30 ****
  extern bool enable_geqo;
  extern int	geqo_threshold;
  
! extern RelOptInfo *make_one_rel(PlannerInfo *root, List *joinlist);
  
  #ifdef OPTIMIZER_DEBUG
  extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel);
  #endif
--- 23,46 ----
  extern bool enable_geqo;
  extern int	geqo_threshold;
  
! /* A macro pointing to the standard optimizer function. */
! #define standard_optimizer make_rel_from joinlist
  
+ /* 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;
+ 
+ /*
+  * Functions related to searching the space
+  * of all possible join orders.
+  */
+ extern RelOptInfo *make_one_rel(PlannerInfo *root, List *joinlist);
+ extern RelOptInfo *make_rel_from_joinlist(PlannerInfo *root,
+ 										  List *joinlist);
+ extern RelOptInfo *make_one_rel_by_joins(PlannerInfo *root,
+ 										 int levels_needed,
+ 										 List *initial_rels);
  #ifdef OPTIMIZER_DEBUG
  extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel);
  #endif
