summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-05-25 17:54:25 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-05-25 17:54:25 +0000
commit604ffd280b955100e5fc24649ee4d42a6f3ebf35 (patch)
treecd4ef43c9f931f86c6e33b58d03ea498b722aa0b /src/backend/optimizer/plan
parentce5b24abedd3db058c832aabb19940935b2903ae (diff)
downloadpostgresql-604ffd280b955100e5fc24649ee4d42a6f3ebf35.tar.gz
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.
Diffstat (limited to 'src/backend/optimizer/plan')
-rw-r--r--src/backend/optimizer/plan/planner.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 366c50f273..0f9776cdca 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -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,11 +83,31 @@ 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;
double tuple_fraction;
PlannerInfo *root;