Repository navigation
Conversation
Resolved: R type of signed BIGINTThe task says "doubles for larger" than 32-bit. Signed BIGINT is integer64 today, set by
If nobody decides, layer 2 implements the first option. Generated by Claude Code |
Resolved: where do the
|
Resolved: ENUM and SETThe client does not report ENUM members or SET values in
If nobody decides, the first option is implemented. Generated by Claude Code |
Resolved: R version floor for ALTREP list columnsALTREP for integer, double and character columns needs R ≥ 3.5. ALTREP lists (
If nobody decides, the first option is implemented. Generated by Claude Code |
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.
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
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
Resolved: ALTREP columns that outlive an unload of the package's DLLThe ALTREP method table and the finalizer of the chunk's external pointer live in RMariaDB's shared library ( Lines 124 to 128 in 6e283f1 Line 331 in 6e283f1 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.
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
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
Superseded: Accepted limitations
Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
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
|
bigint: materialize eagerly if DLL unload: detach live ALTREP vectors (so that they become all- |
Resolved: how to keep detached ALTREP vectors from crashing after the DLL unloadFollow-up to the DLL-unload answer ("detach live ALTREP vectors, so that they become all- One gap remains. R calls an ALTREP vector's methods (
Moot: the limitation is accepted instead (#587 (comment)). Nothing is detached, and the DLL unloads as before. The limitation is documented in 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
|
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
Superseded: Accepted limitations
Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
|
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 |
MySQL types the integer literal 1 as BIGINT, MariaDB as INT, so fixtures built from SELECT literals fetched integer64 on MySQL 8.4. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
|
CI update, run 46275061861 on a968f60, "MySQL server" job (MySQL 8.4): 9134 passed, 23 failed. This branch's Generated by Claude Code |
Superseded: Accepted limitations
Generated by Claude Code |
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. For RMariaDB, layer 1 already separates reading from storing, but through a concrete class:
The MySQL adaptations:
Generated by Claude Code |
Superseded: Accepted limitations
Generated by Claude Code |
|
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
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS # Conflicts: # R/cpp11.R
Handover: state of the ALTREP fetch workThis session is being archived, at Kirill's request. State at 454fb3b:
Generated by Claude Code |
Accepted limitations
Generated by Claude Code |
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 = "integer64"(the default), BIGINT columns are materialized eagerly as integer64. With the otherbigint =values they are ALTREP columns that convert from storage.dbColumnInfo().mariadb_*, documented as experimental.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()drivesmain's row-sink loop (#644,MariaResultPrep::fetch_into()) with aMariaChunkSink(src/MariaChunkSink.*).begin()builds aMariaChunk(src/MariaChunk.*),append()copies each row throughmain's row accessors, andget_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)) aremain's code, moved intoMariaChunk.cpp. The former data frame sink is no longer used and is removed.Rebuilt on #644 in merge 03980b6: the materialized results are
identical()tomainin 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)) withn = Inf: fetching takes 0.22 s instead of 0.41 s onmain, and fetching plus materializing takes 0.36–0.38 s instead of 0.38–0.47 s. Locally against MariaDB 10.11:tests/testthat/test-fetch-altrep.Radds 48 expectations.mainand on this branch were compared across 26 column types × the fourbigint =values × 2 time zones, including chunked,n = 0and parameterized fetches. All results areidentical().gctorture()run was clean.main(docs: ExplainCLIENT_IGNORE_SPACEfor function names followed by a space #649, feat:ssl.mode =argument todbConnect()to require or relax TLS verification #650, with a regeneratedR/cpp11.R); the full suite passes locally on it.n = Inf: fetching takes 0.24 s instead of 0.62 s onmain. Fetching and then touching every value takes 0.64–0.77 s instead of 0.90–0.97 s.Differences from the design below, for layer 1:
Serialized_statereturns NULL, sosaveRDS()writes plain vectors thatreadRDS()reads without RMariaDB.Extract_subsetreturns NULL, so subsets are plain vectors.maindoes, so the endianness issue of Code-reading findings in the C++ binding and fetch code #606 is unchanged here.n = 0still returns plain vectors without S3 classes, as onmain.STRING_ELT()results stay reachable.mainafter fix:dbHasCompleted()anddbGetRowCount()followdbBind()of a query #608, fix: Read result types afterdbBind(), so that placeholder columns keep their values #618, fix: A failed rebind leaves the result unbound instead of out of sync #620 (dbBind()and metadata after execute), fix: Return NA for zero and partial zero dates #598 (zero dates) and fix:dbBind()accepts parameters whose names are all empty #607:dbBind(), so that placeholder columns keep their values #618'supdate_metadata()is the single path that sets up the output binding and refreshes the chunk's column metadata after execute.main, so a chunk never mixes types.MariaChunk::value_real(), which serves single-element access, region access and materialization alike.dbGetQuery(con, "CALL p(?)", params = ...)therefore returns the procedure's rows, wheremainreturned an empty result. fix: Read result types afterdbBind(), so that placeholder columns keep their values #618's NULL-placeholder rule applies on that path too. The connection is still unusable after such aCALL("Commands out of sync", Call of stored procedures givesCommands out of syncerror #276, unchanged).Goal
Each
dbFetch()call captures what libmariadb/libmysql returns, for as many rows as are requested (includingn = 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)MariaResultSimplenever returns data.MYSQL_BINDper column is reused for every row. Each cell is copied straight into a preallocated R vector. Forn = Inf, the vectors start at 100 rows and are grown withRf_lengthgets(), which copies every column on each doubling.cache_metadata()looks only attype,charsetnr == 63andlength == 1. It never readsUNSIGNED_FLAG,decimalsorENUM/SETflags, and every output bind setsis_unsigned = true.bigint =is applied in R after the fetch. Overflow silently becomes NA.dbColumnInfo()reports internal names and ignoresbigint =(dbColumnInfo() should return SQL Data Types #269).Design
Chunk store (C++)
MariaChunkholds one fetched chunk. Per column, it keeps theMYSQL_FIELDmetadata (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.mysql_stmt_fetch()into the per-columnMYSQL_BIND. After each row it appends the bound values to the chunk, and the chunk'sstd::vectors grow amortized. The R vectors are no longer grown.is_unsignedfromUNSIGNED_FLAG.dbFetch()starts.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.Dataptrmaterializes 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 existingDate/POSIXct/hmsclasses) 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 classblob. See Q4 for older R.Length,Elt,Get_region,Dataptr(materializes),Dataptr_or_null(NULL until materialized),Extract_subsetandSerialized_state(saves the materialized plain vector).Extract_subsetreturns a new ALTREP vector that indexes into the same chunk, so subsetting keeps the storage.Dataptrwritability: 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
bigint = "integer"/"numeric"/"character"are exact or error instead of the silent NA of today.mariadb_uint64.as.character()andbit64::as.integer64()read exact values from storage, and values ≥ 2^63 give NA with a warning.mariadb_decimal.as.character()andformat()return the exact server text from storage.mariadb_bit, which is exact up to 53 bits.as.raw(),as.character()andbit64::as.integer64()read from storage.mariadb_json. MariaDB JSON is LONGTEXT on the wire and stays plain character.mariadb_geometry. It holds the 4-byte SRID followed by WKB. Methodsmariadb_srid()andas_wkb()read from storage.c("mariadb_unknown", "blob"), without the current warning-and-string fallback.All
mariadb_*classes inherit from the base type (for examplec("mariadb_decimal", "numeric")), so arithmetic and printing keep working. A genericmariadb_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()argumentsbigint =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_outandmysqlbehave 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
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_logicalstays skipped, since TINYINT(1) is still integer.n = Infno 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)
mariadb_uint64, plusbigint =from storage.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 frommain: #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.sqlloaded, runs the full suite. The baseline onmainpasses, except twotest-timezone.Rerrors before the global time zone was set as in CI. With the global time zone set andtzdata-legacyinstalled, it passes. CI uses MariaDB 11.8 and MySQL 8.4 throughankane/setup-*.https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
Generated by Claude Code