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 354 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().

356 {
357  List *result = NIL;
358  ListCell *l;
359 
360  foreach(l, restrictinfo_list)
361  {
363 
364  if (rinfo->pseudoconstant == pseudoconstant)
365  result = lappend(result, rinfo->clause);
366  }
367  return result;
368 }
#define NIL
Definition: pg_list.h:69
bool pseudoconstant
Definition: relation.h:1755
return result
Definition: formatting.c:1632
#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 381 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().

384 {
385  ListCell *l;
386 
387  *joinquals = NIL;
388  *otherquals = NIL;
389 
390  foreach(l, restrictinfo_list)
391  {
393 
394  if (rinfo->is_pushed_down)
395  {
396  if (!rinfo->pseudoconstant)
397  *otherquals = lappend(*otherquals, rinfo->clause);
398  }
399  else
400  {
401  /* joinquals shouldn't have been marked pseudoconstant */
402  Assert(!rinfo->pseudoconstant);
403  *joinquals = lappend(*joinquals, rinfo->clause);
404  }
405  }
406 }
#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:675
List* get_actual_clauses ( List restrictinfo_list)

Definition at line 331 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().

332 {
333  List *result = NIL;
334  ListCell *l;
335 
336  foreach(l, restrictinfo_list)
337  {
339 
340  Assert(!rinfo->pseudoconstant);
341 
342  result = lappend(result, rinfo->clause);
343  }
344  return result;
345 }
#define NIL
Definition: pg_list.h:69
bool pseudoconstant
Definition: relation.h:1755
return result
Definition: formatting.c:1632
#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:675
Definition: pg_list.h:45
bool join_clause_is_movable_into ( RestrictInfo rinfo,
Relids  currentrelids,
Relids  current_and_outer 
)

Definition at line 508 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().

511 {
512  /* Clause must be evaluable given available context */
513  if (!bms_is_subset(rinfo->clause_relids, current_and_outer))
514  return false;
515 
516  /* Clause must physically reference at least one target rel */
517  if (!bms_overlap(currentrelids, rinfo->clause_relids))
518  return false;
519 
520  /* Cannot move an outer-join clause into the join's outer side */
521  if (bms_overlap(currentrelids, rinfo->outer_relids))
522  return false;
523 
524  /*
525  * Target rel(s) must not be nullable below the clause. This is
526  * approximate, in the safe direction, because the current join might be
527  * above the join where the nulling would happen, in which case the clause
528  * would work correctly here. But we don't have enough info to be sure.
529  */
530  if (bms_overlap(currentrelids, rinfo->nullable_relids))
531  return false;
532 
533  return true;
534 }
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 435 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().

436 {
437  /* Clause must physically reference target rel */
438  if (!bms_is_member(baserel->relid, rinfo->clause_relids))
439  return false;
440 
441  /* Cannot move an outer-join clause into the join's outer side */
442  if (bms_is_member(baserel->relid, rinfo->outer_relids))
443  return false;
444 
445  /* Target rel must not be nullable below the clause */
446  if (bms_is_member(baserel->relid, rinfo->nullable_relids))
447  return false;
448 
449  /* Clause must not use any rels with LATERAL references to this rel */
450  if (bms_overlap(baserel->lateral_referencers, rinfo->clause_relids))
451  return false;
452 
453  return true;
454 }
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(), NULL, 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:224
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
bool restriction_is_or_clause ( RestrictInfo restrictinfo)

Definition at line 293 of file restrictinfo.c.

References NULL, and RestrictInfo::orclause.

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

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

Definition at line 308 of file restrictinfo.c.

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

Referenced by match_clause_to_index(), and TidQualFromBaseRestrictinfo().

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