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

   ### What problem does this PR solve?
   
   Issue Number: close #xxx
   
   Problem Summary:
   
   `USE_MV` was only enforced by charging the matched materialization
   `Double.NEGATIVE_INFINITY` in `CostModel`. The `Cost` constructor clamps 
costs with
   `Math.max(0, ...)`, so that bias collapsed to 0 and became indistinguishable 
from a 0-row
   scan; when statistics were missing the hinted MV was not chosen while the 
hint still
   reported `Used`. The status was also set as a side effect inside the cost 
functions and in
   `OlapTable`'s index selection, i.e. when the MV was considered rather than 
chosen. A
   bare-name `USE_MV(mv)` never matched a sync MV at all: its identifier is
   `[catalog, db, table, index]`, so the 3-segment hint parameter missed 
`containsKey` and the
   MV context was filtered out of the memo.
   
   ### What is changed?
   
   `USE_MV` is now a hard constraint on plan selection instead of a cost trick.
   
   - `NereidsPlanner`: new `chooseBestPlanConsideringUseMv()` intersects the 
hint parameters
     with the rewrite-success set, computes per-memo-group reachable MV 
identifiers with a
     memoized bottom-up DFS, and picks the cheapest `GroupExpression` whose 
subtree covers the
     required MVs; `finalizeUseMvHintStatus()` sets the final hint status from 
the MVs actually
     present in the chosen plan. USE_MV stays best-effort: unreachable MVs are 
dropped and
     reported as `UnUsed` instead of failing the query.
   - `CostModel`: the negative-infinity bias is replaced by a 
normalization-safe bias (hinted
     MV scan costs 0, other relations `rows + 1`), which also steers CBO when 
several hinted MVs
     are mutually exclusive.
   - `UseMvHint` / `InitMaterializationContextHook`: `findUseMvParameter()` 
accepts both the full
     4-segment identifier and the bare-name form for sync MVs; matched bare 
names are normalized
     to the full identifier, unmatched ones are reported as `UnUsed`; sync MVs 
matched by the
     hint are pre-recorded as rewrite-success so the constraint can see them.
   - `OlapTable`: index selection no longer flips the hint status; it is 
decided once after plan
     selection.
   
   ### Behavior changed
   
   Yes. The hinted MV is now guaranteed to be in the final plan when reachable, 
regardless of
   cost; otherwise the query succeeds and the hint reports `UnUsed` with a 
reason instead of a
   false `Used`. Bare-name `USE_MV(mv)` now works for sync materialized views.
   
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [ ] Regression test
       - [ ] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
           - [ ] This is a refactor/code format and no logic has been changed.
           - [ ] Previous test can cover this change.
           - [ ] No code files have been changed.
           - [ ] Other reason <!-- Add your reason?  -->
   
   - Behavior changed:
       - [ ] No.
       - [ ] Yes. <!-- Explain the behavior change -->
   
   - Does this need documentation?
       - [ ] No.
       - [ ] Yes. <!-- Add document PR link here. eg: 
https://github.com/apache/doris-website/pull/1214 -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label <!-- Add branch pick label that this PR should 
merge into -->
   
   


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