Skip to content

feat: implement PostgreSQL extended query protocol (Parse/Bind/Execute/Sync)#1141

Open
SBALAVIGNESH123 wants to merge 4 commits intotimeplus-io:developfrom
SBALAVIGNESH123:feat/postgresql-extended-query-protocol
Open

feat: implement PostgreSQL extended query protocol (Parse/Bind/Execute/Sync)#1141
SBALAVIGNESH123 wants to merge 4 commits intotimeplus-io:developfrom
SBALAVIGNESH123:feat/postgresql-extended-query-protocol

Conversation

@SBALAVIGNESH123
Copy link
Copy Markdown
Contributor

@SBALAVIGNESH123 SBALAVIGNESH123 commented Mar 23, 2026

This PR adds support for the PostgreSQL extended query protocol, which is needed for tools like DBeaver and pgAdmin to connect to Proton. Currently, the handler rejects all extended query messages (Parse, Bind, Describe, Execute, Sync, Close, Flush) with an error saying "proton doesn't support extended query mechanism". This means most modern PostgreSQL drivers and GUI tools fail on connect since they default to the extended query protocol for prepared statements and parameter binding.
The approach here is server-side parameter substitution — the client sends Parse/Bind with $1, $2 placeholders and parameter values, and we substitute them into the SQL before passing it to Proton's existing query engine. This way we get full client compatibility without any changes to the parser or interpreter. A new PreparedStatementManager handles the lifecycle of named and unnamed statements and portals.I also added interception for the various system queries that PG clients send on connect (pg_catalog, SET, SHOW server_version, SELECT version(), SELECT current_schema(), transaction commands, etc.) so that clients don't crash when they can't find system tables. The type mapping was expanded to cover Bool, DateTime, DateTime64, Enum, Map, Array, and large integer types.The parameter substitution is string-literal-aware (won't replace $1 inside single quotes) and escapes single quotes and backslashes to prevent SQL injection. Error handling follows the PG spec — after an error during extended query, all subsequent messages are skipped until a Sync message resets the pipeline.
"This is intentionally a compatibility layer — same approach CockroachDB used in their early PG wire support. Server-side substitution gives us 95% client compatibility with zero query engine changes. True prepared execution is a future enhancement."

Closes #225

…tore

When seek_to uses a relative or absolute time (e.g. '-15m') with
enable_backfill_from_historical_store enabled, the query enters
StreamingConcat mode which scans all historical MergeTree parts
before streaming begins, causing the query to appear hung.

This fix probes NativeLog first: if the streaming store still has
the requested data, convert the time-based seek to a sequence-based
seek and use QueryMode::Streaming, bypassing the expensive historical
scan entirely. Falls back to existing StreamingConcat when the data
has been compacted.

Fixes timeplus-io#558
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL protocol support

1 participant