PGROUTING  2.6
restrictions_input.h File Reference
Include dependency graph for restrictions_input.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void pgr_get_restrictions (char *restrictions_sql, Restriction_t **restrictions, size_t *total_restrictions)
 

Function Documentation

void pgr_get_restrictions ( char *  restrictions_sql,
Restriction_t **  restrictions,
size_t *  total_restrictions 
)

Definition at line 59 of file restrictions_input.c.

References ANY_INTEGER, ANY_INTEGER_ARRAY, ANY_NUMERICAL, Column_info_t::colNumber, Column_info_t::eType, fetch_restriction(), Column_info_t::name, PGR_DBG, pgr_fetch_column_info(), pgr_SPI_cursor_open(), pgr_SPI_prepare(), Column_info_t::strict, time_msg(), and Column_info_t::type.

Referenced by compute_trsp().

62  {
63  const int tuple_limit = 1000000;
64  clock_t start_t = clock();
65 
66  PGR_DBG("pgr_get_restrictions");
67  PGR_DBG("%s", restrictions_sql);
68 
69  Column_info_t info[3];
70 
71  int i;
72  for (i = 0; i < 3; ++i) {
73  info[i].colNumber = -1;
74  info[i].type = 0;
75  info[i].strict = true;
76  }
77 
78  /* restriction id */
79  info[0].name = "id";
80  info[1].name = "cost";
81  /* array of edges */
82  info[2].name = "path";
83 
84  info[0].eType = ANY_INTEGER;
85  info[1].eType = ANY_NUMERICAL;
86  info[2].eType = ANY_INTEGER_ARRAY;
87 
88 
89  size_t ntuples;
90  size_t total_tuples;
91 
92  void *SPIplan;
93  SPIplan = pgr_SPI_prepare(restrictions_sql);
94  Portal SPIportal;
95  SPIportal = pgr_SPI_cursor_open(SPIplan);
96 
97  bool moredata = true;
98  (*total_restrictions) = total_tuples = 0;
99 
100 
101  /* on the first tuple get the column numbers */
102 
103  while (moredata == true) {
104  SPI_cursor_fetch(SPIportal, true, tuple_limit);
105  if (total_tuples == 0) {
106  pgr_fetch_column_info(info, 3);
107  }
108  ntuples = SPI_processed;
109  total_tuples += ntuples;
110  PGR_DBG("Restrictions to be processed %ld", ntuples);
111  PGR_DBG("size of structure %ld", sizeof(Restriction_t));
112  if (ntuples > 0) {
113  if ((*restrictions) == NULL) {
114  (*restrictions) = (Restriction_t *)palloc(
115  total_tuples * sizeof(Restriction_t));
116  } else {
117  (*restrictions) = (Restriction_t *)repalloc(
118  (*restrictions),
119  total_tuples * sizeof(Restriction_t));
120  }
121 
122  if ((*restrictions) == NULL) {
123  elog(ERROR, "Out of memory");
124  }
125 
126  size_t t;
127  SPITupleTable *tuptable = SPI_tuptable;
128  TupleDesc tupdesc = SPI_tuptable->tupdesc;
129  PGR_DBG("processing %ld", ntuples);
130  for (t = 0; t < ntuples; t++) {
131  HeapTuple tuple = tuptable->vals[t];
132  fetch_restriction(&tuple, &tupdesc, info,
133  &(*restrictions)[total_tuples - ntuples + t]);
134  }
135  SPI_freetuptable(tuptable);
136  } else {
137  moredata = false;
138  }
139  }
140 
141  SPI_cursor_close(SPIportal);
142 
143  if (total_tuples == 0) {
144  (*total_restrictions) = 0;
145  PGR_DBG("NO restrictions");
146  return;
147  }
148 
149  (*total_restrictions) = total_tuples;
150  PGR_DBG("Finish reading %ld restrictions, %ld",
151  total_tuples,
152  (*total_restrictions));
153  clock_t end_t = clock();
154  time_msg(" reading Restrictions", start_t, end_t);
155 }
static void fetch_restriction(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[3], Restriction_t *restriction)
#define PGR_DBG(...)
Definition: debug_macro.h:34
uint64_t type
Definition: column_info_t.h:73
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
void pgr_fetch_column_info(Column_info_t info[], int info_size)
Function tells expected type of each column and then check the correspondence type of each column...
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
SPIPlanPtr pgr_SPI_prepare(char *sql)
expectType eType
Definition: column_info_t.h:76

Here is the call graph for this function:

Here is the caller graph for this function: