Skip to content

[Compatibility]: explicit RESPECT NULLS and NTH_VALUE FROM FIRST window syntax is rejected #28031

Closed

Description

@Ariznawlll

Description

MatrixOne accepts the default semantics of LAG() and NTH_VALUE(), but rejects two explicit forms that MySQL accepts and defines as those defaults:

  • RESPECT NULLS for value window functions.
  • FROM FIRST for NTH_VALUE().

This prevents MySQL SQL that spells out its intended default window semantics from running unchanged on MatrixOne.

Environment

  • Branch: main
  • Commit: 17c161a31b47a22e71ca222839143f66717ac365
  • Deployment: local single-CN MatrixOne service

Steps to reproduce

CREATE DATABASE win_mysql_probe;
USE win_mysql_probe;
CREATE TABLE t (id INT PRIMARY KEY, g INT, ordv INT, v INT);
INSERT INTO t VALUES (1,1,1,10), (2,1,2,20), (3,1,2,30), (4,2,1,40);

SELECT LAG(v) RESPECT NULLS OVER (PARTITION BY g ORDER BY ordv) FROM t;
SELECT NTH_VALUE(v, 2) FROM FIRST OVER (PARTITION BY g ORDER BY ordv) FROM t;

Actual behavior

Both statements are rejected during parsing:

syntax error near "respect nulls over(...)"
syntax error near "from first over(...)"

Expected behavior

Accept both forms with MySQL semantics:

  • RESPECT NULLS is the default null treatment.
  • FROM FIRST is the default direction for NTH_VALUE().

For the fixture above, the controls without the explicit modifiers run successfully and produce the same results: LAG(v) yields 10,20 for the non-NULL rows in the first partition, and NTH_VALUE(v,2) yields 20,20,20 there.

Stability and scope

Code analysis

pkg/sql/parsers/dialect/mysql/mysql_sql.y defines the value-window forms without optional null-treatment or direction modifiers. The default function implementations are present; the gap is in accepted MySQL grammar.

Regression coverage

After implementation, add deterministic SQL coverage under test/distributed/cases/window for both explicit forms and their default-form equivalence.

References

Activity

  1. added
    kind/bug
    on Sep 3, 2026
  2. added
    ai-easy
    on Sep 3, 2026
  3. slyunnn commented on Sep 4, 2026

    @slyunnn

    Regression and extended verification for #28031 (2026-09-04)

    Verification Environment

    • Remote latest main and refreshed local origin/main: bf63172c0691e917ed2613c2d3a2d3d76a7f682e — perf(load): add opt-in parquet parallel-load groundwork (#27903).
    • The original local HEAD was a detached older checkout at 17c161a31b47a22e71ca222839143f66717ac365; it was not used as the final baseline. Verification used an isolated worktree at the exact refreshed origin/main commit.
    • Related fix: PR #28064, fix(parser): support explicit default window modifiers, merge commit 97a7f7f155a4042dc1e65d12599f18f91ad364d2. This commit is reachable from the refreshed main baseline.
    • Topology: locally built LOG + TN + CN from the exact source worktree; MOTR connected with MySQL/TCP to 127.0.0.1:26001.
    • Endpoint coverage: the in-process MySQL parser API and the local CN MySQL/TCP endpoint 127.0.0.1:26001 were covered. The standard multi-CN endpoints 127.0.0.1:16001, 127.0.0.1:16002, and Proxy 127.0.0.1:6001 were not covered; :6001 was already owned by a non-baseline Docker container and was deliberately not used.
    • Client protocol: MySQL/TCP through MOTR for the CN end-to-end replay; direct parser API for precise grammar controls.

    What Was Covered

    • OK — go test ./pkg/sql/parsers/dialect/mysql passed on the exact latest main baseline.
    • OK — original LAG(v) RESPECT NULLS OVER (...) parsed successfully.
    • OK — original NTH_VALUE(v, 2) FROM FIRST OVER (...) parsed successfully.
    • OK — extended LEAD, FIRST_VALUE, LAST_VALUE, and combined NTH_VALUE(..., 1) FROM FIRST RESPECT NULLS controls parsed successfully.
    • OK — MOTR record and replay through MySQL/TCP 127.0.0.1:26001 both passed: 12 statements, 12 successful, 0 failed.
    • OK — explicit RESPECT NULLS and FROM FIRST produced the same LAG and NTH_VALUE results as their implicit defaults across partitions, NULL input, and a full-partition window frame.
    • OK — respect remained valid as a non-reserved identifier.
    • OK — explicitly out-of-scope IGNORE NULLS and FROM LAST remained rejected with 1064.
    • Not covered — equivalent MySQL/TCP replay through CN1:16001, CN2:16002, and Proxy :6001.

    Findings

    The latest main contains the parser grammar from PR #28064. Explicit RESPECT NULLS and FROM FIRST are accepted as MySQL-compatible no-op defaults, while RESPECT remains non-reserved and the deliberately unsupported modifiers remain rejected.

    Large-data regression is not needed. This is a deterministic parser-grammar compatibility issue reached before row processing, planning, storage, network transfer, spill, or resource scaling.

    MOTR / BVT Coverage

    • MOTR branch: test/issue-28031-window-default-modifiers.
    • MOTR commit: 90bf32c — test: add MOTR regression for #28031.
    • Files: suites/14_issue_regression/t/issue_28031_window_default_modifiers.test and suites/14_issue_regression/r/issue_28031_window_default_modifiers.result.
    • Record and replay both passed against the locally built latest-main CN endpoint.

    Final Conclusion

    Fixed on refreshed origin/main bf63172c0691e917ed2613c2d3a2d3d76a7f682e. No large-data regression is required because the defect is data-size independent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions