Refactor: Simplify query evaluation and iterator handling - #2
Conversation
| static void rangeItersAddIterator(TrieCallbackCtx *ctx, QueryIterator *it) { | ||
| ctx->its[ctx->nits++] = it; |
There was a problem hiding this comment.
[CriticalError]
Potential buffer overrun: the element is written before ensuring that the array has enough capacity. If ctx->nits == ctx->cap, the write on the previous line indexes one element past the allocated buffer. Re-allocate first, then assign:
| static void rangeItersAddIterator(TrieCallbackCtx *ctx, QueryIterator *it) { | |
| ctx->its[ctx->nits++] = it; | |
| if (ctx->nits == ctx->cap) { | |
| ctx->cap *= 2; | |
| ctx->its = rm_realloc(ctx->its, ctx->cap * sizeof(*ctx->its)); | |
| } | |
| ctx->its[ctx->nits++] = it; |
⚡ Committable suggestion
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
|
/propel review |
There was a problem hiding this comment.
Reviewed the refactor focused on simplifying query evaluation and iterator handling across multiple components. No issues were found, and the cleanup appears to improve readability and maintainability without altering behavior.
Status: No Issues Found | Risk: Low
Review Details
📁 7 files reviewed | 💬 0 comments
Query Engine Cleanup and Simplification
This pull request focuses on extensive code cleanup and simplification within the query evaluation engine. It removes redundant checks, consolidates iterator creation logic, and refines memory management across several core files. The changes aim to streamline the codebase, improve readability, and potentially offer minor performance gains by reducing unnecessary overhead.
Key Changes
• Consolidated iterator creation logic in
NewUnionIteratorand other factory functions, removing redundant checks for zero or single child iterators.• Removed unused functions and dead code, including
RangeNumber_Free,geoRangeLoad,checkResult, andpopulateRange.• Renamed
ContainsCtxtoTrieCallbackCtxfor improved clarity and consistency in callback contexts.• Enhanced memory management in
Redis_OpenReaderby ensuringRSQueryTermis freed regardless of iterator creation success.• Refined the
quickExitlogic inUnionIteratorto also apply when a query node's weight is zero, optimizing result collection for non-scoring sub-trees.• Simplified error handling and control flow in various query evaluation functions, replacing
gotostatements with direct returns orRS_ASSERTwhere appropriate.Affected Areas
• src/query.c (Query evaluation logic)
• src/
geo_index.c (Geospatial indexing and filtering)• src/
redisearch_api.c (CAPIforRediSearch)• src/profile.c (Query profiling output)
• src/iterators/
union_iterator.c (Union iterator implementation)• src/
redis_index.c (Redis-backed index operations)• src/
query_internal.h (Internal query declarations)This summary was automatically generated by @propel-code-bot