Skip to content

Use Common Table Expressions for pgSettings #2975

@haininghu

Description

@haininghu

Feature description

The current implementation sets per-request settings by opening a transaction and issuing set_config before executing the actual query.
This forces every query, even read-only ones, to run inside a transaction, wich carries unnescessary overhead.
A WITH query (CTE) could be an alternative to inject the set_config call inline, avoiding the need to open a transaction for settings-only purposes.

Current solution:

BEGIN;
SELECT set_config ...;
SELECT ...;
COMMIT;

Proposal:

WITH _settings AS (SELECT set_config(...))
SELECT ... FROM ..., _settings WHERE ...;

Motivating example

This approach reduces avoidable commands like BEGIN/COMMIT, eliminating unnecessary overhead. Encapsulating everything within a single query would also allow statement-level load balancing (for example, using pgpool2).

Supporting development

I [tick all that apply]:

  • am interested in building this feature myself
  • am interested in collaborating on building this feature
  • am willing to help testing this feature before it's released
  • am willing to write a test-driven test suite for this feature (before it exists)
  • am a Graphile sponsor ❤️
  • have an active support or consultancy contract with Graphile

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    🌳 Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions