PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_restriction_data (char *restrictions_sql, Restrict_t **restructions, size_t *total_restrictions)
 

Function Documentation

void pgr_get_restriction_data ( char *  restrictions_sql,
Restrict_t **  restructions,
size_t *  total_restrictions 
)

Definition at line 69 of file restrict_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, TEXT, time_msg(), and Column_info_t::type.

Referenced by process().

72  {
73  const int tuple_limit = 1000000;
74  clock_t start_t = clock();
75 
76  PGR_DBG("pgr_get_restriction_data");
77  PGR_DBG("%s", restrictions_sql);
78  Column_info_t info[3];
79 
80  int i;
81  for (i = 0; i < 3; ++i) {
82  info[i].colNumber = -1;
83  info[i].type = 0;
84  info[i].strict = true;
85  info[i].eType = ANY_INTEGER;
86  }
87  info[0].name = strdup("id");
88  info[1].name = strdup("cost");
89  info[2].name = strdup("restricted_edges");
90 
91  info[1].eType = ANY_NUMERICAL;
92  info[2].eType = ANY_INTEGER_ARRAY;
93 
94 #if 0
95  // experiment starts
96 
97  size_t total_tuples = (*total_restrictions) ;
98 
99  (*restrictions) = (Restrict_t *)palloc0(sizeof(Restrict_t));
100 
101  (*restrictions)[0].id = 1;
102  (*restrictions)[0].cost = -1;
103  (*restrictions)[0].restricted_edges[0] = 4;
104  (*restrictions)[0].restricted_edges[1] = 7;
105 
106  // experiment ends
107 #endif
108 
109 #if 1
110  size_t ntuples;
111  size_t total_tuples;
112 
113  void *SPIplan;
114  SPIplan = pgr_SPI_prepare(restrictions_sql);
115  Portal SPIportal;
116  SPIportal = pgr_SPI_cursor_open(SPIplan);
117 
118  bool moredata = TRUE;
119  (*total_restrictions) = total_tuples = 0;
120 
121 
122  while (moredata == TRUE) {
123  SPI_cursor_fetch(SPIportal, TRUE, tuple_limit);
124  if (total_tuples == 0) {
125  pgr_fetch_column_info(info, 3);
126  }
127  ntuples = SPI_processed;
128  total_tuples += ntuples;
129  PGR_DBG("SPI_processed %ld", ntuples);
130  if (ntuples > 0) {
131  if ((*restrictions) == NULL)
132  (*restrictions) = (Restrict_t *)palloc0(
133  total_tuples * sizeof(Restrict_t));
134  else
135  (*restrictions) = (Restrict_t *)repalloc(
136  (*restrictions),
137  total_tuples * sizeof(Restrict_t));
138 
139  if ((*restrictions) == NULL) {
140  elog(ERROR, "Out of memory");
141  }
142 
143  size_t t;
144  SPITupleTable *tuptable = SPI_tuptable;
145  TupleDesc tupdesc = SPI_tuptable->tupdesc;
146  PGR_DBG("processing %ld", ntuples);
147  for (t = 0; t < ntuples; t++) {
148  HeapTuple tuple = tuptable->vals[t];
149  fetch_restriction(&tuple, &tupdesc, info,
150  &(*restrictions)[total_tuples - ntuples + t]);
151  }
152  SPI_freetuptable(tuptable);
153  } else {
154  moredata = FALSE;
155  }
156  }
157 
158  SPI_cursor_close(SPIportal);
159 
160  if (total_tuples == 0) {
161  (*total_restrictions) = 0;
162  PGR_DBG("NO restrictions");
163  return;
164  }
165 
166  (*total_restrictions) = total_tuples;
167 #endif
168  PGR_DBG("Finish reading %ld data, %ld",
169  total_tuples,
170  (*total_restrictions));
171  clock_t end_t = clock();
172  time_msg(" reading Restrictions", start_t, end_t);
173 }
#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)
static void fetch_restriction(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[4], Restrict_t *restriction)
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: