FreeOnePlus opened a new issue, #70913: URL: https://github.com/apache/doris/issues/70913
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no similar issues. ### Version - Reproduced on `doris-4.0.5-rc01-59de8c4c524` (shared-nothing / storage-compute coupled). - The same code is on `branch-4.0`, `branch-4.1` and `master` (checked at `6e66809`). The code dates back to 4.0.0-rc01. - Not affected: 2.1.x. On `doris-2.1.9-rc02` the same statement works, because 2.1 uses the legacy parser path. ### What's Wrong? On 4.0 and later, `SHOW TRANSACTION` rejects every `WHERE STATUS = '<status>'` filter: ``` mysql> SHOW TRANSACTION WHERE STATUS = 'visible'; ERROR 1105 (HY000): errCode = 2, detailMessage = Where clause should looks like one of them: id = 123 or label =/like 'label' or status = 'prepare/precommitted/committed/visible/aborted' ``` The error message suggests exactly the syntax the user wrote. Upper-case values (`'VISIBLE'`) fail the same way. Filtering by `id` and by `label` still works. ### What You Expected? The statement should return the transactions of the database in the given status, as it does on 2.1.x. FE intends to support this filter. The error message above lists it, and `ShowTransactionCommand` has a `status` branch that calls `GlobalTransactionMgrIface#getDbTransInfoByStatus`. ### How to Reproduce? On a 4.0.x cluster: ```sql CREATE DATABASE show_txn_status_repro; USE show_txn_status_repro; CREATE TABLE t (k INT) DUPLICATE KEY(k) DISTRIBUTED BY HASH(k) BUCKETS 1 PROPERTIES ("replication_num" = "1"); INSERT INTO t WITH LABEL show_txn_status_demo VALUES (1); SHOW TRANSACTION WHERE LABEL = 'show_txn_status_demo'; -- OK, 1 row, TransactionStatus = VISIBLE SHOW TRANSACTION WHERE STATUS = 'visible'; -- ERROR 1105 (see above) SHOW TRANSACTION WHERE STATUS = 'VISIBLE'; -- ERROR 1105 (see above) ``` On `doris-2.1.9-rc02`, the same script returns one row for each of the three `SHOW TRANSACTION` statements. ### Anything Else? **Root cause.** In `ShowTransactionCommand#analyzeWhereClause`, the `label` branch accepts any `StringLikeLiteral`, but the `status` branch only accepts `StringLiteral`: https://github.com/apache/doris/blob/6e6680944db655d0b8d9da54eefa950bd2a16765/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTransactionCommand.java#L145-L148 The Nereids parser builds a `VarcharLiteral` for an ordinary string constant. It returns a `StringLiteral` only when the string is longer than `ScalarType.MAX_VARCHAR_LENGTH`: https://github.com/apache/doris/blob/6e6680944db655d0b8d9da54eefa950bd2a16765/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java#L3841-L3848 `VarcharLiteral` and `StringLiteral` both extend `StringLikeLiteral`, and neither is a subclass of the other. So a status value written in SQL never reaches the `status` branch, `analyzeWhereClause()` returns false, and `validate()` throws the error above. **Why the tests did not catch it.** - `ShowTransactionCommandTest#testValidate` builds the predicate with `new StringLiteral("prepare")` directly, so it never goes through the parser. - The regression suite `query_p0/show/test_show_transaction.groovy` only covers `label`. **Origin.** The check was added when `SHOW TRANSACTION` moved to Nereids in #50695. **Out of scope.** In cloud mode, `CloudGlobalTransactionMgr` does not support filtering by status or by label pattern. It throws `NOT_SUPPORTED_MSG`. That is separate from this parsing bug. ### Are you willing to submit PR? - [x] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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]
