morrySnow opened a new pull request, #67885:
URL: https://github.com/apache/doris/pull/67885

   ## Problem
   
   Server-side prepared point queries could reuse a cached scan plan after a 
row policy added a fixed equality on the same key column as a placeholder. A 
later parameter binding could replace the policy literal in the cached 
conjunct, both bypassing the fixed restriction and contaminating subsequent 
executions of the same prepared handle.
   
   ## Root cause
   
   The direct point-query path rediscovered key values from translated scan 
conjuncts and updated every cached binary predicate sharing a column name. That 
representation lost the provenance between caller-controlled placeholders and 
fixed statement or policy literals, and made shared plan state mutable across 
executions.
   
   ## Reproduction
   
   Create a unique-key merge-on-write table with a composite key and a 
restrictive row policy such as `tenant_id = 1`. Prepare a query with `tenant_id 
= ? AND item_id = ?`, then execute the same handle with tenant values `1`, `2`, 
and `1` again (and with `NULL`). The conflicting binding must return no rows, 
while the repeated matching binding must still work without changing the cached 
plan. A lossy predicate such as `CAST(tenant_id AS CHAR(1)) = '1'` must remain 
on the normal planning path.
   
   ## Fix
   
   - Freeze placeholder-to-key bindings and fixed equality literals into an 
immutable point-query key template when the short-circuit context is created.
   - Bind a new SQL-typed key tuple for each execution and distinguish lookup, 
provably empty, and safe fallback outcomes.
   - Return an empty row batch before tablet pruning or backend RPC when a 
placeholder is `NULL` or conflicts with a fixed key literal.
   - Build pruning filters from execution-owned values without rewriting cached 
conjuncts.
   - Fall back to the normal planner for inexact type coercions and any fixed 
predicate that cannot prove an exact physical key, including casts and non-key 
residuals.
   
   ## Tests
   
   - `./run-fe-ut.sh --run 
"org.apache.doris.nereids.trees.plans.commands.ExecuteCommandTest,org.apache.doris.qe.PointQueryExecutorTest,org.apache.doris.qe.ShortCircuitQueryContextTest"`
   - `./build.sh --fe` (through the sandbox FE update flow)
   - `./run-regression-test.sh --conf 
regression-test/conf/regression-conf.groovy.custom --run -f 
regression-test/suites/prepared_stmt_p0/prepared_point_query_row_policy.groovy`
   
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to