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

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

References palloc0().

Referenced by SPI_register_relation().

◆ ENRMetadataGetTupDesc()

TupleDesc ENRMetadataGetTupDesc ( EphemeralNamedRelationMetadata  enrmd)

Definition at line 125 of file queryenvironment.c.

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 }
#define Assert(condition)
Definition: c.h:861
#define NoLock
Definition: lockdefs.h:34
#define InvalidOid
Definition: postgres_ext.h:36
TupleDesc rd_att
Definition: rel.h:112
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

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

Referenced by addRangeTableEntryForENR(), and ExecInitNamedTuplestoreScan().

◆ get_ENR()

EphemeralNamedRelation get_ENR ( QueryEnvironment queryEnv,
const char *  name 
)

Definition at line 96 of file queryenvironment.c.

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 }
#define lfirst(lc)
Definition: pg_list.h:172
EphemeralNamedRelationData * EphemeralNamedRelation
EphemeralNamedRelationMetadataData md
const char * name

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

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

◆ get_visible_ENR_metadata()

EphemeralNamedRelationMetadata get_visible_ENR_metadata ( QueryEnvironment queryEnv,
const char *  refname 
)

Definition at line 45 of file queryenvironment.c.

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 }
EphemeralNamedRelation get_ENR(QueryEnvironment *queryEnv, const char *name)

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

Referenced by get_visible_ENR(), and name_matches_visible_ENR().

◆ register_ENR()

void register_ENR ( QueryEnvironment queryEnv,
EphemeralNamedRelation  enr 
)

Definition at line 69 of file queryenvironment.c.

70 {
71  Assert(enr != NULL);
72  Assert(get_ENR(queryEnv, enr->md.name) == NULL);
73 
74  queryEnv->namedRelList = lappend(queryEnv->namedRelList, enr);
75 }
List * lappend(List *list, void *datum)
Definition: list.c:339

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

Referenced by SPI_register_relation().

◆ unregister_ENR()

void unregister_ENR ( QueryEnvironment queryEnv,
const char *  name 
)

Definition at line 82 of file queryenvironment.c.

83 {
85 
86  match = get_ENR(queryEnv, name);
87  if (match)
88  queryEnv->namedRelList = list_delete(queryEnv->namedRelList, match);
89 }
List * list_delete(List *list, void *datum)
Definition: list.c:853

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

Referenced by SPI_unregister_relation().