PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
restrictinfo.h File Reference
#include "nodes/relation.h"
Include dependency graph for restrictinfo.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define make_simple_restrictinfo(clause)   make_restrictinfo(clause, true, false, false, 0, NULL, NULL, NULL)
 

Functions

RestrictInfomake_restrictinfo (Expr *clause, bool is_pushed_down, bool outerjoin_delayed, bool pseudoconstant, Index security_level, Relids required_relids, Relids outer_relids, Relids nullable_relids)
 
bool restriction_is_or_clause (RestrictInfo *restrictinfo)
 
bool restriction_is_securely_promotable (RestrictInfo *restrictinfo, RelOptInfo *rel)
 
Listget_actual_clauses (List *restrictinfo_list)
 
Listextract_actual_clauses (List *restrictinfo_list, bool pseudoconstant)
 
void extract_actual_join_clauses (List *restrictinfo_list, List **joinquals, List **otherquals)
 
bool join_clause_is_movable_to (RestrictInfo *rinfo, RelOptInfo *baserel)
 
bool join_clause_is_movable_into (RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
 

Macro Definition Documentation

#define make_simple_restrictinfo (   clause)    make_restrictinfo(clause, true, false, false, 0, NULL, NULL, NULL)

Function Documentation

List* extract_actual_clauses ( List restrictinfo_list,
bool  pseudoconstant 
)

Definition at line 356 of file restrictinfo.c.

References RestrictInfo::clause, lappend(), lfirst_node, NIL, RestrictInfo::pseudoconstant, and result.

Referenced by create_bitmap_scan_plan(), create_ctescan_plan(), create_functionscan_plan(), create_hashjoin_plan(), create_indexscan_plan(), create_mergejoin_plan(), create_namedtuplestorescan_plan(), create_nestloop_plan(), create_samplescan_plan(), create_seqscan_plan(), create_subqueryscan_plan(), create_tablefuncscan_plan(), create_tidscan_plan(), create_valuesscan_plan(), create_worktablescan_plan(), fileGetForeignPlan(), get_gating_quals(), and postgresGetForeignPlan().

358 {
359  List *result = NIL;
360  ListCell *l;
361 
362  foreach(l, restrictinfo_list)
363  {
365 
366  if (rinfo->pseudoconstant == pseudoconstant)
367  result = lappend(result, rinfo->clause);
368  }
369  return result;
370 }
#define NIL
Definition: pg_list.h:69
bool pseudoconstant
Definition: relation.h:1755
return result
Definition: formatting.c:1633
#define lfirst_node(type, lc)
Definition: pg_list.h:109
List * lappend(List *list, void *datum)
Definition: list.c:128
Expr * clause
Definition: relation.h:1747
Definition: pg_list.h:45
void extract_actual_join_clauses ( List restrictinfo_list,
List **  joinquals,
List **  otherquals 
)

Definition at line 383 of file restrictinfo.c.

References Assert, RestrictInfo::clause, RestrictInfo::is_pushed_down, lappend(), lfirst_node, NIL, and RestrictInfo::pseudoconstant.

Referenced by create_hashjoin_plan(), create_mergejoin_plan(), and create_nestloop_plan().

386 {
387  ListCell *l;
388 
389  *joinquals = NIL;
390  *otherquals = NIL;
391 
392  foreach(l, restrictinfo_list)
393  {
395 
396  if (rinfo->is_pushed_down)
397  {
398  if (!rinfo->pseudoconstant)
399  *otherquals = lappend(*otherquals, rinfo->clause);
400  }
401  else
402  {
403  /* joinquals shouldn't have been marked pseudoconstant */
404  Assert(!rinfo->pseudoconstant);
405  *joinquals = lappend(*joinquals, rinfo->clause);
406  }
407  }
408 }
#define NIL
Definition: pg_list.h:69
bool pseudoconstant
Definition: relation.h:1755
#define lfirst_node(type, lc)
Definition: pg_list.h:109
List * lappend(List *list, void *datum)
Definition: list.c:128
Expr * clause
Definition: relation.h:1747
bool is_pushed_down
Definition: relation.h:1749
#define Assert(condition)
Definition: c.h:664
List* get_actual_clauses ( List restrictinfo_list)

Definition at line 333 of file restrictinfo.c.

References Assert, RestrictInfo::clause, lappend(), lfirst_node, NIL, RestrictInfo::pseudoconstant, and result.

Referenced by create_bitmap_subplan(), create_hashjoin_plan(), create_indexscan_plan(), create_join_plan(), create_mergejoin_plan(), and find_indexpath_quals().

334 {
335  List *result = NIL;
336  ListCell *l;
337 
338  foreach(l, restrictinfo_list)
339  {
341 
342  Assert(!rinfo->pseudoconstant);
343 
344  result = lappend(result, rinfo->clause);
345  }
346  return result;
347 }
#define NIL
Definition: pg_list.h:69
bool pseudoconstant
Definition: relation.h:1755
return result
Definition: formatting.c:1633
#define lfirst_node(type, lc)
Definition: pg_list.h:109
List * lappend(List *list, void *datum)
Definition: list.c:128
Expr * clause
Definition: relation.h:1747
#define Assert(condition)
Definition: c.h:664
Definition: pg_list.h:45
bool join_clause_is_movable_into ( RestrictInfo rinfo,
Relids  currentrelids,
Relids  current_and_outer 
)

Definition at line 510 of file restrictinfo.c.

References bms_is_subset(), bms_overlap(), RestrictInfo::clause_relids, RestrictInfo::nullable_relids, and RestrictInfo::outer_relids.

Referenced by create_nestloop_path(), get_baserel_parampathinfo(), get_joinrel_parampathinfo(), and has_indexed_join_quals().

513 {
514  /* Clause must be evaluable given available context */
515  if (!bms_is_subset(rinfo->clause_relids, current_and_outer))
516  return false;
517 
518  /* Clause must physically reference at least one target rel */
519  if (!bms_overlap(currentrelids, rinfo->clause_relids))
520  return false;
521 
522  /* Cannot move an outer-join clause into the join's outer side */
523  if (bms_overlap(currentrelids, rinfo->outer_relids))
524  return false;
525 
526  /*
527  * Target rel(s) must not be nullable below the clause. This is
528  * approximate, in the safe direction, because the current join might be
529  * above the join where the nulling would happen, in which case the clause
530  * would work correctly here. But we don't have enough info to be sure.
531  */
532  if (bms_overlap(currentrelids, rinfo->nullable_relids))
533  return false;
534 
535  return true;
536 }
Relids clause_relids
Definition: relation.h:1762
Relids outer_relids
Definition: relation.h:1768
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:308
Relids nullable_relids
Definition: relation.h:1771
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
bool join_clause_is_movable_to ( RestrictInfo rinfo,
RelOptInfo baserel 
)

Definition at line 437 of file restrictinfo.c.

References bms_is_member(), bms_overlap(), RestrictInfo::clause_relids, RelOptInfo::lateral_referencers, RestrictInfo::nullable_relids, RestrictInfo::outer_relids, and RelOptInfo::relid.

Referenced by check_index_predicates(), extract_restriction_or_clauses(), match_join_clauses_to_index(), and postgresGetForeignPaths().

438 {
439  /* Clause must physically reference target rel */
440  if (!bms_is_member(baserel->relid, rinfo->clause_relids))
441  return false;
442 
443  /* Cannot move an outer-join clause into the join's outer side */
444  if (bms_is_member(baserel->relid, rinfo->outer_relids))
445  return false;
446 
447  /* Target rel must not be nullable below the clause */
448  if (bms_is_member(baserel->relid, rinfo->nullable_relids))
449  return false;
450 
451  /* Clause must not use any rels with LATERAL references to this rel */
452  if (bms_overlap(baserel->lateral_referencers, rinfo->clause_relids))
453  return false;
454 
455  return true;
456 }
Relids clause_relids
Definition: relation.h:1762
Relids outer_relids
Definition: relation.h:1768
Index relid
Definition: relation.h:553
Relids lateral_referencers
Definition: relation.h:561
Relids nullable_relids
Definition: relation.h:1771
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:420
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 at line 57 of file restrictinfo.c.

References and_clause(), Assert, make_restrictinfo_internal(), make_sub_restrictinfos(), and or_clause().

Referenced by build_implied_join_equality(), consider_new_or_clause(), distribute_qual_to_rels(), foreign_grouping_ok(), and set_append_rel_size().

65 {
66  /*
67  * If it's an OR clause, build a modified copy with RestrictInfos inserted
68  * above each subclause of the top-level AND/OR structure.
69  */
70  if (or_clause((Node *) clause))
71  return (RestrictInfo *) make_sub_restrictinfos(clause,
72  is_pushed_down,
73  outerjoin_delayed,
74  pseudoconstant,
75  security_level,
76  required_relids,
77  outer_relids,
78  nullable_relids);
79 
80  /* Shouldn't be an AND clause, else AND/OR flattening messed up */
81  Assert(!and_clause((Node *) clause));
82 
83  return make_restrictinfo_internal(clause,
84  NULL,
85  is_pushed_down,
86  outerjoin_delayed,
87  pseudoconstant,
88  security_level,
89  required_relids,
90  outer_relids,
91  nullable_relids);
92 }
static RestrictInfo * make_restrictinfo_internal(Expr *clause, Expr *orclause, bool is_pushed_down, bool outerjoin_delayed, bool pseudoconstant, Index security_level, Relids required_relids, Relids outer_relids, Relids nullable_relids)
Definition: restrictinfo.c:100
Definition: nodes.h:509
bool and_clause(Node *clause)
Definition: clauses.c:314
bool or_clause(Node *clause)
Definition: clauses.c:280
static Expr * make_sub_restrictinfos(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:226
#define Assert(condition)
Definition: c.h:664
bool restriction_is_or_clause ( RestrictInfo restrictinfo)

Definition at line 295 of file restrictinfo.c.

References RestrictInfo::orclause.

Referenced by extract_or_clause(), extract_restriction_or_clauses(), generate_bitmap_or_paths(), and match_join_clauses_to_index().

296 {
297  if (restrictinfo->orclause != NULL)
298  return true;
299  else
300  return false;
301 }
Expr * orclause
Definition: relation.h:1778
bool restriction_is_securely_promotable ( RestrictInfo restrictinfo,
RelOptInfo rel 
)

Definition at line 310 of file restrictinfo.c.

References RelOptInfo::baserestrict_min_security, RestrictInfo::leakproof, and RestrictInfo::security_level.

Referenced by match_clause_to_index(), and TidQualFromBaseRestrictinfo().

312 {
313  /*
314  * It's okay if there are no baserestrictinfo clauses for the rel that
315  * would need to go before this one, *or* if this one is leakproof.
316  */
317  if (restrictinfo->security_level <= rel->baserestrict_min_security ||
318  restrictinfo->leakproof)
319  return true;
320  else
321  return false;
322 }
Index security_level
Definition: relation.h:1759
bool leakproof
Definition: relation.h:1757
Index baserestrict_min_security
Definition: relation.h:587