yujun777 opened a new pull request, #71190:
URL: https://github.com/apache/doris/pull/71190
### Background
Manual refreshes of asynchronous materialized views (`REFRESH MATERIALIZED
VIEW`), IVM dry runs (`REFRESH MATERIALIZED VIEW ... INCREMENTAL WITH DRY
RUN`), and refresh plan inspection (`EXPLAIN REFRESH MATERIALIZED VIEW`) do not
execute in the caller's session context; instead, each creates an internal
`ConnectContext` from the materialized view's persisted metadata and re-parses
the MV definition SQL. In the Nereids parser, `/*+ ... */` hints are tokenized
on comment channel 2 and collected into `selectHintMap`, which the refresh
statement visitors previously ignored.
### What problem does this PR solve?
Issue Number: None
Related PR: None
PR Type: Enhancement
Problem Summary:
Users could not pass per-statement `/*+ SET_VAR(...) */` hints to `REFRESH
MATERIALIZED VIEW`, `REFRESH MATERIALIZED VIEW ... INCREMENTAL WITH DRY RUN`,
or `EXPLAIN REFRESH MATERIALIZED VIEW` to tune timeouts, memory limits,
optimizer rules, workload groups, or compute groups for a single refresh or
plan inspection. This PR adds `SET_VAR` hint support strictly right after
`REFRESH` across all three forms, validates them synchronously during
`analyze()`, persists them on `MTMVTaskContext` for asynchronous execution, and
ensures they take precedence over MTMV defaults and MV definition SQL `SET_VAR`
hints. Existing refreshes without hints keep unchanged behavior and serialized
task JSON.
### Details
- **Change map:** 10 production Java files (+342/-25 lines), 4 FE unit test
files (+301/-0 lines), and 1 new regression suite + golden `.out` (+215/-0
lines).
- Parser & validation (`LogicalPlanBuilder`, `RefreshMTMVInfo`): extract
and validate `/*+ SET_VAR(...) */` hints right after `REFRESH` with
multi-statement semicolon boundary isolation; reject misplaced, malformed, or
unsupported hints; synchronously validate session variable names and values in
`analyze()` using a throwaway `ConnectContext`.
- Task persistence & propagation (`MTMVTaskContext`, `MTMVJobManager`):
add optional `@SerializedName(value = "sv", alternate = "sessionVariables")` on
`MTMVTaskContext`, keeping it `null` (omitted in JSON) when empty.
- Refresh context unification & precedence (`MTMVPlanUtil`, `MTMVTask`,
`RefreshMTMVCommand`, `ConnectContext`, `VariableMgr`, `SelectHintSetVar`): add
`MTMVPlanUtil.createMTMVRefreshContext` unifying `MTMVTask`, dry run, and
`EXPLAIN REFRESH` (disabling MV rewrite by default), skip MV default compute
group overwrite when `cloud_cluster`/`compute_group` is overridden by hint, and
record overridden canonical variable names on `ConnectContext` so MV query SQL
`SET_VAR` hints (both at parse time and during `EliminateLogicalSelectHint`) do
not clobber `REFRESH` hints.
- **Before and after:** Before this change, `/*+ ... */` hints in `REFRESH
MATERIALIZED VIEW`, dry run, and `EXPLAIN REFRESH` were silently ignored, and
`EXPLAIN REFRESH` / dry run did not disable `enable_materialized_view_rewrite`
by default like `MTMVTask`. After this change, `REFRESH /*+ SET_VAR(...) */
MATERIALIZED VIEW ...` (including `EXPLAIN REFRESH` and `WITH DRY RUN`)
validates and applies the specified session variables with precedence `REFRESH
SET_VAR hint > MV SQL SET_VAR > MTMV defaults & properties > global defaults`,
and rejects misplaced or non-`SET_VAR` hints.
- **Configs and defaults:** No new FE/BE configs. `MTMVTaskContext.sv` is
`null` (omitted from Gson output) when no hint is provided.
`enable_materialized_view_rewrite` and `enable_dml_materialized_view_rewrite`
are initialized to `false` in `createMTMVRefreshContext` for all refresh,
dry-run, and `EXPLAIN REFRESH` paths unless explicitly overridden by a
`SET_VAR` hint.
- **Impact on existing users:** Existing `REFRESH MATERIALIZED VIEW`,
`EXPLAIN REFRESH`, and scheduled/on-commit refresh tasks without hints behave
identically and produce identical `MTMVTaskContext` JSON. Any existing script
placing a `/*+ ... */` comment inside a `REFRESH MATERIALIZED VIEW` statement
outside the position right after `REFRESH` or using a non-`SET_VAR` hint will
now fail with an explicit `AnalysisException`.
### Testing
- Built FE with Checkstyle enabled (`DISABLE_BUILD_UI=ON ./build.sh --fe`)
locally: passed.
- FE unit tests run locally (all passed, 0 failures/errors):
- `RefreshMTMVCommandTest` (32 tests): parsing `SET_VAR` hints across
`REFRESH`, `WITH DRY RUN`, and `EXPLAIN REFRESH`; multiple hints last-wins;
misplaced/unsupported/malformed hint rejection; multi-statement isolation;
precedence over MTMV defaults, compute group (`cloud_cluster` / `compute_group`
alias), and MV SQL `SET_VAR` (parse and `EliminateLogicalSelectHint` phases).
- `RefreshMTMVInfoAnalyzeTest` (25 tests): synchronous validation of
unknown variable / invalid value and isolation of caller's `SessionVariable`
and `traceId`.
- `MTMVTaskContextCompatTest` (12 tests): omitting `sv` when empty,
round-trip persistence, and `sessionVariables` alternate name compatibility.
- `MTMVComputeGroupTest` (12 tests): `REFRESH` hint `cloud_cluster`
overriding MV-declared `compute_group` in `MTMVTask`.
- `ExplainRefreshMTMVCommandTest` (24 tests) and `MTMVJobManagerTest` (1
test).
- Regression suites run locally against 1FE+1BE cluster (5/5 passed):
- Added `mtmv_p0/test_refresh_mtmv_hint` (verifying `EXPLAIN REWRITTEN
PLAN REFRESH` COMPLETE and INCREMENTAL overriding MV SQL `SET_VAR`, manual
`REFRESH` persistence in `tasks("type"="mv")` without mutating caller session,
IVM `WITH DRY RUN` with hint, and negative error cases).
- Re-ran `mtmv_p0/ivm/test_ivm_explain_refresh`,
`mtmv_p0/ivm/test_ivm_refresh_dry_run`,
`mtmv_p0/test_auto_refresh_complete_method`,
`mtmv_p0/test_partition_refresh_mtmv`.
### Release note
Support `/*+ SET_VAR(...) */` hints placed right after `REFRESH` in `REFRESH
MATERIALIZED VIEW`, `REFRESH MATERIALIZED VIEW ... INCREMENTAL WITH DRY RUN`,
and `EXPLAIN REFRESH MATERIALIZED VIEW` statements, taking precedence over MV
default settings and `SET_VAR` hints inside the MV definition SQL.
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Ready
--
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]