139
139
aqo_set_baserel_rows_estimate (PlannerInfo * root , RelOptInfo * rel )
140
140
{
141
141
double predicted ;
142
- Oid relid ;
143
- List * relids = NIL ;
142
+ RangeTblEntry * rte ;
143
+ List * relnames = NIL ;
144
144
List * selectivities = NULL ;
145
145
List * clauses ;
146
146
int fss = 0 ;
@@ -161,19 +161,24 @@ aqo_set_baserel_rows_estimate(PlannerInfo *root, RelOptInfo *rel)
161
161
goto default_estimator ;
162
162
}
163
163
164
- relid = planner_rt_fetch (rel -> relid , root )-> relid ;
165
- if (OidIsValid (relid ))
166
- /* Predict for a plane table only. */
167
- relids = list_make1_int (relid );
164
+ rte = planner_rt_fetch (rel -> relid , root );
165
+ if (rte && OidIsValid (rte -> relid ))
166
+ {
167
+ String * s = makeNode (String );
168
+
169
+ /* Predict for a plane table. */
170
+ Assert (rte -> eref && rte -> eref -> aliasname );
171
+ s -> sval = pstrdup (rte -> eref -> aliasname );
172
+ relnames = list_make1 (s );
173
+ }
168
174
169
175
clauses = aqo_get_clauses (root , rel -> baserestrictinfo );
170
- predicted = predict_for_relation (clauses , selectivities ,
171
- relids , & fss );
176
+ predicted = predict_for_relation (clauses , selectivities , relnames , & fss );
172
177
rel -> fss_hash = fss ;
173
178
174
179
list_free_deep (selectivities );
175
180
list_free (clauses );
176
- list_free (relids );
181
+ list_free (relnames );
177
182
178
183
if (predicted >= 0 )
179
184
{
@@ -209,8 +214,8 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
209
214
List * param_clauses )
210
215
{
211
216
double predicted ;
212
- Oid relid = InvalidOid ;
213
- List * relids = NIL ;
217
+ RangeTblEntry * rte = NULL ;
218
+ List * relnames = NIL ;
214
219
List * allclauses = NULL ;
215
220
List * selectivities = NULL ;
216
221
ListCell * l ;
@@ -219,7 +224,7 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
219
224
int * args_hash ;
220
225
int * eclass_hash ;
221
226
int current_hash ;
222
- int fss = 0 ;
227
+ int fss = 0 ;
223
228
224
229
if (IsQueryDisabled ())
225
230
/* Fast path */
@@ -239,7 +244,7 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
239
244
/* Make specific copy of clauses with mutated subplans */
240
245
allclauses = list_concat (aqo_get_clauses (root , param_clauses ),
241
246
aqo_get_clauses (root , rel -> baserestrictinfo ));
242
- relid = planner_rt_fetch (rel -> relid , root )-> relid ;
247
+ rte = planner_rt_fetch (rel -> relid , root );
243
248
get_eclasses (allclauses , & nargs , & args_hash , & eclass_hash );
244
249
245
250
old_ctx_m = MemoryContextSwitchTo (AQO_cache_mem_ctx );
@@ -249,7 +254,7 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
249
254
current_hash = get_clause_hash (
250
255
((RestrictInfo * ) lfirst (l ))-> clause ,
251
256
nargs , args_hash , eclass_hash );
252
- cache_selectivity (current_hash , rel -> relid , relid ,
257
+ cache_selectivity (current_hash , rel -> relid , rte -> relid ,
253
258
* ((double * ) lfirst (l2 )));
254
259
}
255
260
@@ -269,11 +274,17 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
269
274
goto default_estimator ;
270
275
}
271
276
272
- if (OidIsValid (relid ))
273
- /* Predict for a plane table only. */
274
- relids = list_make1_int (relid );
277
+ if (rte && OidIsValid (rte -> relid ))
278
+ {
279
+ String * s = makeNode (String );
280
+
281
+ /* Predict for a plane table. */
282
+ Assert (rte -> eref && rte -> eref -> aliasname );
283
+ s -> sval = pstrdup (rte -> eref -> aliasname );
284
+ relnames = list_make1 (s );
285
+ }
275
286
276
- predicted = predict_for_relation (allclauses , selectivities , relids , & fss );
287
+ predicted = predict_for_relation (allclauses , selectivities , relnames , & fss );
277
288
278
289
predicted_ppi_rows = predicted ;
279
290
fss_ppi_hash = fss ;
@@ -298,7 +309,7 @@ aqo_set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
298
309
List * restrictlist )
299
310
{
300
311
double predicted ;
301
- List * relids ;
312
+ List * relnames ;
302
313
List * outer_clauses ;
303
314
List * inner_clauses ;
304
315
List * allclauses ;
@@ -324,7 +335,7 @@ aqo_set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
324
335
goto default_estimator ;
325
336
}
326
337
327
- relids = get_list_of_relids (root , rel -> relids );
338
+ relnames = get_relnames (root , rel -> relids );
328
339
outer_clauses = get_path_clauses (outer_rel -> cheapest_total_path , root ,
329
340
& outer_selectivities );
330
341
inner_clauses = get_path_clauses (inner_rel -> cheapest_total_path , root ,
@@ -335,7 +346,7 @@ aqo_set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
335
346
list_concat (outer_selectivities ,
336
347
inner_selectivities ));
337
348
338
- predicted = predict_for_relation (allclauses , selectivities , relids , & fss );
349
+ predicted = predict_for_relation (allclauses , selectivities , relnames , & fss );
339
350
rel -> fss_hash = fss ;
340
351
341
352
if (predicted >= 0 )
@@ -366,7 +377,7 @@ aqo_get_parameterized_joinrel_size(PlannerInfo *root,
366
377
List * clauses )
367
378
{
368
379
double predicted ;
369
- List * relids ;
380
+ List * relnames ;
370
381
List * outer_clauses ;
371
382
List * inner_clauses ;
372
383
List * allclauses ;
@@ -392,7 +403,7 @@ aqo_get_parameterized_joinrel_size(PlannerInfo *root,
392
403
goto default_estimator ;
393
404
}
394
405
395
- relids = get_list_of_relids (root , rel -> relids );
406
+ relnames = get_relnames (root , rel -> relids );
396
407
outer_clauses = get_path_clauses (outer_path , root , & outer_selectivities );
397
408
inner_clauses = get_path_clauses (inner_path , root , & inner_selectivities );
398
409
allclauses = list_concat (aqo_get_clauses (root , clauses ),
@@ -401,7 +412,7 @@ aqo_get_parameterized_joinrel_size(PlannerInfo *root,
401
412
list_concat (outer_selectivities ,
402
413
inner_selectivities ));
403
414
404
- predicted = predict_for_relation (allclauses , selectivities , relids , & fss );
415
+ predicted = predict_for_relation (allclauses , selectivities , relnames , & fss );
405
416
406
417
predicted_ppi_rows = predicted ;
407
418
fss_ppi_hash = fss ;
@@ -428,13 +439,13 @@ predict_num_groups(PlannerInfo *root, Path *subpath, List *group_exprs,
428
439
child_fss = subpath -> parent -> fss_hash ;
429
440
else
430
441
{
431
- List * relids ;
442
+ List * relnames ;
432
443
List * clauses ;
433
444
List * selectivities = NIL ;
434
445
435
- relids = get_list_of_relids (root , subpath -> parent -> relids );
446
+ relnames = get_relnames (root , subpath -> parent -> relids );
436
447
clauses = get_path_clauses (subpath , root , & selectivities );
437
- (void ) predict_for_relation (clauses , selectivities , relids , & child_fss );
448
+ (void ) predict_for_relation (clauses , selectivities , relnames , & child_fss );
438
449
}
439
450
440
451
* fss = get_grouped_exprs_hash (child_fss , group_exprs );
0 commit comments