Skip to content

feat: ALTREP-backed dbFetch() with storage-aware column types - #587

Open
krlmlr wants to merge 21 commits into
mainfrom
claude/altrep-fetch
Open

krlmlr wants to merge 21 commits into
mainfrom
claude/altrep-fetch

Conversation

@krlmlr

@krlmlr krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Design PR for solving the data type problem (unsigned and 64-bit integers, DECIMAL, BIT, JSON, GEOMETRY, unknown types) with ALTREP, and layer 1 of its implementation. The design questions are answered:

  • BIGINT (Q1): with bigint = "integer64" (the default), BIGINT columns are materialized eagerly as integer64. With the other bigint = values they are ALTREP columns that convert from storage.
  • S3 classes (Q2): only on types without a lossless plain mapping.
  • ENUM and SET (Q3): plain character, with the flags in dbColumnInfo().
  • R version (Q4): R ≥ 3.6.
  • Class names (Q5): mariadb_*, documented as experimental.
  • DLL unload (revised answer): accepted as a limitation and documented, see Accepted limitations.

Layer 1 also raises the R floor to 3.6. Layer 2 (unsigned integers and bigint) is #634, stacked on this PR; layer 3 follows.

Layer 1 (implemented on this branch)

dbFetch() drives main's row-sink loop (#644, MariaResultPrep::fetch_into()) with a MariaChunkSink (src/MariaChunkSink.*). begin() builds a MariaChunk (src/MariaChunk.*), append() copies each row through main's row accessors, and get_data() returns ALTREP columns (src/MariaAltrep.*). No user-visible type or class changes. The value conversions (dates and times with the zero-date rule, INT UNSIGNED from #639, BIT(1)) are main's code, moved into MariaChunk.cpp. The former data frame sink is no longer used and is removed.

Rebuilt on #644 in merge 03980b6: the materialized results are identical() to main in 54 cases. Those cover 23 column types (including INT and BIGINT UNSIGNED, BIT(1) and BIT(8), TIMESTAMP, YEAR, ENUM and blobs) with NULLs and zero or partial-zero dates, n = -1, 0, 1, 2, 5, chunked fetches across parameter sets, rebinds, statements, empty results, 30k rows and an embedded NUL. Benchmark for 1e6 rows of (int, double, varchar(20)) with n = Inf: fetching takes 0.22 s instead of 0.41 s on main, and fetching plus materializing takes 0.36–0.38 s instead of 0.38–0.47 s. Locally against MariaDB 10.11:

Differences from the design below, for layer 1:

Goal

Each dbFetch() call captures what libmariadb/libmysql returns, for as many rows as are requested (including n = Inf), and holds it. All columns of the returned data frame are ALTREP vectors backed by that chunk. We accept double memory: the raw chunk plus any R vector materialized from it. Numbers use the narrowest R type that fits the declared column type: integer for short and signed 32-bit integers, double for anything wider. Unknown types become lists of raw (blobs). "Exciting" types get an S3 class whose conversion methods can look at the underlying storage, so that exact values are not lost.

Current state (main)

Design

Chunk store (C++)

  • A new MariaChunk holds one fetched chunk. Per column, it keeps the MYSQL_FIELD metadata (type, flags, length, decimals, charsetnr), the row count and a null bitmap. Fixed-width types (all integers, FLOAT, DOUBLE, MYSQL_TIME) go into one contiguous buffer of the bound width. Variable-length types (strings, DECIMAL text, BIT bytes, JSON, GEOMETRY, BLOB, unknown) go into one byte buffer plus an offsets array.
  • The fetch loop stays mysql_stmt_fetch() into the per-column MYSQL_BIND. After each row it appends the bound values to the chunk, and the chunk's std::vectors grow amortized. The R vectors are no longer grown.
  • Output binds change as follows:
    • Each column now gets its true is_unsigned from UNSIGNED_FLAG.
    • DECIMAL and NEWDECIMAL are bound as strings, so the exact text is kept.
    • BIT is bound as bytes.
    • JSON and unknown types are bound as bytes.
  • The chunk sits behind an external pointer. Every ALTREP column holds a reference to it, so the chunk lives as long as any column of the chunk does. The result object releases its own reference when the next dbFetch() starts.
  • The same store is the hook for native Arrow, worked on in a sibling session on claude/arrow. It offers fetch-next-chunk(n) without creating R vectors, plus per-column metadata, buffers, offsets and null bitmaps.

ALTREP classes

  • mariadb_altint (ALTINTEGER) covers TINY, SHORT, INT24 and LONG (signed), the unsigned TINY/SHORT/INT24, and YEAR. Each value is converted from the chunk when it is accessed. Dataptr materializes the vector once and caches it in data2.
  • mariadb_altreal (ALTREAL) covers FLOAT, DOUBLE, INT UNSIGNED, BIGINT (see Q1), DECIMAL, DATE/DATETIME/TIME (as numbers with the existing Date/POSIXct/hms classes) and BIT.
  • mariadb_altstring (ALTSTRING) covers text columns, ENUM, SET and JSON. CHARSXPs are created on access.
  • mariadb_altlist (ALTLIST, R ≥ 4.3) covers binary columns, GEOMETRY and unknown types, as lists of raw with class blob. See Q4 for older R.
  • Methods: Length, Elt, Get_region, Dataptr (materializes), Dataptr_or_null (NULL until materialized), Extract_subset and Serialized_state (saves the materialized plain vector). Extract_subset returns a new ALTREP vector that indexes into the same chunk, so subsetting keeps the storage.
  • Dataptr writability: a write materializes the vector first, and the storage of that column is then detached. A modified value can never be read back as the stale stored one.

MySQL type → R type

  • TINYINT, SMALLINT, MEDIUMINT, INT (signed), unsigned TINYINT/SMALLINT/MEDIUMINT and YEAR map to integer.
  • INT UNSIGNED maps to double, which is exact.
  • BIGINT (signed) maps to integer64 by default, unchanged; see Q1. It is converted from storage, so bigint = "integer"/"numeric"/"character" are exact or error instead of the silent NA of today.
  • BIGINT UNSIGNED maps to double with class mariadb_uint64. as.character() and bit64::as.integer64() read exact values from storage, and values ≥ 2^63 give NA with a warning.
  • FLOAT and DOUBLE map to double.
  • DECIMAL/NUMERIC maps to double with class mariadb_decimal. as.character() and format() return the exact server text from storage.
  • BIT(1) maps to logical, unchanged.
  • BIT(n > 1) maps to double with class mariadb_bit, which is exact up to 53 bits. as.raw(), as.character() and bit64::as.integer64() read from storage.
  • CHAR, VARCHAR and TEXT map to character, and ENUM and SET map to character too (see Q3).
  • MySQL JSON (type 245) maps to character with class mariadb_json. MariaDB JSON is LONGTEXT on the wire and stays plain character.
  • BINARY, VARBINARY and BLOB map to blob.
  • GEOMETRY maps to blob with class mariadb_geometry. It holds the 4-byte SRID followed by WKB. Methods mariadb_srid() and as_wkb() read from storage.
  • DATE, DATETIME, TIMESTAMP and TIME map to Date, POSIXct and hms, unchanged. Zero dates become NA instead of garbage.
  • Unknown types map to a list of raw with class c("mariadb_unknown", "blob"), without the current warning-and-string fallback.

All mariadb_* classes inherit from the base type (for example c("mariadb_decimal", "numeric")), so arithmetic and printing keep working. A generic mariadb_storage(x) returns the stored bytes for any ALTREP column (as a list of raw); it is the low-level escape hatch the conversion methods are built on.

Existing dbConnect() arguments

  • bigint = keeps its four values, and the default "integer64" stays (Q1). The conversion moves from R post-processing to the ALTREP layer, reading exact 64-bit values from storage.
  • timezone, timezone_out and mysql behave as today. The time-zone fix-up stays R-side for now and materializes those columns.
  • dbColumnInfo() gains columns for the SQL type name, unsigned, length, decimals and the R class. This addresses dbColumnInfo() should return SQL Data Types #269.

Other effects

  • DBItest: plain base types are unchanged for every type that DBItest checks. The mariadb_* classes appear only on types that DBItest does not cover (BIGINT UNSIGNED, DECIMAL, BIT(n>1), JSON, GEOMETRY, unknown), so no tweaks or skips are expected to change. data_logical stays skipped, since TINYINT(1) is still integer.
  • Performance: n = Inf no longer copies all columns on each doubling. The extra copy into the chunk is a memcpy per fixed-width cell.

Planned stack (one concern each)

  1. Chunk store and ALTREP columns, with no change of types (pure refactor, DBItest green).
  2. Unsigned flags, so INT UNSIGNED becomes double and BIGINT UNSIGNED becomes mariadb_uint64, plus bigint = from storage.
  3. DECIMAL, BIT, JSON, GEOMETRY and unknown classes, with their conversion methods and dbColumnInfo().

This PR keeps the design and is layer 1. Layers 2 and 3 will be stacked on it once the questions below are answered.

Issues addressed

Solved or superseded: #412, #413 (alternative approach), #132, #171, #98, #84/#201 (BIT generalized), #42/#127/#259 (JSON), #96 (GEOMETRY, read side), #154 (partly), #269, #340 (documentation of the mapping). Not addressed, since they are on the write side: #277, #297, #14, #163.

Found while preparing this design, each filed separately with a reproducer: #592 (CI matrix never runs MySQL server or the MySQL client), #593 (BIGINT UNSIGNED ≥ 2^63, fixed by layer 2), #594 (bigint = "integer" gives a silent NA), #595 (zero dates return garbage). #592, #594 and #595 get their own fix PRs: #597, #600 and #598.

The Arrow sibling session (branch claude/arrow) filed further fetch-path bugs and is fixing them from main: #601 (use-after-free when a result is cleared during a fetch), #602, #603, #604 (result types fixed at prepare) and #605. Layer 1 rebases over those fixes. The fetch-side items of #606 (BIT(1) read endian-independently, .data() for empty buffers, and metadata taken after execute) are folded into layer 1.

Context: #577 (comment) recommended waiting for a type-mapping convention shared across DBI backends. This design keeps the default R types for everything except the cases that are lossy today, and confines new behavior to mariadb_* classes, so a later shared convention can be adopted on top of the storage.

Testing

A local MariaDB 10.11 server in the container, with tools/tz.sql loaded, runs the full suite. The baseline on main passes, except two test-timezone.R errors before the global time zone was set as in CI. With the global time zone set and tzdata-legacy installed, it passes. CI uses MariaDB 11.8 and MySQL 8.4 through ankane/setup-*.

https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: R type of signed BIGINT

The task says "doubles for larger" than 32-bit. Signed BIGINT is integer64 today, set by bigint = "integer64" (the default), and DBItest and many users rely on it. A double cannot hold every BIGINT exactly above 2^53.

  • Keep bigint = "integer64" as the default. Convert from storage, so bigint = "integer"/"numeric"/"character" become exact, and "integer" warns or errors on overflow instead of silently giving NA. Only INT UNSIGNED (exact in double) and BIGINT UNSIGNED (mariadb_uint64) follow the double rule. Non-breaking. (recommended)

  • Follow the width rule literally: BIGINT becomes a double with class mariadb_int64, and bit64::as.integer64() / as.character() read the exact values from storage. Breaking for code that expects integer64. bigint = then picks the conversion applied to that class.

  • Narrow per chunk by the actual values (integer if all fit). Not recommended, because column types would then differ between chunks of the same result.

  • Answer by krlmlr (feat: ALTREP-backed dbFetch() with storage-aware column types #587 (comment)): "bigint: materialize eagerly if bigint = "integer64", otherwise return our ALTREP."

If nobody decides, layer 2 implements the first option.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: where do the mariadb_* S3 classes appear?

Extra classes break identical()/expect_equal() comparisons against plain vectors, which is how DBItest and many user tests compare results. The design gives each class a base type it inherits from (e.g. c("mariadb_decimal", "numeric")), so arithmetic still works, but class(x) changes.

  • Only on types that have no lossless plain mapping: BIGINT UNSIGNED, DECIMAL, BIT(n > 1), MySQL JSON, GEOMETRY and unknown. Every type DBItest checks keeps its plain class, and mariadb_storage(x) works on every ALTREP column regardless of class. (recommended)
  • Same set of types, but opt-in through a new dbConnect() argument (e.g. classes = TRUE), plain base types otherwise. This adds API, which chore: Review for the next CRAN release #577's comment wanted to avoid before a shared convention exists.
  • On every column (e.g. mariadb_int32), so that every column can be converted from storage. Breaks DBItest comparisons and user code widely.

DECIMAL is a borderline case: today it is plain double, so adding a class changes class() for existing users. If that is unwanted, DECIMAL can stay plain double, and only mariadb_storage() exposes the exact text. If nobody decides, the first option is implemented.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: ENUM and SET

The client does not report ENUM members or SET values in MYSQL_FIELD, only ENUM_FLAG/SET_FLAG. Getting the levels would need an information_schema query per result, and that does not work for expressions.

  • Plain character, as today. The flags are reported in dbColumnInfo(). (recommended)
  • Character with class mariadb_enum / mariadb_set, where as.factor() uses the observed values and a SET method splits on , into a list.
  • Factor, with levels looked up from information_schema where the column has an origin table.

If nobody decides, the first option is implemented.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: R version floor for ALTREP list columns

ALTREP for integer, double and character columns needs R ≥ 3.5. ALTREP lists (ALTLIST), needed for blob, GEOMETRY and unknown columns, need R ≥ 4.3. DESCRIPTION says Depends: R (>= 2.8.0), and the CI matrix covers several R versions back from the current one.

  • Raise Depends to R ≥ 3.6 (the tidyverse floor). Use ALTREP for integer, double and string everywhere, and ALTREP lists on R ≥ 4.3, with eagerly materialized lists (classes and mariadb_storage() still working through an attribute) on older R. (recommended)
  • Raise Depends to R ≥ 4.3 and use ALTREP for all columns everywhere.
  • Keep R ≥ 2.8, with a fully eager fallback without ALTREP on R < 3.5.

If nobody decides, the first option is implemented.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: names of the S3 classes

#577's comment recommended waiting for a type-mapping convention shared across DBI backends. Class names are API that is hard to change later.

  • Backend-specific names now (mariadb_uint64, mariadb_decimal, mariadb_bit, mariadb_json, mariadb_geometry, mariadb_unknown), documented as experimental. A shared class can later be added as a parent (e.g. c("mariadb_decimal", "dbi_decimal", "numeric")) without breaking anything. (recommended)
  • Shared names right away (e.g. dbi_decimal), proposed to DBI in parallel.
  • Hold layer 3 (the classes) until the DBI convention exists, and ship only layers 1 and 2 (chunk store with ALTREP, and unsigned correctness).

If nobody decides, the first option is implemented.


Generated by Claude Code

`dbFetch()` now appends each row from the bound `MYSQL_BIND` buffers to a `MariaChunk`,
which keeps per-column field metadata, a NULL byte per row,
and either a fixed-width buffer or a byte buffer with offsets.
The chunk is filled without creating R objects, so the R vectors are no longer grown and copied for `n = Inf`.

Atomic columns are ALTREP vectors (integer, logical, double, character) that share ownership of the chunk.
They convert values on access and materialize once on `DATAPTR()`.
List columns (binary data) are still built eagerly.
Serialization writes plain vectors.
R types, classes and attributes of all columns are unchanged.

From #606, BIT(1) is read from the first byte of its buffer,
and the output binding is set up when the metadata appears only after `mysql_stmt_execute()`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: ALTREP columns that outlive an unload of the package's DLL

The ALTREP method table and the finalizer of the chunk's external pointer live in RMariaDB's shared library (

static void column_ref_finalize(SEXP ptr) {
ColumnRef* ref = static_cast<ColumnRef*>(R_ExternalPtrAddr(ptr));
R_ClearExternalPtr(ptr);
delete ref;
}
,
static void register_altrep_classes(DllInfo* dll) {
). A fetched column that is still alive when the DLL is unloaded crashes R the next time it is accessed or collected. That happens with pkgload::load_all() reloading the package, devtools::unload(), or library.dynam.unload(). Every ALTREP package (vroom, arrow, duckdb) has this limitation. Normal use, including detach() without unloading, is not affected, and neither is saveRDS(), which writes plain vectors.

  • Accept and document it: one sentence in ?dbFetch or the package docs, and a code comment. (recommended)

  • Add an .onUnload() hook that materializes all live ALTREP columns and releases their chunks before the DLL goes away. This needs a registry of live columns (weak references), and the hook cannot also replace the method table, so the columns stay ALTREP objects. It would only make access safe after materialization, so it is partial at best.

  • Do not register a C finalizer, and keep only R-level state, which reduces but does not remove the crash surface.

  • Answer by krlmlr (feat: ALTREP-backed dbFetch() with storage-aware column types #587 (comment)): "DLL unload: detach live ALTREP vectors (so that they become all-NULL) to avoid the rare crash."

  • Revised answer by krlmlr (feat: ALTREP-backed dbFetch() with storage-aware column types #587 (comment)): "Revising ALTREP decision. Accept limitation." This supersedes the detach answer above.

Relevance: affects developers who reload during interactive work. Confidence of the reviewer: high. If nobody decides, the first option goes into layer 1.


Generated by Claude Code

A materialized column no longer holds a reference to the chunk,
so a column kept after its data frame is gone
no longer keeps the buffers of all other columns alive.

`STRING_ELT()` on a character column that is not materialized
now returns an element cached in the vector,
like R's own deferred strings do,
instead of a fresh `CHARSXP` that nothing protects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
Also explain why the `bigint` test disconnects from `mariadbDefault()` right away.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
The call to `setup_output()` in `MariaResultPrep::execute()` landed in b3c4dc4.
Before, names, types and the output binding were not set up
when `mysql_stmt_result_metadata()` returned a result only after `mysql_stmt_execute()`.
This commit documents that change in the code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
Add altrep_materialize_() to force Dataptr instead of relying on R internals,
and assert only guaranteed use counts.
Tidy comments in MariaAltrep.cpp and MariaResultPrep.cpp.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations


Generated by Claude Code

@krlmlr
krlmlr marked this pull request as ready for review November 29, 2026 12:48
update_metadata() from #618 is now the single path for the metadata after an execution.
It replaces setup_output():
its first call caches names, types and the column info and sets up the output binding,
also when the metadata appears only after mysql_stmt_execute().
For the first parameter set it also updates the column info of the placeholder columns,
so that the chunk takes its types from the latest execution,
and later sets keep the types of the first set or raise #618's error.

MariaRow.cpp keeps the chunk version of the row code;
the .data() fix of #618 for empty buffers is already part of it.
bind() keeps #608 and #620 as on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
Resolve the conflict in src/MariaRow.cpp by keeping this branch's version,
which no longer converts MYSQL_TIME values.
Port the zero-date rule of #598 to MariaChunk::value_real(),
which serves element access, regions, and materialization of DATE and DATETIME columns:
a year, month, or day of 0 yields NA, TIME is unaffected.
Add a test that reads zero dates from the unconverted ALTREP columns
by element access and after materialization.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
…ter execution

For a `CALL` whose result metadata is known only after the execution,
the first update cached the metadata and returned early,
so a NULL column was read as integer even with a NULL character parameter.
The placeholder handling now runs for that first set too,
and the output binding is set up once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
@krlmlr

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

bigint: materialize eagerly if bigint = "integer64", otherwise return our ALTREP.

DLL unload: detach live ALTREP vectors (so that they become all-NULL) to avoid the rare crash.

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: how to keep detached ALTREP vectors from crashing after the DLL unload

Follow-up to the DLL-unload answer ("detach live ALTREP vectors, so that they become all-NULL"). The plan is to keep a registry of live ALTREP columns as weak references, and in .onUnload() release every column's chunk and cache, so that each column reads as all NA. The vectors keep their length and class, so they look like a column of NULLs.

One gap remains. R calls an ALTREP vector's methods (Length, Elt, Dataptr, …) through function pointers in the class's method table, and those pointers point into RMariaDB's shared library. Detaching the data does not change the pointers. If the DLL is actually unmapped, the next access to such a vector, or the GC touching it, still jumps into unmapped code and crashes. An object cannot be turned into a non-ALTREP vector in place.

  • Detach in .onUnload(), and skip library.dynam.unload() while the registry still holds live vectors (and say so with a message). The DLL then stays mapped, the detached vectors keep working as all-NA, and a later load_all() loads a fresh copy next to it. That leaks one DLL mapping per reload with live columns, and only then. (recommended)
  • Detach in .onUnload() and unload the DLL anyway. This frees the memory but does not prevent the crash, which only moves from the data to the method calls.
  • Never unload the DLL (no library.dynam.unload() at all) and detach nothing. Simplest, but keeps the chunks' memory alive.

Moot: the limitation is accepted instead (#587 (comment)). Nothing is detached, and the DLL unloads as before. The limitation is documented in ?dbFetch and in a code comment.


Generated by Claude Code

ALTREP integer, double, logical and string columns are now used on every supported R version.
List columns stay eager until ALTLIST, which needs R >= 4.3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
@krlmlr

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Revising ALTREP decision. Accept limitation.

… DLL

Fetched atomic columns are ALTREP vectors whose methods live in RMariaDB's shared library.
Using them after `pkgload::load_all()` or `devtools::unload()` crashes R, as with other ALTREP packages.
This is now stated in `?dbFetch` and next to the class registration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

CI status, run 46273219951 on d147899: the "MySQL server" job, the first run of this branch against a real MySQL 8.4 server, has 41 failures.


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

CI update, run 46275061861 on a968f60, "MySQL server" job (MySQL 8.4): 9134 passed, 23 failed. This branch's test-fetch-altrep.R now passes on MySQL after d16f507. All 23 failures are in tests that came from main: test-dbBind-types.R, test-dbBind-completed.R, test-dbBind.R and test-fetch-error.R, from #607, #608 and #618. MySQL types ? placeholders as VARCHAR. These are not caused by this PR. Run 46274619224 on main is confirming them there. The issue for them will be linked here, and the fix will come from main.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Resolved: adopt the row-sink design of RPostgres#638 here, and where?

RPostgres#638 (r-dbi/RPostgres#638) splits the fetch loop from the consumer. PqResultImpl::fetch_into(PqRowSink&) owns stepping, parameter sets, interrupt checks and completion. A PqRowSink (begin() with column metadata, append() per row-bearing result, remaining()) receives the rows, and the data frame builder becomes the first sink. It is a pure refactor with a documented contract: copy what you need, keep no pointers, and stated semantics for a throw from append() versus the loop.

For RMariaDB, layer 1 already separates reading from storing, but through a concrete class: MariaResultPrep::fetch() fills MariaChunk. With a MariaRowSink interface:

The MySQL adaptations: append() receives a row view over the bound MYSQL_BIND buffers and lengths, copied before the next mysql_stmt_fetch(), and begin() receives MYSQL_FIELD metadata after execute.


Generated by Claude Code

krlmlr commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

Superseded: Accepted limitations


Generated by Claude Code

@krlmlr

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Refactor, independently of #641.

refactor: Fill the chunk store through the row sink interface of #644.
MariaChunkSink appends each row of MariaResultPrep::fetch_into() to a MariaChunk,
and get_data() returns the data frame of ALTREP columns as before.
The fetch loop, MariaRow and MariaRowView are main's,
so layer 1's own loop and MariaRow::append_to() are gone.
MariaDataFrameSink has no user left and is removed.

The chunk stores fixed-width values as the MariaRowView accessors return them,
so BIT(1) and INT UNSIGNED (#639) follow main.
The date and time conversions use the arithmetic of MariaDataFrameSink,
so that the values are bit for bit the same.
The chunk keeps the MariaFieldInfo of begin() instead of its own copy of the fields.

The setup of the output when result metadata appears only after execution
(9578270, 3b01c61) is kept on top of main's update_metadata(),
and the contract in MariaRowSink.h describes it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
The chunk sink copied such strings unchecked,
so the error came only on access to the column, through ALTREP.
Now the fetch fails with R's own message, as on main.

Also drop the chunk's unused storage accessors and field metadata,
and reserve at most 1024 rows up front.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Handover: state of the ALTREP fetch work

This session is being archived, at Kirill's request. State at 454fb3b:


Generated by Claude Code

krlmlr commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Accepted limitations


Generated by Claude Code

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants