bobhan1 opened a new pull request, #60803:
URL: https://github.com/apache/doris/pull/60803
### What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
When multiple SQL statements are sent as a single COM_QUERY (e.g., via JDBC
`allowMultiQueries=true`):
```sql
set enable_unique_key_partial_update=true; insert into t1(k,v1)
values(1,100);
All statements are parsed together by NereidsParser.parseSQL() before any
are executed. In LogicalPlanBuilder.visitInsertTable(),
isEnableUniqueKeyPartialUpdate and getPartialUpdateNewRowPolicy are read from
the session variable during parse phase, but the preceding
SET statement hasn't executed yet, so the INSERT reads stale values. This
causes partial update to silently not take effect, overwriting unspecified
columns with default values instead of preserving them.
Root Cause
visitInsertTable() →
UnboundTableSinkCreator.createUnboundTableSinkMaybeOverwrite() bakes session
variable values into UnboundTableSink at parse time. All downstream code
(normalizePlan, BindSink, OlapInsertExecutor, PhysicalPlanTranslator) reads
from the sink object,
not from session variable. So the stale value propagates through the
entire pipeline.
Fix
Re-read both enable_unique_key_partial_update and
partial_update_new_row_policy session variables from ConnectContext in
InsertUtils.normalizePlanWithoutLock(). This is the earliest point in the
execution phase (after SET has executed), and it's upstream of all
consumers.
Changes:
1. UnboundTableSink.java — remove final from partialUpdateNewKeyPolicy
field and add setPartialUpdateNewKeyPolicy() setter.
2. InsertUtils.java — re-read both session variables from ConnectContext
and set them on the UnboundTableSink before the existing partial update
validation logic.
3. test_partial_update_multi_stmt.out — update expected output to reflect
that multi-statement batch partial update now works correctly (preserves
original values instead of overwriting with defaults).
4.
### Release note
None
### 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]