MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / Graph_Explain

Function Graph_Explain

src/commands/cmd_explain.c:21–77  ·  view source on GitHub ↗

builds an execution plan but does not execute it reports plan back to the client Args: argv[1] graph name argv[2] query

Source from the content-addressed store, hash-verified

19// argv[1] graph name
20// argv[2] query
21void Graph_Explain(void *args) {
22 bool lock_acquired = false;
23 CommandCtx *command_ctx = (CommandCtx *)args;
24 RedisModuleCtx *ctx = CommandCtx_GetRedisCtx(command_ctx);
25 GraphContext *gc = CommandCtx_GetGraphContext(command_ctx);
26 ExecutionCtx *exec_ctx = NULL;
27 QueryCtx *query_ctx = QueryCtx_GetQueryCtx();
28
29 QueryCtx_SetGlobalExecutionCtx(command_ctx);
30 Globals_TrackCommandCtx(command_ctx);
31
32 // retrieve the required execution items and information:
33 // 1. Execution plan
34 // 2. Whether these items were cached or not
35 bool cached = false;
36 ExecutionPlan *plan = NULL;
37 exec_ctx = ExecutionCtx_FromQuery(command_ctx->query);
38 if (exec_ctx == NULL) {
39 query_ctx->status = QueryExecutionStatus_FAILURE;
40 goto cleanup;
41 }
42
43 plan = exec_ctx->plan;
44 ExecutionType exec_type = exec_ctx->exec_type;
45
46 if(exec_type == EXECUTION_TYPE_INDEX_CREATE) {
47 RedisModule_ReplyWithSimpleString(ctx, "Create Index");
48 goto cleanup;
49 } else if(exec_type == EXECUTION_TYPE_INDEX_DROP) {
50 RedisModule_ReplyWithSimpleString(ctx, "Drop Index");
51 goto cleanup;
52 }
53
54 Graph_AcquireReadLock(gc->g);
55 lock_acquired = true;
56
57 ExecutionPlan_PreparePlan(plan);
58 ExecutionPlan_Init(plan); // Initialize the plan's ops.
59
60 if (ErrorCtx_EncounteredError()) {
61 query_ctx->status = QueryExecutionStatus_FAILURE;
62 goto cleanup;
63 }
64
65 ExecutionPlan_Print(plan, ctx); // Print the execution plan.
66
67cleanup:
68 if(ErrorCtx_EncounteredError()) ErrorCtx_EmitException();
69 if(lock_acquired) Graph_ReleaseLock(gc->g);
70 ExecutionCtx_Free(exec_ctx);
71 GraphContext_DecreaseRefCount(gc);
72 Globals_UntrackCommandCtx(command_ctx);
73 CommandCtx_UnblockClient(command_ctx);
74 CommandCtx_Free(command_ctx);
75 QueryCtx_Free(); // Reset the QueryCtx and free its allocations.
76 ErrorCtx_Clear();
77}
78

Callers

nothing calls this directly

Calls 15

CommandCtx_GetRedisCtxFunction · 0.85
QueryCtx_GetQueryCtxFunction · 0.85
Globals_TrackCommandCtxFunction · 0.85
ExecutionCtx_FromQueryFunction · 0.85
Graph_AcquireReadLockFunction · 0.85
ExecutionPlan_InitFunction · 0.85
ExecutionPlan_PrintFunction · 0.85
ErrorCtx_EmitExceptionFunction · 0.85

Tested by

no test coverage detected