Comments (7)
Just memory usage yes, doubling sounds like a good idea in an append scenario.
from duckdb.
Thanks for the report!
duckdb_create_data_chunk
allocates vectors with as size duckdb_vector_size()
. Writing more than duckdb_vector_size()
entries to any of the vectors is undefined behavior. For lists, as in this example, the child vector similarly is allocated with space for duckdb_vector_size()
entries.
The duckdb_list_vector_reserve
can be used to resize the child vector of a list. Note that this must be done before calling methods like duckdb_vector_get_data
on the list child vector because calling duckdb_list_vector_reserve
can invalidate the pointer previously returned by duckdb_vector_get_data
.
Below is a fix for the original example:
duckdb_list_entry entry;
auto listData = (duckdb_list_entry*)duckdb_vector_get_data(listVector);
auto listLength = vectorMaxSize + 3;
duckdb_vector listChildVector = duckdb_list_vector_get_child(listVector);
// reserve enough space for the elements
duckdb_list_vector_reserve(listVector, listLength);
auto listChildVectorData = (int32_t*)duckdb_vector_get_data(listChildVector);
from duckdb.
Thanks for the explanation @Mytherin. This will work if the caller knows the required size upfront, but I guess very frequently they won't know how many rows or how big lists they will be appending. For example, when reading data from some REST service, or sensor data, or something else. In such cases, it's not possible to call duckdb_list_vector_reserve
only once.
The only workaround that I see is to keep data for all rows in memory and actually build the data chunk after every duckdb_vector_size
row. Can the list child vector be resized without invalidating the data that was already written?
from duckdb.
duckdb_list_vector_reserve
does not invalidate the written data, only the pointer. Think of it like realloc
.
from duckdb.
Ok, I'll give it a try.
from duckdb.
What is the downside of allocating a larger vector and writing only part of the data? Is it just increased memory usage (which I hope gets freed when I reset the chunk or destroy the chunk) or is there some other hidden cost?
I'm asking because I'm thinking of doubling the allocation size when I reach the current allocation size.
from duckdb.
Thanks. Actually, I made it a little bit smarter to avoid extra allocation. As I have to call duckdb_append_data_chunk
I already need to track how many rows there are. I use this row count and if I'm at the end of the chunk I will increase it only by 1.2, if in the beginning I will double it and do something in the middle in between.
from duckdb.
Related Issues (20)
- DuckDB Build Failure in Alpine Linux Docker Image (host: mac M1) HOT 5
- Incorrect results returned when using JOIN statement HOT 3
- performance of lateral join on timestamp fields
- current_timestamp cannot be used in having clause (Binder Error) HOT 1
- PIVOT should have syntax to GROUP BY no columns
- build error: jemalloc fails due to strerror_r returning char* instead of int HOT 1
- `clang_format` doesn't support Apple Silicon so format-fix doesn't run HOT 2
- Using GROUP BY ALL with a window function causes "Binder Error: Cannot mix aggregates with non-aggregated columns!" HOT 1
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT assertion failure HOT 1
- Out of Memory Error: Failed to allocate block of 262144 bytes (bad allocation) HOT 2
- Inconsistent Query Results with GREATEST HOT 1
- Very slow performance for query targeting partitioned parquet files with WHERE clause for values inside another duckdb table
- insert with on conflict fails if column has index
- Unexpected error raised by PRINTF HOT 1
- ERROR: duckdb.duckdb.Error: Failed to execute query "UPDATE HOT 1
- DuckDB.jl `execute` doesn't like non-null terminated strings HOT 1
- NaN behaves erratically HOT 2
- build error for fuction "strerror_r" in extention jemalloc
- Can't stream record batches from the same cursor that I'm using to insert rows HOT 3
- struct: no support for UPDATE?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from duckdb.