Repository navigation
Conversation
Add a design document for returning ALTREP columns from dbFetch(), each referencing a chunk that holds what libpq returned for the requested rows. It covers the data flow, the R storage per PostgreSQL type, an S3 class for types without a native mapping, interaction with bigint, dbBind(), immediate queries, lifetime, and serialization, a phased implementation plan, and open questions. The design folder is excluded from the package build. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4c819TffvkRZJ1V2T
Question 1: How is
|
Question 2: Which types count as "exciting" and get the
|
Question 11: When are columns materialized, and how long does the captured data live?The request accepts double memory storage. Copying a column or changing its attributes does not materialize it:
Generated by Claude Code |
Question 3: Which R version is required?
Generated by Claude Code |
Question 5: Is ALTREP opt-in first, or the default right away?Each phase is its own PR. An opt-in period lets each one merge without affecting existing users. If nobody decides, the work goes ahead with the recommended option.
Generated by Claude Code |
Question 4: How is
|
Question 12: Do unknown types become
|
Question 8: Does the chunk copy cell bytes, or keep the
|
Superseded: Should enums be plain character by default (#455)?This question is now one of the options of question 2, "Which types count as exciting". Please answer it there. Generated by Claude Code |
Question: Open an issue for the
|
Describe the row-sink interface agreed with the Arrow effort as phase 0, and move the parser extraction ahead of the first ALTREP phase. Keep chunk memory in R-owned raw blocks with a specified layout, and correct the memory, interrupt, and chunked rows mode analysis. Re-prepare the unnamed statement after a catalog lookup, move the type cache into C++, and keep storage stable for unresolved types. Specify ALTREP methods per class, per-instance state, lazy duplication and subsetting, and the exception, longjmp, warning, and thread-safety rules. Separate the type mapping switch from laziness and list the expected differences. Make int8 a double by default in the new mapping, following the closing comment of #182, and add open questions on garbage collector visibility, the type mapping switch, storage of unresolved types, and the catalog lookup. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4c819TffvkRZJ1V2T
Question 6: Do the type mapping changes get their own switch, separate from laziness?The new mapping changes several column types:
Generated by Claude Code |
Question 7: How does R's garbage collector see chunk memory?The ALTREP columns are tiny R objects. If the captured data lives outside R's heap, R never comes under pressure to collect them, and a loop of large
Generated by Claude Code |
Question 9: Which storage do user-defined types get, so it does not change once an
|
Question 10: How does the catalog lookup on a type-cache miss avoid destroying the prepared statement?RPostgres prepares every query as the unnamed statement
Generated by Claude Code |
Question: Open an issue for zero-row
|
Compute No_NA from NA-producing cells, including NaN and integer overflow, and keep all chunk and view state in R objects, so no C finalizer is needed. Limit the new warnings to the new type mapping, to keep the legacy results identical. Write the row sink against the begin() signature proposed on #638, leave interrupt checks to fetch_into(), and amend the sink contract for chunked rows mode. Chain fixed-size index blocks, note the _cache changes in phase 5, drop the domain special case because the server reports base types, and add an open question on fixing the type cache on the default path. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4c819TffvkRZJ1V2T
Describe the row sink exactly as #638 provides it: begin() with names, OIDs, type modifiers, and types from the column cache, fetch_into() without a row limit, and interrupt checks in the fetch loop. Define NA-producing cells by the storage type's NA, including the legacy NAs, grow the chained data and index blocks geometrically, and state the fixed cost per column. Gate chunked rows mode on the build alone, with every sink adapted first, and add the rules for duplicating views and the attributes the sink sets. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4c819TffvkRZJ1V2T
Question 13: Do the C++ type cache and the refresh on a miss (phase 5) also apply to the default path,
|
Follow the points agreed with the binary transport design in #667: the result format is chosen once per result at prepare time and passed to begin(), fixed-width binary columns are stored densely at native width, and the shared decoders of phase 1 are owned by that effort. Update the chunk layout, memory estimates, phase plan, and the open questions on copying, user-defined type storage, and unknown types, citing the #667 benchmark. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4c819TffvkRZJ1V2T
Store fixed-width text cells decoded in the dense layout, as a new open question, so that each cell is parsed once and NA flags and warnings are exact. Keep binary eligibility independent of the type mapping, and add a timetz formatter instead. Do the int8 conversions from the decoded int64 in phases 2 and 3, move binary results into their own phase after the binary switch, and specify pq_text(), pq_raw(), and the pq_format attribute under both formats. Handle execution types without a binary decoder per mapping, and align the warning rules. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4c819TffvkRZJ1V2T
Claude-Session: https://claude.ai/code/session_01Hr1rd4DRzYu5618pRoCxJ3 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Force text results on ALTREP connections in phase 2, and make phase 2b depend on both ALTREP phase 2 and the binary switch of #667. Decode numeric at copy in both formats, and legacy text timetz into seconds as today. State the binary blob fallback as the one exception to OID-based storage, give the legacy mismatch its own error, and list the stored widths per type. Qualify the exactness of pq_text() under the legacy mapping, and attach pq_format to the blob that pq_raw() returns. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4c819TffvkRZJ1V2T
Compare identity runs in the same result format and name the accepted binary behavior changes of #667 for text-versus-binary tests. Describe oid as today on each platform and binary oid as pending #667, name the "binary allowed" flag, move legacy timetz to the date and time phase, complete the width lists, and attribute the legacy error and the v2 blob to their phases. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4c819TffvkRZJ1V2T
Question 14: Are fixed-width text columns decoded into native form at copy time?[Design doc, lines 1016–1031]( With binary results (#667), fixed-width columns such as
Generated by Claude Code |
# Conflicts: # .Rbuildignore
Question 15: How much of the binary-format alignment stays in the design?The design (head
This session is archived after this comment. The design doc, the 14 questions above and this one, and the two issue questions are the durable state. A new session picks up from here. Generated by Claude Code |
This PR records the design for returning ALTREP-backed columns from
dbFetch(), before any implementation. The design is indesign/altrep-columns.md..Rbuildignoreexcludes the newdesign/folder.The goal, relayed from the maintainer: each
dbFetch()call captures what libpq returns for the requested rows,n = Infincluded, and every column is an ALTREP vector over that chunk. Double memory storage is acceptable. Numbers get the smallest R type that fits. Unknown types become blobs. "Exciting" types get an S3 class whose conversion methods can see the underlying storage.What the design proposes:
dbClearResult()anddbDisconnect().EltandGet_regionparse lazily, andDataptrandSet_eltmaterialize.DuplicateandExtract_subsetreturn new views on the same chunk, so attribute changes and subsetting stay lazy.saveRDS()writes plain vectors.int2andint4become integer.oidandint8become double, with exact values available throughpq_text(); an explicitly setbigintis still honored.byteaand unmapped built-in types become blobs.pq_vctrclass withpq_text(),pq_raw(),pq_type()andpq_convert().NA#509. The lookup is designed so that it does not destroy the unnamed prepared statement.dbConnect(altrep = TRUE). The new type mapping can be switched separately from laziness.numerickeep their captured bytes, and apq_formatattribute records whether these bytes are text or binary.altrep = TRUEconnections get text results until ALTREP phase 2b adds binary support.PqResultImpl::fetch_rows(), built by the Arrow work in refactor: Fetch rows through a pluggable row sink #638 to an interface agreed with this design.moneycolumns as numbers instead of 0 #659 and fix: Parseinfinity, BC dates, and years beyond 9999 in dates and timestamps #660 merge.pq_vctrtypes, and chunked mode.Related: #509, #455, #444, #182, #526, #539, #638, #667.
The design went through three rounds of clean review, and its alignment with #667 through three more. Every finding is addressed in the doc. The open questions are numbered 1–15 and posted as separate comments below. Two more comments ask whether to open issues for bugs on
mainfound along the way: theoidoverflow, and zero-rowimmediate = TRUEresults that have no columns.Session: https://claude.ai/code/session_01Hr1rd4c819TffvkRZJ1V2T
https://claude.ai/code/session_01Hr1rd4c819TffvkRZJ1V2T
Generated by Claude Code