| 461 | } |
| 462 | |
| 463 | void _query |
| 464 | ( |
| 465 | bool profile, |
| 466 | void *args |
| 467 | ) { |
| 468 | CommandCtx *command_ctx = (CommandCtx *)args; |
| 469 | QueryCtx *query_ctx = QueryCtx_GetQueryCtx(); |
| 470 | RedisModuleCtx *ctx = CommandCtx_GetRedisCtx(command_ctx); |
| 471 | GraphContext *gc = CommandCtx_GetGraphContext(command_ctx); |
| 472 | ExecutionCtx *exec_ctx = NULL; |
| 473 | |
| 474 | Globals_TrackCommandCtx(command_ctx); |
| 475 | QueryCtx_SetGlobalExecutionCtx(command_ctx); |
| 476 | |
| 477 | // transition the query from waiting to executing |
| 478 | QueryCtx_AdvanceStage(query_ctx); |
| 479 | |
| 480 | // parse query parameters and build an execution plan |
| 481 | // or retrieve it from the cache |
| 482 | exec_ctx = ExecutionCtx_FromQuery(command_ctx->query); |
| 483 | if(exec_ctx == NULL) goto cleanup; |
| 484 | |
| 485 | // update cached flag |
| 486 | QueryCtx_SetUtilizedCache(query_ctx, exec_ctx->cached); |
| 487 | |
| 488 | ExecutionType exec_type = exec_ctx->exec_type; |
| 489 | bool readonly = AST_ReadOnly(exec_ctx->ast->root); |
| 490 | bool index_op = (exec_type == EXECUTION_TYPE_INDEX_CREATE || |
| 491 | exec_type == EXECUTION_TYPE_INDEX_DROP); |
| 492 | |
| 493 | if(profile && index_op) { |
| 494 | RedisModule_ReplyWithError(ctx, "Can't profile index operations."); |
| 495 | goto cleanup; |
| 496 | } |
| 497 | |
| 498 | // write query executing via GRAPH.RO_QUERY isn't allowed |
| 499 | if(!profile && !readonly && _readonly_cmd_mode(command_ctx)) { |
| 500 | ErrorCtx_SetError("graph.RO_QUERY is to be executed only on read-only queries"); |
| 501 | goto cleanup; |
| 502 | } |
| 503 | |
| 504 | CronTaskHandle timeout_task = 0; |
| 505 | |
| 506 | // enforce specified timeout when query is readonly |
| 507 | // or timeout applies to both read and write |
| 508 | bool enforce_timeout = command_ctx->timeout != 0 && !index_op && |
| 509 | (readonly || command_ctx->timeout_rw) && |
| 510 | !command_ctx->replicated_command; |
| 511 | if(enforce_timeout) { |
| 512 | timeout_task = Query_SetTimeOut(command_ctx->timeout, exec_ctx->plan); |
| 513 | } |
| 514 | |
| 515 | // populate the container struct for invoking _ExecuteQuery. |
| 516 | QueryExecutionTypeFlag flags = QueryExecutionTypeFlag_READ; |
| 517 | if (!readonly) { |
| 518 | flags |= QueryExecutionTypeFlag_WRITE; |
| 519 | } |
| 520 | if (profile) { |
no test coverage detected