PostgreSQL Source Code  git master
allpaths.c File Reference
#include "postgres.h"
#include <limits.h>
#include <math.h>
#include "access/sysattr.h"
#include "access/tsmapi.h"
#include "catalog/pg_class.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_proc.h"
#include "foreign/fdwapi.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/geqo.h"
#include "optimizer/pathnode.h"
#include "optimizer/paths.h"
#include "optimizer/plancat.h"
#include "optimizer/planner.h"
#include "optimizer/prep.h"
#include "optimizer/restrictinfo.h"
#include "optimizer/tlist.h"
#include "optimizer/var.h"
#include "parser/parse_clause.h"
#include "parser/parsetree.h"
#include "rewrite/rewriteManip.h"
#include "utils/lsyscache.h"
Include dependency graph for allpaths.c:

Go to the source code of this file.

Data Structures

struct  pushdown_safety_info
 

Typedefs

typedef struct pushdown_safety_info pushdown_safety_info
 

Functions

static void set_base_rel_consider_startup (PlannerInfo *root)
 
static void set_base_rel_sizes (PlannerInfo *root)
 
static void set_base_rel_pathlists (PlannerInfo *root)
 
static void set_rel_size (PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
 
static void set_rel_pathlist (PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
 
static void set_plain_rel_size (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static void create_plain_partial_paths (PlannerInfo *root, RelOptInfo *rel)
 
static void set_rel_consider_parallel (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static void set_plain_rel_pathlist (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static void set_tablesample_rel_size (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static void set_tablesample_rel_pathlist (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static void set_foreign_size (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static void set_foreign_pathlist (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static void set_append_rel_size (PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
 
static void set_append_rel_pathlist (PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
 
static void generate_mergeappend_paths (PlannerInfo *root, RelOptInfo *rel, List *live_childrels, List *all_child_pathkeys, List *partitioned_rels)
 
static Pathget_cheapest_parameterized_child_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
static void accumulate_append_subpath (Path *path, List **subpaths, List **special_subpaths)
 
static void set_subquery_pathlist (PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
 
static void set_function_pathlist (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static void set_values_pathlist (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static void set_tablefunc_pathlist (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static void set_cte_pathlist (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static void set_namedtuplestore_pathlist (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static void set_worktable_pathlist (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
static RelOptInfomake_rel_from_joinlist (PlannerInfo *root, List *joinlist)
 
static bool subquery_is_pushdown_safe (Query *subquery, Query *topquery, pushdown_safety_info *safetyInfo)
 
static bool recurse_pushdown_safe (Node *setOp, Query *topquery, pushdown_safety_info *safetyInfo)
 
static void check_output_expressions (Query *subquery, pushdown_safety_info *safetyInfo)
 
static void compare_tlist_datatypes (List *tlist, List *colTypes, pushdown_safety_info *safetyInfo)
 
static bool targetIsInAllPartitionLists (TargetEntry *tle, Query *query)
 
static bool qual_is_pushdown_safe (Query *subquery, Index rti, Node *qual, pushdown_safety_info *safetyInfo)
 
static void subquery_push_qual (Query *subquery, RangeTblEntry *rte, Index rti, Node *qual)
 
static void recurse_push_qual (Node *setOp, Query *topquery, RangeTblEntry *rte, Index rti, Node *qual)
 
static void remove_unused_subquery_outputs (Query *subquery, RelOptInfo *rel)
 
static void add_paths_to_append_rel (PlannerInfo *root, RelOptInfo *rel, List *live_childrels)
 
RelOptInfomake_one_rel (PlannerInfo *root, List *joinlist)
 
void set_dummy_rel_pathlist (RelOptInfo *rel)
 
static bool has_multiple_baserels (PlannerInfo *root)
 
void generate_gather_paths (PlannerInfo *root, RelOptInfo *rel)
 
RelOptInfostandard_join_search (PlannerInfo *root, int levels_needed, List *initial_rels)
 
void create_partial_bitmap_paths (PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual)
 
int compute_parallel_worker (RelOptInfo *rel, double heap_pages, double index_pages)
 
void generate_partition_wise_join_paths (PlannerInfo *root, RelOptInfo *rel)
 

Variables

bool enable_geqo = false
 
int geqo_threshold
 
int min_parallel_table_scan_size
 
int min_parallel_index_scan_size
 
set_rel_pathlist_hook_type set_rel_pathlist_hook = NULL
 
join_search_hook_type join_search_hook = NULL
 

Typedef Documentation

◆ pushdown_safety_info

Function Documentation

◆ accumulate_append_subpath()

static void accumulate_append_subpath ( Path path,
List **  subpaths,
List **  special_subpaths 
)
static

Definition at line 1904 of file allpaths.c.

References AppendPath::first_partial_path, IsA, lappend(), list_concat(), list_copy(), list_copy_tail(), list_truncate(), Path::parallel_aware, AppendPath::path, AppendPath::subpaths, and MergeAppendPath::subpaths.

Referenced by add_paths_to_append_rel(), and generate_mergeappend_paths().

1905 {
1906  if (IsA(path, AppendPath))
1907  {
1908  AppendPath *apath = (AppendPath *) path;
1909 
1910  if (!apath->path.parallel_aware || apath->first_partial_path == 0)
1911  {
1912  /* list_copy is important here to avoid sharing list substructure */
1913  *subpaths = list_concat(*subpaths, list_copy(apath->subpaths));
1914  return;
1915  }
1916  else if (special_subpaths != NULL)
1917  {
1918  List *new_special_subpaths;
1919 
1920  /* Split Parallel Append into partial and non-partial subpaths */
1921  *subpaths = list_concat(*subpaths,
1922  list_copy_tail(apath->subpaths,
1923  apath->first_partial_path));
1924  new_special_subpaths =
1926  apath->first_partial_path);
1927  *special_subpaths = list_concat(*special_subpaths,
1928  new_special_subpaths);
1929  }
1930  }
1931  else if (IsA(path, MergeAppendPath))
1932  {
1933  MergeAppendPath *mpath = (MergeAppendPath *) path;
1934 
1935  /* list_copy is important here to avoid sharing list substructure */
1936  *subpaths = list_concat(*subpaths, list_copy(mpath->subpaths));
1937  return;
1938  }
1939 
1940  *subpaths = lappend(*subpaths, path);
1941 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
List * list_truncate(List *list, int new_size)
Definition: list.c:350
List * list_copy(const List *oldlist)
Definition: list.c:1160
List * list_concat(List *list1, List *list2)
Definition: list.c:321
List * list_copy_tail(const List *oldlist, int nskip)
Definition: list.c:1203
Path path
Definition: relation.h:1268
int first_partial_path
Definition: relation.h:1274
List * subpaths
Definition: relation.h:1271
List * lappend(List *list, void *datum)
Definition: list.c:128
bool parallel_aware
Definition: relation.h:1047
List * subpaths
Definition: relation.h:1294
Definition: pg_list.h:45

◆ add_paths_to_append_rel()

static void add_paths_to_append_rel ( PlannerInfo root,
RelOptInfo rel,
List live_childrels 
)
static

Definition at line 1329 of file allpaths.c.

References accumulate_append_subpath(), add_partial_path(), add_path(), Assert, bms_equal(), RelOptInfo::cheapest_total_path, compare_pathkeys(), create_append_path(), elog, enable_parallel_append, ERROR, fls(), generate_mergeappend_paths(), get_cheapest_parallel_safe_total_inner(), get_cheapest_parameterized_child_path(), get_partitioned_child_rels(), get_partitioned_child_rels_for_join(), IS_SIMPLE_REL, lappend(), lfirst, linitial, list_concat(), list_copy(), list_length(), Max, max_parallel_workers_per_gather, Min, NIL, Path::parallel_workers, Path::param_info, RelOptInfo::part_scheme, RelOptInfo::partial_pathlist, AppendPath::path, PATH_REQ_OUTER, Path::pathkeys, PATHKEYS_EQUAL, RelOptInfo::pathlist, planner_rt_fetch, RelOptInfo::relid, RelOptInfo::relids, RangeTblEntry::relkind, RELKIND_PARTITIONED_TABLE, RELOPT_JOINREL, RelOptInfo::reloptkind, Path::rows, RTE_RELATION, RTE_SUBQUERY, RangeTblEntry::rtekind, subpath(), and Path::total_cost.

Referenced by generate_partition_wise_join_paths(), and set_append_rel_pathlist().

1331 {
1332  List *subpaths = NIL;
1333  bool subpaths_valid = true;
1334  List *partial_subpaths = NIL;
1335  List *pa_partial_subpaths = NIL;
1336  List *pa_nonpartial_subpaths = NIL;
1337  bool partial_subpaths_valid = true;
1338  bool pa_subpaths_valid = enable_parallel_append;
1339  List *all_child_pathkeys = NIL;
1340  List *all_child_outers = NIL;
1341  ListCell *l;
1342  List *partitioned_rels = NIL;
1343  RangeTblEntry *rte;
1344  bool build_partitioned_rels = false;
1345  double partial_rows = -1;
1346 
1347  if (IS_SIMPLE_REL(rel))
1348  {
1349  /*
1350  * A root partition will already have a PartitionedChildRelInfo, and a
1351  * non-root partitioned table doesn't need one, because its Append
1352  * paths will get flattened into the parent anyway. For a subquery
1353  * RTE, no PartitionedChildRelInfo exists; we collect all
1354  * partitioned_rels associated with any child. (This assumes that we
1355  * don't need to look through multiple levels of subquery RTEs; if we
1356  * ever do, we could create a PartitionedChildRelInfo with the
1357  * accumulated list of partitioned_rels which would then be found when
1358  * populated our parent rel with paths. For the present, that appears
1359  * to be unnecessary.)
1360  */
1361  rte = planner_rt_fetch(rel->relid, root);
1362  switch (rte->rtekind)
1363  {
1364  case RTE_RELATION:
1365  if (rte->relkind == RELKIND_PARTITIONED_TABLE)
1366  partitioned_rels =
1367  get_partitioned_child_rels(root, rel->relid);
1368  break;
1369  case RTE_SUBQUERY:
1370  build_partitioned_rels = true;
1371  break;
1372  default:
1373  elog(ERROR, "unexpected rtekind: %d", (int) rte->rtekind);
1374  }
1375  }
1376  else if (rel->reloptkind == RELOPT_JOINREL && rel->part_scheme)
1377  {
1378  /*
1379  * Associate PartitionedChildRelInfo of the root partitioned tables
1380  * being joined with the root partitioned join (indicated by
1381  * RELOPT_JOINREL).
1382  */
1383  partitioned_rels = get_partitioned_child_rels_for_join(root,
1384  rel->relids);
1385  }
1386 
1387  /*
1388  * For every non-dummy child, remember the cheapest path. Also, identify
1389  * all pathkeys (orderings) and parameterizations (required_outer sets)
1390  * available for the non-dummy member relations.
1391  */
1392  foreach(l, live_childrels)
1393  {
1394  RelOptInfo *childrel = lfirst(l);
1395  ListCell *lcp;
1396  Path *cheapest_partial_path = NULL;
1397 
1398  /*
1399  * If we need to build partitioned_rels, accumulate the partitioned
1400  * rels for this child.
1401  */
1402  if (build_partitioned_rels)
1403  {
1404  List *cprels;
1405 
1406  cprels = get_partitioned_child_rels(root, childrel->relid);
1407  partitioned_rels = list_concat(partitioned_rels,
1408  list_copy(cprels));
1409  }
1410 
1411  /*
1412  * If child has an unparameterized cheapest-total path, add that to
1413  * the unparameterized Append path we are constructing for the parent.
1414  * If not, there's no workable unparameterized path.
1415  */
1416  if (childrel->cheapest_total_path->param_info == NULL)
1418  &subpaths, NULL);
1419  else
1420  subpaths_valid = false;
1421 
1422  /* Same idea, but for a partial plan. */
1423  if (childrel->partial_pathlist != NIL)
1424  {
1425  cheapest_partial_path = linitial(childrel->partial_pathlist);
1426  accumulate_append_subpath(cheapest_partial_path,
1427  &partial_subpaths, NULL);
1428  }
1429  else
1430  partial_subpaths_valid = false;
1431 
1432  /*
1433  * Same idea, but for a parallel append mixing partial and non-partial
1434  * paths.
1435  */
1436  if (pa_subpaths_valid)
1437  {
1438  Path *nppath = NULL;
1439 
1440  nppath =
1442 
1443  if (cheapest_partial_path == NULL && nppath == NULL)
1444  {
1445  /* Neither a partial nor a parallel-safe path? Forget it. */
1446  pa_subpaths_valid = false;
1447  }
1448  else if (nppath == NULL ||
1449  (cheapest_partial_path != NULL &&
1450  cheapest_partial_path->total_cost < nppath->total_cost))
1451  {
1452  /* Partial path is cheaper or the only option. */
1453  Assert(cheapest_partial_path != NULL);
1454  accumulate_append_subpath(cheapest_partial_path,
1455  &pa_partial_subpaths,
1456  &pa_nonpartial_subpaths);
1457 
1458  }
1459  else
1460  {
1461  /*
1462  * Either we've got only a non-partial path, or we think that
1463  * a single backend can execute the best non-partial path
1464  * faster than all the parallel backends working together can
1465  * execute the best partial path.
1466  *
1467  * It might make sense to be more aggressive here. Even if
1468  * the best non-partial path is more expensive than the best
1469  * partial path, it could still be better to choose the
1470  * non-partial path if there are several such paths that can
1471  * be given to different workers. For now, we don't try to
1472  * figure that out.
1473  */
1475  &pa_nonpartial_subpaths,
1476  NULL);
1477  }
1478  }
1479 
1480  /*
1481  * Collect lists of all the available path orderings and
1482  * parameterizations for all the children. We use these as a
1483  * heuristic to indicate which sort orderings and parameterizations we
1484  * should build Append and MergeAppend paths for.
1485  */
1486  foreach(lcp, childrel->pathlist)
1487  {
1488  Path *childpath = (Path *) lfirst(lcp);
1489  List *childkeys = childpath->pathkeys;
1490  Relids childouter = PATH_REQ_OUTER(childpath);
1491 
1492  /* Unsorted paths don't contribute to pathkey list */
1493  if (childkeys != NIL)
1494  {
1495  ListCell *lpk;
1496  bool found = false;
1497 
1498  /* Have we already seen this ordering? */
1499  foreach(lpk, all_child_pathkeys)
1500  {
1501  List *existing_pathkeys = (List *) lfirst(lpk);
1502 
1503  if (compare_pathkeys(existing_pathkeys,
1504  childkeys) == PATHKEYS_EQUAL)
1505  {
1506  found = true;
1507  break;
1508  }
1509  }
1510  if (!found)
1511  {
1512  /* No, so add it to all_child_pathkeys */
1513  all_child_pathkeys = lappend(all_child_pathkeys,
1514  childkeys);
1515  }
1516  }
1517 
1518  /* Unparameterized paths don't contribute to param-set list */
1519  if (childouter)
1520  {
1521  ListCell *lco;
1522  bool found = false;
1523 
1524  /* Have we already seen this param set? */
1525  foreach(lco, all_child_outers)
1526  {
1527  Relids existing_outers = (Relids) lfirst(lco);
1528 
1529  if (bms_equal(existing_outers, childouter))
1530  {
1531  found = true;
1532  break;
1533  }
1534  }
1535  if (!found)
1536  {
1537  /* No, so add it to all_child_outers */
1538  all_child_outers = lappend(all_child_outers,
1539  childouter);
1540  }
1541  }
1542  }
1543  }
1544 
1545  /*
1546  * If we found unparameterized paths for all children, build an unordered,
1547  * unparameterized Append path for the rel. (Note: this is correct even
1548  * if we have zero or one live subpath due to constraint exclusion.)
1549  */
1550  if (subpaths_valid)
1551  add_path(rel, (Path *) create_append_path(rel, subpaths, NIL,
1552  NULL, 0, false,
1553  partitioned_rels, -1));
1554 
1555  /*
1556  * Consider an append of unordered, unparameterized partial paths. Make
1557  * it parallel-aware if possible.
1558  */
1559  if (partial_subpaths_valid)
1560  {
1561  AppendPath *appendpath;
1562  ListCell *lc;
1563  int parallel_workers = 0;
1564 
1565  /* Find the highest number of workers requested for any subpath. */
1566  foreach(lc, partial_subpaths)
1567  {
1568  Path *path = lfirst(lc);
1569 
1570  parallel_workers = Max(parallel_workers, path->parallel_workers);
1571  }
1572  Assert(parallel_workers > 0);
1573 
1574  /*
1575  * If the use of parallel append is permitted, always request at least
1576  * log2(# of children) paths. We assume it can be useful to have
1577  * extra workers in this case because they will be spread out across
1578  * the children. The precise formula is just a guess, but we don't
1579  * want to end up with a radically different answer for a table with N
1580  * partitions vs. an unpartitioned table with the same data, so the
1581  * use of some kind of log-scaling here seems to make some sense.
1582  */
1584  {
1585  parallel_workers = Max(parallel_workers,
1586  fls(list_length(live_childrels)));
1587  parallel_workers = Min(parallel_workers,
1589  }
1590  Assert(parallel_workers > 0);
1591 
1592  /* Generate a partial append path. */
1593  appendpath = create_append_path(rel, NIL, partial_subpaths, NULL,
1594  parallel_workers,
1596  partitioned_rels, -1);
1597 
1598  /*
1599  * Make sure any subsequent partial paths use the same row count
1600  * estimate.
1601  */
1602  partial_rows = appendpath->path.rows;
1603 
1604  /* Add the path. */
1605  add_partial_path(rel, (Path *) appendpath);
1606  }
1607 
1608  /*
1609  * Consider a parallel-aware append using a mix of partial and non-partial
1610  * paths. (This only makes sense if there's at least one child which has
1611  * a non-partial path that is substantially cheaper than any partial path;
1612  * otherwise, we should use the append path added in the previous step.)
1613  */
1614  if (pa_subpaths_valid && pa_nonpartial_subpaths != NIL)
1615  {
1616  AppendPath *appendpath;
1617  ListCell *lc;
1618  int parallel_workers = 0;
1619 
1620  /*
1621  * Find the highest number of workers requested for any partial
1622  * subpath.
1623  */
1624  foreach(lc, pa_partial_subpaths)
1625  {
1626  Path *path = lfirst(lc);
1627 
1628  parallel_workers = Max(parallel_workers, path->parallel_workers);
1629  }
1630 
1631  /*
1632  * Same formula here as above. It's even more important in this
1633  * instance because the non-partial paths won't contribute anything to
1634  * the planned number of parallel workers.
1635  */
1636  parallel_workers = Max(parallel_workers,
1637  fls(list_length(live_childrels)));
1638  parallel_workers = Min(parallel_workers,
1640  Assert(parallel_workers > 0);
1641 
1642  appendpath = create_append_path(rel, pa_nonpartial_subpaths,
1643  pa_partial_subpaths,
1644  NULL, parallel_workers, true,
1645  partitioned_rels, partial_rows);
1646  add_partial_path(rel, (Path *) appendpath);
1647  }
1648 
1649  /*
1650  * Also build unparameterized MergeAppend paths based on the collected
1651  * list of child pathkeys.
1652  */
1653  if (subpaths_valid)
1654  generate_mergeappend_paths(root, rel, live_childrels,
1655  all_child_pathkeys,
1656  partitioned_rels);
1657 
1658  /*
1659  * Build Append paths for each parameterization seen among the child rels.
1660  * (This may look pretty expensive, but in most cases of practical
1661  * interest, the child rels will expose mostly the same parameterizations,
1662  * so that not that many cases actually get considered here.)
1663  *
1664  * The Append node itself cannot enforce quals, so all qual checking must
1665  * be done in the child paths. This means that to have a parameterized
1666  * Append path, we must have the exact same parameterization for each
1667  * child path; otherwise some children might be failing to check the
1668  * moved-down quals. To make them match up, we can try to increase the
1669  * parameterization of lesser-parameterized paths.
1670  */
1671  foreach(l, all_child_outers)
1672  {
1673  Relids required_outer = (Relids) lfirst(l);
1674  ListCell *lcr;
1675 
1676  /* Select the child paths for an Append with this parameterization */
1677  subpaths = NIL;
1678  subpaths_valid = true;
1679  foreach(lcr, live_childrels)
1680  {
1681  RelOptInfo *childrel = (RelOptInfo *) lfirst(lcr);
1682  Path *subpath;
1683 
1685  childrel,
1686  required_outer);
1687  if (subpath == NULL)
1688  {
1689  /* failed to make a suitable path for this child */
1690  subpaths_valid = false;
1691  break;
1692  }
1693  accumulate_append_subpath(subpath, &subpaths, NULL);
1694  }
1695 
1696  if (subpaths_valid)
1697  add_path(rel, (Path *)
1698  create_append_path(rel, subpaths, NIL,
1699  required_outer, 0, false,
1700  partitioned_rels, -1));
1701  }
1702 }
#define NIL
Definition: pg_list.h:69
static void generate_mergeappend_paths(PlannerInfo *root, RelOptInfo *rel, List *live_childrels, List *all_child_pathkeys, List *partitioned_rels)
Definition: allpaths.c:1728
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
RelOptKind reloptkind
Definition: relation.h:582
static Path * get_cheapest_parameterized_child_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: allpaths.c:1815
List * get_partitioned_child_rels(PlannerInfo *root, Index rti)
Definition: planner.c:6164
#define Min(x, y)
Definition: c.h:802
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * list_copy(const List *oldlist)
Definition: list.c:1160
List * partial_pathlist
Definition: relation.h:601
List * list_concat(List *list1, List *list2)
Definition: list.c:321
bool enable_parallel_append
Definition: costsize.c:131
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:278
#define IS_SIMPLE_REL(rel)
Definition: relation.h:561
Path path
Definition: relation.h:1268
int fls(int mask)
Definition: fls.c:55
#define linitial(l)
Definition: pg_list.h:111
#define planner_rt_fetch(rti, root)
Definition: relation.h:328
#define ERROR
Definition: elog.h:43
struct Path * cheapest_total_path
Definition: relation.h:603
Relids relids
Definition: relation.h:585
Path * get_cheapest_parallel_safe_total_inner(List *paths)
Definition: pathkeys.c:421
Index relid
Definition: relation.h:613
Bitmapset * Relids
Definition: relation.h:28
List * lappend(List *list, void *datum)
Definition: list.c:128
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define Max(x, y)
Definition: c.h:796
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
AppendPath * create_append_path(RelOptInfo *rel, List *subpaths, List *partial_subpaths, Relids required_outer, int parallel_workers, bool parallel_aware, List *partitioned_rels, double rows)
Definition: pathnode.c:1213
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
static int list_length(const List *l)
Definition: pg_list.h:89
RTEKind rtekind
Definition: parsenodes.h:951
void add_partial_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:762
PartitionScheme part_scheme
Definition: relation.h:657
List * pathlist
Definition: relation.h:599
#define elog
Definition: elog.h:219
List * get_partitioned_child_rels_for_join(PlannerInfo *root, Relids join_relids)
Definition: planner.c:6189
static void accumulate_append_subpath(Path *path, List **subpaths, List **special_subpaths)
Definition: allpaths.c:1904
int max_parallel_workers_per_gather
Definition: costsize.c:116
Definition: pg_list.h:45
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131

◆ check_output_expressions()

static void check_output_expressions ( Query subquery,
pushdown_safety_info safetyInfo 
)
static

Definition at line 2872 of file allpaths.c.

References contain_volatile_functions(), Query::distinctClause, TargetEntry::expr, expression_returns_set(), Query::hasDistinctOn, Query::hasTargetSRFs, Query::hasWindowFuncs, InvalidOid, lfirst, TargetEntry::resjunk, TargetEntry::resno, targetIsInAllPartitionLists(), targetIsInSortList(), Query::targetList, and pushdown_safety_info::unsafeColumns.

Referenced by subquery_is_pushdown_safe().

2873 {
2874  ListCell *lc;
2875 
2876  foreach(lc, subquery->targetList)
2877  {
2878  TargetEntry *tle = (TargetEntry *) lfirst(lc);
2879 
2880  if (tle->resjunk)
2881  continue; /* ignore resjunk columns */
2882 
2883  /* We need not check further if output col is already known unsafe */
2884  if (safetyInfo->unsafeColumns[tle->resno])
2885  continue;
2886 
2887  /* Functions returning sets are unsafe (point 1) */
2888  if (subquery->hasTargetSRFs &&
2889  expression_returns_set((Node *) tle->expr))
2890  {
2891  safetyInfo->unsafeColumns[tle->resno] = true;
2892  continue;
2893  }
2894 
2895  /* Volatile functions are unsafe (point 2) */
2896  if (contain_volatile_functions((Node *) tle->expr))
2897  {
2898  safetyInfo->unsafeColumns[tle->resno] = true;
2899  continue;
2900  }
2901 
2902  /* If subquery uses DISTINCT ON, check point 3 */
2903  if (subquery->hasDistinctOn &&
2904  !targetIsInSortList(tle, InvalidOid, subquery->distinctClause))
2905  {
2906  /* non-DISTINCT column, so mark it unsafe */
2907  safetyInfo->unsafeColumns[tle->resno] = true;
2908  continue;
2909  }
2910 
2911  /* If subquery uses window functions, check point 4 */
2912  if (subquery->hasWindowFuncs &&
2913  !targetIsInAllPartitionLists(tle, subquery))
2914  {
2915  /* not present in all PARTITION BY clauses, so mark it unsafe */
2916  safetyInfo->unsafeColumns[tle->resno] = true;
2917  continue;
2918  }
2919  }
2920 }
bool expression_returns_set(Node *clause)
Definition: nodeFuncs.c:670
Definition: nodes.h:512
bool * unsafeColumns
Definition: allpaths.c:53
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:957
bool hasDistinctOn
Definition: parsenodes.h:127
List * targetList
Definition: parsenodes.h:138
bool resjunk
Definition: primnodes.h:1382
List * distinctClause
Definition: parsenodes.h:154
static bool targetIsInAllPartitionLists(TargetEntry *tle, Query *query)
Definition: allpaths.c:2973
AttrNumber resno
Definition: primnodes.h:1376
#define InvalidOid
Definition: postgres_ext.h:36
bool targetIsInSortList(TargetEntry *tle, Oid sortop, List *sortList)
bool hasTargetSRFs
Definition: parsenodes.h:125
#define lfirst(lc)
Definition: pg_list.h:106
bool hasWindowFuncs
Definition: parsenodes.h:124
Expr * expr
Definition: primnodes.h:1375

◆ compare_tlist_datatypes()

static void compare_tlist_datatypes ( List tlist,
List colTypes,
pushdown_safety_info safetyInfo 
)
static

Definition at line 2940 of file allpaths.c.

References elog, ERROR, TargetEntry::expr, exprType(), lfirst, lfirst_oid, list_head(), lnext, TargetEntry::resjunk, TargetEntry::resno, and pushdown_safety_info::unsafeColumns.

Referenced by subquery_is_pushdown_safe().

2942 {
2943  ListCell *l;
2944  ListCell *colType = list_head(colTypes);
2945 
2946  foreach(l, tlist)
2947  {
2948  TargetEntry *tle = (TargetEntry *) lfirst(l);
2949 
2950  if (tle->resjunk)
2951  continue; /* ignore resjunk columns */
2952  if (colType == NULL)
2953  elog(ERROR, "wrong number of tlist entries");
2954  if (exprType((Node *) tle->expr) != lfirst_oid(colType))
2955  safetyInfo->unsafeColumns[tle->resno] = true;
2956  colType = lnext(colType);
2957  }
2958  if (colType != NULL)
2959  elog(ERROR, "wrong number of tlist entries");
2960 }
Definition: nodes.h:512
bool * unsafeColumns
Definition: allpaths.c:53
bool resjunk
Definition: primnodes.h:1382
#define ERROR
Definition: elog.h:43
AttrNumber resno
Definition: primnodes.h:1376
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
#define lnext(lc)
Definition: pg_list.h:105
#define lfirst(lc)
Definition: pg_list.h:106
Expr * expr
Definition: primnodes.h:1375
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
#define elog
Definition: elog.h:219
#define lfirst_oid(lc)
Definition: pg_list.h:108

◆ compute_parallel_worker()

int compute_parallel_worker ( RelOptInfo rel,
double  heap_pages,
double  index_pages 
)

Definition at line 3323 of file allpaths.c.

References Max, max_parallel_workers_per_gather, Min, min_parallel_index_scan_size, min_parallel_table_scan_size, RelOptInfo::rel_parallel_workers, RELOPT_BASEREL, and RelOptInfo::reloptkind.

Referenced by cost_index(), create_partial_bitmap_paths(), and create_plain_partial_paths().

3324 {
3325  int parallel_workers = 0;
3326 
3327  /*
3328  * If the user has set the parallel_workers reloption, use that; otherwise
3329  * select a default number of workers.
3330  */
3331  if (rel->rel_parallel_workers != -1)
3332  parallel_workers = rel->rel_parallel_workers;
3333  else
3334  {
3335  /*
3336  * If the number of pages being scanned is insufficient to justify a
3337  * parallel scan, just return zero ... unless it's an inheritance
3338  * child. In that case, we want to generate a parallel path here
3339  * anyway. It might not be worthwhile just for this relation, but
3340  * when combined with all of its inheritance siblings it may well pay
3341  * off.
3342  */
3343  if (rel->reloptkind == RELOPT_BASEREL &&
3344  ((heap_pages >= 0 && heap_pages < min_parallel_table_scan_size) ||
3345  (index_pages >= 0 && index_pages < min_parallel_index_scan_size)))
3346  return 0;
3347 
3348  if (heap_pages >= 0)
3349  {
3350  int heap_parallel_threshold;
3351  int heap_parallel_workers = 1;
3352 
3353  /*
3354  * Select the number of workers based on the log of the size of
3355  * the relation. This probably needs to be a good deal more
3356  * sophisticated, but we need something here for now. Note that
3357  * the upper limit of the min_parallel_table_scan_size GUC is
3358  * chosen to prevent overflow here.
3359  */
3360  heap_parallel_threshold = Max(min_parallel_table_scan_size, 1);
3361  while (heap_pages >= (BlockNumber) (heap_parallel_threshold * 3))
3362  {
3363  heap_parallel_workers++;
3364  heap_parallel_threshold *= 3;
3365  if (heap_parallel_threshold > INT_MAX / 3)
3366  break; /* avoid overflow */
3367  }
3368 
3369  parallel_workers = heap_parallel_workers;
3370  }
3371 
3372  if (index_pages >= 0)
3373  {
3374  int index_parallel_workers = 1;
3375  int index_parallel_threshold;
3376 
3377  /* same calculation as for heap_pages above */
3378  index_parallel_threshold = Max(min_parallel_index_scan_size, 1);
3379  while (index_pages >= (BlockNumber) (index_parallel_threshold * 3))
3380  {
3381  index_parallel_workers++;
3382  index_parallel_threshold *= 3;
3383  if (index_parallel_threshold > INT_MAX / 3)
3384  break; /* avoid overflow */
3385  }
3386 
3387  if (parallel_workers > 0)
3388  parallel_workers = Min(parallel_workers, index_parallel_workers);
3389  else
3390  parallel_workers = index_parallel_workers;
3391  }
3392  }
3393 
3394  /*
3395  * In no case use more than max_parallel_workers_per_gather workers.
3396  */
3397  parallel_workers = Min(parallel_workers, max_parallel_workers_per_gather);
3398 
3399  return parallel_workers;
3400 }
RelOptKind reloptkind
Definition: relation.h:582
#define Min(x, y)
Definition: c.h:802
uint32 BlockNumber
Definition: block.h:31
int min_parallel_index_scan_size
Definition: allpaths.c:62
int rel_parallel_workers
Definition: relation.h:629
#define Max(x, y)
Definition: c.h:796
int min_parallel_table_scan_size
Definition: allpaths.c:61
int max_parallel_workers_per_gather
Definition: costsize.c:116

◆ create_partial_bitmap_paths()

void create_partial_bitmap_paths ( PlannerInfo root,
RelOptInfo rel,
Path bitmapqual 
)

Definition at line 3291 of file allpaths.c.

References add_partial_path(), compute_bitmap_pages(), compute_parallel_worker(), create_bitmap_heap_path(), and RelOptInfo::lateral_relids.

Referenced by create_index_paths().

3293 {
3294  int parallel_workers;
3295  double pages_fetched;
3296 
3297  /* Compute heap pages for bitmap heap scan */
3298  pages_fetched = compute_bitmap_pages(root, rel, bitmapqual, 1.0,
3299  NULL, NULL);
3300 
3301  parallel_workers = compute_parallel_worker(rel, pages_fetched, -1);
3302 
3303  if (parallel_workers <= 0)
3304  return;
3305 
3306  add_partial_path(rel, (Path *) create_bitmap_heap_path(root, rel,
3307  bitmapqual, rel->lateral_relids, 1.0, parallel_workers));
3308 }
Relids lateral_relids
Definition: relation.h:610
int compute_parallel_worker(RelOptInfo *rel, double heap_pages, double index_pages)
Definition: allpaths.c:3323
void add_partial_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:762
double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, Path *bitmapqual, int loop_count, Cost *cost, double *tuple)
Definition: costsize.c:5334
BitmapHeapPath * create_bitmap_heap_path(PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual, Relids required_outer, double loop_count, int parallel_degree)
Definition: pathnode.c:1077

◆ create_plain_partial_paths()

static void create_plain_partial_paths ( PlannerInfo root,
RelOptInfo rel 
)
static

Definition at line 719 of file allpaths.c.

References add_partial_path(), compute_parallel_worker(), create_seqscan_path(), and RelOptInfo::pages.

Referenced by set_plain_rel_pathlist().

720 {
721  int parallel_workers;
722 
723  parallel_workers = compute_parallel_worker(rel, rel->pages, -1);
724 
725  /* If any limit was set to zero, the user doesn't want a parallel scan. */
726  if (parallel_workers <= 0)
727  return;
728 
729  /* Add an unordered partial path based on a parallel sequential scan. */
730  add_partial_path(rel, create_seqscan_path(root, rel, NULL, parallel_workers));
731 }
int compute_parallel_worker(RelOptInfo *rel, double heap_pages, double index_pages)
Definition: allpaths.c:3323
BlockNumber pages
Definition: relation.h:624
void add_partial_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:762
Path * create_seqscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer, int parallel_workers)
Definition: pathnode.c:948

◆ generate_gather_paths()

void generate_gather_paths ( PlannerInfo root,
RelOptInfo rel 
)

Definition at line 2447 of file allpaths.c.

References add_path(), create_gather_merge_path(), create_gather_path(), lfirst, linitial, NIL, RelOptInfo::partial_pathlist, GatherMergePath::path, Path::pathkeys, RelOptInfo::reltarget, and subpath().

Referenced by merge_clump(), set_rel_pathlist(), and standard_join_search().

2448 {
2449  Path *cheapest_partial_path;
2450  Path *simple_gather_path;
2451  ListCell *lc;
2452 
2453  /* If there are no partial paths, there's nothing to do here. */
2454  if (rel->partial_pathlist == NIL)
2455  return;
2456 
2457  /*
2458  * The output of Gather is always unsorted, so there's only one partial
2459  * path of interest: the cheapest one. That will be the one at the front
2460  * of partial_pathlist because of the way add_partial_path works.
2461  */
2462  cheapest_partial_path = linitial(rel->partial_pathlist);
2463  simple_gather_path = (Path *)
2464  create_gather_path(root, rel, cheapest_partial_path, rel->reltarget,
2465  NULL, NULL);
2466  add_path(rel, simple_gather_path);
2467 
2468  /*
2469  * For each useful ordering, we can consider an order-preserving Gather
2470  * Merge.
2471  */
2472  foreach(lc, rel->partial_pathlist)
2473  {
2474  Path *subpath = (Path *) lfirst(lc);
2475  GatherMergePath *path;
2476 
2477  if (subpath->pathkeys == NIL)
2478  continue;
2479 
2480  path = create_gather_merge_path(root, rel, subpath, rel->reltarget,
2481  subpath->pathkeys, NULL, NULL);
2482  add_path(rel, &path->path);
2483  }
2484 }
#define NIL
Definition: pg_list.h:69
GatherPath * create_gather_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, Relids required_outer, double *rows)
Definition: pathnode.c:1802
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
List * partial_pathlist
Definition: relation.h:601
#define linitial(l)
Definition: pg_list.h:111
GatherMergePath * create_gather_merge_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *pathkeys, Relids required_outer, double *rows)
Definition: pathnode.c:1711
List * pathkeys
Definition: relation.h:1056
#define lfirst(lc)
Definition: pg_list.h:106
struct PathTarget * reltarget
Definition: relation.h:596
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ generate_mergeappend_paths()

static void generate_mergeappend_paths ( PlannerInfo root,
RelOptInfo rel,
List live_childrels,
List all_child_pathkeys,
List partitioned_rels 
)
static

Definition at line 1728 of file allpaths.c.

References accumulate_append_subpath(), add_path(), Assert, RelOptInfo::cheapest_total_path, create_merge_append_path(), get_cheapest_path_for_pathkeys(), lfirst, NIL, Path::param_info, RelOptInfo::pathlist, STARTUP_COST, and TOTAL_COST.

Referenced by add_paths_to_append_rel().

1732 {
1733  ListCell *lcp;
1734 
1735  foreach(lcp, all_child_pathkeys)
1736  {
1737  List *pathkeys = (List *) lfirst(lcp);
1738  List *startup_subpaths = NIL;
1739  List *total_subpaths = NIL;
1740  bool startup_neq_total = false;
1741  ListCell *lcr;
1742 
1743  /* Select the child paths for this ordering... */
1744  foreach(lcr, live_childrels)
1745  {
1746  RelOptInfo *childrel = (RelOptInfo *) lfirst(lcr);
1747  Path *cheapest_startup,
1748  *cheapest_total;
1749 
1750  /* Locate the right paths, if they are available. */
1751  cheapest_startup =
1753  pathkeys,
1754  NULL,
1755  STARTUP_COST,
1756  false);
1757  cheapest_total =
1759  pathkeys,
1760  NULL,
1761  TOTAL_COST,
1762  false);
1763 
1764  /*
1765  * If we can't find any paths with the right order just use the
1766  * cheapest-total path; we'll have to sort it later.
1767  */
1768  if (cheapest_startup == NULL || cheapest_total == NULL)
1769  {
1770  cheapest_startup = cheapest_total =
1771  childrel->cheapest_total_path;
1772  /* Assert we do have an unparameterized path for this child */
1773  Assert(cheapest_total->param_info == NULL);
1774  }
1775 
1776  /*
1777  * Notice whether we actually have different paths for the
1778  * "cheapest" and "total" cases; frequently there will be no point
1779  * in two create_merge_append_path() calls.
1780  */
1781  if (cheapest_startup != cheapest_total)
1782  startup_neq_total = true;
1783 
1784  accumulate_append_subpath(cheapest_startup,
1785  &startup_subpaths, NULL);
1786  accumulate_append_subpath(cheapest_total,
1787  &total_subpaths, NULL);
1788  }
1789 
1790  /* ... and build the MergeAppend paths */
1791  add_path(rel, (Path *) create_merge_append_path(root,
1792  rel,
1793  startup_subpaths,
1794  pathkeys,
1795  NULL,
1796  partitioned_rels));
1797  if (startup_neq_total)
1798  add_path(rel, (Path *) create_merge_append_path(root,
1799  rel,
1800  total_subpaths,
1801  pathkeys,
1802  NULL,
1803  partitioned_rels));
1804  }
1805 }
Path * get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, CostSelector cost_criterion, bool require_parallel_safe)
Definition: pathkeys.c:343
#define NIL
Definition: pg_list.h:69
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
ParamPathInfo * param_info
Definition: relation.h:1045
struct Path * cheapest_total_path
Definition: relation.h:603
MergeAppendPath * create_merge_append_path(PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *pathkeys, Relids required_outer, List *partitioned_rels)
Definition: pathnode.c:1317
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
List * pathlist
Definition: relation.h:599
static void accumulate_append_subpath(Path *path, List **subpaths, List **special_subpaths)
Definition: allpaths.c:1904
Definition: pg_list.h:45

◆ generate_partition_wise_join_paths()

void generate_partition_wise_join_paths ( PlannerInfo root,
RelOptInfo rel 
)

Definition at line 3412 of file allpaths.c.

References add_paths_to_append_rel(), Alias::aliasname, RelOptInfo::baserestrictinfo, bms_next_member(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, check_stack_depth(), RestrictInfo::clause, RangeTblEntry::eref, generate_partition_wise_join_paths(), i, JoinPath::innerjoinpath, MergePath::innersortkeys, IS_DUMMY_REL, IS_JOIN_REL, IsA, RelOptInfo::joininfo, JoinPath::joinrestrictinfo, lappend(), lfirst, list_free(), lnext, mark_dummy_rel(), MergePath::materialize_inner, NIL, nodeTag, RelOptInfo::nparts, JoinPath::outerjoinpath, MergePath::outersortkeys, Path::param_info, Path::parent, PlannerInfo::parse, RelOptInfo::part_rels, Path::pathkeys, RelOptInfo::pathlist, Path::pathtype, ParamPathInfo::ppi_req_outer, print_expr(), print_pathkeys(), RelOptInfo::relids, RelOptInfo::reltarget, RelOptInfo::rows, Path::rows, Query::rtable, set_cheapest(), PlannerInfo::simple_rte_array, Path::startup_cost, subpath(), T_AggPath, T_AppendPath, T_BitmapAndPath, T_BitmapHeapPath, T_BitmapOrPath, T_CteScan, T_ForeignPath, T_FunctionScan, T_GatherPath, T_GroupingSetsPath, T_GroupPath, T_HashPath, T_IndexPath, T_LimitPath, T_LockRowsPath, T_MaterialPath, T_MergeAppendPath, T_MergePath, T_MinMaxAggPath, T_ModifyTablePath, T_NestPath, T_Path, T_ProjectionPath, T_ProjectSetPath, T_RecursiveUnionPath, T_ResultPath, T_SampleScan, T_SeqScan, T_SetOpPath, T_SortPath, T_SubqueryScan, T_SubqueryScanPath, T_TableFuncScan, T_TidPath, T_UniquePath, T_UpperUniquePath, T_ValuesScan, T_WindowAggPath, T_WorkTableScan, Path::total_cost, and PathTarget::width.

Referenced by generate_partition_wise_join_paths(), merge_clump(), and standard_join_search().

3413 {
3414  List *live_children = NIL;
3415  int cnt_parts;
3416  int num_parts;
3417  RelOptInfo **part_rels;
3418 
3419  /* Handle only join relations here. */
3420  if (!IS_JOIN_REL(rel))
3421  return;
3422 
3423  /*
3424  * If we've already proven this join is empty, we needn't consider any
3425  * more paths for it.
3426  */
3427  if (IS_DUMMY_REL(rel))
3428  return;
3429 
3430  /*
3431  * We've nothing to do if the relation is not partitioned. An outer join
3432  * relation which had an empty inner relation in every pair will have the
3433  * rest of the partitioning properties set except the child-join
3434  * RelOptInfos. See try_partition_wise_join() for more details.
3435  */
3436  if (rel->nparts <= 0 || rel->part_rels == NULL)
3437  return;
3438 
3439  /* Guard against stack overflow due to overly deep partition hierarchy. */
3441 
3442  num_parts = rel->nparts;
3443  part_rels = rel->part_rels;
3444 
3445  /* Collect non-dummy child-joins. */
3446  for (cnt_parts = 0; cnt_parts < num_parts; cnt_parts++)
3447  {
3448  RelOptInfo *child_rel = part_rels[cnt_parts];
3449 
3450  /* Add partition-wise join paths for partitioned child-joins. */
3451  generate_partition_wise_join_paths(root, child_rel);
3452 
3453  /* Dummy children will not be scanned, so ignore those. */
3454  if (IS_DUMMY_REL(child_rel))
3455  continue;
3456 
3457  set_cheapest(child_rel);
3458 
3459 #ifdef OPTIMIZER_DEBUG
3460  debug_print_rel(root, rel);
3461 #endif
3462 
3463  live_children = lappend(live_children, child_rel);
3464  }
3465 
3466  /* If all child-joins are dummy, parent join is also dummy. */
3467  if (!live_children)
3468  {
3469  mark_dummy_rel(rel);
3470  return;
3471  }
3472 
3473  /* Build additional paths for this rel from child-join paths. */
3474  add_paths_to_append_rel(root, rel, live_children);
3475  list_free(live_children);
3476 }
#define NIL
Definition: pg_list.h:69
#define IS_JOIN_REL(rel)
Definition: relation.h:566
void generate_partition_wise_join_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: allpaths.c:3412
#define IS_DUMMY_REL(r)
Definition: relation.h:1281
void check_stack_depth(void)
Definition: postgres.c:3150
int nparts
Definition: relation.h:658
List * lappend(List *list, void *datum)
Definition: list.c:128
void set_cheapest(RelOptInfo *parent_rel)
Definition: pathnode.c:244
void mark_dummy_rel(RelOptInfo *rel)
Definition: joinrels.c:1216
struct RelOptInfo ** part_rels
Definition: relation.h:660
void list_free(List *list)
Definition: list.c:1133
static void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, List *live_childrels)
Definition: allpaths.c:1329
Definition: pg_list.h:45

◆ get_cheapest_parameterized_child_path()

static Path * get_cheapest_parameterized_child_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer 
)
static

Definition at line 1815 of file allpaths.c.

References Assert, bms_equal(), bms_is_subset(), compare_path_costs(), get_cheapest_path_for_pathkeys(), lfirst, NIL, PATH_REQ_OUTER, RelOptInfo::pathlist, reparameterize_path(), and TOTAL_COST.

Referenced by add_paths_to_append_rel().

1817 {
1818  Path *cheapest;
1819  ListCell *lc;
1820 
1821  /*
1822  * Look up the cheapest existing path with no more than the needed
1823  * parameterization. If it has exactly the needed parameterization, we're
1824  * done.
1825  */
1826  cheapest = get_cheapest_path_for_pathkeys(rel->pathlist,
1827  NIL,
1828  required_outer,
1829  TOTAL_COST,
1830  false);
1831  Assert(cheapest != NULL);
1832  if (bms_equal(PATH_REQ_OUTER(cheapest), required_outer))
1833  return cheapest;
1834 
1835  /*
1836  * Otherwise, we can "reparameterize" an existing path to match the given
1837  * parameterization, which effectively means pushing down additional
1838  * joinquals to be checked within the path's scan. However, some existing
1839  * paths might check the available joinquals already while others don't;
1840  * therefore, it's not clear which existing path will be cheapest after
1841  * reparameterization. We have to go through them all and find out.
1842  */
1843  cheapest = NULL;
1844  foreach(lc, rel->pathlist)
1845  {
1846  Path *path = (Path *) lfirst(lc);
1847 
1848  /* Can't use it if it needs more than requested parameterization */
1849  if (!bms_is_subset(PATH_REQ_OUTER(path), required_outer))
1850  continue;
1851 
1852  /*
1853  * Reparameterization can only increase the path's cost, so if it's
1854  * already more expensive than the current cheapest, forget it.
1855  */
1856  if (cheapest != NULL &&
1857  compare_path_costs(cheapest, path, TOTAL_COST) <= 0)
1858  continue;
1859 
1860  /* Reparameterize if needed, then recheck cost */
1861  if (!bms_equal(PATH_REQ_OUTER(path), required_outer))
1862  {
1863  path = reparameterize_path(root, path, required_outer, 1.0);
1864  if (path == NULL)
1865  continue; /* failed to reparameterize this one */
1866  Assert(bms_equal(PATH_REQ_OUTER(path), required_outer));
1867 
1868  if (cheapest != NULL &&
1869  compare_path_costs(cheapest, path, TOTAL_COST) <= 0)
1870  continue;
1871  }
1872 
1873  /* We have a new best path */
1874  cheapest = path;
1875  }
1876 
1877  /* Return the best path, or NULL if we found no suitable candidate */
1878  return cheapest;
1879 }
Path * get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, CostSelector cost_criterion, bool require_parallel_safe)
Definition: pathkeys.c:343
#define NIL
Definition: pg_list.h:69
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:308
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
Path * reparameterize_path(PlannerInfo *root, Path *path, Relids required_outer, double loop_count)
Definition: pathnode.c:3476
List * pathlist
Definition: relation.h:599
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131

◆ has_multiple_baserels()

static bool has_multiple_baserels ( PlannerInfo root)
static

Definition at line 1977 of file allpaths.c.

References RELOPT_BASEREL, RelOptInfo::reloptkind, PlannerInfo::simple_rel_array, and PlannerInfo::simple_rel_array_size.

Referenced by set_subquery_pathlist().

1978 {
1979  int num_base_rels = 0;
1980  Index rti;
1981 
1982  for (rti = 1; rti < root->simple_rel_array_size; rti++)
1983  {
1984  RelOptInfo *brel = root->simple_rel_array[rti];
1985 
1986  if (brel == NULL)
1987  continue;
1988 
1989  /* ignore RTEs that are "other rels" */
1990  if (brel->reloptkind == RELOPT_BASEREL)
1991  if (++num_base_rels > 1)
1992  return true;
1993  }
1994  return false;
1995 }
RelOptKind reloptkind
Definition: relation.h:582
struct RelOptInfo ** simple_rel_array
Definition: relation.h:179
int simple_rel_array_size
Definition: relation.h:180
unsigned int Index
Definition: c.h:413

◆ make_one_rel()

RelOptInfo* make_one_rel ( PlannerInfo root,
List joinlist 
)

Definition at line 147 of file allpaths.c.

References PlannerInfo::all_baserels, Assert, bms_add_member(), bms_equal(), make_rel_from_joinlist(), RelOptInfo::relid, RelOptInfo::relids, RELOPT_BASEREL, RelOptInfo::reloptkind, set_base_rel_consider_startup(), set_base_rel_pathlists(), set_base_rel_sizes(), PlannerInfo::simple_rel_array, and PlannerInfo::simple_rel_array_size.

Referenced by query_planner().

148 {
149  RelOptInfo *rel;
150  Index rti;
151 
152  /*
153  * Construct the all_baserels Relids set.
154  */
155  root->all_baserels = NULL;
156  for (rti = 1; rti < root->simple_rel_array_size; rti++)
157  {
158  RelOptInfo *brel = root->simple_rel_array[rti];
159 
160  /* there may be empty slots corresponding to non-baserel RTEs */
161  if (brel == NULL)
162  continue;
163 
164  Assert(brel->relid == rti); /* sanity check on array */
165 
166  /* ignore RTEs that are "other rels" */
167  if (brel->reloptkind != RELOPT_BASEREL)
168  continue;
169 
170  root->all_baserels = bms_add_member(root->all_baserels, brel->relid);
171  }
172 
173  /* Mark base rels as to whether we care about fast-start plans */
175 
176  /*
177  * Compute size estimates and consider_parallel flags for each base rel,
178  * then generate access paths.
179  */
180  set_base_rel_sizes(root);
182 
183  /*
184  * Generate access paths for the entire join tree.
185  */
186  rel = make_rel_from_joinlist(root, joinlist);
187 
188  /*
189  * The result should join all and only the query's base rels.
190  */
191  Assert(bms_equal(rel->relids, root->all_baserels));
192 
193  return rel;
194 }
RelOptKind reloptkind
Definition: relation.h:582
static void set_base_rel_sizes(PlannerInfo *root)
Definition: allpaths.c:250
static void set_base_rel_consider_startup(PlannerInfo *root)
Definition: allpaths.c:207
struct RelOptInfo ** simple_rel_array
Definition: relation.h:179
Relids all_baserels
Definition: relation.h:196
static RelOptInfo * make_rel_from_joinlist(PlannerInfo *root, List *joinlist)
Definition: allpaths.c:2494
Relids relids
Definition: relation.h:585
int simple_rel_array_size
Definition: relation.h:180
Index relid
Definition: relation.h:613
static void set_base_rel_pathlists(PlannerInfo *root)
Definition: allpaths.c:293
unsigned int Index
Definition: c.h:413
#define Assert(condition)
Definition: c.h:670
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:698
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131

◆ make_rel_from_joinlist()

static RelOptInfo * make_rel_from_joinlist ( PlannerInfo root,
List joinlist 
)
static

Definition at line 2494 of file allpaths.c.

References elog, enable_geqo, ERROR, find_base_rel(), geqo(), geqo_threshold, PlannerInfo::initial_rels, IsA, join_search_hook, lappend(), lfirst, linitial, list_length(), NIL, nodeTag, and standard_join_search().

Referenced by make_one_rel().

2495 {
2496  int levels_needed;
2497  List *initial_rels;
2498  ListCell *jl;
2499 
2500  /*
2501  * Count the number of child joinlist nodes. This is the depth of the
2502  * dynamic-programming algorithm we must employ to consider all ways of
2503  * joining the child nodes.
2504  */
2505  levels_needed = list_length(joinlist);
2506 
2507  if (levels_needed <= 0)
2508  return NULL; /* nothing to do? */
2509 
2510  /*
2511  * Construct a list of rels corresponding to the child joinlist nodes.
2512  * This may contain both base rels and rels constructed according to
2513  * sub-joinlists.
2514  */
2515  initial_rels = NIL;
2516  foreach(jl, joinlist)
2517  {
2518  Node *jlnode = (Node *) lfirst(jl);
2519  RelOptInfo *thisrel;
2520 
2521  if (IsA(jlnode, RangeTblRef))
2522  {
2523  int varno = ((RangeTblRef *) jlnode)->rtindex;
2524 
2525  thisrel = find_base_rel(root, varno);
2526  }
2527  else if (IsA(jlnode, List))
2528  {
2529  /* Recurse to handle subproblem */
2530  thisrel = make_rel_from_joinlist(root, (List *) jlnode);
2531  }
2532  else
2533  {
2534  elog(ERROR, "unrecognized joinlist node type: %d",
2535  (int) nodeTag(jlnode));
2536  thisrel = NULL; /* keep compiler quiet */
2537  }
2538 
2539  initial_rels = lappend(initial_rels, thisrel);
2540  }
2541 
2542  if (levels_needed == 1)
2543  {
2544  /*
2545  * Single joinlist node, so we're done.
2546  */
2547  return (RelOptInfo *) linitial(initial_rels);
2548  }
2549  else
2550  {
2551  /*
2552  * Consider the different orders in which we could join the rels,
2553  * using a plugin, GEQO, or the regular join search code.
2554  *
2555  * We put the initial_rels list into a PlannerInfo field because
2556  * has_legal_joinclause() needs to look at it (ugly :-().
2557  */
2558  root->initial_rels = initial_rels;
2559 
2560  if (join_search_hook)
2561  return (*join_search_hook) (root, levels_needed, initial_rels);
2562  else if (enable_geqo && levels_needed >= geqo_threshold)
2563  return geqo(root, levels_needed, initial_rels);
2564  else
2565  return standard_join_search(root, levels_needed, initial_rels);
2566  }
2567 }
RelOptInfo * standard_join_search(PlannerInfo *root, int levels_needed, List *initial_rels)
Definition: allpaths.c:2599
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
Definition: nodes.h:512
#define linitial(l)
Definition: pg_list.h:111
#define ERROR
Definition: elog.h:43
bool enable_geqo
Definition: allpaths.c:59
static RelOptInfo * make_rel_from_joinlist(PlannerInfo *root, List *joinlist)
Definition: allpaths.c:2494
List * lappend(List *list, void *datum)
Definition: list.c:128
join_search_hook_type join_search_hook
Definition: allpaths.c:68
int geqo_threshold
Definition: allpaths.c:60
RelOptInfo * geqo(PlannerInfo *root, int number_of_rels, List *initial_rels)
Definition: geqo_main.c:67
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
#define nodeTag(nodeptr)
Definition: nodes.h:517
List * initial_rels
Definition: relation.h:272
#define elog
Definition: elog.h:219
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
Definition: relnode.c:277
Definition: pg_list.h:45

◆ qual_is_pushdown_safe()

static bool qual_is_pushdown_safe ( Query subquery,
Index  rti,
Node qual,
pushdown_safety_info safetyInfo 
)
static

Definition at line 3015 of file allpaths.c.

References Assert, contain_leaked_vars(), contain_subplans(), contain_volatile_functions(), contain_window_function(), IsA, lfirst, list_free(), pull_var_clause(), PVC_INCLUDE_PLACEHOLDERS, pushdown_safety_info::unsafeColumns, pushdown_safety_info::unsafeLeaky, pushdown_safety_info::unsafeVolatile, Var::varattno, and Var::varno.

Referenced by set_subquery_pathlist().

3017 {
3018  bool safe = true;
3019  List *vars;
3020  ListCell *vl;
3021 
3022  /* Refuse subselects (point 1) */
3023  if (contain_subplans(qual))
3024  return false;
3025 
3026  /* Refuse volatile quals if we found they'd be unsafe (point 2) */
3027  if (safetyInfo->unsafeVolatile &&
3029  return false;
3030 
3031  /* Refuse leaky quals if told to (point 3) */
3032  if (safetyInfo->unsafeLeaky &&
3033  contain_leaked_vars(qual))
3034  return false;
3035 
3036  /*
3037  * It would be unsafe to push down window function calls, but at least for
3038  * the moment we could never see any in a qual anyhow. (The same applies
3039  * to aggregates, which we check for in pull_var_clause below.)
3040  */
3042 
3043  /*
3044  * Examine all Vars used in clause; since it's a restriction clause, all
3045  * such Vars must refer to subselect output columns.
3046  */
3048  foreach(vl, vars)
3049  {
3050  Var *var = (Var *) lfirst(vl);
3051 
3052  /*
3053  * XXX Punt if we find any PlaceHolderVars in the restriction clause.
3054  * It's not clear whether a PHV could safely be pushed down, and even
3055  * less clear whether such a situation could arise in any cases of
3056  * practical interest anyway. So for the moment, just refuse to push
3057  * down.
3058  */
3059  if (!IsA(var, Var))
3060  {
3061  safe = false;
3062  break;
3063  }
3064 
3065  Assert(var->varno == rti);
3066  Assert(var->varattno >= 0);
3067 
3068  /* Check point 4 */
3069  if (var->varattno == 0)
3070  {
3071  safe = false;
3072  break;
3073  }
3074 
3075  /* Check point 5 */
3076  if (safetyInfo->unsafeColumns[var->varattno])
3077  {
3078  safe = false;
3079  break;
3080  }
3081  }
3082 
3083  list_free(vars);
3084 
3085  return safe;
3086 }
bool contain_leaked_vars(Node *clause)
Definition: clauses.c:1515
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
AttrNumber varattno
Definition: primnodes.h:168
bool * unsafeColumns
Definition: allpaths.c:53
List * pull_var_clause(Node *node, int flags)
Definition: var.c:535
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:957
Definition: primnodes.h:163
bool contain_subplans(Node *clause)
Definition: clauses.c:843
#define PVC_INCLUDE_PLACEHOLDERS
Definition: var.h:24
bool contain_window_function(Node *clause)
Definition: clauses.c:727
Index varno
Definition: primnodes.h:166
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
void list_free(List *list)
Definition: list.c:1133
Definition: regcomp.c:224
Definition: pg_list.h:45

◆ recurse_push_qual()

static void recurse_push_qual ( Node setOp,
Query topquery,
RangeTblEntry rte,
Index  rti,
Node qual 
)
static

Definition at line 3139 of file allpaths.c.

References Assert, elog, ERROR, IsA, SetOperationStmt::larg, nodeTag, SetOperationStmt::rarg, rt_fetch, Query::rtable, RangeTblRef::rtindex, RangeTblEntry::subquery, and subquery_push_qual().

Referenced by subquery_push_qual().

3141 {
3142  if (IsA(setOp, RangeTblRef))
3143  {
3144  RangeTblRef *rtr = (RangeTblRef *) setOp;
3145  RangeTblEntry *subrte = rt_fetch(rtr->rtindex, topquery->rtable);
3146  Query *subquery = subrte->subquery;
3147 
3148  Assert(subquery != NULL);
3149  subquery_push_qual(subquery, rte, rti, qual);
3150  }
3151  else if (IsA(setOp, SetOperationStmt))
3152  {
3153  SetOperationStmt *op = (SetOperationStmt *) setOp;
3154 
3155  recurse_push_qual(op->larg, topquery, rte, rti, qual);
3156  recurse_push_qual(op->rarg, topquery, rte, rti, qual);
3157  }
3158  else
3159  {
3160  elog(ERROR, "unrecognized node type: %d",
3161  (int) nodeTag(setOp));
3162  }
3163 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
List * rtable
Definition: parsenodes.h:135
#define ERROR
Definition: elog.h:43
#define rt_fetch(rangetable_index, rangetable)
Definition: parsetree.h:31
#define Assert(condition)
Definition: c.h:670
static void subquery_push_qual(Query *subquery, RangeTblEntry *rte, Index rti, Node *qual)
Definition: allpaths.c:3092
static void recurse_push_qual(Node *setOp, Query *topquery, RangeTblEntry *rte, Index rti, Node *qual)
Definition: allpaths.c:3139
#define nodeTag(nodeptr)
Definition: nodes.h:517
Query * subquery
Definition: parsenodes.h:974
#define elog
Definition: elog.h:219

◆ recurse_pushdown_safe()

static bool recurse_pushdown_safe ( Node setOp,
Query topquery,
pushdown_safety_info safetyInfo 
)
static

Definition at line 2805 of file allpaths.c.

References Assert, elog, ERROR, IsA, SetOperationStmt::larg, nodeTag, SetOperationStmt::op, SetOperationStmt::rarg, rt_fetch, Query::rtable, RangeTblRef::rtindex, SETOP_EXCEPT, RangeTblEntry::subquery, and subquery_is_pushdown_safe().

Referenced by subquery_is_pushdown_safe().

2807 {
2808  if (IsA(setOp, RangeTblRef))
2809  {
2810  RangeTblRef *rtr = (RangeTblRef *) setOp;
2811  RangeTblEntry *rte = rt_fetch(rtr->rtindex, topquery->rtable);
2812  Query *subquery = rte->subquery;
2813 
2814  Assert(subquery != NULL);
2815  return subquery_is_pushdown_safe(subquery, topquery, safetyInfo);
2816  }
2817  else if (IsA(setOp, SetOperationStmt))
2818  {
2819  SetOperationStmt *op = (SetOperationStmt *) setOp;
2820 
2821  /* EXCEPT is no good (point 2 for subquery_is_pushdown_safe) */
2822  if (op->op == SETOP_EXCEPT)
2823  return false;
2824  /* Else recurse */
2825  if (!recurse_pushdown_safe(op->larg, topquery, safetyInfo))
2826  return false;
2827  if (!recurse_pushdown_safe(op->rarg, topquery, safetyInfo))
2828  return false;
2829  }
2830  else
2831  {
2832  elog(ERROR, "unrecognized node type: %d",
2833  (int) nodeTag(setOp));
2834  }
2835  return true;
2836 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
static bool recurse_pushdown_safe(Node *setOp, Query *topquery, pushdown_safety_info *safetyInfo)
Definition: allpaths.c:2805
List * rtable
Definition: parsenodes.h:135
#define ERROR
Definition: elog.h:43
#define rt_fetch(rangetable_index, rangetable)
Definition: parsetree.h:31
#define Assert(condition)
Definition: c.h:670
SetOperation op
Definition: parsenodes.h:1580
#define nodeTag(nodeptr)
Definition: nodes.h:517
static bool subquery_is_pushdown_safe(Query *subquery, Query *topquery, pushdown_safety_info *safetyInfo)
Definition: allpaths.c:2753
Query * subquery
Definition: parsenodes.h:974
#define elog
Definition: elog.h:219

◆ remove_unused_subquery_outputs()

static void remove_unused_subquery_outputs ( Query subquery,
RelOptInfo rel 
)
static

Definition at line 3186 of file allpaths.c.

References RelOptInfo::baserestrictinfo, bms_is_member(), RestrictInfo::clause, contain_volatile_functions(), Query::distinctClause, TargetEntry::expr, exprCollation(), expression_returns_set(), PathTarget::exprs, exprType(), exprTypmod(), FirstLowInvalidHeapAttributeNumber, Query::hasDistinctOn, Query::hasTargetSRFs, lfirst, makeNullConst(), pull_varattnos(), RelOptInfo::relid, RelOptInfo::reltarget, TargetEntry::resjunk, TargetEntry::resno, TargetEntry::ressortgroupref, Query::setOperations, and Query::targetList.

Referenced by set_subquery_pathlist().

3187 {
3188  Bitmapset *attrs_used = NULL;
3189  ListCell *lc;
3190 
3191  /*
3192  * Do nothing if subquery has UNION/INTERSECT/EXCEPT: in principle we
3193  * could update all the child SELECTs' tlists, but it seems not worth the
3194  * trouble presently.
3195  */
3196  if (subquery->setOperations)
3197  return;
3198 
3199  /*
3200  * If subquery has regular DISTINCT (not DISTINCT ON), we're wasting our
3201  * time: all its output columns must be used in the distinctClause.
3202  */
3203  if (subquery->distinctClause && !subquery->hasDistinctOn)
3204  return;
3205 
3206  /*
3207  * Collect a bitmap of all the output column numbers used by the upper
3208  * query.
3209  *
3210  * Add all the attributes needed for joins or final output. Note: we must
3211  * look at rel's targetlist, not the attr_needed data, because attr_needed
3212  * isn't computed for inheritance child rels, cf set_append_rel_size().
3213  * (XXX might be worth changing that sometime.)
3214  */
3215  pull_varattnos((Node *) rel->reltarget->exprs, rel->relid, &attrs_used);
3216 
3217  /* Add all the attributes used by un-pushed-down restriction clauses. */
3218  foreach(lc, rel->baserestrictinfo)
3219  {
3220  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
3221 
3222  pull_varattnos((Node *) rinfo->clause, rel->relid, &attrs_used);
3223  }
3224 
3225  /*
3226  * If there's a whole-row reference to the subquery, we can't remove
3227  * anything.
3228  */
3230  return;
3231 
3232  /*
3233  * Run through the tlist and zap entries we don't need. It's okay to
3234  * modify the tlist items in-place because set_subquery_pathlist made a
3235  * copy of the subquery.
3236  */
3237  foreach(lc, subquery->targetList)
3238  {
3239  TargetEntry *tle = (TargetEntry *) lfirst(lc);
3240  Node *texpr = (Node *) tle->expr;
3241 
3242  /*
3243  * If it has a sortgroupref number, it's used in some sort/group
3244  * clause so we'd better not remove it. Also, don't remove any
3245  * resjunk columns, since their reason for being has nothing to do
3246  * with anybody reading the subquery's output. (It's likely that
3247  * resjunk columns in a sub-SELECT would always have ressortgroupref
3248  * set, but even if they don't, it seems imprudent to remove them.)
3249  */
3250  if (tle->ressortgroupref || tle->resjunk)
3251  continue;
3252 
3253  /*
3254  * If it's used by the upper query, we can't remove it.
3255  */
3257  attrs_used))
3258  continue;
3259 
3260  /*
3261  * If it contains a set-returning function, we can't remove it since
3262  * that could change the number of rows returned by the subquery.
3263  */
3264  if (subquery->hasTargetSRFs &&
3265  expression_returns_set(texpr))
3266  continue;
3267 
3268  /*
3269  * If it contains volatile functions, we daren't remove it for fear
3270  * that the user is expecting their side-effects to happen.
3271  */
3272  if (contain_volatile_functions(texpr))
3273  continue;
3274 
3275  /*
3276  * OK, we don't need it. Replace the expression with a NULL constant.
3277  * Preserve the exposed type of the expression, in case something
3278  * looks at the rowtype of the subquery's result.
3279  */
3280  tle->expr = (Expr *) makeNullConst(exprType(texpr),
3281  exprTypmod(texpr),
3282  exprCollation(texpr));
3283  }
3284 }
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:276
List * baserestrictinfo
Definition: relation.h:645
bool expression_returns_set(Node *clause)
Definition: nodeFuncs.c:670
Definition: nodes.h:512
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:28
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:957
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
Definition: var.c:219
bool hasDistinctOn
Definition: parsenodes.h:127
List * targetList
Definition: parsenodes.h:138
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Definition: makefuncs.c:336
bool resjunk
Definition: primnodes.h:1382
List * distinctClause
Definition: parsenodes.h:154
AttrNumber resno
Definition: primnodes.h:1376
Index relid
Definition: relation.h:613
Expr * clause
Definition: relation.h:1841
List * exprs
Definition: relation.h:972
bool hasTargetSRFs
Definition: parsenodes.h:125
#define lfirst(lc)
Definition: pg_list.h:106
Expr * expr
Definition: primnodes.h:1375
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:720
Node * setOperations
Definition: parsenodes.h:163
Index ressortgroupref
Definition: primnodes.h:1378
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:420
struct PathTarget * reltarget
Definition: relation.h:596

◆ set_append_rel_pathlist()

static void set_append_rel_pathlist ( PlannerInfo root,
RelOptInfo rel,
Index  rti,
RangeTblEntry rte 
)
static

Definition at line 1259 of file allpaths.c.

References add_paths_to_append_rel(), PlannerInfo::append_rel_list, AppendRelInfo::child_relid, RelOptInfo::consider_parallel, IS_DUMMY_REL, lappend(), lfirst, NIL, AppendRelInfo::parent_relid, set_rel_pathlist(), PlannerInfo::simple_rel_array, and PlannerInfo::simple_rte_array.

Referenced by set_rel_pathlist().

1261 {
1262  int parentRTindex = rti;
1263  List *live_childrels = NIL;
1264  ListCell *l;
1265 
1266  /*
1267  * Generate access paths for each member relation, and remember the
1268  * non-dummy children.
1269  */
1270  foreach(l, root->append_rel_list)
1271  {
1272  AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
1273  int childRTindex;
1274  RangeTblEntry *childRTE;
1275  RelOptInfo *childrel;
1276 
1277  /* append_rel_list contains all append rels; ignore others */
1278  if (appinfo->parent_relid != parentRTindex)
1279  continue;
1280 
1281  /* Re-locate the child RTE and RelOptInfo */
1282  childRTindex = appinfo->child_relid;
1283  childRTE = root->simple_rte_array[childRTindex];
1284  childrel = root->simple_rel_array[childRTindex];
1285 
1286  /*
1287  * If set_append_rel_size() decided the parent appendrel was
1288  * parallel-unsafe at some point after visiting this child rel, we
1289  * need to propagate the unsafety marking down to the child, so that
1290  * we don't generate useless partial paths for it.
1291  */
1292  if (!rel->consider_parallel)
1293  childrel->consider_parallel = false;
1294 
1295  /*
1296  * Compute the child's access paths.
1297  */
1298  set_rel_pathlist(root, childrel, childRTindex, childRTE);
1299 
1300  /*
1301  * If child is dummy, ignore it.
1302  */
1303  if (IS_DUMMY_REL(childrel))
1304  continue;
1305 
1306  /*
1307  * Child is live, so add it to the live_childrels list for use below.
1308  */
1309  live_childrels = lappend(live_childrels, childrel);
1310  }
1311 
1312  /* Add paths to the append relation. */
1313  add_paths_to_append_rel(root, rel, live_childrels);
1314 }
#define NIL
Definition: pg_list.h:69
struct RelOptInfo ** simple_rel_array
Definition: relation.h:179
#define IS_DUMMY_REL(r)
Definition: relation.h:1281
List * lappend(List *list, void *datum)
Definition: list.c:128
RangeTblEntry ** simple_rte_array
Definition: relation.h:188
List * append_rel_list
Definition: relation.h:252
static void set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
Definition: allpaths.c:423
#define lfirst(lc)
Definition: pg_list.h:106
bool consider_parallel
Definition: relation.h:593
static void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, List *live_childrels)
Definition: allpaths.c:1329
Index child_relid
Definition: relation.h:2072
Index parent_relid
Definition: relation.h:2071
Definition: pg_list.h:45

◆ set_append_rel_size()

static void set_append_rel_size ( PlannerInfo root,
RelOptInfo rel,
Index  rti,
RangeTblEntry rte 
)
static

Definition at line 861 of file allpaths.c.

References add_child_rel_equivalences(), adjust_appendrel_attrs(), PlannerInfo::append_rel_list, Assert, RelOptInfo::attr_needed, RelOptInfo::attr_widths, RelOptInfo::baserestrict_min_security, RelOptInfo::baserestrictinfo, check_stack_depth(), AppendRelInfo::child_relid, RestrictInfo::clause, RelOptInfo::consider_parallel, contain_vars_of_level(), contain_volatile_functions(), DatumGetBool, eval_const_expressions(), PathTarget::exprs, exprType(), exprTypmod(), find_base_rel(), forboth, get_typavgwidth(), PlannerInfo::glob, RelOptInfo::has_eclass_joins, has_useful_pathkeys(), PlannerInfo::hasPseudoConstantQuals, i, IS_DUMMY_REL, RestrictInfo::is_pushed_down, IS_SIMPLE_REL, IsA, RelOptInfo::joininfo, lappend(), lfirst, list_nth_node, make_ands_implicit(), make_restrictinfo(), RelOptInfo::max_attr, Min, RelOptInfo::min_attr, NIL, RestrictInfo::outerjoin_delayed, palloc0(), PlannerGlobal::parallelModeOK, AppendRelInfo::parent_relid, RelOptInfo::part_scheme, pfree(), relation_excluded_by_constraints(), RelOptInfo::relid, RELOPT_OTHER_MEMBER_REL, RelOptInfo::reloptkind, RelOptInfo::reltarget, rint(), RelOptInfo::rows, RestrictInfo::security_level, RangeTblEntry::securityQuals, set_dummy_rel_pathlist(), set_rel_consider_parallel(), set_rel_size(), PlannerInfo::simple_rte_array, AppendRelInfo::translated_vars, RelOptInfo::tuples, Var::varattno, and PathTarget::width.

Referenced by set_rel_size().

863 {
864  int parentRTindex = rti;
865  bool has_live_children;
866  double parent_rows;
867  double parent_size;
868  double *parent_attrsizes;
869  int nattrs;
870  ListCell *l;
871 
872  /* Guard against stack overflow due to overly deep inheritance tree. */
874 
875  Assert(IS_SIMPLE_REL(rel));
876 
877  /*
878  * Initialize to compute size estimates for whole append relation.
879  *
880  * We handle width estimates by weighting the widths of different child
881  * rels proportionally to their number of rows. This is sensible because
882  * the use of width estimates is mainly to compute the total relation
883  * "footprint" if we have to sort or hash it. To do this, we sum the
884  * total equivalent size (in "double" arithmetic) and then divide by the
885  * total rowcount estimate. This is done separately for the total rel
886  * width and each attribute.
887  *
888  * Note: if you consider changing this logic, beware that child rels could
889  * have zero rows and/or width, if they were excluded by constraints.
890  */
891  has_live_children = false;
892  parent_rows = 0;
893  parent_size = 0;
894  nattrs = rel->max_attr - rel->min_attr + 1;
895  parent_attrsizes = (double *) palloc0(nattrs * sizeof(double));
896 
897  foreach(l, root->append_rel_list)
898  {
899  AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
900  int childRTindex;
901  RangeTblEntry *childRTE;
902  RelOptInfo *childrel;
903  List *childquals;
904  Index cq_min_security;
905  bool have_const_false_cq;
906  ListCell *parentvars;
907  ListCell *childvars;
908  ListCell *lc;
909 
910  /* append_rel_list contains all append rels; ignore others */
911  if (appinfo->parent_relid != parentRTindex)
912  continue;
913 
914  childRTindex = appinfo->child_relid;
915  childRTE = root->simple_rte_array[childRTindex];
916 
917  /*
918  * The child rel's RelOptInfo was already created during
919  * add_base_rels_to_query.
920  */
921  childrel = find_base_rel(root, childRTindex);
923 
924  if (rel->part_scheme)
925  {
926  AttrNumber attno;
927 
928  /*
929  * We need attr_needed data for building targetlist of a join
930  * relation representing join between matching partitions for
931  * partition-wise join. A given attribute of a child will be
932  * needed in the same highest joinrel where the corresponding
933  * attribute of parent is needed. Hence it suffices to use the
934  * same Relids set for parent and child.
935  */
936  for (attno = rel->min_attr; attno <= rel->max_attr; attno++)
937  {
938  int index = attno - rel->min_attr;
939  Relids attr_needed = rel->attr_needed[index];
940 
941  /* System attributes do not need translation. */
942  if (attno <= 0)
943  {
944  Assert(rel->min_attr == childrel->min_attr);
945  childrel->attr_needed[index] = attr_needed;
946  }
947  else
948  {
949  Var *var = list_nth_node(Var,
950  appinfo->translated_vars,
951  attno - 1);
952  int child_index;
953 
954  /*
955  * Ignore any column dropped from the parent.
956  * Corresponding Var won't have any translation. It won't
957  * have attr_needed information, since it can not be
958  * referenced in the query.
959  */
960  if (var == NULL)
961  {
962  Assert(attr_needed == NULL);
963  continue;
964  }
965 
966  child_index = var->varattno - childrel->min_attr;
967  childrel->attr_needed[child_index] = attr_needed;
968  }
969  }
970  }
971 
972  /*
973  * Copy/Modify targetlist. Even if this child is deemed empty, we need
974  * its targetlist in case it falls on nullable side in a child-join
975  * because of partition-wise join.
976  *
977  * NB: the resulting childrel->reltarget->exprs may contain arbitrary
978  * expressions, which otherwise would not occur in a rel's targetlist.
979  * Code that might be looking at an appendrel child must cope with
980  * such. (Normally, a rel's targetlist would only include Vars and
981  * PlaceHolderVars.) XXX we do not bother to update the cost or width
982  * fields of childrel->reltarget; not clear if that would be useful.
983  */
984  childrel->reltarget->exprs = (List *)
986  (Node *) rel->reltarget->exprs,
987  1, &appinfo);
988 
989  /*
990  * We have to make child entries in the EquivalenceClass data
991  * structures as well. This is needed either if the parent
992  * participates in some eclass joins (because we will want to consider
993  * inner-indexscan joins on the individual children) or if the parent
994  * has useful pathkeys (because we should try to build MergeAppend
995  * paths that produce those sort orderings). Even if this child is
996  * deemed dummy, it may fall on nullable side in a child-join, which
997  * in turn may participate in a MergeAppend, where we will need the
998  * EquivalenceClass data structures.
999  */
1000  if (rel->has_eclass_joins || has_useful_pathkeys(root, rel))
1001  add_child_rel_equivalences(root, appinfo, rel, childrel);
1002  childrel->has_eclass_joins = rel->has_eclass_joins;
1003 
1004  /*
1005  * We have to copy the parent's quals to the child, with appropriate
1006  * substitution of variables. However, only the baserestrictinfo
1007  * quals are needed before we can check for constraint exclusion; so
1008  * do that first and then check to see if we can disregard this child.
1009  *
1010  * The child rel's targetlist might contain non-Var expressions, which
1011  * means that substitution into the quals could produce opportunities
1012  * for const-simplification, and perhaps even pseudoconstant quals.
1013  * Therefore, transform each RestrictInfo separately to see if it
1014  * reduces to a constant or pseudoconstant. (We must process them
1015  * separately to keep track of the security level of each qual.)
1016  */
1017  childquals = NIL;
1018  cq_min_security = UINT_MAX;
1019  have_const_false_cq = false;
1020  foreach(lc, rel->baserestrictinfo)
1021  {
1022  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1023  Node *childqual;
1024  ListCell *lc2;
1025 
1026  Assert(IsA(rinfo, RestrictInfo));
1027  childqual = adjust_appendrel_attrs(root,
1028  (Node *) rinfo->clause,
1029  1, &appinfo);
1030  childqual = eval_const_expressions(root, childqual);
1031  /* check for flat-out constant */
1032  if (childqual && IsA(childqual, Const))
1033  {
1034  if (((Const *) childqual)->constisnull ||
1035  !DatumGetBool(((Const *) childqual)->constvalue))
1036  {
1037  /* Restriction reduces to constant FALSE or NULL */
1038  have_const_false_cq = true;
1039  break;
1040  }
1041  /* Restriction reduces to constant TRUE, so drop it */
1042  continue;
1043  }
1044  /* might have gotten an AND clause, if so flatten it */
1045  foreach(lc2, make_ands_implicit((Expr *) childqual))
1046  {
1047  Node *onecq = (Node *) lfirst(lc2);
1048  bool pseudoconstant;
1049 
1050  /* check for pseudoconstant (no Vars or volatile functions) */
1051  pseudoconstant =
1052  !contain_vars_of_level(onecq, 0) &&
1054  if (pseudoconstant)
1055  {
1056  /* tell createplan.c to check for gating quals */
1057  root->hasPseudoConstantQuals = true;
1058  }
1059  /* reconstitute RestrictInfo with appropriate properties */
1060  childquals = lappend(childquals,
1061  make_restrictinfo((Expr *) onecq,
1062  rinfo->is_pushed_down,
1063  rinfo->outerjoin_delayed,
1064  pseudoconstant,
1065  rinfo->security_level,
1066  NULL, NULL, NULL));
1067  /* track minimum security level among child quals */
1068  cq_min_security = Min(cq_min_security, rinfo->security_level);
1069  }
1070  }
1071 
1072  /*
1073  * In addition to the quals inherited from the parent, we might have
1074  * securityQuals associated with this particular child node.
1075  * (Currently this can only happen in appendrels originating from
1076  * UNION ALL; inheritance child tables don't have their own
1077  * securityQuals, see expand_inherited_rtentry().) Pull any such
1078  * securityQuals up into the baserestrictinfo for the child. This is
1079  * similar to process_security_barrier_quals() for the parent rel,
1080  * except that we can't make any general deductions from such quals,
1081  * since they don't hold for the whole appendrel.
1082  */
1083  if (childRTE->securityQuals)
1084  {
1085  Index security_level = 0;
1086 
1087  foreach(lc, childRTE->securityQuals)
1088  {
1089  List *qualset = (List *) lfirst(lc);
1090  ListCell *lc2;
1091 
1092  foreach(lc2, qualset)
1093  {
1094  Expr *qual = (Expr *) lfirst(lc2);
1095 
1096  /* not likely that we'd see constants here, so no check */
1097  childquals = lappend(childquals,
1098  make_restrictinfo(qual,
1099  true, false, false,
1100  security_level,
1101  NULL, NULL, NULL));
1102  cq_min_security = Min(cq_min_security, security_level);
1103  }
1104  security_level++;
1105  }
1106  Assert(security_level <= root->qual_security_level);
1107  }
1108 
1109  /*
1110  * OK, we've got all the baserestrictinfo quals for this child.
1111  */
1112  childrel->baserestrictinfo = childquals;
1113  childrel->baserestrict_min_security = cq_min_security;
1114 
1115  if (have_const_false_cq)
1116  {
1117  /*
1118  * Some restriction clause reduced to constant FALSE or NULL after
1119  * substitution, so this child need not be scanned.
1120  */
1121  set_dummy_rel_pathlist(childrel);
1122  continue;
1123  }
1124 
1125  if (relation_excluded_by_constraints(root, childrel, childRTE))
1126  {
1127  /*
1128  * This child need not be scanned, so we can omit it from the
1129  * appendrel.
1130  */
1131  set_dummy_rel_pathlist(childrel);
1132  continue;
1133  }
1134 
1135  /* CE failed, so finish copying/modifying join quals. */
1136  childrel->joininfo = (List *)
1138  (Node *) rel->joininfo,
1139  1, &appinfo);
1140 
1141  /*
1142  * If parallelism is allowable for this query in general, see whether
1143  * it's allowable for this childrel in particular. But if we've
1144  * already decided the appendrel is not parallel-safe as a whole,
1145  * there's no point in considering parallelism for this child. For
1146  * consistency, do this before calling set_rel_size() for the child.
1147  */
1148  if (root->glob->parallelModeOK && rel->consider_parallel)
1149  set_rel_consider_parallel(root, childrel, childRTE);
1150 
1151  /*
1152  * Compute the child's size.
1153  */
1154  set_rel_size(root, childrel, childRTindex, childRTE);
1155 
1156  /*
1157  * It is possible that constraint exclusion detected a contradiction
1158  * within a child subquery, even though we didn't prove one above. If
1159  * so, we can skip this child.
1160  */
1161  if (IS_DUMMY_REL(childrel))
1162  continue;
1163 
1164  /* We have at least one live child. */
1165  has_live_children = true;
1166 
1167  /*
1168  * If any live child is not parallel-safe, treat the whole appendrel
1169  * as not parallel-safe. In future we might be able to generate plans
1170  * in which some children are farmed out to workers while others are
1171  * not; but we don't have that today, so it's a waste to consider
1172  * partial paths anywhere in the appendrel unless it's all safe.
1173  * (Child rels visited before this one will be unmarked in
1174  * set_append_rel_pathlist().)
1175  */
1176  if (!childrel->consider_parallel)
1177  rel->consider_parallel = false;
1178 
1179  /*
1180  * Accumulate size information from each live child.
1181  */
1182  Assert(childrel->rows > 0);
1183 
1184  parent_rows += childrel->rows;
1185  parent_size += childrel->reltarget->width * childrel->rows;
1186 
1187  /*
1188  * Accumulate per-column estimates too. We need not do anything for
1189  * PlaceHolderVars in the parent list. If child expression isn't a
1190  * Var, or we didn't record a width estimate for it, we have to fall
1191  * back on a datatype-based estimate.
1192  *
1193  * By construction, child's targetlist is 1-to-1 with parent's.
1194  */
1195  forboth(parentvars, rel->reltarget->exprs,
1196  childvars, childrel->reltarget->exprs)
1197  {
1198  Var *parentvar = (Var *) lfirst(parentvars);
1199  Node *childvar = (Node *) lfirst(childvars);
1200 
1201  if (IsA(parentvar, Var))
1202  {
1203  int pndx = parentvar->varattno - rel->min_attr;
1204  int32 child_width = 0;
1205 
1206  if (IsA(childvar, Var) &&
1207  ((Var *) childvar)->varno == childrel->relid)
1208  {
1209  int cndx = ((Var *) childvar)->varattno - childrel->min_attr;
1210 
1211  child_width = childrel->attr_widths[cndx];
1212  }
1213  if (child_width <= 0)
1214  child_width = get_typavgwidth(exprType(childvar),
1215  exprTypmod(childvar));
1216  Assert(child_width > 0);
1217  parent_attrsizes[pndx] += child_width * childrel->rows;
1218  }
1219  }
1220  }
1221 
1222  if (has_live_children)
1223  {
1224  /*
1225  * Save the finished size estimates.
1226  */
1227  int i;
1228 
1229  Assert(parent_rows > 0);
1230  rel->rows = parent_rows;
1231  rel->reltarget->width = rint(parent_size / parent_rows);
1232  for (i = 0; i < nattrs; i++)
1233  rel->attr_widths[i] = rint(parent_attrsizes[i] / parent_rows);
1234 
1235  /*
1236  * Set "raw tuples" count equal to "rows" for the appendrel; needed
1237  * because some places assume rel->tuples is valid for any baserel.
1238  */
1239  rel->tuples = parent_rows;
1240  }
1241  else
1242  {
1243  /*
1244  * All children were excluded by constraints, so mark the whole
1245  * appendrel dummy. We must do this in this phase so that the rel's
1246  * dummy-ness is visible when we generate paths for other rels.
1247  */
1249  }
1250 
1251  pfree(parent_attrsizes);
1252 }
bool has_eclass_joins
Definition: relation.h:651
#define NIL
Definition: pg_list.h:69
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
Index security_level
Definition: relation.h:1853
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:180
RelOptKind reloptkind
Definition: relation.h:582
RestrictInfo * make_restrictinfo(Expr *clause, bool is_pushed_down, bool outerjoin_delayed, bool pseudoconstant, Index security_level, Relids required_relids, Relids outer_relids, Relids nullable_relids)
Definition: restrictinfo.c:57
Relids * attr_needed
Definition: relation.h:618
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:276
List * securityQuals
Definition: parsenodes.h:1064
double tuples
Definition: relation.h:625
List * baserestrictinfo
Definition: relation.h:645
#define Min(x, y)
Definition: c.h:802
bool relation_excluded_by_constraints(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: plancat.c:1357
Definition: nodes.h:512
AttrNumber varattno
Definition: primnodes.h:168
Node * eval_const_expressions(PlannerInfo *root, Node *node)
Definition: clauses.c:2459
Index baserestrict_min_security
Definition: relation.h:647
void add_child_rel_equivalences(PlannerInfo *root, AppendRelInfo *appinfo, RelOptInfo *parent_rel, RelOptInfo *child_rel)
Definition: equivclass.c:2108
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:957
Definition: primnodes.h:163
List * translated_vars
Definition: relation.h:2099
#define IS_SIMPLE_REL(rel)
Definition: relation.h:561
signed int int32
Definition: c.h:284
Definition: type.h:89
void set_dummy_rel_pathlist(RelOptInfo *rel)
Definition: allpaths.c:1953
void pfree(void *pointer)
Definition: mcxt.c:949
List * make_ands_implicit(Expr *clause)
Definition: clauses.c:378
#define IS_DUMMY_REL(r)
Definition: relation.h:1281
bool parallelModeOK
Definition: relation.h:129
bool outerjoin_delayed
Definition: relation.h:1845
#define list_nth_node(type, list, n)
Definition: pg_list.h:227
static void set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:531
List * joininfo
Definition: relation.h:649
void check_stack_depth(void)
Definition: postgres.c:3150
PlannerGlobal * glob
Definition: relation.h:157
#define DatumGetBool(X)
Definition: postgres.h:399
double rint(double x)
Definition: rint.c:22
Index relid
Definition: relation.h:613
List * lappend(List *list, void *datum)
Definition: list.c:128
RangeTblEntry ** simple_rte_array
Definition: relation.h:188
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Definition: prepunion.c:1946
Expr * clause
Definition: relation.h:1841
List * exprs
Definition: relation.h:972
void * palloc0(Size size)
Definition: mcxt.c:877
List * append_rel_list
Definition: relation.h:252
unsigned int Index
Definition: c.h:413
int32 get_typavgwidth(Oid typid, int32 typmod)
Definition: lsyscache.c:2347
double rows
Definition: relation.h:588
bool hasPseudoConstantQuals
Definition: relation.h:306
bool is_pushed_down
Definition: relation.h:1843
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
bool contain_vars_of_level(Node *node, int levelsup)
Definition: var.c:369
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
bool consider_parallel
Definition: relation.h:593
int width
Definition: relation.h:975
AttrNumber max_attr
Definition: relation.h:617
int i
bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel)
Definition: pathkeys.c:1558
PartitionScheme part_scheme
Definition: relation.h:657
Index child_relid
Definition: relation.h:2072
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
Definition: relnode.c:277
Index parent_relid
Definition: relation.h:2071
int32 * attr_widths
Definition: relation.h:619
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:596
int16 AttrNumber
Definition: attnum.h:21
static void set_rel_size(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
Definition: allpaths.c:320
AttrNumber min_attr
Definition: relation.h:616

◆ set_base_rel_consider_startup()

static void set_base_rel_consider_startup ( PlannerInfo root)
static

Definition at line 207 of file allpaths.c.

References bms_get_singleton_member(), RelOptInfo::consider_param_startup, find_base_rel(), JOIN_ANTI, PlannerInfo::join_info_list, JOIN_SEMI, SpecialJoinInfo::jointype, lfirst, and SpecialJoinInfo::syn_righthand.

Referenced by make_one_rel().

208 {
209  /*
210  * Since parameterized paths can only be used on the inside of a nestloop
211  * join plan, there is usually little value in considering fast-start
212  * plans for them. However, for relations that are on the RHS of a SEMI
213  * or ANTI join, a fast-start plan can be useful because we're only going
214  * to care about fetching one tuple anyway.
215  *
216  * To minimize growth of planning time, we currently restrict this to
217  * cases where the RHS is a single base relation, not a join; there is no
218  * provision for consider_param_startup to get set at all on joinrels.
219  * Also we don't worry about appendrels. costsize.c's costing rules for
220  * nestloop semi/antijoins don't consider such cases either.
221  */
222  ListCell *lc;
223 
224  foreach(lc, root->join_info_list)
225  {
226  SpecialJoinInfo *sjinfo = (SpecialJoinInfo *) lfirst(lc);
227  int varno;
228 
229  if ((sjinfo->jointype == JOIN_SEMI || sjinfo->jointype == JOIN_ANTI) &&
230  bms_get_singleton_member(sjinfo->syn_righthand, &varno))
231  {
232  RelOptInfo *rel = find_base_rel(root, varno);
233 
234  rel->consider_param_startup = true;
235  }
236  }
237 }
List * join_info_list
Definition: relation.h:250
bool consider_param_startup
Definition: relation.h:592
bool bms_get_singleton_member(const Bitmapset *a, int *member)
Definition: bitmapset.c:569
Relids syn_righthand
Definition: relation.h:2016
#define lfirst(lc)
Definition: pg_list.h:106
JoinType jointype
Definition: relation.h:2017
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
Definition: relnode.c:277

◆ set_base_rel_pathlists()

static void set_base_rel_pathlists ( PlannerInfo root)
static

Definition at line 293 of file allpaths.c.

References Assert, RelOptInfo::relid, RELOPT_BASEREL, RelOptInfo::reloptkind, set_rel_pathlist(), PlannerInfo::simple_rel_array, PlannerInfo::simple_rel_array_size, and PlannerInfo::simple_rte_array.

Referenced by make_one_rel().

294 {
295  Index rti;
296 
297  for (rti = 1; rti < root->simple_rel_array_size; rti++)
298  {
299  RelOptInfo *rel = root->simple_rel_array[rti];
300 
301  /* there may be empty slots corresponding to non-baserel RTEs */
302  if (rel == NULL)
303  continue;
304 
305  Assert(rel->relid == rti); /* sanity check on array */
306 
307  /* ignore RTEs that are "other rels" */
308  if (rel->reloptkind != RELOPT_BASEREL)
309  continue;
310 
311  set_rel_pathlist(root, rel, rti, root->simple_rte_array[rti]);
312  }
313 }
RelOptKind reloptkind
Definition: relation.h:582
struct RelOptInfo ** simple_rel_array
Definition: relation.h:179
int simple_rel_array_size
Definition: relation.h:180
Index relid
Definition: relation.h:613
RangeTblEntry ** simple_rte_array
Definition: relation.h:188
unsigned int Index
Definition: c.h:413
static void set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
Definition: allpaths.c:423
#define Assert(condition)
Definition: c.h:670

◆ set_base_rel_sizes()

static void set_base_rel_sizes ( PlannerInfo root)
static

Definition at line 250 of file allpaths.c.

References Assert, PlannerInfo::glob, PlannerGlobal::parallelModeOK, RelOptInfo::relid, RELOPT_BASEREL, RelOptInfo::reloptkind, set_rel_consider_parallel(), set_rel_size(), PlannerInfo::simple_rel_array, PlannerInfo::simple_rel_array_size, and PlannerInfo::simple_rte_array.

Referenced by make_one_rel().

251 {
252  Index rti;
253 
254  for (rti = 1; rti < root->simple_rel_array_size; rti++)
255  {
256  RelOptInfo *rel = root->simple_rel_array[rti];
257  RangeTblEntry *rte;
258 
259  /* there may be empty slots corresponding to non-baserel RTEs */
260  if (rel == NULL)
261  continue;
262 
263  Assert(rel->relid == rti); /* sanity check on array */
264 
265  /* ignore RTEs that are "other rels" */
266  if (rel->reloptkind != RELOPT_BASEREL)
267  continue;
268 
269  rte = root->simple_rte_array[rti];
270 
271  /*
272  * If parallelism is allowable for this query in general, see whether
273  * it's allowable for this rel in particular. We have to do this
274  * before set_rel_size(), because (a) if this rel is an inheritance
275  * parent, set_append_rel_size() will use and perhaps change the rel's
276  * consider_parallel flag, and (b) for some RTE types, set_rel_size()
277  * goes ahead and makes paths immediately.
278  */
279  if (root->glob->parallelModeOK)
280  set_rel_consider_parallel(root, rel, rte);
281 
282  set_rel_size(root, rel, rti, rte);
283  }
284 }
RelOptKind reloptkind
Definition: relation.h:582
struct RelOptInfo ** simple_rel_array
Definition: relation.h:179
bool parallelModeOK
Definition: relation.h:129
static void set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:531
PlannerGlobal * glob
Definition: relation.h:157
int simple_rel_array_size
Definition: relation.h:180
Index relid
Definition: relation.h:613
RangeTblEntry ** simple_rte_array
Definition: relation.h:188
unsigned int Index
Definition: c.h:413
#define Assert(condition)
Definition: c.h:670
static void set_rel_size(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
Definition: allpaths.c:320

◆ set_cte_pathlist()

static void set_cte_pathlist ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 2299 of file allpaths.c.

References add_path(), Assert, create_ctescan_path(), PlannerInfo::cte_plan_ids, RangeTblEntry::ctelevelsup, Query::cteList, RangeTblEntry::ctename, CommonTableExpr::ctename, elog, ERROR, PlannerInfo::glob, RelOptInfo::lateral_relids, lfirst, list_length(), list_nth(), list_nth_int(), PlannerInfo::parent_root, PlannerInfo::parse, Plan::plan_rows, set_cte_size_estimates(), and PlannerGlobal::subplans.

Referenced by set_rel_size().

2300 {
2301  Plan *cteplan;
2302  PlannerInfo *cteroot;
2303  Index levelsup;
2304  int ndx;
2305  ListCell *lc;
2306  int plan_id;
2307  Relids required_outer;
2308 
2309  /*
2310  * Find the referenced CTE, and locate the plan previously made for it.
2311  */
2312  levelsup = rte->ctelevelsup;
2313  cteroot = root;
2314  while (levelsup-- > 0)
2315  {
2316  cteroot = cteroot->parent_root;
2317  if (!cteroot) /* shouldn't happen */
2318  elog(ERROR, "bad levelsup for CTE \"%s\"", rte->ctename);
2319  }
2320 
2321  /*
2322  * Note: cte_plan_ids can be shorter than cteList, if we are still working
2323  * on planning the CTEs (ie, this is a side-reference from another CTE).
2324  * So we mustn't use forboth here.
2325  */
2326  ndx = 0;
2327  foreach(lc, cteroot->parse->cteList)
2328  {
2329  CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc);
2330 
2331  if (strcmp(cte->ctename, rte->ctename) == 0)
2332  break;
2333  ndx++;
2334  }
2335  if (lc == NULL) /* shouldn't happen */
2336  elog(ERROR, "could not find CTE \"%s\"", rte->ctename);
2337  if (ndx >= list_length(cteroot->cte_plan_ids))
2338  elog(ERROR, "could not find plan for CTE \"%s\"", rte->ctename);
2339  plan_id = list_nth_int(cteroot->cte_plan_ids, ndx);
2340  Assert(plan_id > 0);
2341  cteplan = (Plan *) list_nth(root->glob->subplans, plan_id - 1);
2342 
2343  /* Mark rel with estimated output rows, width, etc */
2344  set_cte_size_estimates(root, rel, cteplan->plan_rows);
2345 
2346  /*
2347  * We don't support pushing join clauses into the quals of a CTE scan, but
2348  * it could still have required parameterization due to LATERAL refs in
2349  * its tlist.
2350  */
2351  required_outer = rel->lateral_relids;
2352 
2353  /* Generate appropriate path */
2354  add_path(rel, create_ctescan_path(root, rel, required_outer));
2355 }
double plan_rows
Definition: plannodes.h:131
Query * parse
Definition: relation.h:155
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:4933
Relids lateral_relids
Definition: relation.h:610
#define ERROR
Definition: elog.h:43
void * list_nth(const List *list, int n)
Definition: list.c:410
List * subplans
Definition: relation.h:98
PlannerGlobal * glob
Definition: relation.h:157
struct PlannerInfo * parent_root
Definition: relation.h:161
int list_nth_int(const List *list, int n)
Definition: list.c:421
List * cte_plan_ids
Definition: relation.h:230
unsigned int Index
Definition: c.h:413
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
Index ctelevelsup
Definition: parsenodes.h:1022
List * cteList
Definition: parsenodes.h:133
char * ctename
Definition: parsenodes.h:1021
#define elog
Definition: elog.h:219
Path * create_ctescan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: pathnode.c:1947

◆ set_dummy_rel_pathlist()

void set_dummy_rel_pathlist ( RelOptInfo rel)

Definition at line 1953 of file allpaths.c.

References add_path(), create_append_path(), NIL, RelOptInfo::partial_pathlist, RelOptInfo::pathlist, RelOptInfo::reltarget, RelOptInfo::rows, set_cheapest(), and PathTarget::width.

Referenced by inheritance_planner(), set_append_rel_size(), set_rel_size(), and set_subquery_pathlist().

1954 {
1955  /* Set dummy size estimates --- we leave attr_widths[] as zeroes */
1956  rel->rows = 0;
1957  rel->reltarget->width = 0;
1958 
1959  /* Discard any pre-existing paths; no further need for them */
1960  rel->pathlist = NIL;
1961  rel->partial_pathlist = NIL;
1962 
1963  add_path(rel, (Path *) create_append_path(rel, NIL, NIL, NULL,
1964  0, false, NIL, -1));
1965 
1966  /*
1967  * We set the cheapest path immediately, to ensure that IS_DUMMY_REL()
1968  * will recognize the relation as dummy if anyone asks. This is redundant
1969  * when we're called from set_rel_size(), but not when called from
1970  * elsewhere, and doing it twice is harmless anyway.
1971  */
1972  set_cheapest(rel);
1973 }
#define NIL
Definition: pg_list.h:69
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
List * partial_pathlist
Definition: relation.h:601
void set_cheapest(RelOptInfo *parent_rel)
Definition: pathnode.c:244
double rows
Definition: relation.h:588
AppendPath * create_append_path(RelOptInfo *rel, List *subpaths, List *partial_subpaths, Relids required_outer, int parallel_workers, bool parallel_aware, List *partitioned_rels, double rows)
Definition: pathnode.c:1213
int width
Definition: relation.h:975
List * pathlist
Definition: relation.h:599
struct PathTarget * reltarget
Definition: relation.h:596

◆ set_foreign_pathlist()

static void set_foreign_pathlist ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 843 of file allpaths.c.

References RelOptInfo::fdwroutine, FdwRoutine::GetForeignPaths, and RangeTblEntry::relid.

Referenced by set_rel_pathlist().

844 {
845  /* Call the FDW's GetForeignPaths function to generate path(s) */
846  rel->fdwroutine->GetForeignPaths(root, rel, rte->relid);
847 }
struct FdwRoutine * fdwroutine
Definition: relation.h:636
GetForeignPaths_function GetForeignPaths
Definition: fdwapi.h:181

◆ set_foreign_size()

static void set_foreign_size ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 826 of file allpaths.c.

References clamp_row_est(), RelOptInfo::fdwroutine, FdwRoutine::GetForeignRelSize, RangeTblEntry::relid, RelOptInfo::rows, and set_foreign_size_estimates().

Referenced by set_rel_size().

827 {
828  /* Mark rel with estimated output rows, width, etc */
829  set_foreign_size_estimates(root, rel);
830 
831  /* Let FDW adjust the size estimates, if it can */
832  rel->fdwroutine->GetForeignRelSize(root, rel, rte->relid);
833 
834  /* ... but do not let it set the rows estimate to zero */
835  rel->rows = clamp_row_est(rel->rows);
836 }
struct FdwRoutine * fdwroutine
Definition: relation.h:636
GetForeignRelSize_function GetForeignRelSize
Definition: fdwapi.h:180
double rows
Definition: relation.h:588
void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:5009
double clamp_row_est(double nrows)
Definition: costsize.c:177

◆ set_function_pathlist()

static void set_function_pathlist ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 2187 of file allpaths.c.

References add_path(), build_expression_pathkey(), create_functionscan_path(), PathTarget::exprs, RangeTblEntry::funcordinality, Int8LessOperator, IsA, RelOptInfo::lateral_relids, lfirst, RelOptInfo::max_attr, NIL, RelOptInfo::relid, RelOptInfo::relids, RelOptInfo::reltarget, Var::varattno, Var::varlevelsup, and Var::varno.

Referenced by set_rel_pathlist().

2188 {
2189  Relids required_outer;
2190  List *pathkeys = NIL;
2191 
2192  /*
2193  * We don't support pushing join clauses into the quals of a function
2194  * scan, but it could still have required parameterization due to LATERAL
2195  * refs in the function expression.
2196  */
2197  required_outer = rel->lateral_relids;
2198 
2199  /*
2200  * The result is considered unordered unless ORDINALITY was used, in which
2201  * case it is ordered by the ordinal column (the last one). See if we
2202  * care, by checking for uses of that Var in equivalence classes.
2203  */
2204  if (rte->funcordinality)
2205  {
2206  AttrNumber ordattno = rel->max_attr;
2207  Var *var = NULL;
2208  ListCell *lc;
2209 
2210  /*
2211  * Is there a Var for it in rel's targetlist? If not, the query did
2212  * not reference the ordinality column, or at least not in any way
2213  * that would be interesting for sorting.
2214  */
2215  foreach(lc, rel->reltarget->exprs)
2216  {
2217  Var *node = (Var *) lfirst(lc);
2218 
2219  /* checking varno/varlevelsup is just paranoia */
2220  if (IsA(node, Var) &&
2221  node->varattno == ordattno &&
2222  node->varno == rel->relid &&
2223  node->varlevelsup == 0)
2224  {
2225  var = node;
2226  break;
2227  }
2228  }
2229 
2230  /*
2231  * Try to build pathkeys for this Var with int8 sorting. We tell
2232  * build_expression_pathkey not to build any new equivalence class; if
2233  * the Var isn't already mentioned in some EC, it means that nothing
2234  * cares about the ordering.
2235  */
2236  if (var)
2237  pathkeys = build_expression_pathkey(root,
2238  (Expr *) var,
2239  NULL, /* below outer joins */
2241  rel->relids,
2242  false);
2243  }
2244 
2245  /* Generate appropriate path */
2246  add_path(rel, create_functionscan_path(root, rel,
2247  pathkeys, required_outer));
2248 }
#define NIL
Definition: pg_list.h:69
#define Int8LessOperator
Definition: pg_operator.h:181
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
List * build_expression_pathkey(PlannerInfo *root, Expr *expr, Relids nullable_relids, Oid opno, Relids rel, bool create_it)
Definition: pathkeys.c:553
Index varlevelsup
Definition: primnodes.h:173
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
AttrNumber varattno
Definition: primnodes.h:168
bool funcordinality
Definition: parsenodes.h:1006
Definition: primnodes.h:163
Path * create_functionscan_path(PlannerInfo *root, RelOptInfo *rel, List *pathkeys, Relids required_outer)
Definition: pathnode.c:1869
Relids lateral_relids
Definition: relation.h:610
Relids relids
Definition: relation.h:585
Index relid
Definition: relation.h:613
Index varno
Definition: primnodes.h:166
List * exprs
Definition: relation.h:972
#define lfirst(lc)
Definition: pg_list.h:106
AttrNumber max_attr
Definition: relation.h:617
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:596
int16 AttrNumber
Definition: attnum.h:21

◆ set_namedtuplestore_pathlist()

static void set_namedtuplestore_pathlist ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 2365 of file allpaths.c.

References add_path(), create_namedtuplestorescan_path(), RelOptInfo::lateral_relids, set_cheapest(), and set_namedtuplestore_size_estimates().

Referenced by set_rel_size().

2367 {
2368  Relids required_outer;
2369 
2370  /* Mark rel with estimated output rows, width, etc */
2372 
2373  /*
2374  * We don't support pushing join clauses into the quals of a tuplestore
2375  * scan, but it could still have required parameterization due to LATERAL
2376  * refs in its tlist.
2377  */
2378  required_outer = rel->lateral_relids;
2379 
2380  /* Generate appropriate path */
2381  add_path(rel, create_namedtuplestorescan_path(root, rel, required_outer));
2382 
2383  /* Select cheapest path (pretty easy in this case...) */
2384  set_cheapest(rel);
2385 }
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
Relids lateral_relids
Definition: relation.h:610
void set_cheapest(RelOptInfo *parent_rel)
Definition: pathnode.c:244
void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4970
Path * create_namedtuplestorescan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: pathnode.c:1972

◆ set_plain_rel_pathlist()

static void set_plain_rel_pathlist ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 689 of file allpaths.c.

References add_path(), RelOptInfo::consider_parallel, create_index_paths(), create_plain_partial_paths(), create_seqscan_path(), create_tidscan_paths(), and RelOptInfo::lateral_relids.

Referenced by set_rel_pathlist().

690 {
691  Relids required_outer;
692 
693  /*
694  * We don't support pushing join clauses into the quals of a seqscan, but
695  * it could still have required parameterization due to LATERAL refs in
696  * its tlist.
697  */
698  required_outer = rel->lateral_relids;
699 
700  /* Consider sequential scan */
701  add_path(rel, create_seqscan_path(root, rel, required_outer, 0));
702 
703  /* If appropriate, consider parallel sequential scan */
704  if (rel->consider_parallel && required_outer == NULL)
705  create_plain_partial_paths(root, rel);
706 
707  /* Consider index scans */
708  create_index_paths(root, rel);
709 
710  /* Consider TID scans */
711  create_tidscan_paths(root, rel);
712 }
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
void create_index_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: indxpath.c:232
Relids lateral_relids
Definition: relation.h:610
void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: tidpath.c:253
bool consider_parallel
Definition: relation.h:593
static void create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: allpaths.c:719
Path * create_seqscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer, int parallel_workers)
Definition: pathnode.c:948

◆ set_plain_rel_size()

static void set_plain_rel_size ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 514 of file allpaths.c.

References check_index_predicates(), and set_baserel_size_estimates().

Referenced by set_rel_size().

515 {
516  /*
517  * Test any partial indexes of rel for applicability. We must do this
518  * first since partial unique indexes can affect size estimates.
519  */
520  check_index_predicates(root, rel);
521 
522  /* Mark rel with estimated output rows, width, etc */
523  set_baserel_size_estimates(root, rel);
524 }
void check_index_predicates(PlannerInfo *root, RelOptInfo *rel)
Definition: indxpath.c:2774
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4249

◆ set_rel_consider_parallel()

static void set_rel_consider_parallel ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 531 of file allpaths.c.

References TableSampleClause::args, Assert, RelOptInfo::baserestrictinfo, RelOptInfo::consider_parallel, PathTarget::exprs, RelOptInfo::fdwroutine, func_parallel(), RangeTblEntry::functions, get_rel_persistence(), PlannerInfo::glob, is_parallel_safe(), IS_SIMPLE_REL, FdwRoutine::IsForeignScanParallelSafe, PlannerGlobal::parallelModeOK, PROPARALLEL_SAFE, RangeTblEntry::relid, RangeTblEntry::relkind, RELKIND_FOREIGN_TABLE, RELPERSISTENCE_TEMP, RelOptInfo::reltarget, RTE_CTE, RTE_FUNCTION, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, RangeTblEntry::tablesample, TableSampleClause::tsmhandler, and RangeTblEntry::values_lists.

Referenced by set_append_rel_size(), and set_base_rel_sizes().

533 {
534  /*
535  * The flag has previously been initialized to false, so we can just
536  * return if it becomes clear that we can't safely set it.
537  */
538  Assert(!rel->consider_parallel);
539 
540  /* Don't call this if parallelism is disallowed for the entire query. */
541  Assert(root->glob->parallelModeOK);
542 
543  /* This should only be called for baserels and appendrel children. */
544  Assert(IS_SIMPLE_REL(rel));
545 
546  /* Assorted checks based on rtekind. */
547  switch (rte->rtekind)
548  {
549  case RTE_RELATION:
550 
551  /*
552  * Currently, parallel workers can't access the leader's temporary
553  * tables. We could possibly relax this if the wrote all of its
554  * local buffers at the start of the query and made no changes
555  * thereafter (maybe we could allow hint bit changes), and if we
556  * taught the workers to read them. Writing a large number of
557  * temporary buffers could be expensive, though, and we don't have
558  * the rest of the necessary infrastructure right now anyway. So
559  * for now, bail out if we see a temporary table.
560  */
562  return;
563 
564  /*
565  * Table sampling can be pushed down to workers if the sample
566  * function and its arguments are safe.
567  */
568  if (rte->tablesample != NULL)
569  {
570  char proparallel = func_parallel(rte->tablesample->tsmhandler);
571 
572  if (proparallel != PROPARALLEL_SAFE)
573  return;
574  if (!is_parallel_safe(root, (Node *) rte->tablesample->args))
575  return;
576  }
577 
578  /*
579  * Ask FDWs whether they can support performing a ForeignScan
580  * within a worker. Most often, the answer will be no. For
581  * example, if the nature of the FDW is such that it opens a TCP
582  * connection with a remote server, each parallel worker would end
583  * up with a separate connection, and these connections might not
584  * be appropriately coordinated between workers and the leader.
585  */
586  if (rte->relkind == RELKIND_FOREIGN_TABLE)
587  {
588  Assert(rel->fdwroutine);
590  return;
591  if (!rel->fdwroutine->IsForeignScanParallelSafe(root, rel, rte))
592  return;
593  }
594 
595  /*
596  * There are additional considerations for appendrels, which we'll
597  * deal with in set_append_rel_size and set_append_rel_pathlist.
598  * For now, just set consider_parallel based on the rel's own
599  * quals and targetlist.
600  */
601  break;
602 
603  case RTE_SUBQUERY:
604 
605  /*
606  * There's no intrinsic problem with scanning a subquery-in-FROM
607  * (as distinct from a SubPlan or InitPlan) in a parallel worker.
608  * If the subquery doesn't happen to have any parallel-safe paths,
609  * then flagging it as consider_parallel won't change anything,
610  * but that's true for plain tables, too. We must set
611  * consider_parallel based on the rel's own quals and targetlist,
612  * so that if a subquery path is parallel-safe but the quals and
613  * projection we're sticking onto it are not, we correctly mark
614  * the SubqueryScanPath as not parallel-safe. (Note that
615  * set_subquery_pathlist() might push some of these quals down
616  * into the subquery itself, but that doesn't change anything.)
617  */
618  break;
619 
620  case RTE_JOIN:
621  /* Shouldn't happen; we're only considering baserels here. */
622  Assert(false);
623  return;
624 
625  case RTE_FUNCTION:
626  /* Check for parallel-restricted functions. */
627  if (!is_parallel_safe(root, (Node *) rte->functions))
628  return;
629  break;
630 
631  case RTE_TABLEFUNC:
632  /* not parallel safe */
633  return;
634 
635  case RTE_VALUES:
636  /* Check for parallel-restricted functions. */
637  if (!is_parallel_safe(root, (Node *) rte->values_lists))
638  return;
639  break;
640 
641  case RTE_CTE:
642 
643  /*
644  * CTE tuplestores aren't shared among parallel workers, so we
645  * force all CTE scans to happen in the leader. Also, populating
646  * the CTE would require executing a subplan that's not available
647  * in the worker, might be parallel-restricted, and must get
648  * executed only once.
649  */
650  return;
651 
652  case RTE_NAMEDTUPLESTORE:
653 
654  /*
655  * tuplestore cannot be shared, at least without more
656  * infrastructure to support that.
657  */
658  return;
659  }
660 
661  /*
662  * If there's anything in baserestrictinfo that's parallel-restricted, we
663  * give up on parallelizing access to this relation. We could consider
664  * instead postponing application of the restricted quals until we're
665  * above all the parallelism in the plan tree, but it's not clear that
666  * that would be a win in very many cases, and it might be tricky to make
667  * outer join clauses work correctly. It would likely break equivalence
668  * classes, too.
669  */
670  if (!is_parallel_safe(root, (Node *) rel->baserestrictinfo))
671  return;
672 
673  /*
674  * Likewise, if the relation's outputs are not parallel-safe, give up.
675  * (Usually, they're just Vars, but sometimes they're not.)
676  */
677  if (!is_parallel_safe(root, (Node *) rel->reltarget->exprs))
678  return;
679 
680  /* We have a winner. */
681  rel->consider_parallel = true;
682 }
List * baserestrictinfo
Definition: relation.h:645
Definition: nodes.h:512
List * values_lists
Definition: parsenodes.h:1016
#define IS_SIMPLE_REL(rel)
Definition: relation.h:561
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1087
IsForeignScanParallelSafe_function IsForeignScanParallelSafe
Definition: fdwapi.h:230
bool parallelModeOK
Definition: relation.h:129
PlannerGlobal * glob
Definition: relation.h:157
struct FdwRoutine * fdwroutine
Definition: relation.h:636
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
#define PROPARALLEL_SAFE
Definition: pg_proc.h:5546
List * exprs
Definition: relation.h:972
#define Assert(condition)
Definition: c.h:670
List * functions
Definition: parsenodes.h:1005
char func_parallel(Oid funcid)
Definition: lsyscache.c:1603
bool consider_parallel
Definition: relation.h:593
char get_rel_persistence(Oid relid)
Definition: lsyscache.c:1871
RTEKind rtekind
Definition: parsenodes.h:951
#define RELPERSISTENCE_TEMP
Definition: pg_class.h:172
struct PathTarget * reltarget
Definition: relation.h:596
struct TableSampleClause * tablesample
Definition: parsenodes.h:969

◆ set_rel_pathlist()

static void set_rel_pathlist ( PlannerInfo root,
RelOptInfo rel,
Index  rti,
RangeTblEntry rte 
)
static

Definition at line 423 of file allpaths.c.

References elog, ERROR, generate_gather_paths(), RangeTblEntry::inh, IS_DUMMY_REL, RangeTblEntry::relkind, RELKIND_FOREIGN_TABLE, RELOPT_BASEREL, RelOptInfo::reloptkind, RTE_CTE, RTE_FUNCTION, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RelOptInfo::rtekind, set_append_rel_pathlist(), set_cheapest(), set_foreign_pathlist(), set_function_pathlist(), set_plain_rel_pathlist(), set_rel_pathlist_hook, set_tablefunc_pathlist(), set_tablesample_rel_pathlist(), set_values_pathlist(), and RangeTblEntry::tablesample.

Referenced by set_append_rel_pathlist(), and set_base_rel_pathlists().

425 {
426  if (IS_DUMMY_REL(rel))
427  {
428  /* We already proved the relation empty, so nothing more to do */
429  }
430  else if (rte->inh)
431  {
432  /* It's an "append relation", process accordingly */
433  set_append_rel_pathlist(root, rel, rti, rte);
434  }
435  else
436  {
437  switch (rel->rtekind)
438  {
439  case RTE_RELATION:
440  if (rte->relkind == RELKIND_FOREIGN_TABLE)
441  {
442  /* Foreign table */
443  set_foreign_pathlist(root, rel, rte);
444  }
445  else if (rte->tablesample != NULL)
446  {
447  /* Sampled relation */
448  set_tablesample_rel_pathlist(root, rel, rte);
449  }
450  else
451  {
452  /* Plain relation */
453  set_plain_rel_pathlist(root, rel, rte);
454  }
455  break;
456  case RTE_SUBQUERY:
457  /* Subquery --- fully handled during set_rel_size */
458  break;
459  case RTE_FUNCTION:
460  /* RangeFunction */
461  set_function_pathlist(root, rel, rte);
462  break;
463  case RTE_TABLEFUNC:
464  /* Table Function */
465  set_tablefunc_pathlist(root, rel, rte);
466  break;
467  case RTE_VALUES:
468  /* Values list */
469  set_values_pathlist(root, rel, rte);
470  break;
471  case RTE_CTE:
472  /* CTE reference --- fully handled during set_rel_size */
473  break;
474  case RTE_NAMEDTUPLESTORE:
475  /* tuplestore reference --- fully handled during set_rel_size */
476  break;
477  default:
478  elog(ERROR, "unexpected rtekind: %d", (int) rel->rtekind);
479  break;
480  }
481  }
482 
483  /*
484  * If this is a baserel, consider gathering any partial paths we may have
485  * created for it. (If we tried to gather inheritance children, we could
486  * end up with a very large number of gather nodes, each trying to grab
487  * its own pool of workers, so don't do this for otherrels. Instead,
488  * we'll consider gathering partial paths for the parent appendrel.)
489  */
490  if (rel->reloptkind == RELOPT_BASEREL)
491  generate_gather_paths(root, rel);
492 
493  /*
494  * Allow a plugin to editorialize on the set of Paths for this base
495  * relation. It could add new paths (such as CustomPaths) by calling
496  * add_path(), or delete or modify paths added by the core code.
497  */
499  (*set_rel_pathlist_hook) (root, rel, rti, rte);
500 
501  /* Now find the cheapest of the paths for this rel */
502  set_cheapest(rel);
503 
504 #ifdef OPTIMIZER_DEBUG
505  debug_print_rel(root, rel);
506 #endif
507 }
RelOptKind reloptkind
Definition: relation.h:582
set_rel_pathlist_hook_type set_rel_pathlist_hook
Definition: allpaths.c:65
#define ERROR
Definition: elog.h:43
#define IS_DUMMY_REL(r)
Definition: relation.h:1281
static void set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
Definition: allpaths.c:1259
static void set_foreign_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:843
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
void generate_gather_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: allpaths.c:2447
static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:689
void set_cheapest(RelOptInfo *parent_rel)
Definition: pathnode.c:244
RTEKind rtekind
Definition: relation.h:615
static void set_tablesample_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:778
static void set_tablefunc_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:2275
#define elog
Definition: elog.h:219
static void set_function_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:2187
static void set_values_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:2255
struct TableSampleClause * tablesample
Definition: parsenodes.h:969

◆ set_rel_size()

static void set_rel_size ( PlannerInfo root,
RelOptInfo rel,
Index  rti,
RangeTblEntry rte 
)
static

Definition at line 320 of file allpaths.c.

References Assert, elog, ERROR, RangeTblEntry::inh, IS_DUMMY_REL, relation_excluded_by_constraints(), RangeTblEntry::relkind, RELKIND_FOREIGN_TABLE, RELKIND_PARTITIONED_TABLE, RELOPT_BASEREL, RelOptInfo::reloptkind, RelOptInfo::rows, RTE_CTE, RTE_FUNCTION, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RelOptInfo::rtekind, RangeTblEntry::self_reference, set_append_rel_size(), set_cte_pathlist(), set_dummy_rel_pathlist(), set_foreign_size(), set_function_size_estimates(), set_namedtuplestore_pathlist(), set_plain_rel_size(), set_subquery_pathlist(), set_tablefunc_size_estimates(), set_tablesample_rel_size(), set_values_size_estimates(), set_worktable_pathlist(), and RangeTblEntry::tablesample.

Referenced by set_append_rel_size(), and set_base_rel_sizes().

322 {
323  if (rel->reloptkind == RELOPT_BASEREL &&
324  relation_excluded_by_constraints(root, rel, rte))
325  {
326  /*
327  * We proved we don't need to scan the rel via constraint exclusion,
328  * so set up a single dummy path for it. Here we only check this for
329  * regular baserels; if it's an otherrel, CE was already checked in
330  * set_append_rel_size().
331  *
332  * In this case, we go ahead and set up the relation's path right away
333  * instead of leaving it for set_rel_pathlist to do. This is because
334  * we don't have a convention for marking a rel as dummy except by
335  * assigning a dummy path to it.
336  */
338  }
339  else if (rte->inh)
340  {
341  /* It's an "append relation", process accordingly */
342  set_append_rel_size(root, rel, rti, rte);
343  }
344  else
345  {
346  switch (rel->rtekind)
347  {
348  case RTE_RELATION:
349  if (rte->relkind == RELKIND_FOREIGN_TABLE)
350  {
351  /* Foreign table */
352  set_foreign_size(root, rel, rte);
353  }
354  else if (rte->relkind == RELKIND_PARTITIONED_TABLE)
355  {
356  /*
357  * A partitioned table without any partitions is marked as
358  * a dummy rel.
359  */
361  }
362  else if (rte->tablesample != NULL)
363  {
364  /* Sampled relation */
365  set_tablesample_rel_size(root, rel, rte);
366  }
367  else
368  {
369  /* Plain relation */
370  set_plain_rel_size(root, rel, rte);
371  }
372  break;
373  case RTE_SUBQUERY:
374 
375  /*
376  * Subqueries don't support making a choice between
377  * parameterized and unparameterized paths, so just go ahead
378  * and build their paths immediately.
379  */
380  set_subquery_pathlist(root, rel, rti, rte);
381  break;
382  case RTE_FUNCTION:
383  set_function_size_estimates(root, rel);
384  break;
385  case RTE_TABLEFUNC:
386  set_tablefunc_size_estimates(root, rel);
387  break;
388  case RTE_VALUES:
389  set_values_size_estimates(root, rel);
390  break;
391  case RTE_CTE:
392 
393  /*
394  * CTEs don't support making a choice between parameterized
395  * and unparameterized paths, so just go ahead and build their
396  * paths immediately.
397  */
398  if (rte->self_reference)
399  set_worktable_pathlist(root, rel, rte);
400  else
401  set_cte_pathlist(root, rel, rte);
402  break;
403  case RTE_NAMEDTUPLESTORE:
404  set_namedtuplestore_pathlist(root, rel, rte);
405  break;
406  default:
407  elog(ERROR, "unexpected rtekind: %d", (int) rel->rtekind);
408  break;
409  }
410  }
411 
412  /*
413  * We insist that all non-dummy rels have a nonzero rowcount estimate.
414  */
415  Assert(rel->rows > 0 || IS_DUMMY_REL(rel));
416 }
RelOptKind reloptkind
Definition: relation.h:582
static void set_cte_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:2299
static void set_foreign_size(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:826
bool relation_excluded_by_constraints(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: plancat.c:1357
static void set_namedtuplestore_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:2365
static void set_append_rel_size(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
Definition: allpaths.c:861
void set_dummy_rel_pathlist(RelOptInfo *rel)
Definition: allpaths.c:1953
#define ERROR
Definition: elog.h:43
#define IS_DUMMY_REL(r)
Definition: relation.h:1281
static void set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
Definition: allpaths.c:2010
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
static void set_tablesample_rel_size(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:738
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
bool self_reference
Definition: parsenodes.h:1023
RTEKind rtekind
Definition: relation.h:615
double rows
Definition: relation.h:588
#define Assert(condition)
Definition: c.h:670
void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4901
static void set_plain_rel_size(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:514
void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4879
void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4841
#define elog
Definition: elog.h:219
struct TableSampleClause * tablesample
Definition: parsenodes.h:969
static void set_worktable_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
Definition: allpaths.c:2395

◆ set_subquery_pathlist()

static void set_subquery_pathlist ( PlannerInfo root,
RelOptInfo rel,
Index  rti,
RangeTblEntry rte 
)
static

Definition at line 2010 of file allpaths.c.

References add_path(), Assert, RelOptInfo::baserestrictinfo, RestrictInfo::clause, convert_subquery_pathkeys(), copyObject, create_subqueryscan_path(), Query::distinctClause, fetch_upper_rel(), PlannerInfo::glob, Query::groupClause, Query::groupingSets, has_multiple_baserels(), Query::hasAggs, Query::havingQual, IS_DUMMY_REL, lappend(), RelOptInfo::lateral_relids, lfirst, list_length(), make_tlist_from_pathtarget(), NIL, palloc0(), parse(), PlannerInfo::parse, Path::pathkeys, RelOptInfo::pathlist, Path::pathtarget, pfree(), PlannerInfo::plan_params, RestrictInfo::pseudoconstant, qual_is_pushdown_safe(), remove_unused_subquery_outputs(), RangeTblEntry::security_barrier, set_dummy_rel_pathlist(), set_subquery_size_estimates(), Query::sortClause, subpath(), RelOptInfo::subplan_params, RangeTblEntry::subquery, subquery_is_pushdown_safe(), subquery_planner(), subquery_push_qual(), RelOptInfo::subroot, Query::targetList, PlannerInfo::tuple_fraction, pushdown_safety_info::unsafeColumns, pushdown_safety_info::unsafeLeaky, and UPPERREL_FINAL.

Referenced by set_rel_size().

2012 {
2013  Query *parse = root->parse;
2014  Query *subquery = rte->subquery;
2015  Relids required_outer;
2016  pushdown_safety_info safetyInfo;
2017  double tuple_fraction;
2018  RelOptInfo *sub_final_rel;
2019  ListCell *lc;
2020 
2021  /*
2022  * Must copy the Query so that planning doesn't mess up the RTE contents
2023  * (really really need to fix the planner to not scribble on its input,
2024  * someday ... but see remove_unused_subquery_outputs to start with).
2025  */
2026  subquery = copyObject(subquery);
2027 
2028  /*
2029  * If it's a LATERAL subquery, it might contain some Vars of the current
2030  * query level, requiring it to be treated as parameterized, even though
2031  * we don't support pushing down join quals into subqueries.
2032  */
2033  required_outer = rel->lateral_relids;
2034 
2035  /*
2036  * Zero out result area for subquery_is_pushdown_safe, so that it can set
2037  * flags as needed while recursing. In particular, we need a workspace
2038  * for keeping track of unsafe-to-reference columns. unsafeColumns[i]
2039  * will be set true if we find that output column i of the subquery is
2040  * unsafe to use in a pushed-down qual.
2041  */
2042  memset(&safetyInfo, 0, sizeof(safetyInfo));
2043  safetyInfo.unsafeColumns = (bool *)
2044  palloc0((list_length(subquery->targetList) + 1) * sizeof(bool));
2045 
2046  /*
2047  * If the subquery has the "security_barrier" flag, it means the subquery
2048  * originated from a view that must enforce row level security. Then we
2049  * must not push down quals that contain leaky functions. (Ideally this
2050  * would be checked inside subquery_is_pushdown_safe, but since we don't
2051  * currently pass the RTE to that function, we must do it here.)
2052  */
2053  safetyInfo.unsafeLeaky = rte->security_barrier;
2054 
2055  /*
2056  * If there are any restriction clauses that have been attached to the
2057  * subquery relation, consider pushing them down to become WHERE or HAVING
2058  * quals of the subquery itself. This transformation is useful because it
2059  * may allow us to generate a better plan for the subquery than evaluating
2060  * all the subquery output rows and then filtering them.
2061  *
2062  * There are several cases where we cannot push down clauses. Restrictions
2063  * involving the subquery are checked by subquery_is_pushdown_safe().
2064  * Restrictions on individual clauses are checked by
2065  * qual_is_pushdown_safe(). Also, we don't want to push down
2066  * pseudoconstant clauses; better to have the gating node above the
2067  * subquery.
2068  *
2069  * Non-pushed-down clauses will get evaluated as qpquals of the
2070  * SubqueryScan node.
2071  *
2072  * XXX Are there any cases where we want to make a policy decision not to
2073  * push down a pushable qual, because it'd result in a worse plan?
2074  */
2075  if (rel->baserestrictinfo != NIL &&
2076  subquery_is_pushdown_safe(subquery, subquery, &safetyInfo))
2077  {
2078  /* OK to consider pushing down individual quals */
2079  List *upperrestrictlist = NIL;
2080  ListCell *l;
2081 
2082  foreach(l, rel->baserestrictinfo)
2083  {
2084  RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
2085  Node *clause = (Node *) rinfo->clause;
2086 
2087  if (!rinfo->pseudoconstant &&
2088  qual_is_pushdown_safe(subquery, rti, clause, &safetyInfo))
2089  {
2090  /* Push it down */
2091  subquery_push_qual(subquery, rte, rti, clause);
2092  }
2093  else
2094  {
2095  /* Keep it in the upper query */
2096  upperrestrictlist = lappend(upperrestrictlist, rinfo);
2097  }
2098  }
2099  rel->baserestrictinfo = upperrestrictlist;
2100  /* We don't bother recomputing baserestrict_min_security */
2101  }
2102 
2103  pfree(safetyInfo.unsafeColumns);
2104 
2105  /*
2106  * The upper query might not use all the subquery's output columns; if
2107  * not, we can simplify.
2108  */
2109  remove_unused_subquery_outputs(subquery, rel);
2110 
2111  /*
2112  * We can safely pass the outer tuple_fraction down to the subquery if the
2113  * outer level has no joining, aggregation, or sorting to do. Otherwise
2114  * we'd better tell the subquery to plan for full retrieval. (XXX This
2115  * could probably be made more intelligent ...)
2116  */
2117  if (parse->hasAggs ||
2118  parse->groupClause ||
2119  parse->groupingSets ||
2120  parse->havingQual ||
2121  parse->distinctClause ||
2122  parse->sortClause ||
2123  has_multiple_baserels(root))
2124  tuple_fraction = 0.0; /* default case */
2125  else
2126  tuple_fraction = root->tuple_fraction;
2127 
2128  /* plan_params should not be in use in current query level */
2129  Assert(root->plan_params == NIL);
2130 
2131  /* Generate a subroot and Paths for the subquery */
2132  rel->subroot = subquery_planner(root->glob, subquery,
2133  root,
2134  false, tuple_fraction);
2135 
2136  /* Isolate the params needed by this specific subplan */
2137  rel->subplan_params = root->plan_params;
2138  root->plan_params = NIL;
2139 
2140  /*
2141  * It's possible that constraint exclusion proved the subquery empty. If
2142  * so, it's desirable to produce an unadorned dummy path so that we will
2143  * recognize appropriate optimizations at this query level.
2144  */
2145  sub_final_rel = fetch_upper_rel(rel->subroot, UPPERREL_FINAL, NULL);
2146 
2147  if (IS_DUMMY_REL(sub_final_rel))
2148  {
2150  return;
2151  }
2152 
2153  /*
2154  * Mark rel with estimated output rows, width, etc. Note that we have to
2155  * do this before generating outer-query paths, else cost_subqueryscan is
2156  * not happy.
2157  */
2158  set_subquery_size_estimates(root, rel);
2159 
2160  /*
2161  * For each Path that subquery_planner produced, make a SubqueryScanPath
2162  * in the outer query.
2163  */
2164  foreach(lc, sub_final_rel->pathlist)
2165  {
2166  Path *subpath = (Path *) lfirst(lc);
2167  List *pathkeys;
2168 
2169  /* Convert subpath's pathkeys to outer representation */
2170  pathkeys = convert_subquery_pathkeys(root,
2171  rel,
2172  subpath->pathkeys,
2174 
2175  /* Generate outer path using this subpath */
2176  add_path(rel, (Path *)
2177  create_subqueryscan_path(root, rel, subpath,
2178  pathkeys, required_outer));
2179  }
2180 }
void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4761
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
Query * parse
Definition: relation.h:155
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
SubqueryScanPath * create_subqueryscan_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, Relids required_outer)
Definition: pathnode.c:1841
List * plan_params
Definition: relation.h:169
List * sortClause
Definition: parsenodes.h:156
List * baserestrictinfo
Definition: relation.h:645
bool hasAggs
Definition: parsenodes.h:123
bool pseudoconstant
Definition: relation.h:1849
List * groupingSets
Definition: parsenodes.h:148
Definition: nodes.h:512
List * make_tlist_from_pathtarget(PathTarget *target)
Definition: tlist.c:595
bool * unsafeColumns
Definition: allpaths.c:53
char bool
Definition: c.h:247
List * targetList
Definition: parsenodes.h:138
PlannerInfo * subroot
Definition: relation.h:627
Relids lateral_relids
Definition: relation.h:610
double tuple_fraction
Definition: relation.h:294
void set_dummy_rel_pathlist(RelOptInfo *rel)
Definition: allpaths.c:1953
void pfree(void *pointer)
Definition: mcxt.c:949
List * distinctClause
Definition: parsenodes.h:154
#define IS_DUMMY_REL(r)
Definition: relation.h:1281
RelOptInfo * fetch_upper_rel(PlannerInfo *root, UpperRelationKind kind, Relids relids)
Definition: relnode.c:1137
List * convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, List *subquery_pathkeys, List *subquery_tlist)
Definition: pathkeys.c:607
PlannerGlobal * glob
Definition: relation.h:157
static void remove_unused_subquery_outputs(Query *subquery, RelOptInfo *rel)
Definition: allpaths.c:3186
List * lappend(List *list, void *datum)
Definition: list.c:128
Expr * clause
Definition: relation.h:1841
static bool qual_is_pushdown_safe(Query *subquery, Index rti, Node *qual, pushdown_safety_info *safetyInfo)
Definition: allpaths.c:3015
void * palloc0(Size size)
Definition: mcxt.c:877
bool security_barrier
Definition: parsenodes.h:975
List * pathkeys
Definition: relation.h:1056
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
static bool has_multiple_baserels(PlannerInfo *root)
Definition: allpaths.c:1977
static void subquery_push_qual(Query *subquery, RangeTblEntry *rte, Index rti, Node *qual)
Definition: allpaths.c:3092
static int list_length(const List *l)
Definition: pg_list.h:89
static bool subquery_is_pushdown_safe(Query *subquery, Query *topquery, pushdown_safety_info *safetyInfo)
Definition: allpaths.c:2753
Query * subquery
Definition: parsenodes.h:974
List * groupClause
Definition: parsenodes.h:146
List * pathlist
Definition: relation.h:599
#define copyObject(obj)
Definition: nodes.h:625
Node * havingQual
Definition: parsenodes.h:150
Definition: pg_list.h:45
List * subplan_params
Definition: relation.h:628
PlannerInfo * subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root, bool hasRecursion, double tuple_fraction)
Definition: planner.c:517
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
static struct subre * parse(struct vars *, int, int, struct state *, struct state *)
Definition: regcomp.c:649

◆ set_tablefunc_pathlist()

static void set_tablefunc_pathlist ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 2275 of file allpaths.c.

References add_path(), create_tablefuncscan_path(), and RelOptInfo::lateral_relids.

Referenced by set_rel_pathlist().

2276 {
2277  Relids required_outer;
2278 
2279  /*
2280  * We don't support pushing join clauses into the quals of a tablefunc
2281  * scan, but it could still have required parameterization due to LATERAL
2282  * refs in the function expression.
2283  */
2284  required_outer = rel->lateral_relids;
2285 
2286  /* Generate appropriate path */
2287  add_path(rel, create_tablefuncscan_path(root, rel,
2288  required_outer));
2289 }
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
Relids lateral_relids
Definition: relation.h:610
Path * create_tablefuncscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: pathnode.c:1895

◆ set_tablesample_rel_pathlist()

static void set_tablesample_rel_pathlist ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 778 of file allpaths.c.

References add_path(), PlannerInfo::all_baserels, bms_membership(), BMS_SINGLETON, create_material_path(), create_samplescan_path(), GetTsmRoutine(), RelOptInfo::lateral_relids, PlannerInfo::query_level, TsmRoutine::repeatable_across_scans, RangeTblEntry::tablesample, and TableSampleClause::tsmhandler.

Referenced by set_rel_pathlist().

779 {
780  Relids required_outer;
781  Path *path;
782 
783  /*
784  * We don't support pushing join clauses into the quals of a samplescan,
785  * but it could still have required parameterization due to LATERAL refs
786  * in its tlist or TABLESAMPLE arguments.
787  */
788  required_outer = rel->lateral_relids;
789 
790  /* Consider sampled scan */
791  path = create_samplescan_path(root, rel, required_outer);
792 
793  /*
794  * If the sampling method does not support repeatable scans, we must avoid
795  * plans that would scan the rel multiple times. Ideally, we'd simply
796  * avoid putting the rel on the inside of a nestloop join; but adding such
797  * a consideration to the planner seems like a great deal of complication
798  * to support an uncommon usage of second-rate sampling methods. Instead,
799  * if there is a risk that the query might perform an unsafe join, just
800  * wrap the SampleScan in a Materialize node. We can check for joins by
801  * counting the membership of all_baserels (note that this correctly
802  * counts inheritance trees as single rels). If we're inside a subquery,
803  * we can't easily check whether a join might occur in the outer query, so
804  * just assume one is possible.
805  *
806  * GetTsmRoutine is relatively expensive compared to the other tests here,
807  * so check repeatable_across_scans last, even though that's a bit odd.
808  */
809  if ((root->query_level > 1 ||
812  {
813  path = (Path *) create_material_path(rel, path);
814  }
815 
816  add_path(rel, path);
817 
818  /* For the moment, at least, there are no other paths to consider */
819 }
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
MaterialPath * create_material_path(RelOptInfo *rel, Path *subpath)
Definition: pathnode.c:1453
Relids lateral_relids
Definition: relation.h:610
Relids all_baserels
Definition: relation.h:196
BMS_Membership bms_membership(const Bitmapset *a)
Definition: bitmapset.c:634
Path * create_samplescan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: pathnode.c:973
TsmRoutine * GetTsmRoutine(Oid tsmhandler)
Definition: tablesample.c:27
bool repeatable_across_scans
Definition: tsmapi.h:64
Index query_level
Definition: relation.h:159
struct TableSampleClause * tablesample
Definition: parsenodes.h:969

◆ set_tablesample_rel_size()

static void set_tablesample_rel_size ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 738 of file allpaths.c.

References TableSampleClause::args, check_index_predicates(), GetTsmRoutine(), RelOptInfo::pages, TsmRoutine::SampleScanGetSampleSize, set_baserel_size_estimates(), RangeTblEntry::tablesample, TableSampleClause::tsmhandler, and RelOptInfo::tuples.

Referenced by set_rel_size().

739 {
740  TableSampleClause *tsc = rte->tablesample;
741  TsmRoutine *tsm;
742  BlockNumber pages;
743  double tuples;
744 
745  /*
746  * Test any partial indexes of rel for applicability. We must do this
747  * first since partial unique indexes can affect size estimates.
748  */
749  check_index_predicates(root, rel);
750 
751  /*
752  * Call the sampling method's estimation function to estimate the number
753  * of pages it will read and the number of tuples it will return. (Note:
754  * we assume the function returns sane values.)
755  */
756  tsm = GetTsmRoutine(tsc->tsmhandler);
757  tsm->SampleScanGetSampleSize(root, rel, tsc->args,
758  &pages, &tuples);
759 
760  /*
761  * For the moment, because we will only consider a SampleScan path for the
762  * rel, it's okay to just overwrite the pages and tuples estimates for the
763  * whole relation. If we ever consider multiple path types for sampled
764  * rels, we'll need more complication.
765  */
766  rel->pages = pages;
767  rel->tuples = tuples;
768 
769  /* Mark rel with estimated output rows, width, etc */
770  set_baserel_size_estimates(root, rel);
771 }
double tuples
Definition: relation.h:625
uint32 BlockNumber
Definition: block.h:31
void check_index_predicates(PlannerInfo *root, RelOptInfo *rel)
Definition: indxpath.c:2774
SampleScanGetSampleSize_function SampleScanGetSampleSize
Definition: tsmapi.h:67
void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
Definition: costsize.c:4249
TsmRoutine * GetTsmRoutine(Oid tsmhandler)
Definition: tablesample.c:27
BlockNumber pages
Definition: relation.h:624
struct TableSampleClause * tablesample
Definition: parsenodes.h:969

◆ set_values_pathlist()

static void set_values_pathlist ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 2255 of file allpaths.c.

References add_path(), create_valuesscan_path(), and RelOptInfo::lateral_relids.

Referenced by set_rel_pathlist().

2256 {
2257  Relids required_outer;
2258 
2259  /*
2260  * We don't support pushing join clauses into the quals of a values scan,
2261  * but it could still have required parameterization due to LATERAL refs
2262  * in the values expressions.
2263  */
2264  required_outer = rel->lateral_relids;
2265 
2266  /* Generate appropriate path */
2267  add_path(rel, create_valuesscan_path(root, rel, required_outer));
2268 }
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
Path * create_valuesscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: pathnode.c:1921
Relids lateral_relids
Definition: relation.h:610

◆ set_worktable_pathlist()

static void set_worktable_pathlist ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)
static

Definition at line 2395 of file allpaths.c.

References add_path(), create_worktablescan_path(), RangeTblEntry::ctelevelsup, RangeTblEntry::ctename, elog, ERROR, RelOptInfo::lateral_relids, PlannerInfo::non_recursive_path, PlannerInfo::parent_root, Path::rows, and set_cte_size_estimates().

Referenced by set_rel_size().

2396 {
2397  Path *ctepath;
2398  PlannerInfo *cteroot;
2399  Index levelsup;
2400  Relids required_outer;
2401 
2402  /*
2403  * We need to find the non-recursive term's path, which is in the plan
2404  * level that's processing the recursive UNION, which is one level *below*
2405  * where the CTE comes from.
2406  */
2407  levelsup = rte->ctelevelsup;
2408  if (levelsup == 0) /* shouldn't happen */
2409  elog(ERROR, "bad levelsup for CTE \"%s\"", rte->ctename);
2410  levelsup--;
2411  cteroot = root;
2412  while (levelsup-- > 0)
2413  {
2414  cteroot = cteroot->parent_root;
2415  if (!cteroot) /* shouldn't happen */
2416  elog(ERROR, "bad levelsup for CTE \"%s\"", rte->ctename);
2417  }
2418  ctepath = cteroot->non_recursive_path;
2419  if (!ctepath) /* shouldn't happen */
2420  elog(ERROR, "could not find path for CTE \"%s\"", rte->ctename);
2421 
2422  /* Mark rel with estimated output rows, width, etc */
2423  set_cte_size_estimates(root, rel, ctepath->rows);
2424 
2425  /*
2426  * We don't support pushing join clauses into the quals of a worktable
2427  * scan, but it could still have required parameterization due to LATERAL
2428  * refs in its tlist. (I'm not sure this is actually possible given the
2429  * restrictions on recursive references, but it's easy enough to support.)
2430  */
2431  required_outer = rel->lateral_relids;
2432 
2433  /* Generate appropriate path */
2434  add_path(rel, create_worktablescan_path(root, rel, required_outer));
2435 }
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:422
void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows)
Definition: costsize.c:4933
Relids lateral_relids
Definition: relation.h:610
#define ERROR
Definition: elog.h:43
Path * create_worktablescan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: pathnode.c:1998
struct PlannerInfo * parent_root
Definition: relation.h:161
unsigned int Index
Definition: c.h:413
double rows
Definition: relation.h:1052
struct Path * non_recursive_path
Definition: relation.h:312
Index ctelevelsup
Definition: parsenodes.h:1022
char * ctename
Definition: parsenodes.h:1021
#define elog
Definition: elog.h:219

◆ standard_join_search()

RelOptInfo* standard_join_search ( PlannerInfo root,
int  levels_needed,
List initial_rels 
)

Definition at line 2599 of file allpaths.c.

References Assert, elog, ERROR, generate_gather_paths(), generate_partition_wise_join_paths(), PlannerInfo::join_rel_level, join_search_one_level(), lfirst, linitial, list_length(), NIL, palloc0(), and set_cheapest().

Referenced by make_rel_from_joinlist().

2600 {
2601  int lev;
2602  RelOptInfo *rel;
2603 
2604  /*
2605  * This function cannot be invoked recursively within any one planning
2606  * problem, so join_rel_level[] can't be in use already.
2607  */
2608  Assert(root->join_rel_level == NULL);
2609 
2610  /*
2611  * We employ a simple "dynamic programming" algorithm: we first find all
2612  * ways to build joins of two jointree items, then all ways to build joins
2613  * of three items (from two-item joins and single items), then four-item
2614  * joins, and so on until we have considered all ways to join all the
2615  * items into one rel.
2616  *
2617  * root->join_rel_level[j] is a list of all the j-item rels. Initially we
2618  * set root->join_rel_level[1] to represent all the single-jointree-item
2619  * relations.
2620  */
2621  root->join_rel_level = (List **) palloc0((levels_needed + 1) * sizeof(List *));
2622 
2623  root->join_rel_level[1] = initial_rels;
2624 
2625  for (lev = 2; lev <= levels_needed; lev++)
2626  {
2627  ListCell *lc;
2628 
2629  /*
2630  * Determine all possible pairs of relations to be joined at this
2631  * level, and build paths for making each one from every available
2632  * pair of lower-level relations.
2633  */
2634  join_search_one_level(root, lev);
2635 
2636  /*
2637  * Run generate_partition_wise_join_paths() and
2638  * generate_gather_paths() for each just-processed joinrel. We could
2639  * not do this earlier because both regular and partial paths can get
2640  * added to a particular joinrel at multiple times within
2641  * join_search_one_level.
2642  *
2643  * After that, we're done creating paths for the joinrel, so run
2644  * set_cheapest().
2645  */
2646  foreach(lc, root->join_rel_level[lev])
2647  {
2648  rel = (RelOptInfo *) lfirst(lc);
2649 
2650  /* Create paths for partition-wise joins. */
2652 
2653  /* Create GatherPaths for any useful partial paths for rel */
2654  generate_gather_paths(root, rel);
2655 
2656  /* Find and save the cheapest paths for this rel */
2657  set_cheapest(rel);
2658 
2659 #ifdef OPTIMIZER_DEBUG
2660  debug_print_rel(root, rel);
2661 #endif
2662  }
2663  }
2664 
2665  /*
2666  * We should have a single rel at the final level.
2667  */
2668  if (root->join_rel_level[levels_needed] == NIL)
2669  elog(ERROR, "failed to build any %d-way joins", levels_needed);
2670  Assert(list_length(root->join_rel_level[levels_needed]) == 1);
2671 
2672  rel = (RelOptInfo *) linitial(root->join_rel_level[levels_needed]);
2673 
2674  root->join_rel_level = NULL;
2675 
2676  return rel;
2677 }
#define NIL
Definition: pg_list.h:69
void generate_partition_wise_join_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: allpaths.c:3412
#define linitial(l)
Definition: pg_list.h:111
#define ERROR
Definition: elog.h:43
void generate_gather_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: allpaths.c:2447
void join_search_one_level(PlannerInfo *root, int level)
Definition: joinrels.c:66
void set_cheapest(RelOptInfo *parent_rel)
Definition: pathnode.c:244
void * palloc0(Size size)
Definition: mcxt.c:877
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
List ** join_rel_level
Definition: relation.h:225
static int list_length(const List *l)
Definition: pg_list.h:89
#define elog
Definition: elog.h:219
Definition: pg_list.h:45

◆ subquery_is_pushdown_safe()

static bool subquery_is_pushdown_safe ( Query subquery,
Query topquery,
pushdown_safety_info safetyInfo 
)
static

Definition at line 2753 of file allpaths.c.

References Assert, castNode, check_output_expressions(), SetOperationStmt::colTypes, compare_tlist_datatypes(), Query::distinctClause, Query::hasTargetSRFs, Query::hasWindowFuncs, Query::limitCount, Query::limitOffset, recurse_pushdown_safe(), Query::setOperations, Query::targetList, and pushdown_safety_info::unsafeVolatile.

Referenced by recurse_pushdown_safe(), and set_subquery_pathlist().

2755 {
2756  SetOperationStmt *topop;
2757 
2758  /* Check point 1 */
2759  if (subquery->limitOffset != NULL || subquery->limitCount != NULL)
2760  return false;
2761 
2762  /* Check points 3, 4, and 5 */
2763  if (subquery->distinctClause ||
2764  subquery->hasWindowFuncs ||
2765  subquery->hasTargetSRFs)
2766  safetyInfo->unsafeVolatile = true;
2767 
2768  /*
2769  * If we're at a leaf query, check for unsafe expressions in its target
2770  * list, and mark any unsafe ones in unsafeColumns[]. (Non-leaf nodes in
2771  * setop trees have only simple Vars in their tlists, so no need to check
2772  * them.)
2773  */
2774  if (subquery->setOperations == NULL)
2775  check_output_expressions(subquery, safetyInfo);
2776 
2777  /* Are we at top level, or looking at a setop component? */
2778  if (subquery == topquery)
2779  {
2780  /* Top level, so check any component queries */
2781  if (subquery->setOperations != NULL)
2782  if (!recurse_pushdown_safe(subquery->setOperations, topquery,
2783  safetyInfo))
2784  return false;
2785  }
2786  else
2787  {
2788  /* Setop component must not have more components (too weird) */
2789  if (subquery->setOperations != NULL)
2790  return false;
2791  /* Check whether setop component output types match top level */
2792  topop = castNode(SetOperationStmt, topquery->setOperations);
2793  Assert(topop);
2795  topop->colTypes,
2796  safetyInfo);
2797  }
2798  return true;
2799 }
Node * limitOffset
Definition: parsenodes.h:158
#define castNode(_type_, nodeptr)
Definition: nodes.h:581
static bool recurse_pushdown_safe(Node *setOp, Query *topquery, pushdown_safety_info *safetyInfo)
Definition: allpaths.c:2805
static void compare_tlist_datatypes(List *tlist, List *colTypes, pushdown_safety_info *safetyInfo)
Definition: allpaths.c:2940
List * targetList
Definition: parsenodes.h:138
List * distinctClause
Definition: parsenodes.h:154
Node * limitCount
Definition: parsenodes.h:159
static void check_output_expressions(Query *subquery, pushdown_safety_info *safetyInfo)
Definition: allpaths.c:2872
bool hasTargetSRFs
Definition: parsenodes.h:125
#define Assert(condition)
Definition: c.h:670
bool hasWindowFuncs
Definition: parsenodes.h:124
Node * setOperations
Definition: parsenodes.h:163

◆ subquery_push_qual()

static void subquery_push_qual ( Query subquery,
RangeTblEntry rte,
Index  rti,
Node qual 
)
static

Definition at line 3092 of file allpaths.c.

References Query::groupClause, Query::groupingSets, Query::hasAggs, Query::hasSubLinks, Query::havingQual, Query::jointree, make_and_qual(), FromExpr::quals, recurse_push_qual(), REPLACEVARS_REPORT_ERROR, ReplaceVarsFromTargetList(), Query::setOperations, and Query::targetList.

Referenced by recurse_push_qual(), and set_subquery_pathlist().

3093 {
3094  if (subquery->setOperations != NULL)
3095  {
3096  /* Recurse to push it separately to each component query */
3097  recurse_push_qual(subquery->setOperations, subquery,
3098  rte, rti, qual);
3099  }
3100  else
3101  {
3102  /*
3103  * We need to replace Vars in the qual (which must refer to outputs of
3104  * the subquery) with copies of the subquery's targetlist expressions.
3105  * Note that at this point, any uplevel Vars in the qual should have
3106  * been replaced with Params, so they need no work.
3107  *
3108  * This step also ensures that when we are pushing into a setop tree,
3109  * each component query gets its own copy of the qual.
3110  */
3111  qual = ReplaceVarsFromTargetList(qual, rti, 0, rte,
3112  subquery->targetList,
3114  &subquery->hasSubLinks);
3115 
3116  /*
3117  * Now attach the qual to the proper place: normally WHERE, but if the
3118  * subquery uses grouping or aggregation, put it in HAVING (since the
3119  * qual really refers to the group-result rows).
3120  */
3121  if (subquery->hasAggs || subquery->groupClause || subquery->groupingSets || subquery->havingQual)
3122  subquery->havingQual = make_and_qual(subquery->havingQual, qual);
3123  else
3124  subquery->jointree->quals =
3125  make_and_qual(subquery->jointree->quals, qual);
3126 
3127  /*
3128  * We need not change the subquery's hasAggs or hasSubLinks flags,
3129  * since we can't be pushing down any aggregates that weren't there
3130  * before, and we don't push down subselects at all.
3131  */
3132  }
3133 }
Node * make_and_qual(Node *qual1, Node *qual2)
Definition: clauses.c:348
FromExpr * jointree
Definition: parsenodes.h:136
bool hasAggs
Definition: parsenodes.h:123
List * groupingSets
Definition: parsenodes.h:148
Node * quals
Definition: primnodes.h:1479
List * targetList
Definition: parsenodes.h:138
Node * ReplaceVarsFromTargetList(Node *node, int target_varno, int sublevels_up, RangeTblEntry *target_rte, List *targetlist, ReplaceVarsNoMatchOption nomatch_option, int nomatch_varno, bool *outer_hasSubLinks)
static void recurse_push_qual(Node *setOp, Query *topquery, RangeTblEntry *rte, Index rti, Node *qual)
Definition: allpaths.c:3139
Node * setOperations
Definition: parsenodes.h:163
List * groupClause
Definition: parsenodes.h:146
bool hasSubLinks
Definition: parsenodes.h:126
Node * havingQual
Definition: parsenodes.h:150

◆ targetIsInAllPartitionLists()

static bool targetIsInAllPartitionLists ( TargetEntry tle,
Query query 
)
static

Definition at line 2973 of file allpaths.c.

References InvalidOid, lfirst, WindowClause::partitionClause, targetIsInSortList(), and Query::windowClause.

Referenced by check_output_expressions().

2974 {
2975  ListCell *lc;
2976 
2977  foreach(lc, query->windowClause)
2978  {
2979  WindowClause *wc = (WindowClause *) lfirst(lc);
2980 
2982  return false;
2983  }
2984  return true;
2985 }
List * windowClause
Definition: parsenodes.h:152
List * partitionClause
Definition: parsenodes.h:1289
#define InvalidOid
Definition: postgres_ext.h:36
bool targetIsInSortList(TargetEntry *tle, Oid sortop, List *sortList)
#define lfirst(lc)
Definition: pg_list.h:106

Variable Documentation

◆ enable_geqo

bool enable_geqo = false

Definition at line 59 of file allpaths.c.

Referenced by make_rel_from_joinlist().

◆ geqo_threshold

int geqo_threshold

Definition at line 60 of file allpaths.c.

Referenced by make_rel_from_joinlist().

◆ join_search_hook

join_search_hook_type join_search_hook = NULL

Definition at line 68 of file allpaths.c.

Referenced by make_rel_from_joinlist().

◆ min_parallel_index_scan_size

int min_parallel_index_scan_size

Definition at line 62 of file allpaths.c.

Referenced by compute_parallel_worker().

◆ min_parallel_table_scan_size

int min_parallel_table_scan_size

Definition at line 61 of file allpaths.c.

Referenced by compute_parallel_worker().

◆ set_rel_pathlist_hook

set_rel_pathlist_hook_type set_rel_pathlist_hook = NULL

Definition at line 65 of file allpaths.c.

Referenced by set_rel_pathlist().