Skip to content

Conversation

@theory
Copy link
Collaborator

@theory theory commented Dec 13, 2025

Compare with #94.

A new structure, kv_list, represents a list of key/value pairs. Its constructor takes a Postgres List argument, iterates over the keys and values, allocates memory for each, and copies them into the struct. It uses malloc() to allocate the memory, because the we store the value in a global that mustn't be subject to the GUC memory context.

Use it in chfdw_settings_assign_hook() to create a kv_list from the List returned by chfdw_parse_options() and assign it to the ch_session_settings_list global, which can then be fetched via chfdw_get_session_settings().

The downside to this approach is that the new value must be parsed twice. We consider this acceptable, since it means they're no longer parsed for every query.

While at it, change chfdw_parse_options() to use pstrdup() instead of strdup, since its memory is handled by a Postgres memory context (and surely was leaking before).

@theory theory requested a review from serprex December 13, 2025 19:43
@theory theory self-assigned this Dec 13, 2025
@theory theory added the enhancement New feature or request label Dec 13, 2025
Base automatically changed from fix-tpch-links to main December 15, 2025 21:36
@theory theory force-pushed the kv-malloc-guc branch 3 times, most recently from 3d89ed3 to 04429a7 Compare December 15, 2025 22:48
A new structure, kv_list, represents a list of key/value pairs. Its
constructor takes a Postgres `List` argument, iterates over the keys and
values, allocates memory for each, and copies them into the struct. It
uses `malloc()` to allocate the memory, because the we store the value
in a global that mustn't be subject to the GUC memory context.

Use it in `chfdw_settings_assign_hook()` to create a `kv_list` from the
`List` returned by `chfdw_parse_options()` and assign it to the
`ch_session_settings_list` global, which can then be fetched via
`chfdw_get_session_settings()`.

The downside to this approach is that the new value must be parsed
twice. We consider this acceptable, since it means they're no longer
parsed for every query.

While at it, change `chfdw_parse_options()` to use `pstrdup()` instead
of `strdup`, since its memory is handled by a Postgres memory context
(and surely was leaking before).
@theory
Copy link
Collaborator Author

theory commented Dec 15, 2025

Closing in favor of #94.

@theory theory closed this Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants