-
Notifications
You must be signed in to change notification settings - Fork 1
Add kv_list and refactor session_settings with it #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+242
−40
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f42492b to
a79b05a
Compare
serprex
reviewed
Dec 13, 2025
serprex
reviewed
Dec 13, 2025
Member
|
I prefer this to #95 but see merit of both |
serprex
approved these changes
Dec 15, 2025
5825410 to
4c379aa
Compare
serprex
reviewed
Dec 15, 2025
serprex
approved these changes
Dec 15, 2025
serprex
reviewed
Dec 15, 2025
serprex
reviewed
Dec 15, 2025
serprex
reviewed
Dec 15, 2025
serprex
reviewed
Dec 15, 2025
A new structure, kv_list, represents a list of key/value pairs. It does not use an array of structs for each pair, because a custom GUC value must be allocated as a single block, The `kv_list` constructor takes a Postgres `List` argument, iterates over the keys and values, and then allocates a block of memory for them (with options to use `palloc`, `malloc`, or `guc_malloc` (which falls back on `malloc` prior to Postgrs 16)). It then iterates over them again to pack them into the memory space beyond the `kv_list` struct itself. The design follows the precedent of the `ConvertTimeZoneAbbrevs()` function in Postgres's `datetime.c`. Use it in `chfdw_check_settings_guc()` to create a `kv_list` from the `List` returned by `chfdw_parse_options()` and assign it to `**extra`. Postgres hands this pointer to `chfdw_settings_assign_hook()`, where we assign it to the `ch_session_settings_list` global, which can then be fetched via `chfdw_get_session_settings()`. Of course this would be a tricky interface to iterate manually, so also add another struct, `kv_iter`, that handles the logic of iterating through the keys and values in a `kv_list`. Since it sets up the values for each iteration of the loop, the logic using it is simpler than the previous use of `List`, as seen in the http and binary engines. While at it, cChange `chfdw_parse_options()` to use `pstrdup()` instead of `strdup`, since its memory is handled by a Postgres memory context (and surely was leaking before).
serprex
approved these changes
Dec 15, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Compare with #95.
A new structure, kv_list, represents a list of key/value pairs. It does not use an array of structs for each pair, because a custom GUC value must be allocated as a single block,
The
kv_listconstructor takes a PostgresListargument, iterates over the keys and values, and then allocates a block of memory for them (with options to usepalloc,malloc, orguc_malloc(which falls back onmallocprior to Postgrs 16)). It then iterates over them again to pack them into the memory space beyond thekv_liststruct itself. The design follows the precedent of theConvertTimeZoneAbbrevs()function in Postgres'sdatetime.c.Use it in
chfdw_check_settings_guc()to create akv_listfrom theListreturned bychfdw_parse_options()and assign it to**extra. Postgres hands this pointer tochfdw_settings_assign_hook(), where we assign it to thech_session_settings_listglobal, which can then be fetched viachfdw_get_session_settings().Of course this would be a tricky interface to iterate manually, so also add another struct,
kv_iter, that handles the logic of iterating through the keys and values in akv_list. Since it sets up the values for each iteration of the loop, the logic using it is simpler than the previous use ofList, as seen in the http and binary engines.While at it, cChange
chfdw_parse_options()to usepstrdup()instead ofstrdup, since its memory is handled by a Postgres memory context (and surely was leaking before).