139139aqo_set_baserel_rows_estimate (PlannerInfo * root , RelOptInfo * rel )
140140{
141141 double predicted ;
142- Oid relid ;
143- List * relids = NIL ;
142+ RangeTblEntry * rte ;
143+ List * relnames = NIL ;
144144 List * selectivities = NULL ;
145145 List * clauses ;
146146 int fss = 0 ;
@@ -161,19 +161,24 @@ aqo_set_baserel_rows_estimate(PlannerInfo *root, RelOptInfo *rel)
161161 goto default_estimator ;
162162 }
163163
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+ }
168174
169175 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 );
172177 rel -> fss_hash = fss ;
173178
174179 list_free_deep (selectivities );
175180 list_free (clauses );
176- list_free (relids );
181+ list_free (relnames );
177182
178183 if (predicted >= 0 )
179184 {
@@ -209,8 +214,8 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
209214 List * param_clauses )
210215{
211216 double predicted ;
212- Oid relid = InvalidOid ;
213- List * relids = NIL ;
217+ RangeTblEntry * rte = NULL ;
218+ List * relnames = NIL ;
214219 List * allclauses = NULL ;
215220 List * selectivities = NULL ;
216221 ListCell * l ;
@@ -219,7 +224,7 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
219224 int * args_hash ;
220225 int * eclass_hash ;
221226 int current_hash ;
222- int fss = 0 ;
227+ int fss = 0 ;
223228
224229 if (IsQueryDisabled ())
225230 /* Fast path */
@@ -239,7 +244,7 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
239244 /* Make specific copy of clauses with mutated subplans */
240245 allclauses = list_concat (aqo_get_clauses (root , param_clauses ),
241246 aqo_get_clauses (root , rel -> baserestrictinfo ));
242- relid = planner_rt_fetch (rel -> relid , root )-> relid ;
247+ rte = planner_rt_fetch (rel -> relid , root );
243248 get_eclasses (allclauses , & nargs , & args_hash , & eclass_hash );
244249
245250 old_ctx_m = MemoryContextSwitchTo (AQO_cache_mem_ctx );
@@ -249,7 +254,7 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
249254 current_hash = get_clause_hash (
250255 ((RestrictInfo * ) lfirst (l ))-> clause ,
251256 nargs , args_hash , eclass_hash );
252- cache_selectivity (current_hash , rel -> relid , relid ,
257+ cache_selectivity (current_hash , rel -> relid , rte -> relid ,
253258 * ((double * ) lfirst (l2 )));
254259 }
255260
@@ -269,11 +274,17 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
269274 goto default_estimator ;
270275 }
271276
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+ }
275286
276- predicted = predict_for_relation (allclauses , selectivities , relids , & fss );
287+ predicted = predict_for_relation (allclauses , selectivities , relnames , & fss );
277288
278289 predicted_ppi_rows = predicted ;
279290 fss_ppi_hash = fss ;
@@ -298,7 +309,7 @@ aqo_set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
298309 List * restrictlist )
299310{
300311 double predicted ;
301- List * relids ;
312+ List * relnames ;
302313 List * outer_clauses ;
303314 List * inner_clauses ;
304315 List * allclauses ;
@@ -324,7 +335,7 @@ aqo_set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
324335 goto default_estimator ;
325336 }
326337
327- relids = get_list_of_relids (root , rel -> relids );
338+ relnames = get_relnames (root , rel -> relids );
328339 outer_clauses = get_path_clauses (outer_rel -> cheapest_total_path , root ,
329340 & outer_selectivities );
330341 inner_clauses = get_path_clauses (inner_rel -> cheapest_total_path , root ,
@@ -335,7 +346,7 @@ aqo_set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
335346 list_concat (outer_selectivities ,
336347 inner_selectivities ));
337348
338- predicted = predict_for_relation (allclauses , selectivities , relids , & fss );
349+ predicted = predict_for_relation (allclauses , selectivities , relnames , & fss );
339350 rel -> fss_hash = fss ;
340351
341352 if (predicted >= 0 )
@@ -366,7 +377,7 @@ aqo_get_parameterized_joinrel_size(PlannerInfo *root,
366377 List * clauses )
367378{
368379 double predicted ;
369- List * relids ;
380+ List * relnames ;
370381 List * outer_clauses ;
371382 List * inner_clauses ;
372383 List * allclauses ;
@@ -392,7 +403,7 @@ aqo_get_parameterized_joinrel_size(PlannerInfo *root,
392403 goto default_estimator ;
393404 }
394405
395- relids = get_list_of_relids (root , rel -> relids );
406+ relnames = get_relnames (root , rel -> relids );
396407 outer_clauses = get_path_clauses (outer_path , root , & outer_selectivities );
397408 inner_clauses = get_path_clauses (inner_path , root , & inner_selectivities );
398409 allclauses = list_concat (aqo_get_clauses (root , clauses ),
@@ -401,7 +412,7 @@ aqo_get_parameterized_joinrel_size(PlannerInfo *root,
401412 list_concat (outer_selectivities ,
402413 inner_selectivities ));
403414
404- predicted = predict_for_relation (allclauses , selectivities , relids , & fss );
415+ predicted = predict_for_relation (allclauses , selectivities , relnames , & fss );
405416
406417 predicted_ppi_rows = predicted ;
407418 fss_ppi_hash = fss ;
@@ -428,13 +439,13 @@ predict_num_groups(PlannerInfo *root, Path *subpath, List *group_exprs,
428439 child_fss = subpath -> parent -> fss_hash ;
429440 else
430441 {
431- List * relids ;
442+ List * relnames ;
432443 List * clauses ;
433444 List * selectivities = NIL ;
434445
435- relids = get_list_of_relids (root , subpath -> parent -> relids );
446+ relnames = get_relnames (root , subpath -> parent -> relids );
436447 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 );
438449 }
439450
440451 * fss = get_grouped_exprs_hash (child_fss , group_exprs );
0 commit comments