Run the next chunk of start nodes through the pipeline into the sink. The * start nodes' strings move into their bindings and are released with them. * *start_index is the chunk's position in the whole start set. */
| 6173 | * start nodes' strings move into their bindings and are released with them. |
| 6174 | * *start_index is the chunk's position in the whole start set. */ |
| 6175 | static int execute_chunk(cbm_store_t *store, cbm_query_t *q, const char *project, int max_rows, |
| 6176 | start_source_t *src, int chunk, int *start_index, cypher_sink_t *sink) { |
| 6177 | cbm_pattern_t *pat0 = &q->patterns[0]; |
| 6178 | cbm_node_t *nodes = NULL; |
| 6179 | int node_count = 0; |
| 6180 | if (pull_start_nodes(src, chunk, &nodes, &node_count) != 0) { |
| 6181 | return CBM_NOT_FOUND; /* start node array refused */ |
| 6182 | } |
| 6183 | if (src->failed) { |
| 6184 | start_nodes_free(nodes, node_count); |
| 6185 | return CBM_NOT_FOUND; /* the scan failed: no answer from part of it */ |
| 6186 | } |
| 6187 | |
| 6188 | /* Build initial bindings with early WHERE */ |
| 6189 | int bind_cap = node_count; |
| 6190 | binding_t *bindings = malloc(((size_t)bind_cap + SKIP_ONE) * sizeof(binding_t)); |
| 6191 | if (!bindings) { |
| 6192 | start_nodes_free(nodes, node_count); |
| 6193 | return CBM_NOT_FOUND; /* initial binding array refused */ |
| 6194 | } |
| 6195 | int bind_count = 0; |
| 6196 | const char *var_name = pat0->nodes[0].variable ? pat0->nodes[0].variable : CYP_ANON_HEAD_VAR; |
| 6197 | |
| 6198 | int first = *start_index; |
| 6199 | for (int i = 0; i < node_count; i++) { |
| 6200 | if (((first + i) & CYPHER_DEADLINE_CHECK_MASK) == 0 && cypher_deadline_exceeded()) { |
| 6201 | break; |
| 6202 | } |
| 6203 | binding_t b = {0}; |
| 6204 | b.store = store; |
| 6205 | binding_take_node(&b, var_name, &nodes[i]); |
| 6206 | bool pass = eval_where_partial(q->where, &b) != CYP_PARTIAL_FALSE; |
| 6207 | if (pass) { |
| 6208 | bindings[bind_count++] = b; |
| 6209 | } else { |
| 6210 | binding_free(&b); |
| 6211 | } |
| 6212 | } |
| 6213 | *start_index = first + node_count; |
| 6214 | start_nodes_free(nodes, node_count); /* + strings of nodes a deadline left untaken */ |
| 6215 | |
| 6216 | /* Expand first pattern's relationships */ |
| 6217 | expand_pattern_rels(store, pat0, &bindings, &bind_count, &bind_cap, &var_name, |
| 6218 | q->pattern_optional[0]); |
| 6219 | |
| 6220 | /* Additional patterns */ |
| 6221 | int rc = |
| 6222 | expand_additional_patterns(store, q, project, max_rows, &bindings, &bind_count, &bind_cap); |
| 6223 | if (rc == 0) { |
| 6224 | /* Late WHERE */ |
| 6225 | if (q->where && (pat0->rel_count > 0 || q->pattern_count > SKIP_ONE)) { |
| 6226 | filter_bindings_where(q->where, bindings, &bind_count); |
| 6227 | } |
| 6228 | sink_feed(sink, bindings, bind_count); |
| 6229 | if (sink->with.oom) { |
| 6230 | rc = CBM_NOT_FOUND; /* a WITH row buffer could not grow */ |
| 6231 | } |
| 6232 | } |
no test coverage detected