42 char *str = DatumGetCString(
43 SPI_getvalue(*tuple, *tupdesc, info[2].colNumber));
55 token = (
char *)strtok(str,
" ,");
57 while (token != NULL && i < MAX_RULE_LENGTH) {
58 restriction->
via[i] = atoi(token);
60 token = (
char *)strtok(NULL,
" ,");
68 char *restrictions_sql,
70 size_t *total_restrictions) {
71 const int tuple_limit = 1000000;
72 clock_t start_t = clock();
74 PGR_DBG(
"pgr_get_restriction_data");
75 PGR_DBG(
"%s", restrictions_sql);
80 for (i = 0; i < 3; ++i) {
86 info[0].
name = strdup(
"target_id");
87 info[1].
name = strdup(
"to_cost");
88 info[2].
name = strdup(
"via_path");
102 bool moredata = TRUE;
103 (*total_restrictions) = total_tuples = 0;
107 while (moredata == TRUE) {
108 SPI_cursor_fetch(SPIportal, TRUE, tuple_limit);
109 if (total_tuples == 0) {
112 ntuples = SPI_processed;
113 total_tuples += ntuples;
114 PGR_DBG(
"SPI_processed %ld", ntuples);
116 if ((*restrictions) == NULL)
124 if ((*restrictions) == NULL) {
125 elog(ERROR,
"Out of memory");
129 SPITupleTable *tuptable = SPI_tuptable;
130 TupleDesc tupdesc = SPI_tuptable->tupdesc;
131 PGR_DBG(
"processing %ld", ntuples);
132 for (t = 0; t < ntuples; t++) {
133 HeapTuple tuple = tuptable->vals[t];
135 &(*restrictions)[total_tuples - ntuples + t]);
137 SPI_freetuptable(tuptable);
143 SPI_cursor_close(SPIportal);
145 if (total_tuples == 0) {
146 (*total_restrictions) = 0;
151 (*total_restrictions) = total_tuples;
152 PGR_DBG(
"Finish reading %ld data, %ld",
154 (*total_restrictions));
155 clock_t end_t = clock();
156 time_msg(
" reading Restrictions", start_t, end_t);
int64_t pgr_SPI_getBigInt(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
void time_msg(char *msg, clock_t start_t, clock_t end_t)
void pgr_fetch_column_info(Column_info_t info[], int info_size)
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
double pgr_SPI_getFloat8(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
SPIPlanPtr pgr_SPI_prepare(char *sql)