with_props=false skips the per-label/per-type JSON property-key discovery: * those json_each() scans walk EVERY row of each label/type (minutes-scale on * multi-million-node graphs) and get_architecture only needs the counts. */
| 8379 | * those json_each() scans walk EVERY row of each label/type (minutes-scale on |
| 8380 | * multi-million-node graphs) and get_architecture only needs the counts. */ |
| 8381 | static int get_schema_impl(cbm_store_t *s, const char *project, cbm_schema_info_t *out, |
| 8382 | bool with_props) { |
| 8383 | memset(out, 0, sizeof(*out)); |
| 8384 | if (!s || !s->db) { |
| 8385 | return CBM_NOT_FOUND; |
| 8386 | } |
| 8387 | |
| 8388 | /* Node labels */ |
| 8389 | { |
| 8390 | const char *sql = ST_LABEL_COUNTS_SQL; |
| 8391 | sqlite3_stmt *stmt = NULL; |
| 8392 | if (sqlite3_prepare_v2(s->db, sql, CBM_NOT_FOUND, &stmt, NULL) != SQLITE_OK || !stmt) { |
| 8393 | if (stmt) { |
| 8394 | sqlite3_finalize(stmt); |
| 8395 | } |
| 8396 | return CBM_NOT_FOUND; |
| 8397 | } |
| 8398 | bind_text(stmt, SKIP_ONE, project); |
| 8399 | |
| 8400 | int cap = ST_INIT_CAP_8; |
| 8401 | int n = 0; |
| 8402 | cbm_label_count_t *arr = malloc(cap * sizeof(cbm_label_count_t)); |
| 8403 | if (!arr) { |
| 8404 | sqlite3_finalize(stmt); |
| 8405 | return CBM_NOT_FOUND; |
| 8406 | } |
| 8407 | int scan_rc16; |
| 8408 | while ((scan_rc16 = sqlite3_step(stmt)) == SQLITE_ROW) { |
| 8409 | if (n >= cap) { |
| 8410 | int new_cap = cap * ST_GROWTH; |
| 8411 | void *tmp = realloc(arr, new_cap * sizeof(cbm_label_count_t)); |
| 8412 | if (!tmp) { |
| 8413 | for (int i = 0; i < n; i++) { |
| 8414 | safe_str_free(&arr[i].label); |
| 8415 | } |
| 8416 | free(arr); |
| 8417 | sqlite3_finalize(stmt); |
| 8418 | return CBM_NOT_FOUND; |
| 8419 | } |
| 8420 | arr = tmp; |
| 8421 | cap = new_cap; |
| 8422 | } |
| 8423 | arr[n].label = heap_strdup((const char *)sqlite3_column_text(stmt, 0)); |
| 8424 | arr[n].count = sqlite3_column_int(stmt, SKIP_ONE); |
| 8425 | arr[n].properties = NULL; |
| 8426 | arr[n].property_count = 0; |
| 8427 | n++; |
| 8428 | } |
| 8429 | if (scan_rc16 != SQLITE_DONE) { /* SCANCHK:16:stmt */ |
| 8430 | store_set_error_sqlite(s, "row scan aborted"); |
| 8431 | sqlite3_finalize(stmt); |
| 8432 | out->node_labels = arr; |
| 8433 | out->node_label_count = n; |
| 8434 | return CBM_STORE_ERR; |
| 8435 | } |
| 8436 | sqlite3_finalize(stmt); |
| 8437 | out->node_labels = arr; |
| 8438 | out->node_label_count = n; |
no test coverage detected