MCPcopy Create free account
hub / github.com/apache/cloudberry / set_append_rel_size

Function set_append_rel_size

src/backend/optimizer/path/allpaths.c:1257–1519  ·  view source on GitHub ↗

* set_append_rel_size * Set size estimates for a simple "append relation" * * The passed-in rel and RTE represent the entire append relation. The * relation's contents are computed by appending together the output of the * individual member relations. Note that in the non-partitioned inheritance * case, the first member relation is actually the same table as is mentioned * in the parent

Source from the content-addressed store, hash-verified

1255 * a good thing because their outputs are not the same size.
1256 */
1257static void
1258set_append_rel_size(PlannerInfo *root, RelOptInfo *rel,
1259 Index rti, RangeTblEntry *rte)
1260{
1261 int parentRTindex = rti;
1262 bool has_live_children;
1263 double parent_rows;
1264 double parent_size;
1265 double *parent_attrsizes;
1266 int nattrs;
1267 ListCell *l;
1268
1269 /* Guard against stack overflow due to overly deep inheritance tree. */
1270 check_stack_depth();
1271
1272 Assert(IS_SIMPLE_REL(rel));
1273
1274 /*
1275 * If this is a partitioned baserel, set the consider_partitionwise_join
1276 * flag; currently, we only consider partitionwise joins with the baserel
1277 * if its targetlist doesn't contain a whole-row Var.
1278 */
1279 if (enable_partitionwise_join &&
1280 rel->reloptkind == RELOPT_BASEREL &&
1281 rte->relkind == RELKIND_PARTITIONED_TABLE &&
1282 rel->attr_needed[InvalidAttrNumber - rel->min_attr] == NULL)
1283 rel->consider_partitionwise_join = true;
1284
1285 /*
1286 * Initialize to compute size estimates for whole append relation.
1287 *
1288 * We handle width estimates by weighting the widths of different child
1289 * rels proportionally to their number of rows. This is sensible because
1290 * the use of width estimates is mainly to compute the total relation
1291 * "footprint" if we have to sort or hash it. To do this, we sum the
1292 * total equivalent size (in "double" arithmetic) and then divide by the
1293 * total rowcount estimate. This is done separately for the total rel
1294 * width and each attribute.
1295 *
1296 * Note: if you consider changing this logic, beware that child rels could
1297 * have zero rows and/or width, if they were excluded by constraints.
1298 */
1299 has_live_children = false;
1300 parent_rows = 0;
1301 parent_size = 0;
1302 nattrs = rel->max_attr - rel->min_attr + 1;
1303 parent_attrsizes = (double *) palloc0(nattrs * sizeof(double));
1304
1305 foreach(l, root->append_rel_list)
1306 {
1307 AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
1308 int childRTindex;
1309 RangeTblEntry *childRTE;
1310 RelOptInfo *childrel;
1311 ListCell *parentvars;
1312 ListCell *childvars;
1313
1314 /* append_rel_list contains all append rels; ignore others */

Callers 1

set_rel_sizeFunction · 0.85

Calls 15

check_stack_depthFunction · 0.85
find_base_relFunction · 0.85
set_dummy_rel_pathlistFunction · 0.85
adjust_appendrel_attrsFunction · 0.85
has_useful_pathkeysFunction · 0.85
set_rel_sizeFunction · 0.85
forbothFunction · 0.85
get_typavgwidthFunction · 0.85
exprTypeFunction · 0.85

Tested by

no test coverage detected