risingwavelabs/risingwave · error

checked above

Error message

checked above

What it means

`to_stream` on `LogicalMatchRecognize` calls `.expect("checked above")` on `partition_key_indices()`, which returns `None` here. An earlier check in the stream-planning entry point is supposed to have already rejected a `MATCH_RECOGNIZE` without `PARTITION BY`, so hitting this expect means the earlier guard did not run on this code path.

Source

Thrown at src/frontend/src/optimizer/plan_node/logical_match_recognize.rs:220

        use crate::error::ErrorCode;
        use crate::expr::{ExprType, FunctionCall, InputRef};
        use crate::optimizer::property::RequiredDist;
        use crate::utils::Condition;
        // v1 restrictions: PARTITION BY / ORDER BY must be plain columns, PARTITION BY non-empty.
        // `NotSupported(cause, hint)` throughout, matching this feature's binder-side validation.
        if self.core.partition_key_indices().is_none() || self.core.order_key_indices().is_none() {
            return Err(ErrorCode::NotSupported(
                "MATCH_RECOGNIZE with an expression in PARTITION BY or ORDER BY".to_owned(),
                "use plain column references; compute the expression in a view below and \
                 partition/order by the resulting column"
                    .to_owned(),
            )
            .into());
        }
        if self
            .core
            .partition_key_indices()
            .expect("checked above")
            .is_empty()
        {
            return Err(ErrorCode::NotSupported(
                "MATCH_RECOGNIZE without a PARTITION BY".to_owned(),
                "add PARTITION BY; for a global pattern, partition by a constant column computed \
                 in a view below (all rows then match within one partition)"
                    .to_owned(),
            )
            .into());
        }
        let order_indices = self.core.order_key_indices().expect("checked above");
        let Some(&time_col) = order_indices.first() else {
            bail!("MATCH_RECOGNIZE requires an ORDER BY clause");
        };
        let partition_key_indices = self.core.partition_key_indices().expect("checked above");

        let stream_input = self.input().to_stream(ctx)?;
        // The executor matches over an append-only sequence and emits insert-only results; it has no

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Ensure `MATCH_RECOGNIZE` queries include a `PARTITION BY` clause so `partition_key_indices()` returns `Some`.
  2. Route planning through the normal `to_stream` entry point that performs the pre-check instead of constructing/reusing the node ad hoc.
  3. If the panic occurs despite the pre-check, inspect which entry point skipped it and file a bug with the query.

Example fix

-- before: no PARTITION BY triggers the checked-above invariant
SELECT * FROM t MATCH_RECOGNIZE (ORDER BY ts ...) ;
-- after
SELECT * FROM t MATCH_RECOGNIZE (PARTITION BY id ORDER BY ts ...) ;
Defensive patterns

Strategy: validation

Validate before calling

// SQL-side guard: always include PARTITION BY in MATCH_RECOGNIZE
// SELECT * FROM t MATCH_RECOGNIZE (PARTITION BY id ORDER BY ts PATTERN ...)

Try / catch

match result {
    Err(e) if e.to_string().contains("PARTITION BY") => eprintln!("Add PARTITION BY to MATCH_RECOGNIZE"),
    r => r?,
}

Prevention

When it happens

Trigger: Planning a streaming `MATCH_RECOGNIZE` whose logical node lacks partition key indices, bypassing or skipping the earlier `to_stream` pre-check that raises `NotSupported("MATCH_RECOGNIZE without a PARTITION BY")`.

Common situations: A `MATCH_RECOGNIZE` query reaches this node through an unexpected planning entry point (e.g. `logical_rewrite_for_stream` output, tests, or a partially-validated plan) instead of the guarded `to_stream` path.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/4a3a19df3dfc409e. Report an issue: GitHub.