Skip to content

[Performance]: partition Top-1 repeatedly copies payload rows within one group run #31002

Closed

Description

@LeftHandCold

Is there an existing issue for performance?

  • I have checked the existing issues.

Environment

  • MatrixOne main base: b78794175e65f8cf5a4a4ac1fcd2715534f48552.
  • Local Linux x86-64; the whole engine, native client and validator share 4 CPU cores/quota and a 12 GiB cgroup limit, swap disabled. Go soft memory limit 4 GiB; file-service cache caps include LOCAL.
  • TSBS CPU-only scale1000_1d_10s_seed123: 8,640,000 measurement rows, 1,000 tags, all original columns and original five queries retained.
  • Benchmark source: matrixorigin/mo-benchmark at f36e31710dbb42d50a6e4061fb23f5e2cf738df4.

Details of Performance

The latest-point-per-host query uses ROW_NUMBER() OVER (PARTITION BY c.tags_id ORDER BY c.created_at DESC) after joining cpu c to tags t, and filters rn = 1. When rows of one group arrive in increasing time order, the partition Top-1 operator repeatedly copies the retained payload row even though only the final best row in a consecutive group run can survive.

A separate 20-second CPU profile of the original query attributes 89.27% cumulative sampled CPU to replaceRow and 72.02% to Vector.Copy beneath it (overlapping percentages). This is unnecessary row-copy/metadata work, rather than evidence that the full data scan or SQL result may be skipped.

Paired A/B/B/A testing, one warmup and five measured executions per query per block, gives ten measured samples for each version. Original Q4 median client wall time is 1.271639 s; whole-unit CPU is 4.870377 s. A narrow candidate that retains only the first strictly best row in each consecutive same-group run within the existing 256-row hash chunk reaches 0.115064 s and 0.409131 CPU s. It requires no sorted-input assumption, extra state, or allocation. The original full native outputs match for all five CPU-only queries; other query median changes are between -1.1% and +1.9%. Whole-block peak memory is 1.49–1.52 GiB, with no OOM or memory-limit events.

Expected behavior: for Top-1 without ties, avoid repeated payload replacement within a group run while retaining existing SQL comparator, NULL, composite-order and first-peer semantics. Higher K, WITH TIES, hash admission, spilling, payload ownership and cleanup must retain their contracts. No change to query coverage or benchmark answers is requested.

Additional information

Draft fix: #31001

The candidate has independent stable-sort operator tests, metadata/reset/two-stage controls, and a six-row public SQL regression case that passed normal mo-tester comparison twice. On delivery base 156b7cc6f8, the full owning partition package and incremental vet/lint/native-provenance checks pass. Relevant operator dependencies are unchanged between the causal benchmark and delivery bases.

These numbers describe the stated CPU-only data and layout. DevOps/IoT and broader benchmark improvements are separate validation work; this report does not claim their completion. This is a measured performance problem, with no claim of a bisected regression or wrong SQL results.

Activity

  1. self-assigned this
    on Oct 24, 2026
  2. added
    severity/s0
    on Oct 24, 2026
  3. added a commit that references this issue on Oct 24, 2026
    8fdc275
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/performanceseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions