Skip to content

fix(plan): preserve temporal fractional precision in CTAS metadata - #30798

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix/temporal-ctas-fsp
Oct 22, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix/temporal-ctas-fsp

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #28236.

  • Derive CONVERT_TZ's result fractional precision from a constant datetime string, while retaining the declared precision of a temporal input.
  • Recognize fractional seconds only after the time portion. Dots in valid calendar dates such as 2024.01.15 no longer produce a false datetime(2) result. Compact YYYYMMDDHHMMSS.fraction values retain their fractional precision. The shared inference also serves generate_series.
  • Normalize temporal CTAS column width to its fractional precision, including prepared CTAS inferred columns. This makes COLUMN_TYPE and DATETIME_PRECISION agree with the stored value.
  • Add binder, CTAS planner, and SQL metadata regressions for dotted dates, dotted datetimes without fractions, genuine fractions, compact datetime literals, and the existing ADDTIME/SUBTIME cases.

Verification

The original PR head 529584181e9d89b2b83e0871f846e30d1185634a was independently reproduced through SQL and planning in the change-request review: dotted date and dotted datetime inputs yielded datetime(2) instead of precision zero.

For updated head 106541b35681a66dc861ac6b349e90c01433b84d, the GitHub CI shared build passed and its BUILD_INFO confirms the exact SHA. On [email protected], func_convert_tz_ctas_fsp.sql passed twice in normal mo-tester comparison mode against that binary (6/6 statements, zero failures each run). The isolated test database was removed. The focused local-to-remote Go test attempt was cancelled during an overloaded linker phase and is not counted as passing; CI unit and coverage checks have passed; the static check is still running.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 529584181e9d89b2b83e0871f846e30d1185634a

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · superseded

Commit: 529584181e9d89b2b83e0871f846e30d1185634a

"interrupted"

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 529584181e9d89b2b83e0871f846e30d1185634a

Assessment: request_changes

Reviewed the complete four-file delta and affected binder, CTAS, prepared-execution, cast and catalog paths. Normalizing inferred temporal columns at the existing CTAS owner is reasonable and preserves explicit column definitions. However, literal precision inference incorrectly treats dotted date separators as fractional seconds. Added work is confined to binding and schema inference; no per-row overhead was introduced.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

  • P2 pkg/sql/plan/base_binder.go:8252: CREATE TABLE tz_fsp AS SELECT CONVERT_TZ('2024.01.15', '+00:00', '+00:00') AS d;
    Impact: This valid date-only literal acquires Scale=2 and Width=2, so CTAS exposes datetime(2) and DATETIME_PRECISION=2 instead of precision 0. Equivalent dashed and dotted dates therefore produce different schemas.
    Evidence: ParseDatetime accepts this input through ParseDateCast; date_test.go explicitly includes '2024.01.15' as a valid dotted date. datetimeLiteralScale in generate_series.go:196 counts digits after the last dot, interpreting the day '15' as fractional seconds. The new caller assigns that count to the result type, and CTAS preserves it. Catalog formatting reads Width for COLUMN_TYPE and Scale for DATETIME_PRECISION. Derive precision from the actual fractional-seconds component and add dotted-date controls, including a dotted datetime without fractions.

Validation:

  • Reviewed all changed implementation and tests, existing prepared temporal reuse tests, CTAS SQL regressions, implicit-cast precision handling and catalog formatting.

  • Frozen evidence reports successful exact-head Ubuntu UT, SCA, coverage, proxy BVT and multi-CN pessimistic BVT checks. These statuses do not establish coverage of the dotted-date counterexample.

  • git diff --check passed. Reconciled checks/1792645906150398847-3.json with diff-check.log under /home/xupeng/.local/state/mo-bot/jobs/10d85d11f584940d63e673f8/attempt-1; receipt records the assigned head, clean source fingerprint and exit 0.

  • Isolation preflight passed. Reconciled checks/1792645906240191074-29.json with preflight.log in the same directory. This verifies executor setup, not product behavior.

Limitations:

  • The finding is established by source tracing; no local Go tests or SQL server reproduction were executed.

  • local_validation is empty, and raw CI logs and per-test execution manifests were not supplied. The author's recorded SQL reproduction tested the base revision only.

  • The linked issue #28236 body was not included in the frozen evidence; its contract was assessed from the PR description.

  • No performance benchmark was run; the added literal parse and scan occur during binding.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 5295841, the complete four-file change, linked issue, and all review discussion.

The common CTAS temporal-width normalization is placed at the existing inferred-schema owner and preserves explicit target definitions. One blocker remains in the new CONVERT_TZ literal precision inference: calendar punctuation is mistaken for fractional seconds.

I independently reproduced it in both actual DDL planning and the SQL frontend/catalog: dotted date and dotted datetime-without-fractions become datetime(2) / DATETIME_PRECISION=2, while equivalent dashed-date and genuine-fraction controls behave correctly. Details and reproducible SQL are inline. Exact-head green planner/SCA CI does not cover this counterexample. No production files were changed.

Comment thread pkg/sql/plan/base_binder.go Resolved

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE on exact head 106541b35681a66dc861ac6b349e90c01433b84d (base/merge-base a949c88af0ed2cc4fe98e2ac32f0732a1235bd85).

Re-reviewed all historical reviews, inline discussion and resolved-thread state, every hunk since my previous reviewed head 529584181e9d89b2b83e0871f846e30d1185634a, and the complete current eight-file diff. The previous blocker is genuinely fixed, rather than merely marked resolved: calendar dots are excluded from fractional precision, while dotted datetimes with real fractions and compact 14-digit datetime fractions retain their precision. I also traced the shared generate_series consumer and normal/prepared CTAS normalization; explicit target definitions remain protected. This is a focused bug fix, exempt from the major-refactor design gate.

Independent verification in an isolated exact-head worktree:

  • Eight focused planner test roots passed (-count=1, package 0.065s), including the new binder/CTAS/helper tests, prepared temporal contracts/reuse, and an independent eight-input BuildPlan probe. The previous dotted-date witnesses now yield Width=Scale=0; real fractions yield 3/6, including compact, ISO and short-calendar controls.
  • Real SQL frontend/catalog probe passed (4.957s): six CONVERT_TZ CTAS inputs agree on COLUMN_TYPE, DATETIME_PRECISION and stored microseconds. Prepared ADDTIME CTAS was executed twice with different values and retained datetime(6). Database teardown was checked.
  • Ran the committed func_convert_tz_ctas_fsp.sql with its unchanged .result through mo-tester in normal comparison mode, equivalent -n -g -o -p options, twice on the same test-owned single-CN embedded instance. Both reports name the exact case and show 6/6 success, 0 ignored/failed/abnormal, in 0.113s and 0.105s; database absence was checked between runs. An initial harness attempt failed before any case execution because my temporary tester configuration lacked outfiles; after correcting only that configuration, both comparisons passed. No result file was generated or accepted from output.
  • Reused exact-head CI coverage UT job 119713597337: raw checkout matches this SHA; producer receipt is passed/exit 0, 509 package starts and no package/test failure events; changed helper/normalization blocks have positive coverage. Full race UT, SCA and multi-CN BVT are still running and are not claimed green.

No remaining blocking issue found. Temporary tests were removed; no production source or expected result was modified.

@XuPeng-SH

XuPeng-SH commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 106541b35681a66dc861ac6b349e90c01433b84d

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 106541b35681a66dc861ac6b349e90c01433b84d

Assessment: approve

Reviewed the complete eight-file delta and affected callers. The existing binder and CTAS schema owners restore consistent temporal precision across ordinary and prepared CTAS while preserving explicit definitions. Reusing the corrected literal helper closes the dotted-date finding without adding state or per-row work. No actionable defects remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Passed 11 focused planner test roots covering new regressions, generate_series inference, temporal contracts and prepared reuse.

  • Passed an independent single-CN MySQL-protocol probe checking catalog metadata and stored microseconds, fractional rounding, timezone conversion, NULL handling, explicit target precision and repeated prepared CTAS execution.

  • Configured incremental planner lint reported zero issues; formatting and diff checks passed.

  • Isolation preflight passed. Verified 192 matching native inputs and seven build-owner output hashes before executing tests.

  • Reconciled commands, clean-head fingerprints, exits and retained logs in /home/xupeng/.local/state/mo-bot/jobs/3aac129a72931a731d1a5dc9/attempt-1/review-evidence-audit.json. Source remains unchanged.

Limitations:

  • The initial SQL probe had an incorrect integer-control expectation; its failure and corrected passing run are retained separately. Native setup failures were resolved before product tests.

  • No full distributed-suite rerun or performance benchmark. Added work is confined to literal binding and constant-size normalization per inferred CTAS column.

  • The frozen packet lacks original linked-issue text and raw author/CI execution artifacts; those assertions were not counted as independently verified passes.

@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

This branch was previously deployed

1 inactive deployment
ci — 425e6725 Deployed Oct 22, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: temporal-expression CTAS columns retain microseconds but report DATETIME(0)

4 participants