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

   ### What problem does this PR solve?
   
   Issue Number: close #DORIS-19133
   
   Problem Summary: When creating a sync materialized view, if the MV name 
specified a different database than the base table (e.g. `CREATE MATERIALIZED 
VIEW db1.mv_t AS SELECT d FROM db.t`), Doris silently succeeded instead of 
raising an error. A sync materialized view is stored as an index on its base 
table and must therefore reside in the same database. The same error now also 
fires when the current session database differs from the base table's database.
   
   ### Root cause
   
   In `CreateMaterializedViewCommand.validate()`, the `dbName` field is 
extracted from the base table (via the plan validator), but the MV name's 
database (`name.getDb()`) was never compared against it. As a result, 
specifying a different database in the MV name was silently ignored and the MV 
was always created under the base table's database without any error.
   
   ### Fix
   
   After extracting `dbName` from the validator, determine the MV's effective 
database:
   - Use `name.getDb()` if explicitly specified.
   - Fall back to the session's current database otherwise.
   
   If the effective MV database differs from the base table's database, throw 
an `AnalysisException`.
   
   ### Release note
   
   Sync materialized view creation now fails with an explicit error when the 
materialized view's effective database (explicitly specified or current session 
database) does not match the base table's database.
   
   ### Check List (For Author)
   
   - Test: Regression test added under 
`regression-test/suites/mv_p0/test_cross_db_mv_error/`
   - Behavior changed: Yes — previously the statement succeeded silently; now 
it raises an AnalysisException
   - Does this need documentation: No


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