doris icon indicating copy to clipboard operation
doris copied to clipboard

[Bug] IllegalStateException Exception when running short-circuit query on table with `PARTITION BY LIST`

Open bzhang-obsec opened this issue 4 months ago • 1 comments

Search before asking

  • [x] I had searched in the issues and found no similar issues.

Version

Tested doris-4.1.1-rc01-b10073ad9ca and 4.1.2-rc01-aec169d2025. The following exceptions are captured with doris-4.1.1-rc01-b10073ad9ca.

What's Wrong?

Given a table with both PARTITION BY LIST and store_row_column, enable_unique_key_merge_on_write and light_schema_change properties, which enables short-circuit queries, a point query will fail with java.lang.IllegalStateException.

Exception captured from FE:

[StmtExecutor.executeAndSendResult():1440] cancel fragment query_id:90349b0792234501-bd299dcc9db13ada cause null
[StmtExecutor.execute():570] Nereids execute failed. stmt[2396, 90349b0792234501-bd299dcc9db13ada]
java.lang.IllegalStateException
  at com.google.common.base.Preconditions.checkState(Preconditions.java:499)
  at org.apache.doris.qe.PointQueryExecutor.setScanRangeLocations(PointQueryExecutor.java:120)
  at org.apache.doris.qe.PointQueryExecutor.getNext(PointQueryExecutor.java:254)
  at org.apache.doris.qe.StmtExecutor.executeAndSendResult(StmtExecutor.java:1344)
  at org.apache.doris.qe.StmtExecutor.handleQueryStmt(StmtExecutor.java:1274)
  at org.apache.doris.qe.StmtExecutor.handleQueryWithRetry(StmtExecutor.java:931)
  at org.apache.doris.qe.StmtExecutor.executeByNereids(StmtExecutor.java:838)
  at org.apache.doris.qe.StmtExecutor.execute(StmtExecutor.java:555)
  at org.apache.doris.qe.StmtExecutor.queryRetry(StmtExecutor.java:514)
  at org.apache.doris.qe.StmtExecutor.execute(StmtExecutor.java:499)
  at org.apache.doris.nereids.trees.plans.commands.ExecuteCommand.run(ExecuteCommand.java:115)
  at org.apache.doris.qe.StmtExecutor.executeByNereids(StmtExecutor.java:698)
  at org.apache.doris.qe.StmtExecutor.execute(StmtExecutor.java:555)
  at org.apache.doris.qe.StmtExecutor.queryRetry(StmtExecutor.java:514)
  at org.apache.doris.qe.StmtExecutor.execute(StmtExecutor.java:499)
  at org.apache.doris.qe.MysqlConnectProcessor.handleExecute(MysqlConnectProcessor.java:174)
  at org.apache.doris.qe.MysqlConnectProcessor.handleExecute(MysqlConnectProcessor.java:221)
  at org.apache.doris.qe.MysqlConnectProcessor.dispatch(MysqlConnectProcessor.java:266)
  at org.apache.doris.qe.MysqlConnectProcessor.processOnce(MysqlConnectProcessor.java:407)
  at org.apache.doris.mysql.ReadListener.lambda$handleEvent$0(ReadListener.java:52)
  at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
  at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
  at java.base/java.lang.Thread.run(Thread.java:833)
RuntimeLogger 2026-07-25 01:28:27,545 WARN (mysql-nio-pool-5|355) [StmtExecutor.execute():566] Analyze failed. stmt[2396, 90349b0792234501-bd299dcc9db13ada]
org.apache.doris.common.NereidsException: errCode = 2, detailMessage = java.lang.IllegalStateException
  at org.apache.doris.qe.StmtExecutor.executeByNereids(StmtExecutor.java:726)
  at org.apache.doris.qe.StmtExecutor.execute(StmtExecutor.java:555)
  at org.apache.doris.qe.StmtExecutor.queryRetry(StmtExecutor.java:514)
  at org.apache.doris.qe.StmtExecutor.execute(StmtExecutor.java:499)
  at org.apache.doris.qe.MysqlConnectProcessor.handleExecute(MysqlConnectProcessor.java:174)
  at org.apache.doris.qe.MysqlConnectProcessor.handleExecute(MysqlConnectProcessor.java:221)
  at org.apache.doris.qe.MysqlConnectProcessor.dispatch(MysqlConnectProcessor.java:266)
  at org.apache.doris.qe.MysqlConnectProcessor.processOnce(MysqlConnectProcessor.java:407)
  at org.apache.doris.mysql.ReadListener.lambda$handleEvent$0(ReadListener.java:52)
  at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
  at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
  at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.apache.doris.common.AnalysisException: errCode = 2, detailMessage = java.lang.IllegalStateException
  ... 12 more
Caused by: java.lang.IllegalStateException
  at com.google.common.base.Preconditions.checkState(Preconditions.java:499)
  at org.apache.doris.qe.PointQueryExecutor.setScanRangeLocations(PointQueryExecutor.java:120)
  at org.apache.doris.qe.PointQueryExecutor.getNext(PointQueryExecutor.java:254)
  at org.apache.doris.qe.StmtExecutor.executeAndSendResult(StmtExecutor.java:1344)
  at org.apache.doris.qe.StmtExecutor.handleQueryStmt(StmtExecutor.java:1274)
  at org.apache.doris.qe.StmtExecutor.handleQueryWithRetry(StmtExecutor.java:931)
  at org.apache.doris.qe.StmtExecutor.executeByNereids(StmtExecutor.java:838)
  at org.apache.doris.qe.StmtExecutor.execute(StmtExecutor.java:555)
  at org.apache.doris.qe.StmtExecutor.queryRetry(StmtExecutor.java:514)
  at org.apache.doris.qe.StmtExecutor.execute(StmtExecutor.java:499)
  at org.apache.doris.nereids.trees.plans.commands.ExecuteCommand.run(ExecuteCommand.java:115)
  at org.apache.doris.qe.StmtExecutor.executeByNereids(StmtExecutor.java:698)
  ... 11 more

finished to tablet scheduler. cost: 0 ms
Null packet received from network. remote: 127.0.0.1:43650

While no log from BE is seen.

What You Expected?

The point query should succeed.

How to Reproduce?

  1. Create a doris cluster.
  2. Create a table with both PARTITION BY LIST and enables short circuit query:
    CREATE TABLE tbl_point_query (
        pk varchar(64),
        _id bigint
    )
    UNIQUE KEY(pk, _id)
    PARTITION BY LIST (`pk`) (PARTITION p_abcd VALUES IN ('abcd'))
    DISTRIBUTED BY HASH(pk, _id) BUCKETS AUTO
    PROPERTIES (
        "replication_num" = "1",
        "enable_unique_key_merge_on_write" = "true",
        "store_row_column" = "true",
        "light_schema_change" = "true"
    );
    
  3. INSERT INTO tbl_point_query (pk, _id) VALUES ('abcd', 1);
  4. EXPLAIN SELECT * FROM tbl_point_query WHERE pk = 'abcd' AND _id = 1; This shows SHORT-CIRCUIT in one of the steps.
  5. Execute SELECT * FROM tbl_point_query WHERE pk = 'abcd' AND _id = 1.

An error is returned as (1105, 'IllegalStateException, msg: null').

Anything Else?

No response

Are you willing to submit PR?

  • [x] Yes I am willing to submit a PR!

Code of Conduct

bzhang-obsec avatar Jul 25 '26 01:07 bzhang-obsec

Breakwater-GitHub-Analysis-Slot: slot_4fd365c156f3

Preliminary maintainer assessment

Verdict: confirmed FE planner/short-circuit contract bug, with a high-confidence code-level root cause. The supplied DDL, query, versions, and stack are sufficient for triage. The issue is open with no labels, assignee, milestone, or linked development item; it should be routed as an FE/Nereids point-query bug.

Root cause

The exception is the exact invariant at PointQueryExecutor.setScanRangeLocations() line 120: after lazy range evaluation, a point query must target exactly one tablet.

The invariant is violated because a predicate required by the short-circuit path is removed earlier:

  1. LogicalResultSinkToShortCircuitPointQuery marks this query as short-circuit while both key equalities (pk = 'abcd' and _id = 1) are still present. The rewrite order intentionally runs this rule before PruneOlapScanPartition.
  2. For the singleton LIST partition VALUES IN ('abcd'), partition pruning proves pk = 'abcd' is always true inside the selected partition. In b10073ad9ca, PruneOlapScanPartition calls PartitionPruner.prunePredicate(), which removes that conjunct. In aec169d2025, removal is deferred but still performed by PrunePartitionPredicate.
  3. The translated legacy OlapScanNode consequently retains only _id = 1. During short-circuit execution, lazyEvaluateRangeLocations() recomputes filters and tablet ranges from those remaining conjuncts.
  4. Because the distribution is HASH(pk, _id), HashDistributionPruner cannot compute the hash without the removed pk filter and returns every bucket tablet. BUCKETS AUTO resolved to more than one tablet in this reproduction, so the size() == 1 precondition fails.

This also fully explains why there is no BE log: the FE throws before selecting a tablet/backend or sending the lookup RPC. It is not a BE storage or row-store failure.

The missing predicate is more than a routing problem. PointQueryExecutor.addKeyTuples() later builds the primary-key lookup tuple from the same scan conjuncts. Merely weakening the one-tablet assertion or choosing an arbitrary tablet would therefore be incorrect and could expose a null/missing key literal or wrong-result path.

Recommended fix

Keep partition pruning enabled, but do not remove partition predicates for a query already marked as short-circuit. The focused fix is to include:

ctx.statementContext.isShortCircuitQuery()

in the skipPrunePredicate condition in PruneOlapScanPartition. This works with both affected implementations: it prevents direct removal in b10073ad9ca and prevents recording the predicate for deferred removal in aec169d2025/newer code. It also preserves all primary-key literals for both distribution pruning and addKeyTuples().

Changing PointQueryExecutor to accept multiple tablets is not recommended: the short-circuit request and retry path are designed around one tablet, and that would mask the lost-key-predicate defect rather than repair it.

Regression coverage

  • Add a point_query_p0 case based on the supplied DDL, but use a fixed multi-bucket count such as BUCKETS 4 so the failure is deterministic.
  • With default skip_prune_predicate = false, verify EXPLAIN still reports SHORT-CIRCUIT and the query returns ('abcd', 1).
  • Cover both a normal statement and server-side prepare/execute, including repeated execution so cached short-circuit context is exercised.
  • Add a second LIST-partition case where the partition key is a primary-key column but is not a distribution column. That case guards key-tuple construction even when tablet pruning can succeed without the partition key.
  • Retain a missing-key lookup case and verify it returns an empty result rather than an FE exception.

Workaround and missing information

A safe session-level workaround on both reported builds is:

SET skip_prune_predicate = true;

This preserves the predicate while retaining short-circuit execution. If that setting is undesirable, SET enable_short_circuit_query = false avoids the failing path at the cost of point-query performance.

No additional FE/BE logs or Doris profile are needed to establish the root cause. Two non-blocking details would help make the regression match the report exactly: the actual bucket count selected by BUCKETS AUTO, and whether step 5 was issued through server-side prepare/execute (the stack includes ExecuteCommand). Neither affects the diagnosis.

Doris-Breakwater avatar Jul 25 '26 01:07 Doris-Breakwater