Skip to content

[Performance]: DATETIME-to-DECIMAL predicates repeatedly format and parse each row #29580

Closed

Description

@LeftHandCold

Summary and confidence

Confirmed performance inefficiency in the actually executed predicate path: DATETIME-to-DECIMAL conversion formats each temporal value with fmt.Sprintf and parses it back through types.ParseDecimal128. In two Main BigData runs, this path dominates a large sorted-column lookup's CPU samples.

This report is not a claim that the October 2 changes introduced this cost, or that all adjacent-run BigData timing increases share this root cause. The conversion implementation is identical at both tested SHAs. The non-sargable mixed-domain predicate may legitimately require a scan; the optimization target is the expensive per-row temporal conversion while preserving MySQL-compatible semantics.

Original evidence and exact subjects

  • Previous BigData Run 36886052323, product 32f54981401fd3888702f2dab8702d2e62c6997a, namespace mo-bigdata-pilot-36886052323-1.
  • Current Bykey Job 111093804933 / Run 37032919798, product 5a09e1ffbf40a59f50c55fe89e6f0c23eba143a3, namespace mo-bigdata-pilot-37032919798-1.
  • Current immutable image: ccr.ccs.tencentyun.com/matrixone-dev/matrixone@sha256:ca791c8e2f2bb8ada0eb56fb00d06cb8cc341d0ef3ddeb6f2221f70cb62c047e.
  • Three CNs, each 14 CPU / 55Gi; TN 14 CPU / 55Gi. Same frozen SQL assets 5615d3c97496307c9b5027c84b528e8c321777e5; harness revisions differ and therefore these runs are not a pure product-only A/B.
  • Source: frozen 12_bykey_1B.sql, statement 31:
SELECT * FROM big_data_test.table_with_sortkey_for_load_1B
WHERE col13 IN (
  '1000-01-01 00:59:05',
  10000,100000,1000000,5000000,10000000,20000000,
  40000000,60000000,80000000
);

The mixed temporal-string/numeric predicate is present in the frozen workload, not introduced as a new diagnostic. Both attempts completed successfully; this Case is no_golden_execute_success, so success is not an independent wrong-result certification.

Runtime CPU evidence

Pyroscope CPU type: process_cpu:cpu:nanoseconds:cpu:nanoseconds; selector {service_name="<namespace>/main",pod=~".*cn.*"}.

  • Previous sample: October 2, 2026, 01:46:00–01:48:00 UTC, within statement 31 (01:45:21.844–01:49:59.333 UTC).
  • Current sample: October 3, 2026, 01:47:00–01:49:00 UTC, within statement 31 (01:44:39.599–01:50:02.330 UTC).
Inclusive sampled CPU share Previous Current
datetimeToDecimal128 94.64% 81.90%
packedDatetimeDecimal128 92.89% 80.26%
types.ParseDecimal128 52.03% 45.22%
packedDatetimeDecimalString 40.57% 34.80%

These are nested percentages; they must not be added. The current interval also contains a concurrent basic-table INSERT SELECT, so it is an aggregate CN profile, not CPU attribution to one statement in isolation. The ancestry of the dominant conversion is nevertheless unambiguous:

TableScan.readBatch
  reader.ReadWithFilter / reader.read
    BlockDataReadWithFilter / blockDataReadWithFilter
      TableScan.applyReaderFilter / evalFilter
        FunctionExpressionExecutor.Eval
          NewCast / datetimeToOthers
            datetimeToDecimal128
              packedDatetimeDecimal128
                packedDatetimeDecimalString / fmt.Sprintf
                types.ParseDecimal128 / Parse128

Statement 31 increased from 277.488s to 322.731s (+16.3%); it was already expensive in the previous run. Overall Bykey SQL time increased from 2525.84s to 2883.59s (+14.2%). Neither number establishes the introducing commit.

Code-level cause

At both tested revisions:

  • packedDatetimeDecimalString computes packed calendar digits, then formats %d.%06d into a string.
  • packedDatetimeDecimal128 calls types.ParseDecimal128 on that newly formatted string.
  • datetimeToDecimal128 invokes this conversion for each non-NULL row.

The profile and exact source agree on the bottleneck: a numeric/calendar value is repeatedly serialized as decimal text and immediately parsed back during predicate evaluation. This has real customer relevance for temporal numeric comparisons/CASTs over large relations; it is not simply an INSERT preparation issue.

Adjacent timing increases that must not be conflated

  • Basic-table INSERT SELECT increased from 445.08s to 755.04s (+69.6%). The previous insertion overlapped earlier Bykey range predicates; the current insertion overlaps this CPU-heavy temporal conversion. Thus this increase is not proof of a new insertion-engine regression.
  • Other secondary-index Bykey statements show larger relative increases (e.g. statement 14, 5.952s to 29.893s), but their concurrent insert workloads differ. This conversion profile does not prove the cause of those statements.
  • The current BigData image is 5a09e1..., not the separate Main Family image 9078a8...; notably it does not contain fix(vector): restore UnionOne copy and marshal performance #29573. Do not treat the two runs as testing identical product revisions.

Expected behavior / focused follow-up

  1. Preserve the required implicit/explicit temporal-to-numeric semantics, NULL/zero temporal behavior, fractional precision, rounding, scale, overflow and error behavior. Do not "fix" this by silently converting all mixed operands into DATETIME or deleting the test predicate.
  2. Measure an arithmetic packed-temporal-to-decimal implementation against the existing formatting/parsing path with representative scales; establish allocation and CPU deltas before proposing a production change.
  3. Check this existing predicate's plan and result against the supported MySQL-compatible oracle; distinguish the unavoidable scan from avoidable per-row formatting/parsing.
  4. Re-run the existing Bykey statement on identical physical data without concurrent writes, then repeat the original mixed load as a separate observation. No controlled isolated A/B has been run for this report.

Duplicate check

Searched open/closed reports for packedDatetimeDecimal128, datetimeToDecimal128, 12_bykey_1B, temporal/decimal CAST performance. No specific report for this conversion bottleneck was found.

This is a confirmed hot-path performance problem; first-bad revision and the contribution to other workload timings remain unproven.

Activity

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s-1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions