From c3c35296d30e8197343efa8ce84b6f849277d666 Mon Sep 17 00:00:00 2001 From: Prabhakar Date: Wed, 2 Dec 2026 15:14:09 +0530 Subject: [PATCH] docs: explain sharded PREPARE and EXECUTE routing --- .../connection-pooler/prepared-statements.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/features/connection-pooler/prepared-statements.md b/docs/features/connection-pooler/prepared-statements.md index f9c6bba7..fa9aa316 100644 --- a/docs/features/connection-pooler/prepared-statements.md +++ b/docs/features/connection-pooler/prepared-statements.md @@ -123,8 +123,20 @@ You can enable simple statement rewrites in [`pgdog.toml`](../../configuration/p Statements prepared using this method can be executed normally with `Bind` and `Execute` messages. Result data types can be inspected with `Describe`, just like a regular prepared statement. -!!! warning "Sharding support" - Currently, `EXECUTE` command for [sharded](../sharding/index.md) prepared statements is not supported. Such commands will be sent to all shards. +### Sharding support + +With `prepared_statements = "full"`, PgDog uses the statement saved by `PREPARE` together with the values passed to `EXECUTE` to route the query. This supports direct-to-shard and cross-shard routing for `SELECT`, `INSERT`, `UPDATE`, and `DELETE`. + +For example, when `id` is the sharding key: + +```postgresql +PREPARE user_by_id AS + SELECT * FROM users WHERE id = $1; + +EXECUTE user_by_id(11); +``` + +PgDog uses `11` to route the `EXECUTE` command to the shard that owns that row, rather than sending it to every shard. ## Unnamed statements