33
33
#include "utils/date.h"
34
34
#include "utils/typcache.h"
35
35
#include "utils/lsyscache.h"
36
+ #include "utils/guc.h"
36
37
#include "access/heapam.h"
37
38
#include "access/nbtree.h"
38
39
#include "storage/ipc.h"
@@ -55,6 +56,9 @@ typedef struct
55
56
List * rangeset ;
56
57
}WrapperNode ;
57
58
59
+ bool pg_pathman_enable ;
60
+ PathmanState * pmstate ;
61
+
58
62
/* Original hooks */
59
63
static set_rel_pathlist_hook_type set_rel_pathlist_hook_original = NULL ;
60
64
static shmem_startup_hook_type shmem_startup_hook_original = NULL ;
@@ -152,6 +156,17 @@ _PG_init(void)
152
156
post_parse_analyze_hook = pathman_post_parse_analysis_hook ;
153
157
planner_hook_original = planner_hook ;
154
158
planner_hook = pathman_planner_hook ;
159
+
160
+ DefineCustomBoolVariable ("pg_pathman.enable" ,
161
+ "Enables pg_pathman's optimizations during the planner stage" ,
162
+ NULL ,
163
+ & pg_pathman_enable ,
164
+ true,
165
+ PGC_USERSET ,
166
+ 0 ,
167
+ NULL ,
168
+ NULL ,
169
+ NULL );
155
170
}
156
171
157
172
void
@@ -227,27 +242,30 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
227
242
PlannedStmt * result ;
228
243
ListCell * lc ;
229
244
230
- inheritance_disabled = false;
231
- switch (parse -> commandType )
245
+ if (pg_pathman_enable )
232
246
{
233
- case CMD_SELECT :
234
- disable_inheritance (parse );
235
- break ;
236
- case CMD_UPDATE :
237
- case CMD_DELETE :
238
- handle_modification_query (parse );
239
- break ;
240
- default :
241
- break ;
242
- }
247
+ inheritance_disabled = false;
248
+ switch (parse -> commandType )
249
+ {
250
+ case CMD_SELECT :
251
+ disable_inheritance (parse );
252
+ break ;
253
+ case CMD_UPDATE :
254
+ case CMD_DELETE :
255
+ handle_modification_query (parse );
256
+ break ;
257
+ default :
258
+ break ;
259
+ }
243
260
244
- /* If query contains CTE (WITH statement) then handle subqueries too */
245
- foreach (lc ,parse -> cteList )
246
- {
247
- CommonTableExpr * cte = (CommonTableExpr * )lfirst (lc );
261
+ /* If query contains CTE (WITH statement) then handle subqueries too */
262
+ foreach (lc ,parse -> cteList )
263
+ {
264
+ CommonTableExpr * cte = (CommonTableExpr * )lfirst (lc );
248
265
249
- if (IsA (cte -> ctequery ,Query ))
250
- disable_inheritance ((Query * )cte -> ctequery );
266
+ if (IsA (cte -> ctequery ,Query ))
267
+ disable_inheritance ((Query * )cte -> ctequery );
268
+ }
251
269
}
252
270
253
271
/* Invoke original hook */
@@ -382,6 +400,9 @@ pathman_set_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, Ran
382
400
bool found ;
383
401
int first_child_relid = 0 ;
384
402
403
+ if (!pg_pathman_enable )
404
+ return ;
405
+
385
406
/* This works only for SELECT queries */
386
407
if (root -> parse -> commandType != CMD_SELECT || !inheritance_disabled )
387
408
return ;
@@ -1017,29 +1038,29 @@ handle_binary_opexpr(const PartRelationInfo *prel, WrapperNode *result,
1017
1038
1018
1039
if ((cmp_min < 0 &&
1019
1040
(strategy == BTLessEqualStrategyNumber ||
1020
- strategy == BTEqualStrategyNumber ))||
1041
+ strategy == BTEqualStrategyNumber ))||
1021
1042
(cmp_min <=0 && strategy == BTLessStrategyNumber ))
1022
1043
{
1023
1044
result -> rangeset = NIL ;
1024
1045
return ;
1025
1046
}
1026
1047
1027
- if (cmp_max >=0 && (strategy == BTGreaterEqualStrategyNumber ||
1048
+ if (cmp_max >=0 && (strategy == BTGreaterEqualStrategyNumber ||
1028
1049
strategy == BTGreaterStrategyNumber ||
1029
1050
strategy == BTEqualStrategyNumber ))
1030
1051
{
1031
1052
result -> rangeset = NIL ;
1032
1053
return ;
1033
1054
}
1034
1055
1035
- if ((cmp_min < 0 && strategy == BTGreaterStrategyNumber )||
1056
+ if ((cmp_min < 0 && strategy == BTGreaterStrategyNumber )||
1036
1057
(cmp_min <=0 && strategy == BTGreaterEqualStrategyNumber ))
1037
1058
{
1038
1059
result -> rangeset = list_make1_irange (make_irange (startidx ,endidx , false));
1039
1060
return ;
1040
1061
}
1041
1062
1042
- if (cmp_max >=0 && (strategy == BTLessEqualStrategyNumber ||
1063
+ if (cmp_max >=0 && (strategy == BTLessEqualStrategyNumber ||
1043
1064
strategy == BTLessStrategyNumber ))
1044
1065
{
1045
1066
result -> rangeset = list_make1_irange (make_irange (startidx ,endidx , false));