Skip to content

fix: correct IPv4 and IPv6 function semantics - #28800

Merged
XuPeng-SH merged 10 commits into
mainfrom
codex/issue-28214-28217-ip-functions-20260913
Sep 15, 2026
Merged

XuPeng-SH merged 10 commits into
mainfrom
codex/issue-28214-28217-ip-functions-20260913

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #28214
Fixes #28215
Fixes #28216
Fixes #28217

What this PR does / why we need it:

  • Parse MySQL-compatible IPv4 text for INET_ATON, including one-, two-,
    three-, and four-part decimal forms. The mappings are a → 0.0.0.a,
    a.b → a.0.0.b, a.b.c → a.b.0.c, and a.b.c.d unchanged. Leading
    zeroes are decimal, every part remains bounded to 0..255, and malformed
    signs, whitespace, empty parts, excess parts, and out-of-range parts return
    NULL.
  • Keep IS_IPV4 and the IPv4 form of INET6_ATON on the strict four-part
    parser; adding historical INET_ATON abbreviations does not broaden those
    consumers.
  • Preserve INET_NTOA input signedness and type-specific conversion. Validate
    after conversion/rounding, before narrowing, so negative or out-of-range
    values cannot wrap into another IPv4 address. DECIMAL remains exact and
    rounds half away from zero; FLOAT/DOUBLE uses ties-to-even and rejects
    non-finite values.
  • Preserve address identity: plain IPv4 remains four bytes, explicit IPv6
    (including IPv4-mapped IPv6) remains sixteen bytes, and mapped formatting
    includes ::ffff:. IS_IPV6 recognizes mapped values, IS_IPV4 does not,
    and IPv4-compatible classification excludes :: and ::1.

No shared cache, background work, or retained state is introduced. The short
form parser uses fixed-size stack storage and bounded arithmetic; ordinary
four-part and numeric paths remain vectorized.

Validation

  • ./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run 'TestIPv4ParsingPolicies|TestIPFunctionRegisteredExecutors|TestIPFunctionsSelectionMasksInvalidRows' ./pkg/sql/plan/function — pass.
  • The same focused selection with -race — pass.
  • ./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/sql/plan/function — pass (12.8s).
  • The owning package with -race -count=1 — pass (33.2s).
  • Incremental golangci-lint --new-from-rev=30b568022b3c -- ./pkg/sql/plan/function
    with the repository native include flags — 0 issues.
  • license-eye -c .licenserc.yml header check on the four changed files —
    valid/ignored as expected.
  • gofmt and git diff --check — pass.
  • BVT fixture test/distributed/cases/function/func_misc_inet.test and its
    reviewed .result now cover scalar, VARCHAR-column, short-form, leading-zero,
    malformed, and mapped-IPv6 controls. A clean service-side mo-tester run is
    still pending; no BVT pass is claimed here.

The prior CheckpointChaos2 timeout was a pre-existing timing-sensitive test
covered by #20956 and is unrelated to this function change. The PR remains on
the non-default feature branch; CI is not being awaited for this update.

Rollout compatibility

  • Remote execution for the changed IP overloads is fenced at protocol version 72; senders re-check the worker capability and receivers reject unsupported requests. This keeps rolling upgrades from mixing the old and new semantics.
  • Catalog-bound default, generated, CHECK, CTAS, CREATE TABLE, and ALTER target definitions are admitted only when the deployment protocol reaches version 71. An ALTER that removes the protected expression checks the replacement target, not the old source definition.
  • The remaining view-SQL/reintroduced-old-CN persistence boundary is tracked in [Bug]: guard persisted SQL and expressions across rolling protocol downgrade #28883; this PR does not claim to solve that separate lifecycle.

Additional validation

  • TestPersistedIPFunctionProtocolAdmission, TestPersistedIPFunctionProtocolAdmissionAcrossOwners, and TestPersistedIPFunctionProtocolAdmissionForCatalogBuilders pass.
  • TestPersistedIPFunctionAlterTargetAdmission passes for v70/v71 and replacement/no-replacement ALTER targets.
  • ./.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s ./pkg/sql/plan ./pkg/sql/compile — pass.
  • GPT-6 medium final review of exact head 363b00b450 — no P0–P2 blocker.

The earlier review note claiming REAL INET_NTOA should round 1.5 to 1 was withdrawn after checking MySQL's Item_float::val_int() behavior (rint, ties-to-even); no code change is required for that point.

Rebase correction

  • Current main already uses MORPC v71 for checked integer arithmetic (fix(function): preserve mixed integer arithmetic domains #28704). The IP semantic fence and all persisted-IP admission checks therefore use the next protocol epoch, v72; the main v71 detector and sender/receiver checks are preserved unchanged.
  • The v72 boundary is tested explicitly: v70 and v71 reject protected IP expressions, while v72 admits them; worker downgrade/send rechecks cover the same boundary.
  • GPT-6 medium reviewed exact rebased head 363b00b450 and found no P0–P2 blocker. The prior v71-labelled experimental build is not part of the supported upgrade chain.

@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 →

@mergify mergify Bot added the kind/bug Something isn't working label Sep 12, 2026
@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Sep 12, 2026
@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

CI triage and rebase update:

  • The failed Matrixone CI execution / UT Test on Ubuntu/x86 run 34820366730 failed only in the pre-existing pkg/vm/engine/tae/db/test/Test_CheckpointChaos2.
  • The failure was an intermittent checkpoint fault-injection assertion: the injected GCKP save returned context deadline exceeded, and the rollback snapshot differed by one temporary object. This test is outside this PR's IPv4/IPv6 implementation and BVT changes. Historical issue [Bug]: UT Test_CheckpointChaos2 fail #20956 tracks the same test family.
  • I reran the exact test 3 times on the reviewed head and 3 times on current main; all reruns passed. No PR-specific failure or new reproducible base defect was found, so no new issue was opened.

The branch was rebased onto current main (a72a224ce8) and updated in place. New head: abd2719a9e74c919b1d1ebf80dd708acaaca8f48. Existing local function UT/race/coverage/SCA evidence remains valid; no CI wait requested.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Pure rebase update: started from upstream PR head abd2719a9e74c919b1d1ebf80dd708acaaca8f48 and rebased onto latest main c61ed374a8; new head 30b568022b3c39c5d0e0613b902e07dac3b645b5. No semantic changes were made; git diff --check passes. The earlier UT failure was the pre-existing CheckpointChaos2 timing-sensitive test (issue #20956), reproduced on base and not related to this PR. Existing IP function UT/race/SCA/coverage evidence remains applicable. Only the existing non-default PR branch was updated; main was not touched and CI was not awaited.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

GPT-6 medium deep review at exact head 30b5680.

P2 — explicit REAL INET_NTOA conversion rounds differently from MySQL. At pkg/sql/plan/function/func_unary.go:8099, INET_NTOA(CAST(1.5 AS DOUBLE)) uses round-to-even and yields .2 instead of MySQL's truncating .1; near the maximum IPv4 value the current path can return NULL instead of the maximum address.

P2 — mixed-version overload fence is absent. New overload IDs 4–8 are not covered by a protocol/admission/remote capability fence, so a distributed expression can reach an older CN whose registry only knows IDs 0–3 and fail overload lookup.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Scope completion after the review challenge:

  • INET_ATON now handles MySQL's one-, two-, three-, and four-part decimal forms (a → 0.0.0.a, a.b → a.0.0.b, a.b.c → a.b.0.c). Each part remains 0..255; malformed and over-range forms return NULL.
  • IS_IPV4 and the IPv4 form of INET6_ATON intentionally remain strict four-part consumers.
  • Added focused normal/race coverage and extended the existing func_misc_inet scalar/column fixture with the issue [Bug]: INET_ATON rejects MySQL short IPv4 forms and leading-zero octets #28214 witnesses and malformed controls.

Commit: 75a703ad16807cd673e89fbde4daa36174b503e4.

Focused UT, focused race, and full native CGo-linked pkg/sql/plan/function UT pass. A clean service-side BVT run remains pending; the PR body records that boundary explicitly.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Follow-up after the exact-head re-review (df4187e5ac):

  • I withdraw my earlier P2 claiming REAL INET_NTOA(1.5) must round to 1. Checking MySQL's Item_float::val_int() shows it uses rint, i.e. ties-to-even; the PR's current behavior is correct, so no code change is requested for that note.
  • The mixed-version protocol finding remains valid and is now addressed by v71 sender/receiver fences.
  • Persisted default/generated/CHECK/CTAS and CREATE/ALTER target admission now rejects protected IP expressions until all CNs support v71. The old-source-versus-replacement ALTER case is covered by TestPersistedIPFunctionAlterTargetAdmission.
  • View SQL and downgraded/reintroduced old-CN read admission remain tracked separately in [Bug]: guard persisted SQL and expressions across rolling protocol downgrade #28883.

GPT-6 medium reviewed exact head df4187e5ac and found no P0–P2 blocker. Focused and full plan/compile package tests pass; CI is not being awaited.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Rebase conflict resolution update for main 23c8cb676e: main now owns MORPC v71 for checked integer arithmetic (#28704), so the IP compatibility fence is correctly moved to v72. The final patch keeps main's v71 integer detector/sender/receiver checks and updates IP worker admission, destination validation, receiver validation, persisted CREATE/ALTER admission, diagnostics, and tests to v72. v70/v71 rejection and v72 acceptance now pass in normal and race-focused suites. GPT-6 medium reviewed exact head 363b00b450 and found no P0–P2 blocker. The old v71-labeled experimental build must not be treated as a supported upgrade node.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

GPT-6 medium deep review at 363b00b450cdf1475f832ffeb5e20bfb86749467 — PASS; no blocking findings.

I reviewed the IPv4/IPv6 parser contract, strict dotted-quad validation for IS_IPV4, short-form compatibility retained only for INET_ATON, IPv6 and IPv4-mapped/compatible classification, numeric INET_NTOA range/rounding behavior, generated-column and persisted-expression rollout gates, and remote protocol dispatch. The current implementation separates strict consumers from MySQL short-form INET_ATON parsing and fences persisted expressions by the protocol-version marker, so a legacy serialized expression is not silently executed with the new semantics. Focused IP tests pass locally (go test -mod=readonly ./pkg/sql/plan/function -run 'Test.*(IP|Inet|INet|inet)' -count=1, 2.7s), and current-head CI is green. No concrete incorrect-result, rollout, or compatibility blocker found.

This branch was previously deployed

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

Labels

kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

2 participants