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

Function ExecutionCtx_FromQuery

src/commands/execution_ctx.c:97–201  ·  view source on GitHub ↗

returns the objects and information required for query execution if the query contains error, a ExecutionCtx struct with the AST and Execution plan objects will be NULL and EXECUTION_TYPE_INVALID is returned returns ExecutionCtx populated with the current execution relevant objects

Source from the content-addressed store, hash-verified

95// and EXECUTION_TYPE_INVALID is returned
96// returns ExecutionCtx populated with the current execution relevant objects
97ExecutionCtx *ExecutionCtx_FromQuery
98(
99 const char *q // string representing the query
100) {
101 ASSERT(q != NULL);
102
103 ExecutionCtx *ret;
104 const char *q_str; // query string excluding query parameters
105
106 if(unlikely(strlen(q) == 0)) {
107 ErrorCtx_SetError("Error: empty query.");
108 return NULL;
109 }
110
111 // parse and validate parameters only
112 // extract query string
113 // return invalid execution context if failed to parse params
114 cypher_parse_result_t *params_parse_result = parse_params(q, &q_str);
115
116 // parameter parsing failed, return NULL
117 if(params_parse_result == NULL) {
118 return NULL;
119 }
120
121 // seems like we should be able to free 'params_parse_result'
122 // at this point but this messes up the parsing of the actual query
123
124 // query included only params e.g. 'cypher a=1' was provided
125 if(unlikely(strlen(q_str) == 0)) {
126 parse_result_free(params_parse_result);
127 ErrorCtx_SetError("Error: empty query.");
128 return NULL;
129 }
130
131 // update query context with the query without params
132 // (here the QueryInfo is created as well, starting the stage timer)
133 QueryCtx *ctx = QueryCtx_GetQueryCtx();
134 ctx->query_data.query_no_params = q_str;
135
136 // get cache
137 Cache *cache = GraphContext_GetCache(QueryCtx_GetGraphCtx());
138
139 // see if we already have a cached execution-ctx for given query
140 ret = Cache_GetValue(cache, q_str);
141
142 //--------------------------------------------------------------------------
143 // cache hit
144 //--------------------------------------------------------------------------
145
146 if(ret != NULL) {
147 parse_result_free(params_parse_result); // free parsed params
148 ret->cached = true; // mark cached execution
149 return ret;
150 }
151
152 //--------------------------------------------------------------------------
153 // cache miss
154 //--------------------------------------------------------------------------

Callers 2

_queryFunction · 0.85
Graph_ExplainFunction · 0.85

Calls 15

ErrorCtx_SetErrorFunction · 0.85
parse_paramsFunction · 0.85
parse_result_freeFunction · 0.85
QueryCtx_GetQueryCtxFunction · 0.85
GraphContext_GetCacheFunction · 0.85
QueryCtx_GetGraphCtxFunction · 0.85
Cache_GetValueFunction · 0.85
_ExecutionCtx_ParseASTFunction · 0.85
AST_SetParamsParseResultFunction · 0.85
_GetExecutionTypeFromASTFunction · 0.85

Tested by

no test coverage detected