Repository navigation
fix: close four table-copy gaps in read_rows/insert_records (#214) - #216
Merged
Merged
Conversation
Four gaps in the table-copy path added by #211, blocking the host (TabularisDB/tabularis#1625) from consuming the copy RPC pair without data loss or a dropped feature: 1. Wide NUMERIC / NaN read back as NULL (data loss). read_rows decoded NUMERIC through rust_decimal::Decimal (96-bit, ~28-29 significant digits, no NaN), so a numeric(38,10) value over 29 digits or a NaN silently became Null — the worst failure mode on the "lossless" path. Add a PgNumeric FromSql that decodes the base-10000 wire bytes directly (reproducing PG16's numeric_out/get_str_from_var) so wide values and NaN/Infinity survive. The write side (bind_pg_numeric_string) falls back to a TEXT+CAST($N AS numeric) bind for values Decimal can't hold, with a numeric-shape guard so garbage is still rejected client-side; small numerics still bind as Type::NUMERIC. 2. Column metadata mismatch. get_columns now returns the canonical type name (pg_catalog.format_type) and the oid — the same vocabulary read_rows uses via Type::name() — so the host has one type mapping for both row data and column metadata. Additive; get_view_columns, get_materialized_view_columns, and the batch fetch get the same fields. 3. insert_records on_conflict. Add an optional on_conflict param ("fail" default, "skip" -> ON CONFLICT DO NOTHING); the response changes from a bare u64 to { affected_rows, skipped } so the host's rows_written/rows_skipped stay honest. 4. read_rows pages with LIMIT/OFFSET (quadratic, no stable order). The session-pinned path now DECLAREs a NO SCROLL cursor and FETCH FORWARD per page — linear in table size, one stable row order — like the removed built-in driver did. The cursor lives/dies with the pinned transaction, so release_session cleans it up. has_more is rows.len() == page_size (a NO SCROLL cursor can't probe ahead without consuming a row). The one-shot path keeps LIMIT/OFFSET. Tests: 12 PgNumeric wire-format + 3 binding unit tests (no live DB); live tests cover wide-numeric/NaN round-trip, large-table cursor paging, and on_conflict skip. 701 lib tests pass; 59 live_db + 82/84 live matrix pass (the 2 failures are pre-existing env gaps: a multi-backend pgbouncer container not running and a missing SSL host env var). Co-Authored-By: Adam J Esslinger <esslinger@gmail.com>
Version suggestionBased on this PR's title (
This is informational only — no tag or release is created automatically yet. |
aesslinger
marked this pull request as ready for review
December 1, 2026 22:47
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Previous Review Summary (commit 2ff5cb8)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 2ff5cb8)Status: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)CRITICAL
WARNING
Files Reviewed (8 files)
Reviewed by claude-sonnet-5.5 · Input: 4.1K · Output: 1.4K · Cached: 141.2K |
Two issues found by kilo code bot review of PR #216: 1. CRITICAL: PgNumeric decoded values with weight < -1 wrong. The integer branch set d = 0 and kept it there when weight < 0, so the fractional loop read digits[0] as the first fractional group instead of reading leading zero groups first. 0.00001234 (weight=-2, digits=[1234], dscale=8) decoded as 0.12340000 — silent data corruption on any value below 0.0001, exactly the lossless-path bug the PR exists to fix. Set d = weight + 1 in the weight<0 branch (matching PostgreSQL's get_str_from_var); the existing d >= 0 guard handles the negative indices. Added pg_numeric_weight_below_minus_one and pg_numeric_weight_minus_three regression tests. 2. WARNING: the cursor-path doc comments claimed a zero-row FETCH still carries column metadata (fixing the empty-page gap). It does not — query_typed returns Vec<Row>, so a zero-row FETCH has no rows to read columns from. Dropped the false claim from run_snapshot/fetch_cursor docs and noted the host falls back to get_columns for an empty source. Co-Authored-By: Adam J Esslinger <esslinger@gmail.com>
23-agent ensemble review (11 dimensions × 2 passes + generalist) found 15 confirmed issues. All are fixed here; the two kilo code bot findings (weight<-1 data corruption, false empty-page claim) were already fixed in the prior commit (1de5f50). Security: - Session-cursor DECLARE now uses query_typed (extended protocol) instead of batch_execute (simple-query protocol), restoring the single-statement invariant the one-shot path has — a multi-statement `query` with `;` stacking is rejected the same way both paths (3 independent sources). Concurrency/retry-safety: - is_first_page now keys off pinned.is_none(), not the client-supplied `page` number, so a retried/duplicate page=1 reuses the existing cursor via FETCH instead of re-DECLAREing (which errored "cursor already exists" and tore down the live snapshot) (4 sources). - CancelGuard is dropped before cleanup_on_error's ROLLBACK so a re-sent cancel can't interrupt the cleanup. Validation: - page_size clamped to .max(1) — limit:0 previously made FETCH FORWARD 0 loop forever (has_more = 0>=0 = true) on the cursor path (4 sources). - on_conflict present-but-non-string (number/bool/array/object) is now rejected with -32602, not silently defaulted to "fail" (3 sources). JSON null still defaults (treated as absent). Data integrity: - bind_pg_numeric_string NUMERIC/DECIMAL arm now always binds via TEXT+CAST, dropping the Decimal::parse success arm that silently rounded high-scale values (e.g. numeric(40,36)) to 28 significant digits — the exact round-trip corruption #214 item 1 exists to fix (2 sources). - PgNumeric validates each base-10000 digit is <= 9999 (rejects garbage chars) and rejects unrecognized sign values (0xE000, 0x2000) instead of silently fabricating "NaN" or positive (3 sources). API/contract: - get_columns/get_view_columns/get_materialized_view_columns `type` field now uses pg_type.typname (the short internal name: int8, numeric, timestamptz) matching read_rows' Type::name(), NOT format_type (which gives bigint, numeric(38,10)). The "one type vocabulary" claim is now true (2 sources). - get_view_columns uses LEFT JOIN pg_attribute so a view column whose pg_attribute row is absent (foreign table, ALTER edge case) isn't silently dropped from the result. Docs: - extract_value_lossless / extract_simple_kind_lossless doc comments corrected: NUMERIC is no longer listed as "already lossless, delegates" — it has a dedicated PgNumeric override arm; "four" → "five" overrides. Tests: 713 lib tests pass (up from 703); 59 live_db + 75/84 live matrix pass (the 9 failures are pre-existing env gaps: TLS/unix-socket/multi- backend pgbouncer containers not running). New unit tests cover PgNumeric wire validation (digit>=10000, unknown signs), numeric-column garbage rejection + edge-form acceptance, cursor_name sanitization, and on_conflict type validation. The vacuous page>1 test is replaced with non-vacuous limit:0 and on_conflict-type tests. Co-Authored-By: Adam J Esslinger <esslinger@gmail.com>
aesslinger
added a commit
that referenced
this pull request
Dec 2, 2026
Merge main (PRs #216, #217) into release/rc.15 and update the CHANGELOG: - Added: session-pinned cursor paging, on_conflict skip, get_columns type+oid (#214, #216) - Fixed: wide NUMERIC/NaN data-loss on read_rows, read_rows byte-budget bounding (#215, #217) - Test count: 682 → 713 Co-Authored-By: Adam J Esslinger <esslinger@gmail.com>
aesslinger
added a commit
that referenced
this pull request
Dec 2, 2026
* chore: release 1.0.0-rc.15 Bumps version to 1.0.0-rc.15 in .tabularium, Cargo.toml, Cargo.lock, and the CHANGELOG. This release includes: - feat: lossless table-to-table copy path (#207) — read_rows RPC (lossless, optionally-snapshot read) + insert_records RPC (batch typed insert) + table_copy capability - fix: replace unmaintained chrono with custom wire-decode (#200) — full Postgres date range parity, jiff dependency removed - fix: avoid SQL pagination for data-modifying CTE statements (#212) — WITH ... INSERT/UPDATE/DELETE no longer gets LIMIT appended or re-executed - fix: paginate queries that end in a comment (#204) — comment-aware lexer - fix: large limit/page no longer wraps to LIMIT 0 Co-authored-by: Adam J. Esslinger <14128427@aesslinger@users.noreply.github.com> * chore: update rc.15 CHANGELOG with #214/#216 and #215/#217 entries Merge main (PRs #216, #217) into release/rc.15 and update the CHANGELOG: - Added: session-pinned cursor paging, on_conflict skip, get_columns type+oid (#214, #216) - Fixed: wide NUMERIC/NaN data-loss on read_rows, read_rows byte-budget bounding (#215, #217) - Test count: 682 → 713 Co-Authored-By: Adam J Esslinger <esslinger@gmail.com> --------- Co-authored-by: Adam J. Esslinger <14128427@aesslinger@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #214 — four gaps in the table-copy path added by #211 (
read_rows/insert_records), opened by the host side (TabularisDB/tabularis#1625) before it can consume the copy RPC pair without risking data loss or dropping a feature the built-in driver had. The host will pin its CI fixture and migration gate to the release carrying these.The four items, in the order the issue blocks on them:
1. Wide
NUMERIC/NaNread back asNULL(data loss) — read + write sidesread_rowsis the "lossless" path but decodedNUMERICthroughrust_decimal::Decimal(96-bit mantissa, ~28–29 significant digits, noNaN), so anumeric(38,10)value over 29 digits or aNaNsilently becameJsonValue::Null.extract.rs): newPgNumericFromSqldecodes the base-10000 wire bytes directly, reproducing PG16'snumeric_out/get_str_from_var. Wide values andNaN/Infinitysurvive. The display path keepsDecimal.binding.rs):bind_pg_numeric_stringalways binds NUMERIC/DECIMAL viaTEXT+CAST($N AS numeric)(validated bylooks_like_numeric_literal), notDecimal::parse— which silently rounds high-scale values to 28 significant digits.2.
get_columnscanonical type name + OIDget_columnsnow returnstype(pg_type.typname— the short internal name matchingread_rows'Type::name()) andoid. Additive;get_view_columns,get_materialized_view_columns, and the batch fetch get the same fields.3.
insert_recordson_conflict: "skip"Optional
on_conflictparam ("fail"default,"skip"→ON CONFLICT DO NOTHING). Response:{ affected_rows, skipped }. Breaking response-shape change — the only consumer is the host PR (tabularis#1625), which the issue says to coordinate with.4. Server-side cursor for session-pinned
read_rowsThe session path
DECLAREs aNO SCROLLcursor +FETCH FORWARDper page — linear, one stable order. The cursor is declared once (keyed offpinned.is_none(), not thepagenumber, so a retriedpage=1reuses the cursor).has_more = rows.len() == page_size. The one-shot path keepsLIMIT/OFFSET. An empty source still reportscolumns: []— the host falls back toget_columns.Post-review fixes
Commit 1de5f50 (kilo code bot review)
weight < -1data corruption: decoder setd = 0and kept it there whenweight < 0, so0.00001234(weight=-2) decoded as0.12340000. Fixed:d = weight + 1. Regression tests added.FETCHcarries column metadata.Commit 6e15650 (23-agent ensemble review — 15 confirmed findings, all fixed)
Security:
DECLAREnow usesquery_typed(extended protocol) notbatch_execute(simple-query), restoring the single-statement invariant —;-stacked SQL injection is rejected on both paths (3 sources).Concurrency/retry-safety:
is_first_pagekeys offpinned.is_none(), notpage— a retriedpage=1reuses the cursor instead of re-DECLAREing and corrupting the snapshot (4 sources).CancelGuarddropped beforecleanup_on_error's ROLLBACK so a re-sent cancel can't interrupt cleanup.Validation:
page_sizeclamped to.max(1)—limit:0previously madeFETCH FORWARD 0loop forever (4 sources).on_conflictpresent-but-non-string (number/bool/array/object) rejected with-32602, not silently defaulted (3 sources). JSONnullstill defaults.Data integrity:
bind_pg_numeric_stringalwaysTEXT+CAST— theDecimal::parsesuccess arm silently rounded high-scale numerics (numeric(40,36)) to 28 digits (2 sources).PgNumericvalidates digit ≤ 9999 (rejects garbage chars) and rejects unrecognized sign values (3 sources).API/contract:
get_columnstypeusespg_type.typname(int8,numeric) notformat_type(bigint,numeric(38,10)) — the "one type vocabulary" claim is now true (2 sources).get_view_columnsusesLEFT JOIN pg_attributeso a view column whosepg_attributerow is absent isn't silently dropped.Docs:
extract_value_lossless/extract_simple_kind_losslesscorrected (NUMERIC no longer "already lossless, delegates"; "four" → "five" overrides).Test plan
cursor_namesanitization,on_conflicttype validation, and empty-batch return.cargo clippy --all-targets -- -D warningsclean;cargo fmt --all --checkclean.live_dbintegration tests pass; 75/84client_live_testspass. The 9 failures are pre-existing env gaps (TLS/unix-socket/multi-backend pgbouncer containers not running locally — needtests/podman/env.sh up+ a native PostgreSQL socket).read_rows_session_cursor_pages_a_large_table_linearly(2500 rows, 3 pages),insert_records_on_conflict_skip_reports_inserted_and_skipped, wide-numeric/NaN coverage.Notes for review
get_str_from_var, verified against hand-built wire bytes for 38/30-digit integers, NaN/±Inf, dscale trailing zeros, weight<-1, digit≥10000, unknown signs.u64→ object). The host PR (tabularis#1625) coordinates on it.affected_rows/skippednaming: the host'sTableTransferTableResultusesrows_written/rows_skipped. The plugin's field names differ; the host remaps. This is a judgment call (1 source flagged it, 1 source filtered it as disclosed).