@@ -83,6 +83,7 @@ static void handle_binary_opexpr_param(const PartRelationInfo *prel, WrapperNode
83
83
static WrapperNode * handle_opexpr (const OpExpr * expr , WalkerContext * context );
84
84
static WrapperNode * handle_boolexpr (const BoolExpr * expr , WalkerContext * context );
85
85
static WrapperNode * handle_arrexpr (const ScalarArrayOpExpr * expr , WalkerContext * context );
86
+ static double estimate_paramsel_using_prel (const PartRelationInfo * prel , int strategy );
86
87
static RestrictInfo * rebuild_restrictinfo (Node * clause , RestrictInfo * old_rinfo );
87
88
static bool pull_var_param (const WalkerContext * ctx , const OpExpr * expr , Node * * var_ptr , Node * * param_ptr );
88
89
@@ -1189,6 +1190,7 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
1189
1190
uint32 idx = hash_to_part_index (DatumGetInt32 (value ),
1190
1191
PrelChildrenCount (prel ));
1191
1192
1193
+ result -> paramsel = estimate_paramsel_using_prel (prel , strategy );
1192
1194
result -> rangeset = list_make1_irange (make_irange (idx , idx , true));
1193
1195
1194
1196
return ; /* exit on equal */
@@ -1203,6 +1205,7 @@ handle_binary_opexpr(WalkerContext *context, WrapperNode *result,
1203
1205
PrelChildrenCount (context -> prel ),
1204
1206
strategy ,
1205
1207
result );
1208
+ result -> paramsel = estimate_paramsel_using_prel (prel , strategy );
1206
1209
return ;
1207
1210
}
1208
1211
@@ -1237,19 +1240,25 @@ handle_binary_opexpr_param(const PartRelationInfo *prel,
1237
1240
strategy = get_op_opfamily_strategy (expr -> opno , tce -> btree_opf );
1238
1241
1239
1242
result -> rangeset = list_make1_irange (make_irange (0 , PrelLastChild (prel ), true));
1243
+ result -> paramsel = estimate_paramsel_using_prel (prel , strategy );
1244
+ }
1240
1245
1246
+ /*
1247
+ * Extracted common 'paramsel' estimator.
1248
+ */
1249
+ static double
1250
+ estimate_paramsel_using_prel (const PartRelationInfo * prel , int strategy )
1251
+ {
1252
+ /* If it's "=", divide by partitions number */
1241
1253
if (strategy == BTEqualStrategyNumber )
1242
- {
1243
- result -> paramsel = 1.0 / ( double ) PrelChildrenCount ( prel );
1244
- }
1254
+ return 1.0 / ( double ) PrelChildrenCount ( prel );
1255
+
1256
+ /* Default selectivity estimate for inequalities */
1245
1257
else if (prel -> parttype == PT_RANGE && strategy > 0 )
1246
- {
1247
- result -> paramsel = DEFAULT_INEQ_SEL ;
1248
- }
1249
- else
1250
- {
1251
- result -> paramsel = 1.0 ;
1252
- }
1258
+ return DEFAULT_INEQ_SEL ;
1259
+
1260
+ /* Else there's not much to do */
1261
+ else return 1.0 ;
1253
1262
}
1254
1263
1255
1264
/*
@@ -1324,6 +1333,7 @@ handle_const(const Const *c, WalkerContext *context)
1324
1333
{
1325
1334
const PartRelationInfo * prel = context -> prel ;
1326
1335
WrapperNode * result = (WrapperNode * ) palloc (sizeof (WrapperNode ));
1336
+ int strategy = BTEqualStrategyNumber ;
1327
1337
1328
1338
result -> orig = (const Node * ) c ;
1329
1339
@@ -1348,6 +1358,8 @@ handle_const(const Const *c, WalkerContext *context)
1348
1358
Datum value = OidFunctionCall1 (prel -> hash_proc , c -> constvalue );
1349
1359
uint32 idx = hash_to_part_index (DatumGetInt32 (value ),
1350
1360
PrelChildrenCount (prel ));
1361
+
1362
+ result -> paramsel = estimate_paramsel_using_prel (prel , strategy );
1351
1363
result -> rangeset = list_make1_irange (make_irange (idx , idx , true));
1352
1364
}
1353
1365
break ;
@@ -1362,8 +1374,10 @@ handle_const(const Const *c, WalkerContext *context)
1362
1374
& tce -> cmp_proc_finfo ,
1363
1375
PrelGetRangesArray (context -> prel ),
1364
1376
PrelChildrenCount (context -> prel ),
1365
- BTEqualStrategyNumber ,
1377
+ strategy ,
1366
1378
result );
1379
+
1380
+ result -> paramsel = estimate_paramsel_using_prel (prel , strategy );
1367
1381
}
1368
1382
break ;
1369
1383
0 commit comments