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

   ### Background
   
   `SHOW TRANSACTION [FROM <db>] WHERE ...` lists a database's load 
transactions, filtered by `id`, by `label` (`=` or `LIKE`), or by `status`. 
Since 4.0 it is the Nereids command `ShowTransactionCommand`, which validates 
the parsed `WHERE` expression. When Nereids parses an ordinary string constant, 
it builds a `VarcharLiteral`. A `StringLiteral` is built only for strings 
longer than `ScalarType.MAX_VARCHAR_LENGTH`. Both classes extend 
`StringLikeLiteral`, and neither is a subclass of the other.
   
   ### What problem does this PR solve?
   
   Issue Number: close #70913
   Related PR: #50695 (introduced the bug)
   PR Type: Bugfix
   
   Problem Summary:
   
   On 4.0 and later, `SHOW TRANSACTION ... WHERE STATUS = '<status>'` always 
fails with an invalid `WHERE` clause error, even for the values that the error 
message itself suggests. Users who filter transactions by status are affected, 
for example when looking for stuck `PRECOMMITTED` two-phase-commit loads. The 
fix makes the `status` filter accept any `StringLikeLiteral`, as the `label` 
filter already does. Most of the diff is new tests.
   
   ```sql
   SHOW TRANSACTION WHERE STATUS = 'visible';
   ```
   
   | Before the fix (4.0.5-rc01) | With the fix |
   |---|---|
   | `errCode = 2, detailMessage = Where clause should looks like one of them: 
id = 123 or label =/like 'label' or status = 
'prepare/precommitted/committed/visible/aborted'` | Returns the transactions in 
that status (0 rows on a fresh database) |
   
   ### Details
   
   - **Frequency:** Always, for any status value in any letter case. The issue 
has the full reproduction script and a comparison with 2.1.9, where the 
statement works.
   - **Root cause:** In `ShowTransactionCommand#analyzeWhereClause()`, the 
`status` branch accepts only `StringLiteral`. Every parsed status value is a 
`VarcharLiteral`, so the branch never matches, the method returns `false`, and 
`validate()` throws.
   - **Why existing tests missed it:**
     - Unit test: `ShowTransactionCommandTest#testValidate` builds the 
predicate with `new StringLiteral("prepare")` directly, so it never goes 
through the parser.
     - Regression: `query_p0/show/test_show_transaction.groovy` covers `label 
=` and `label like` only.
   - **Fix:** Check `StringLikeLiteral` and read the value with 
`getStringValue()` in the `status` branch, the same way as the `label` branch.
   - **Other paths and branches:**
     - **Not affected:** within this command, the `id` and `label` branches.
     - **Out of scope here:** in cloud mode, 
`CloudGlobalTransactionMgr#getDbTransInfoByStatus()` does not support status 
filtering and throws a not-supported error. The new regression checks therefore 
run only when `!isCloudMode()`, like the existing `label like` check.
     - **Same pattern, not fixed here:**
       - `ShowCopyCommand` has the same `instanceof StringLiteral` check. On a 
4.0.5-rc01 cloud-mode cluster, `SHOW COPY FROM <db> WHERE STATE = 'FINISHED'` 
fails with its own "Where clause should looks like" error. It can be fixed the 
same way in a follow-up.
       - `ShowReplicaStatusCommand` also has this check. However, `ADMIN SHOW 
REPLICA STATUS FROM <tbl> WHERE STATUS = 'OK'` already fails earlier on 
4.0.5-rc01, with a parser error, so that is a separate problem.
     - **Release branches:** the bug was introduced by #50695. `branch-4.0` 
(since 4.0.0-rc01), `branch-4.1`, and `master` have the faulty check. 
`branch-3.1` does not have the Nereids `ShowTransactionCommand` and is not 
affected.
   
   ### Testing
   
   - `ShowTransactionCommandTest`, run with `./run-fe-ut.sh --run 
org.apache.doris.nereids.trees.plans.commands.ShowTransactionCommandTest` on a 
Linux build host in the `apache/doris:build-env-ldb-toolchain-latest` image:
     - **Without the fix** (only the test changes applied to `6e66809`): `Tests 
run: 2, Failures: 2`. Both `testValidate` (a `VarcharLiteral` predicate) and 
the new `testValidateParsedStatus` (SQL parsed with `NereidsParser`) throw 
`Where clause should looks like one of them: ...`.
     - **With the fix** (`0f8f16a`): `Tests run: 2, Failures: 0, Errors: 0`.
     - **Coverage:** lowercase and uppercase values; `precommitted`, 
`committed`, and `aborted`; invalid values that must fail with `status should 
be ...`.
   - **End-to-end check:** a standalone FE built from `0f8f16a` with 
`./build.sh --fe`, without a BE.
     - `SHOW TRANSACTION FROM <db> WHERE STATUS = 'visible'`, `'PREPARE'`, and 
`'precommitted'` return an empty result set.
     - `'unknow'` and `'unknown'` fail with `status should be 
prepare/precommitted/committed/visible/aborted`.
     - `LABEL =`, `LABEL LIKE`, and `ID =` behave as before.
   - **Regression case** in `query_p0/show/test_show_transaction.groovy` (group 
`p0`, not excluded by the P0 pipeline configuration): not run locally, because 
no BE was built; it runs in CI.
   
   ### Release note
   
   Fix `SHOW TRANSACTION ... WHERE STATUS = '<status>'` always failing with 
"Where clause should looks like one of them" since 4.0.
   
   ### Check List (For Author)
   
   - Behavior changed: No
   - Does this need documentation: No
   - Pre-submission status: Partially verified: the regression case was not run 
locally and runs in CI
   
   ### AI Disclosure
   
   - Tool: Antigravity CLI (Gemini 4 Neon) for the code, tests, and builds; 
Claude Code (Claude Opus 5.5) for the root-cause analysis, the reproduction, 
the review of the change, and this description
   - Generated: the fix, the unit and regression tests, and this description
   - Human review: None before submission; the author asked for the PR to be 
opened without reviewing it first
   - Prompts: Report the `SHOW TRANSACTION ... WHERE STATUS` bug found while 
building a transaction health check, and open a fix following the Doris issue 
and PR conventions, in English. Build and test on a remote Linux host instead 
of the local machine, and open the PR without waiting for the author's review.
   


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