Skip to content

FEAT: Add native JSON columns to synchronous TVPs - #929

Draft
Jahnvi Thakkar (jahnvi480) wants to merge 1 commit into
mainfrom
jahnvi/json-api-coverage-study
Draft

Jahnvi Thakkar (jahnvi480) wants to merge 1 commit into
mainfrom
jahnvi/json-api-coverage-study

Conversation

@jahnvi480

Copy link
Copy Markdown
Contributor

Work Item / Issue Reference

N/A; related GitHub issue below.

GitHub Issue: #261


Summary

Add native JSON columns to the existing synchronous TableValuedParameter API.

  • Declare columns with SQL_JSON and pass Json snapshots or None. JSON size/scale must be omitted or zero; bare dict/list/str cells are rejected.
  • Bind native SQL_SS_JSON / SQL_C_WCHAR child columns. Unwrap Json text only in the copied binding row, without parsing, reserializing or mutating caller rows.
  • Preserve lazy generators, large Unicode cell streaming, SQL NULLs, multiple TVPs/scalars, execution-scoped JSON output and statement recovery. Unsupported providers retain ODBC diagnostics; there is no text fallback or retry.
  • Add contract, live streaming/results/recovery, shipped-driver rejection and consumer typing coverage; document usage and provider requirements. Async, Rust, bulk/Arrow and callproc TVP support are unchanged.

Validation:

  • Windows x64, Python 3.13.17: build.bat x64 from mssql_python\pybind — passed.
  • Linux x64, Python 3.13.15/GCC 12.2: fresh Release CMake build with two build workers — passed.
  • On each OS, python -m pytest tests/test_028_table_valued_parameters.py tests/test_json.py tests/test_042_execute_param_rebind.py -q --no-cov with the qualified preview and MSSQL_TEST_NATIVE_JSON=1 — 342 passed, 9 expected shipped/legacy skips, 1 stress deselection.
  • Same test selection on Windows with the shipped provider and without the preview flag — 140 passed, 211 expected preview-only skips, 1 stress deselection. Native JSON TVP rejection preserves HY004 and leaves the source unconsumed; cursor reuse succeeds.
  • python -m pytest tests/test_typing.py -m typing -q --no-cov — 9 passed.
  • python -m pre_commit run black-check --all-files --hook-stage pre-push — passed.
  • git diff --check — passed.

Provider/server qualification:

  • Reused native-JSON preview ODBC 18.7.1.1, feature/JsonFeature@ee87e0c6b, build 194329; SQL Server 2025 17.0.5005.3.
  • Windows DLL SHA256: e373fd476d97d4870c1adbac65d0590dd5d7624ddef43c0b7ae5d4711654f635.
  • Linux library SHA256: 85a667eb8e237015d0de2691055ea4c0b0c9235262f68a27f8b7f501f20fe1d0.
  • Actual binary bytes were checked: package metadata still reports 18.6.2.2. Linux used an isolated runtime alias to the verified preview library.
  • Disposable localhost-only SQL containers and the Linux client were removed; absence verified. No preview binaries, credentials, environment changes or test harnesses are included in this PR.
  • These are targeted source-build results, not release enablement or all-platform qualification. macOS, ARM64 and the full repository suite were not run. The shipped provider does not yet support native JSON TVP binding.

Support explicit Json snapshots and NULLs in native JSON TVP columns, preserving lazy streaming and provider diagnostics.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 09:15
@github-actions github-actions Bot added the pr-size: medium Moderate update size label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Performance Report

✅ No regression detected

No consistent slowdowns detected across all 2 environments.

0 IMPROVEMENTS 0 SLOWDOWNS 2/2 ENVIRONMENTS

Coverage: 2 of 2 environments completed. Advisory result; does not block merging.

Performance diagnostics

Phase times are inclusive diagnostics and must not be added together. They identify where measured time changed, not why it changed.

No affected phases or call-count changes were recorded.

All database tasks and timings

Unix / SQL Server 2022

Database task Before After Paired change Result
Connection opening 10.380 ms 10.295 ms -0.7% no signal
SELECT queries 1.304 ms 1.298 ms -1.3% no signal
Row insertion 32.315 ms 32.189 ms -0.3% no signal
Executemany inserts 161.662 ms 158.111 ms -0.6% no signal
Fetch-all queries 119.550 ms 119.723 ms +0.1% no signal
Row-by-row fetching 6.090 ms 6.083 ms -0.1% no signal
Batched row fetching 117.857 ms 118.487 ms +0.9% no signal
Transaction commit and rollback 109.361 ms 108.156 ms -2.2% no signal
Arrow row fetching 97.045 ms 101.044 ms +4.1% no signal
100,000-row insertion 377.266 ms 358.137 ms -5.2% no signal
Row fetching in batches of 100 130.839 ms 124.726 ms -4.7% no signal
Row fetching in batches of 10,000 122.001 ms 123.374 ms +2.0% no signal
Repeated positional queries 34.201 ms 33.901 ms -2.4% no signal
Repeated named-parameter queries 34.503 ms 33.901 ms -1.4% no signal
Legacy 100,000-row insertion 273.622 ms 272.931 ms -1.1% no signal
Insertion with explicit input sizes 547.024 ms 524.739 ms -4.1% no signal
Joined aggregation queries 185.294 ms 183.699 ms -0.7% no signal
Large joined-result fetching 198.814 ms 192.239 ms -1.6% no signal
1.2-million-row fetching 3520.976 ms 3541.748 ms +0.5% no signal
Common table expression queries 5.446 ms 5.492 ms -0.2% no signal
256 KiB VARCHAR(MAX) / fetchall() 1.247 ms 1.217 ms +0.9% no signal
10,000 scalar values / fetchval() (debug disabled) 19.340 ms 19.187 ms -1.2% no signal
10,000 output-converted rows / fetchall() 19.153 ms 19.154 ms -2.4% no signal
10,000 output-converted rows / fetchmany(1000) 24.204 ms 22.954 ms -2.7% no signal
10,000 INT/NVARCHAR rows / fetchmany(1) 27.734 ms 27.674 ms -1.0% no signal
5,000 x 8 VARCHAR(8000) / ASCII to UTF-16 41.152 ms 44.365 ms +10.2% no signal
5,000 x 8 VARCHAR(8000) / CP1252 to UTF-16 55.518 ms 50.162 ms -2.3% no signal
5,000 x 8 VARCHAR(8000) / UTF-8 to UTF-16 (astral) 107.008 ms 92.345 ms -13.9% no signal
5,000 x 8 NVARCHAR(4000) / UTF-16 (astral) 90.421 ms 85.922 ms -5.4% no signal
5,000 x 8 VARCHAR(8000) / short ASCII 10.244 ms 10.166 ms -1.5% no signal
200 x 8 VARCHAR(8000) / full-width ASCII 43.220 ms 41.833 ms -3.2% no signal
5,000 x 8 VARCHAR(8000) / short CP1252 12.633 ms 12.448 ms -1.5% no signal
200 x 8 VARCHAR(8000) / full-width CP1252 42.407 ms 42.088 ms -1.5% no signal
5,000 x 8 VARCHAR(8000) / short UTF-8 (astral) 15.919 ms 15.763 ms -1.6% no signal
200 x 8 VARCHAR(8000) / full-width UTF-8 (astral) 46.588 ms 46.564 ms -0.7% no signal
5,000 x 8 NVARCHAR(4000) / short UTF-16 (astral) 13.872 ms 14.192 ms +2.5% no signal
200 x 8 NVARCHAR(4000) / full-width UTF-16 (astral) 59.375 ms 61.239 ms -0.3% no signal
200,000 x 8 VARCHAR(32) / fetchall control 512.810 ms 520.351 ms +0.4% no signal
200,000 x 8 INT / fetchall control 278.202 ms 271.799 ms -1.8% no signal
10,000 rows x 32 columns / dict(row._mapping) (warm) 31.813 ms 30.661 ms -3.3% no signal

Unix / SQL Server 2025

Database task Before After Paired change Result
Connection opening 82.491 ms 81.759 ms -2.6% no signal
SELECT queries 1.442 ms 1.310 ms -0.7% no signal
Row insertion 31.666 ms 31.810 ms -0.1% no signal
Executemany inserts 152.568 ms 154.893 ms -0.6% no signal
Fetch-all queries 122.130 ms 121.153 ms -0.5% no signal
Row-by-row fetching 6.260 ms 6.164 ms -1.3% no signal
Batched row fetching 120.930 ms 119.573 ms -2.5% no signal
Transaction commit and rollback 108.137 ms 108.882 ms +0.2% no signal
Arrow row fetching 99.929 ms 100.387 ms +0.2% no signal
100,000-row insertion 361.507 ms 378.911 ms +4.8% no signal
Row fetching in batches of 100 126.402 ms 129.319 ms +2.5% no signal
Row fetching in batches of 10,000 123.966 ms 129.773 ms +1.2% no signal
Repeated positional queries 33.146 ms 34.220 ms +1.5% no signal
Repeated named-parameter queries 33.657 ms 33.872 ms +1.2% no signal
Legacy 100,000-row insertion 293.585 ms 281.029 ms -3.5% no signal
Insertion with explicit input sizes 545.894 ms 548.994 ms +1.3% no signal
Joined aggregation queries 163.444 ms 168.260 ms +3.0% no signal
Large joined-result fetching 192.084 ms 184.870 ms -5.3% no signal
1.2-million-row fetching 3544.586 ms 3561.698 ms +0.6% no signal
Common table expression queries 5.307 ms 5.271 ms -0.6% no signal
256 KiB VARCHAR(MAX) / fetchall() 1.682 ms 1.661 ms -0.1% no signal
10,000 scalar values / fetchval() (debug disabled) 20.205 ms 19.507 ms -2.4% no signal
10,000 output-converted rows / fetchall() 20.389 ms 19.937 ms -2.2% no signal
10,000 output-converted rows / fetchmany(1000) 23.586 ms 23.048 ms -2.6% no signal
10,000 INT/NVARCHAR rows / fetchmany(1) 29.109 ms 28.238 ms -1.4% no signal
5,000 x 8 VARCHAR(8000) / ASCII to UTF-16 50.696 ms 50.172 ms -0.3% no signal
5,000 x 8 VARCHAR(8000) / CP1252 to UTF-16 61.133 ms 61.609 ms +1.8% no signal
5,000 x 8 VARCHAR(8000) / UTF-8 to UTF-16 (astral) 119.246 ms 119.540 ms -0.8% no signal
5,000 x 8 NVARCHAR(4000) / UTF-16 (astral) 122.573 ms 122.808 ms +1.4% no signal
5,000 x 8 VARCHAR(8000) / short ASCII 10.267 ms 10.123 ms -1.4% no signal
200 x 8 VARCHAR(8000) / full-width ASCII 51.220 ms 50.991 ms -2.9% no signal
5,000 x 8 VARCHAR(8000) / short CP1252 12.395 ms 12.287 ms -0.8% no signal
200 x 8 VARCHAR(8000) / full-width CP1252 49.764 ms 50.708 ms +1.5% no signal
5,000 x 8 VARCHAR(8000) / short UTF-8 (astral) 15.652 ms 15.633 ms +0.3% no signal
200 x 8 VARCHAR(8000) / full-width UTF-8 (astral) 52.500 ms 54.585 ms +4.5% no signal
5,000 x 8 NVARCHAR(4000) / short UTF-16 (astral) 13.937 ms 14.018 ms -0.2% no signal
200 x 8 NVARCHAR(4000) / full-width UTF-16 (astral) 76.927 ms 72.773 ms -1.5% no signal
200,000 x 8 VARCHAR(32) / fetchall control 523.718 ms 519.289 ms -1.1% no signal
200,000 x 8 INT / fetchall control 297.666 ms 273.106 ms -2.0% no signal
10,000 rows x 32 columns / dict(row._mapping) (warm) 30.927 ms 31.590 ms +3.0% no signal
Build and measurement details

ADO build 196152

PR head: 630e631388ed540982844b426f5bd6563494acda
Base: df875895484e9219753bb5bdce9f62cfb462692b
Measured merge: 54713ffaa267d1595b0aa0c03e14ae777927da16

  • Unix / SQL Server 2022: Python 3.12.3, x86_64, SQL 16.0.4325.4; 5 paired comparisons and 1 warmup.
  • Unix / SQL Server 2025: Python 3.12.3, x86_64, SQL 17.0.5065.9; 5 paired comparisons and 1 warmup.

A consistent change requires more than 20% median paired movement, at least 1 ms between the median runtimes, and at least 80% of pairs exceeding the relative threshold in the same direction. A slowdown without enough pair agreement is reported as inconsistent.

The displayed change is the median of paired before-and-after ratios. It is not recalculated from the two displayed median runtimes.

Both revisions use profiling-enabled builds on the same agent and database, with alternating order and discarded warmups. Results are diagnostic and do not represent production-wheel latency.

Raw samples and logs are attached to the ADO run as profiler-* artifacts.

Copilot AI 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.

🔵 Needs a closer look

The native JSON TVP path requires maintainer confirmation because its reported binding and recovery results cannot be independently validated without the unbundled preview ODBC provider and a live SQL Server.

No open issues 🎉

What changed in this PR

Adds native JSON columns to the existing synchronous TableValuedParameter API, using explicit Json snapshots and native ODBC binding without a text fallback. Successful execution requires a JSON-TVP-capable provider; the bundled released provider is not yet supported.

Changes:

  • Accepts SQL_JSON columns with Json or None cells and validates size/scale restrictions.
  • Unwraps JSON snapshots in copied binding rows and preserves unsupported-provider diagnostics.
  • Adds contract, streaming, recovery, result-handling, and typing coverage, plus usage documentation.
File Description
tests/​test_typing.py Adds consumer typing coverage for JSON TVP cells.
tests/​test_028_table_valued_parameters.py Tests JSON contracts, streaming, results, recovery, and unsupported-provider rejection.
README.md Documents JSON TVP usage, restrictions, and provider requirements.
mssql_python/​table_valued_parameter.py Accepts JSON columns and validates their metadata and cell types.
mssql_python/​pybind/​tvp.hpp Unwraps JSON snapshots for binding and handles JSON-specific binding errors.

Review effort: Balanced

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

Labels

pr-size: medium Moderate update size

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants