Skip to content

refactor: bind transaction settings in static statement#5010

Draft
mkleczek wants to merge 1 commit into
PostgREST:mainfrom
mkleczek:push-opzmrxsnynvy
Draft

refactor: bind transaction settings in static statement#5010
mkleczek wants to merge 1 commit into
PostgREST:mainfrom
mkleczek:push-opzmrxsnynvy

Conversation

@mkleczek

@mkleczek mkleczek commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Build the transaction GUC setup as a static SQL statement that binds setting names and values as two text arrays.

The change is to avoid growth in the number of prepared statements for each combination of preferred timezone, role settings, application settings, and function settings.

@mkleczek mkleczek force-pushed the push-opzmrxsnynvy branch 4 times, most recently from f72e713 to d451524 Compare June 16, 2026 13:04
@mkleczek mkleczek marked this pull request as draft June 16, 2026 13:10
Comment thread test/io/test_io.py
Comment on lines +959 to +961
r".+: select set_config\(setting, value, true\) "
r"from unnest\(\$1::text\[\], \$2::text\[\]\) with ordinality as _\(setting, value, ordinality\) "
r"order by ordinality"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit lost here, so this involves changing the emitted SQL?

What is the advantage? So far I'm not seeing a reduction in LOC.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the advantage? So far I'm not seeing a reduction in LOC.

Haven't looked at the changes, yet, but the PR body reads:

The change is to avoid growth in the number of prepared statements for each combination of preferred timezone, role settings, application settings, and function settings.

That seems like a good thing?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is to avoid growth in the number of prepared statements for each combination of preferred timezone, role settings, application settings, and function settings.
That seems like a good thing?

Right, @mkleczek it would be good to know what is the resultant query after this on the PR description or commit message, so it's easier to understand.

@wolfgangwalther wolfgangwalther left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe once the unused functions in SqlFragment are removed, it should be visibly simpler overall. Plus, the reduction of prepared statements is a clear win.

👍 for the concept.

Comment on lines -27 to -31
import PostgREST.Query.SqlFragment (escapeIdentList, fromQi,
intercalateSnippet,
setConfigWithConstantName,
setConfigWithConstantNameJSON,
setConfigWithDynamicName)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not look in-depth, but I would expect some (all?) of these function to be deleted from the SqlFragment module now.

I would not expect them to be used elsewhere.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread postgrest.cabal
@mkleczek mkleczek force-pushed the push-opzmrxsnynvy branch 7 times, most recently from 41b782b to 0f7937d Compare June 17, 2026 07:22
Build the transaction GUC setup as a static SQL statement that binds setting names and values as two text arrays.

The change is to avoid growth in the number of prepared statements for each combination of preferred timezone, role settings, application settings, and function settings.

refactor: encode transaction settings as binary text arrays

Encode the transaction setting name/value arrays as binary text[] parameters while keeping the executed SQL static.

This lets PostgreSQL apply its normal text receive/client_encoding conversion rules for each array element, avoiding app-side UTF-8 conversion and text array literal escaping for the bound setting arrays.

refactor: use postgresql-binary array encoder

Replace the local text array binary encoder with postgresql-binary array_foldable while keeping transaction setting values as raw text element payloads. This avoids maintaining the array header and element loop in PreQuery directly.
@mkleczek mkleczek force-pushed the push-opzmrxsnynvy branch from 0f7937d to 73b2f8d Compare June 17, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants