mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Create hooks to let a loadable plugin monitor (or even replace) the planner
and/or create plans for hypothetical situations; in particular, investigate plans that would be generated using hypothetical indexes. This is a heavily-rewritten version of the hooks proposed by Gurjeet Singh for his Index Advisor project. In this formulation, the index advisor can be entirely a loadable module instead of requiring a significant part to be in the core backend, and plans can be generated for hypothetical indexes without requiring the creation and rolling-back of system catalog entries. The index advisor patch as-submitted is not compatible with these hooks, but it needs significant work anyway due to other 8.2-to-8.3 planner changes. With these hooks in the core backend, development of the advisor can proceed as a pgfoundry project.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.219 2007/05/04 01:13:44 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.220 2007/05/25 17:54:25 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -42,6 +42,10 @@
|
||||
#include "utils/syscache.h"
|
||||
|
||||
|
||||
/* Hook for plugins to get control in planner() */
|
||||
planner_hook_type planner_hook = NULL;
|
||||
|
||||
|
||||
/* Expression kind codes for preprocess_expression */
|
||||
#define EXPRKIND_QUAL 0
|
||||
#define EXPRKIND_TARGET 1
|
||||
@ -79,9 +83,29 @@ static List *postprocess_setop_tlist(List *new_tlist, List *orig_tlist);
|
||||
*
|
||||
* Query optimizer entry point
|
||||
*
|
||||
* To support loadable plugins that monitor or modify planner behavior,
|
||||
* we provide a hook variable that lets a plugin get control before and
|
||||
* after the standard planning process. The plugin would normally call
|
||||
* standard_planner().
|
||||
*
|
||||
* Note to plugin authors: standard_planner() scribbles on its Query input,
|
||||
* so you'd better copy that data structure if you want to plan more than once.
|
||||
*
|
||||
*****************************************************************************/
|
||||
PlannedStmt *
|
||||
planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
|
||||
{
|
||||
PlannedStmt *result;
|
||||
|
||||
if (planner_hook)
|
||||
result = (*planner_hook) (parse, cursorOptions, boundParams);
|
||||
else
|
||||
result = standard_planner(parse, cursorOptions, boundParams);
|
||||
return result;
|
||||
}
|
||||
|
||||
PlannedStmt *
|
||||
standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
|
||||
{
|
||||
PlannedStmt *result;
|
||||
PlannerGlobal *glob;
|
||||
|
@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.134 2007/04/21 21:01:45 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.135 2007/05/25 17:54:25 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -40,6 +40,9 @@
|
||||
/* GUC parameter */
|
||||
bool constraint_exclusion = false;
|
||||
|
||||
/* Hook for plugins to get control in get_relation_info() */
|
||||
get_relation_info_hook_type get_relation_info_hook = NULL;
|
||||
|
||||
|
||||
static void estimate_rel_size(Relation rel, int32 *attr_widths,
|
||||
BlockNumber *pages, double *tuples);
|
||||
@ -279,6 +282,14 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
|
||||
rel->indexlist = indexinfos;
|
||||
|
||||
heap_close(relation, NoLock);
|
||||
|
||||
/*
|
||||
* Allow a plugin to editorialize on the info we obtained from the
|
||||
* catalogs. Actions might include altering the assumed relation size,
|
||||
* removing an index, or adding a hypothetical index to the indexlist.
|
||||
*/
|
||||
if (get_relation_info_hook)
|
||||
(*get_relation_info_hook) (root, relationObjectId, inhparent, rel);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user