PGROUTING  3.2
restrictions_input.h File Reference
#include <stddef.h>
#include "c_types/restriction_t.h"
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

◆ pgr_get_restrictions()

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

Definition at line 63 of file restrictions_input.c.

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

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(), and process().

Column_info_t::colNumber
int colNumber
Definition: column_info_t.h:51
fetch_restriction
static void fetch_restriction(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[3], Restriction_t *restriction)
Definition: restrictions_input.c:35
Column_info_t::strict
bool strict
Definition: column_info_t.h:53
pgr_SPI_prepare
SPIPlanPtr pgr_SPI_prepare(char *sql)
Definition: postgres_connection.c:94
pgr_fetch_column_info
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.
Definition: get_check_data.c:78
Column_info_t::name
char * name
Definition: column_info_t.h:54
pgr_SPI_cursor_open
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
Definition: postgres_connection.c:107
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
ANY_INTEGER_ARRAY
@ ANY_INTEGER_ARRAY
Definition: column_info_t.h:45
Column_info_t::eType
expectType eType
Definition: column_info_t.h:55
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
ANY_INTEGER
@ ANY_INTEGER
Definition: column_info_t.h:41
Restriction_t
Definition: restriction_t.h:37
ANY_NUMERICAL
@ ANY_NUMERICAL
Definition: column_info_t.h:42
Column_info_t::type
uint64_t type
Definition: column_info_t.h:52
Column_info_t
Definition: column_info_t.h:49