JackieTien97 commented on issue #18792:
URL: https://github.com/apache/iotdb/issues/18792#issuecomment-6028356212

   The root cause is a cache lifecycle bug in the ColumnTransformer DAG used by 
FilterAndProjectOperator.
   
   Cached columns are normally released when their reference count reaches 
zero. However, CASE short-circuit evaluation explicitly clears its child 
expression caches. If a later projection reuses one of those expressions, 
recomputation resets its cache reference count to the full number of references 
in the DAG, without accounting for references already consumed in the current 
block.
   
   For example, when an aggregate column is referenced by both the CASE 
condition and a subsequent output:
   
   1. The CASE condition consumes the aggregate column, then CASE clears its 
cache.
   2. The subsequent output recomputes the column, resetting its reference 
count to 2.
   3. That output consumes one reference, leaving the cached column with a 
count of 1.
   4. On the next TsBlock, LeafColumnTransformer.initFromTsBlock() updates the 
input but does not invalidate the cached column. A subsequent tryEvaluate() 
therefore reuses data from the previous block.
   
   This mixes columns from different TsBlocks. Different block sizes can cause 
out-of-bounds access or produce an inconsistent result block, leading to client 
decoding errors. Equal-sized blocks can also silently return stale values.
   
   This explains why putting CASE last avoids the reported failure: CASE clears 
the shared cache after the other output has consumed it. Aggregation and the 
non-pushdown filter expose the problem by producing multiple input blocks; the 
underlying defect is in expression cache management.
   
   A fix should ensure that expression caches cannot survive across input 
blocks, including caches of intermediate expressions and descendants of nested 
CASE expressions, while preserving reuse within the current block.
   
   @ColinLeeo You can take a look and fix that.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to