PostgreSQL Source Code  git master
queryenvironment.c File Reference
#include "postgres.h"
#include "access/table.h"
#include "utils/queryenvironment.h"
#include "utils/rel.h"
Include dependency graph for queryenvironment.c:

Go to the source code of this file.

Data Structures

struct  QueryEnvironment
 

Functions

QueryEnvironmentcreate_queryEnv ()
 
EphemeralNamedRelationMetadata get_visible_ENR_metadata (QueryEnvironment *queryEnv, const char *refname)
 
void register_ENR (QueryEnvironment *queryEnv, EphemeralNamedRelation enr)
 
void unregister_ENR (QueryEnvironment *queryEnv, const char *name)
 
EphemeralNamedRelation get_ENR (QueryEnvironment *queryEnv, const char *name)
 
TupleDesc ENRMetadataGetTupDesc (EphemeralNamedRelationMetadata enrmd)
 

Function Documentation

◆ create_queryEnv()

QueryEnvironment* create_queryEnv ( void  )

Definition at line 39 of file queryenvironment.c.

References palloc0().

Referenced by SPI_register_relation().

40 {
41  return (QueryEnvironment *) palloc0(sizeof(QueryEnvironment));
42 }
void * palloc0(Size size)
Definition: mcxt.c:955

◆ ENRMetadataGetTupDesc()

TupleDesc ENRMetadataGetTupDesc ( EphemeralNamedRelationMetadata  enrmd)

Definition at line 125 of file queryenvironment.c.

References Assert, InvalidOid, NoLock, RelationData::rd_att, EphemeralNamedRelationMetadataData::reliddesc, table_close(), table_open(), and EphemeralNamedRelationMetadataData::tupdesc.

Referenced by addRangeTableEntryForENR(), and ExecInitNamedTuplestoreScan().

126 {
127  TupleDesc tupdesc;
128 
129  /* One, and only one, of these fields must be filled. */
130  Assert((enrmd->reliddesc == InvalidOid) != (enrmd->tupdesc == NULL));
131 
132  if (enrmd->tupdesc != NULL)
133  tupdesc = enrmd->tupdesc;
134  else
135  {
136  Relation relation;
137 
138  relation = table_open(enrmd->reliddesc, NoLock);
139  tupdesc = relation->rd_att;
140  table_close(relation, NoLock);
141  }
142 
143  return tupdesc;
144 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define NoLock
Definition: lockdefs.h:34
TupleDesc rd_att
Definition: rel.h:84
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:732
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ get_ENR()

EphemeralNamedRelation get_ENR ( QueryEnvironment queryEnv,
const char *  name 
)

Definition at line 96 of file queryenvironment.c.

References Assert, lfirst, EphemeralNamedRelationData::md, EphemeralNamedRelationMetadataData::name, and QueryEnvironment::namedRelList.

Referenced by _SPI_find_ENR_by_name(), ExecInitNamedTuplestoreScan(), get_visible_ENR_metadata(), register_ENR(), and unregister_ENR().

97 {
98  ListCell *lc;
99 
100  Assert(name != NULL);
101 
102  if (queryEnv == NULL)
103  return NULL;
104 
105  foreach(lc, queryEnv->namedRelList)
106  {
108 
109  if (strcmp(enr->md.name, name) == 0)
110  return enr;
111  }
112 
113  return NULL;
114 }
EphemeralNamedRelationMetadataData md
EphemeralNamedRelationData * EphemeralNamedRelation
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
const char * name
Definition: encode.c:521

◆ get_visible_ENR_metadata()

EphemeralNamedRelationMetadata get_visible_ENR_metadata ( QueryEnvironment queryEnv,
const char *  refname 
)

Definition at line 45 of file queryenvironment.c.

References Assert, get_ENR(), and EphemeralNamedRelationData::md.

Referenced by get_visible_ENR(), and name_matches_visible_ENR().

46 {
48 
49  Assert(refname != NULL);
50 
51  if (queryEnv == NULL)
52  return NULL;
53 
54  enr = get_ENR(queryEnv, refname);
55 
56  if (enr)
57  return &(enr->md);
58 
59  return NULL;
60 }
EphemeralNamedRelationMetadataData md
#define Assert(condition)
Definition: c.h:732
EphemeralNamedRelation get_ENR(QueryEnvironment *queryEnv, const char *name)

◆ register_ENR()

void register_ENR ( QueryEnvironment queryEnv,
EphemeralNamedRelation  enr 
)

Definition at line 69 of file queryenvironment.c.

References Assert, get_ENR(), lappend(), EphemeralNamedRelationData::md, EphemeralNamedRelationMetadataData::name, and QueryEnvironment::namedRelList.

Referenced by SPI_register_relation().

70 {
71  Assert(enr != NULL);
72  Assert(get_ENR(queryEnv, enr->md.name) == NULL);
73 
74  queryEnv->namedRelList = lappend(queryEnv->namedRelList, enr);
75 }
EphemeralNamedRelationMetadataData md
List * lappend(List *list, void *datum)
Definition: list.c:321
#define Assert(condition)
Definition: c.h:732
EphemeralNamedRelation get_ENR(QueryEnvironment *queryEnv, const char *name)

◆ unregister_ENR()

void unregister_ENR ( QueryEnvironment queryEnv,
const char *  name 
)

Definition at line 82 of file queryenvironment.c.

References get_ENR(), list_delete(), and QueryEnvironment::namedRelList.

Referenced by SPI_unregister_relation().

83 {
85 
86  match = get_ENR(queryEnv, name);
87  if (match)
88  queryEnv->namedRelList = list_delete(queryEnv->namedRelList, match);
89 }
const char * name
Definition: encode.c:521
List * list_delete(List *list, void *datum)
Definition: list.c:774
EphemeralNamedRelation get_ENR(QueryEnvironment *queryEnv, const char *name)