Skip to content

Commit 4dbe0f9

Browse files
committed
Add support for default_row_group_size configuration
1 parent 2726a5e commit 4dbe0f9

7 files changed

Lines changed: 55 additions & 10 deletions

File tree

src/include/duckdb/main/config.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ struct DBConfigOptions {
201201
idx_t default_block_alloc_size = DEFAULT_BLOCK_ALLOC_SIZE;
202202
//! The default block header size for new duckdb database files.
203203
idx_t default_block_header_size = DUCKDB_BLOCK_HEADER_STORAGE_SIZE;
204+
//! The default row group size for new duckdb database files (new as-in, they do not yet exist).
205+
idx_t default_row_group_size = DEFAULT_ROW_GROUP_SIZE;
204206
//! Whether or not to abort if a serialization exception is thrown during WAL playback (when reading truncated WAL)
205207
bool abort_on_wal_failure = false;
206208
//! Paths that are explicitly allowed, even if enable_external_access is false

src/include/duckdb/main/settings.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,17 @@ struct DefaultBlockSizeSetting {
368368
static Value GetSetting(const ClientContext &context);
369369
};
370370

371+
struct DefaultRowGroupSizeSetting {
372+
using RETURN_TYPE = idx_t;
373+
static constexpr const char *Name = "default_row_group_size";
374+
static constexpr const char *Description =
375+
"The default row group size for new duckdb database files (new as-in, they do not yet exist).";
376+
static constexpr const char *InputType = "UBIGINT";
377+
static void SetGlobal(DatabaseInstance *db, DBConfig &config, const Value &parameter);
378+
static void ResetGlobal(DatabaseInstance *db, DBConfig &config);
379+
static Value GetSetting(const ClientContext &context);
380+
};
381+
371382
struct DefaultCollationSetting {
372383
using RETURN_TYPE = string;
373384
static constexpr const char *Name = "default_collation";

src/include/duckdb/storage/storage_info.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct Storage {
6464
//! Ensures that a user-provided block allocation size matches all requirements.
6565
static void VerifyBlockAllocSize(const idx_t block_alloc_size);
6666
static void VerifyBlockHeaderSize(const idx_t block_header_size);
67+
static void VerifyRowGroupSize(const idx_t row_group_size);
6768
};
6869

6970
//! The version number default, lower and upper bounds of the database storage format

src/main/config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static const ConfigurationOption internal_options[] = {
8989
DUCKDB_SETTING_CALLBACK(DebugVerifyVectorSetting),
9090
DUCKDB_SETTING_CALLBACK(DebugWindowModeSetting),
9191
DUCKDB_GLOBAL(DefaultBlockSizeSetting),
92+
DUCKDB_GLOBAL(DefaultRowGroupSizeSetting),
9293
DUCKDB_SETTING_CALLBACK(DefaultCollationSetting),
9394
DUCKDB_SETTING_CALLBACK(DefaultNullOrderSetting),
9495
DUCKDB_SETTING_CALLBACK(DefaultOrderSetting),

src/main/settings/custom_settings.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,24 @@ Value DefaultBlockSizeSetting::GetSetting(const ClientContext &context) {
427427
return Value::UBIGINT(config.options.default_block_alloc_size);
428428
}
429429

430+
//===----------------------------------------------------------------------===//
431+
// Default Row Group Size
432+
//===----------------------------------------------------------------------===//
433+
void DefaultRowGroupSizeSetting::SetGlobal(DatabaseInstance *db, DBConfig &config, const Value &input) {
434+
auto row_group_size = input.GetValue<uint64_t>();
435+
Storage::VerifyRowGroupSize(row_group_size);
436+
config.options.default_row_group_size = row_group_size;
437+
}
438+
439+
void DefaultRowGroupSizeSetting::ResetGlobal(DatabaseInstance *db, DBConfig &config) {
440+
config.options.default_row_group_size = DBConfigOptions().default_row_group_size;
441+
}
442+
443+
Value DefaultRowGroupSizeSetting::GetSetting(const ClientContext &context) {
444+
auto &config = DBConfig::GetConfig(context);
445+
return Value::UBIGINT(config.options.default_row_group_size);
446+
}
447+
430448
//===----------------------------------------------------------------------===//
431449
// Default Collation
432450
//===----------------------------------------------------------------------===//

src/storage/storage_info.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,21 @@ void Storage::VerifyBlockHeaderSize(const idx_t block_header_size) {
233233
}
234234
}
235235

236+
void Storage::VerifyRowGroupSize(const idx_t row_group_size) {
237+
if (row_group_size == 0) {
238+
throw InvalidInputException("Invalid row group size: %llu - row group size must be bigger than 0",
239+
row_group_size);
240+
}
241+
if (row_group_size % STANDARD_VECTOR_SIZE != 0) {
242+
throw InvalidInputException(
243+
"Invalid row group size: %llu - row group size must be divisible by the vector size (%llu)",
244+
row_group_size, STANDARD_VECTOR_SIZE);
245+
}
246+
if (row_group_size > MAX_ROW_GROUP_SIZE) {
247+
throw InvalidInputException(
248+
"Invalid row group size: %llu - row group size must not exceed the maximum of %llu",
249+
row_group_size, MAX_ROW_GROUP_SIZE);
250+
}
251+
}
252+
236253
} // namespace duckdb

src/storage/storage_manager.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,14 @@ void SingleFileStorageManager::LoadDatabase(QueryContext context) {
214214
options.encryption_options.user_key = std::move(storage_options.user_key);
215215
}
216216

217-
idx_t row_group_size = DEFAULT_ROW_GROUP_SIZE;
217+
idx_t row_group_size;
218218
if (storage_options.row_group_size.IsValid()) {
219219
row_group_size = storage_options.row_group_size.GetIndex();
220-
if (row_group_size == 0) {
221-
throw NotImplementedException("Invalid row group size: %llu - row group size must be bigger than 0",
222-
row_group_size);
223-
}
224-
if (row_group_size % STANDARD_VECTOR_SIZE != 0) {
225-
throw NotImplementedException(
226-
"Invalid row group size: %llu - row group size must be divisible by the vector size (%llu)",
227-
row_group_size, STANDARD_VECTOR_SIZE);
228-
}
220+
} else {
221+
row_group_size = config.options.default_row_group_size;
229222
}
223+
Storage::VerifyRowGroupSize(row_group_size);
224+
230225
// Check if the database file already exists.
231226
// Note: a file can also exist if there was a ROLLBACK on a previous transaction creating that file.
232227
if (!read_only && !fs.FileExists(path)) {

0 commit comments

Comments
 (0)