pg.ddx.io  pgdogdev/pgdog GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgdogdev/pgdog] PR #2040: perf: skip decode -> re-encode of subquery rows (binary DataRow -> binary array)
6+ messages / 3 participants
[nested] [flat]

* [pgdogdev/pgdog] PR #2040: perf: skip decode -> re-encode of subquery rows (binary DataRow -> binary array)
@ 2026-11-15 00:14  "jkaczman (@jkaczman)" <noreply+jkaczman@github.com>
  0 siblings, 0 replies; 6+ messages in thread

From: jkaczman (@jkaczman) @ 2026-11-15 00:14 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>

Previously, for a statement such as

> `SELECT * FROM orders WHERE user_id IN (SELECT id FROM users WHERE status = 'VIP')`

Say that the subquery here returns the IDs 1 and 2. We fetched those rows in text format, then
1. We decoded those rows into the `Datum` type; `Datum::Bigint(1)`, `Datum::Bigint(2)`
2. We encoded the Datums again (`Array::encode`) into the array `{1,2}`
3. We sent the array to the shards as $1 of the rewritten statement `SELECT * FROM orders WHERE user_id IN (SELECT u.c1 FROM unnest($1::pg_catalog._int8) u(c1))`

Steps 1 and 2 here used to act as intermediate steps for a decode -> re-encode process that are now replaced with a binary -> binary conversion (data row binary -> bind parameter binary), as we don't need the decoded values elsewhere.

How? This forces all subqueries we execute to use the binary format (even if client requested text) to allow binary -> binary for massive speedup. This is fine, as the client never sees the rows of those subqueries; we only use them to rewrite the outer statement.

This gives us two advantages, (1) a performance increase, (2) being able to handle values that our decoding / encoding process doesn't support or has bugs for.

Measured to be roughly a 30% performance improvement of subquery handling.

inline patch 1: pgdog-postgres-types/src/array.rs, pgdog/src/backend/pool/connection/mod.rs, pgdog/src/backend/pool/connection/multi_shard/binding.rs and 7 more (+137/-24 lines) download inline-1.patchdiff --git a/pgdog-postgres-types/src/array.rs b/pgdog-postgres-types/src/array.rs index 97cefbb1f..1173dd4d7 100644 --- a/pgdog-postgres-types/src/array.rs +++ b/pgdog-postgres-types/src/array.rs @@ -147,6 +147,51 @@ impl Array { Ok(Bytes::from(result)) } + /// Builds a 1D array in binary format + /// + /// INVARIANT: the elements are values that Postgres returned in binary for the type `element_oid`, e.g., the rows of subqueries, which we pass on to the shards as `unnest(..)` arrays. + /// We don't reuse `Array::encode` here, since `Array::encode` takes decoded elements, thus, we would have to decode those values first. + pub fn binary_from_encoded_elements<'a>( + element_oid: i32, + elements: impl ExactSizeIterator<Item = Option<&'a [u8]>> + Clone, + ) -> Bytes { + let element_count = elements.len(); + let dimensions = if element_count > 0 { 1 } else { 0 }; + + let mut has_nulls = false; + let mut elements_len = 0; + for element in elements.clone() { + match element { + Some(element) => elements_len += element.len(), + None => has_nulls = true, + } + } + + let mut buf = BytesMut::with_capacity(12 + 8 + element_count * 4 + elements_len); + + buf.put_i32(dimensions); + buf.put_i32(i32::from(has_nulls)); + buf.put_i32(element_oid); + + if dimensions > 0 { + buf.put_i32(element_count as i32); + // Index of the first element. + buf.put_i32(1); + } + + for element in elements { + match element { + Some(element) => { + buf.put_i32(element.len() as i32); + buf.extend_from_slice(element); + } + None => buf.put_i32(-1), + } + } + + buf.freeze() + } + fn encode_binary(&self) -> Result<Bytes, Error> { let mut buf = BytesMut::with_capacity(12 + 8 + self.elements.len() * 8); // Use ndims=0 only for truly empty arrays with default bounds. diff --git a/pgdog/src/backend/pool/connection/mod.rs b/pgdog/src/backend/pool/connection/mod.rs index 45130fd5b..be8b2e130 100644 --- a/pgdog/src/backend/pool/connection/mod.rs +++ b/pgdog/src/backend/pool/connection/mod.rs @@ -442,6 +442,20 @@ impl Connection { } } + // Replaces the Binds from `bind` (above) with the Binds of `request`. + // The result formats of these Binds decide how we decode rows when we merge rows across shards. + // E.g., `multi_step::fetch_rows` calls this, since we fetch the rows of subqueries in binary even if the client requested text. + pub(crate) fn set_binds(&mut self, request: &ClientRequest) { + let binds = request.messages.iter().filter_map(|message| match message { + ProtocolMessage::Bind(bind) => Some(bind), + _ => None, + }); + + if let Binding::MultiShard(ref mut servers) = self.binding { + servers.set_binds(binds); + } + } + /// Execute an internal query on all connected servers. pub(crate) async fn execute( &mut self, diff --git a/pgdog/src/backend/pool/connection/multi_shard/binding.rs b/pgdog/src/backend/pool/connection/multi_shard/binding.rs index d0e275446..c77882a31 100644 --- a/pgdog/src/backend/pool/connection/multi_shard/binding.rs +++ b/pgdog/src/backend/pool/connection/multi_shard/binding.rs @@ -163,6 +163,14 @@ impl MultiBinding { self.state.push_bind(bind); } + /// See `Connection::set_binds`. + pub(in crate::backend::pool::connection) fn set_binds<'a>( + &mut self, + binds: impl Iterator<Item = &'a Bind>, + ) { + self.state.set_binds(binds); + } + /// Indicates that the backend(s) have more messages for the client /// so it should continue to pull them from the connection (until this returns false). pub(in crate::backend::pool::connection) fn has_more_messages(&self) -> bool { diff --git a/pgdog/src/backend/pool/connection/multi_shard/mod.rs b/pgdog/src/backend/pool/connection/multi_shard/mod.rs index 0337ee7ee..cd7196888 100644 --- a/pgdog/src/backend/pool/connection/multi_shard/mod.rs +++ b/pgdog/src/backend/pool/connection/multi_shard/mod.rs @@ -200,6 +200,12 @@ impl MultiShard { self.bound_statements.push_back(bind.clone()); } + /// See `Connection::set_binds`. + pub(super) fn set_binds<'a>(&mut self, binds: impl Iterator<Item = &'a Bind>) { + self.bound_statements.clear(); + self.bound_statements.extend(binds.cloned()); + } + /// Who asked for each description in the request we just sent. fn set_describes(&mut self, describes: VecDeque<DescribedBy>) { self.describes = describes; diff --git a/pgdog/src/frontend/client/query_engine/multi_step/fetch.rs b/pgdog/src/frontend/client/query_engine/multi_step/fetch.rs index 744bf02f8..18e378faf 100644 --- a/pgdog/src/frontend/client/query_engine/multi_step/fetch.rs +++ b/pgdog/src/frontend/client/query_engine/multi_step/fetch.rs @@ -16,6 +16,8 @@ pub(crate) async fn fetch_rows( backend: &mut Connection, request: &ClientRequest, ) -> Result<(Vec<DataRow>, Option<RowDescription>), Error> { + backend.set_binds(request); + backend .handle_client_request(request, &mut Router::default(), false) .await?; diff --git a/pgdog/src/frontend/client/query_engine/multi_step/subquery/from_clause.rs b/pgdog/src/frontend/client/query_engine/multi_step/subquery/from_clause.rs index bd6506118..549080241 100644 --- a/pgdog/src/frontend/client/query_engine/multi_step/subquery/from_clause.rs +++ b/pgdog/src/frontend/client/query_engine/multi_step/subquery/from_clause.rs @@ -6,12 +6,12 @@ use pg_raw_parse::{ nodes::{self, Alias, RangeFunction, SelectStmt}, transform, }; -use pgdog_postgres_types::{Array, Datum}; +use pgdog_postgres_types::{Array, Format}; use crate::{ frontend::client::query_engine::multi_step::SubqueryMulti, frontend::router::parser::rewrite::statement::insert::is_constant, - net::{Bind, DataRow, Decoder, RowDescription, bind::Parameter}, + net::{Bind, DataRow, RowDescription, bind::Parameter}, }; impl<'a> SubqueryMulti<'a> { @@ -110,9 +110,6 @@ impl<'a> SubqueryMulti<'a> { data_rows: &[DataRow], row_description: &RowDescription, ) -> Unique<'mem, &'mem SelectStmt> { - let mut decoder = Decoder::default(); - decoder.set_row_description(row_description.clone()); - let base_param_len = old_bind.params_raw().len() as i32; let original_targets = match original_ast { @@ -157,12 +154,17 @@ impl<'a> SubqueryMulti<'a> { unnest_column_names.push(mem.make_string(Some(unnest_column_name.as_str())).uncast()); - let pg_catalog_type: &str = field - .data_type() + let data_type = field.data_type(); + + let pg_catalog_type: &str = data_type .into_array_type() .expect("rewrite_outer_statement_with_subquery_response checked the column types") .as_pg_catalog_type(); + let element_oid = data_type + .to_oid() + .expect("all data types with an array type have an OID"); + let node = { let mut node = mem.make_node::<nodes::ParamRef>(); @@ -172,21 +174,19 @@ impl<'a> SubqueryMulti<'a> { node }; - let mut list_of_rows_for_col: Vec<Datum> = Vec::new(); - for row in data_rows { - // TODO(jkaczman): replace all unwraps() - let col = row.get_column(idx, &decoder).unwrap().unwrap(); - list_of_rows_for_col.push(col.value); - } + // We build one array for each column that the subquery returned. + // E.g., if SELECT id, status FROM users returns the rows (1, 'VIP'), (2, NULL) and (3, 'VIP'), we build + // - {1,2,3} for id + // - {VIP,NULL,VIP} for status + let elements = data_rows.iter().map(|row| { + row.get_raw(idx) + .filter(|value| !value.is_null) + .map(|value| value.data.as_ref()) + }); - let array = Array::new(list_of_rows_for_col, field.type_oid); + let array = Array::binary_from_encoded_elements(element_oid, elements); - // TODO(jkaczman): wonder what the performance tradeoffs are btwn. Binary and Text - let default_fmt = old_bind.default_param_format(); - old_bind.push_param( - Parameter::new(array.encode(default_fmt).unwrap().as_ref()), - default_fmt, - ); + old_bind.push_param(Parameter::from_bytes(array), Format::Binary); let node = mem .make_type_cast( diff --git a/pgdog/src/frontend/client/query_engine/multi_step/subquery/mod.rs b/pgdog/src/frontend/client/query_engine/multi_step/subquery/mod.rs index 6b00973c4..27ebba953 100644 --- a/pgdog/src/frontend/client/query_engine/multi_step/subquery/mod.rs +++ b/pgdog/src/frontend/client/query_engine/multi_step/subquery/mod.rs @@ -32,7 +32,7 @@ use crate::{ }, }, }, - net::{Bind, DataRow, ProtocolMessage, RowDescription}, + net::{Bind, DataRow, Format, ProtocolMessage, RowDescription}, }; /// Evaluates the Subquery and injects the results into the top-level statement. @@ -212,6 +212,18 @@ impl<'ast> SubqueryMulti<'ast> { )); } + // INVARIANT: the rows that subqueries return are in binary format + // `form_client_request` sets the result format of subqueries to binary + // `new_select_with_unnest` relies on this; it copies the bytes of the values into binary arrays without decoding the values + if let Some(row_description) = &results.1 { + assert!( + row_description + .fields + .iter() + .all(|field| field.format() == Format::Binary), + ); + } + self.subquery_results.push(results); } diff --git a/pgdog/src/frontend/client/query_engine/multi_step/subquery/request.rs b/pgdog/src/frontend/client/query_engine/multi_step/subquery/request.rs index 04cf146c7..6f2bd082c 100644 --- a/pgdog/src/frontend/client/query_engine/multi_step/subquery/request.rs +++ b/pgdog/src/frontend/client/query_engine/multi_step/subquery/request.rs @@ -29,7 +29,7 @@ impl<'a> SubqueryMulti<'a> { is_subquery: bool, ) -> Result<Option<(Vec<DataRow>, Option<RowDescription>)>, Error> { let mut client_request: ClientRequest = self - .form_client_request(engine, query_string, context) + .form_client_request(engine, query_string, context, is_subquery) .await?; multi_step::update::route(engine, &mut client_request, context)?; @@ -133,9 +133,16 @@ impl<'a> SubqueryMulti<'a> { engine: &mut QueryEngine, mut query_string: String, context: &mut QueryEngineContext<'_>, + is_subquery: bool, ) -> Result<ClientRequest, Error> { let mut client_request = { let mut bind = Bind::default(); + + if is_subquery { + // We fetch the rows in binary, which allows us to copy the values into the unnest(..) arrays of the outer statement as-is (instead of decoding the values). + bind.set_binary_results(); + } + let mut actual_param_index = 1; let mut actual_param_index_str = format!("${actual_param_index}"); diff --git a/pgdog/src/frontend/router/parser/rewrite/statement/insert.rs b/pgdog/src/frontend/router/parser/rewrite/statement/insert.rs index 8dcdb2097..d6b71eec9 100644 --- a/pgdog/src/frontend/router/parser/rewrite/statement/insert.rs +++ b/pgdog/src/frontend/router/parser/rewrite/statement/insert.rs @@ -133,15 +133,19 @@ impl UnnestInsert { let single_row_requests = (0..row_count) .map(|row_index| { + // These requests are only for routing (we never send them). + // Bit of a workaround used here: we encode the elements as text, as the router can't read binary elements of a different type than the sharding key column + // E.g., in INSERT INTO orders (id, user_id) SELECT sum(id), sum(user_id) FROM orders, sum(user_id) is a numeric and the sharding key user_id is a bigint + // TODO(jkaczman): Give the router this capability let mut single_row_bind = Bind::new_statement(""); for unnest_array in &unnest_arrays { let element_param = match unnest_array.elements.get(row_index) { Some(element) if !element.is_null() => { - Parameter::new(&element.encode(unnest_array.format)?) + Parameter::new(&element.encode(Format::Text)?) } _ => Parameter::new_null(), }; - single_row_bind.push_param(element_param, unnest_array.format); + single_row_bind.push_param(element_param, Format::Text); } Ok(ClientRequest { diff --git a/pgdog/src/net/messages/bind.rs b/pgdog/src/net/messages/bind.rs index cf72dfa11..c6652dcd0 100644 --- a/pgdog/src/net/messages/bind.rs +++ b/pgdog/src/net/messages/bind.rs @@ -55,6 +55,14 @@ impl Parameter { data: Bytes::copy_from_slice(data), } } + + // Takes `data` without copying the bytes. + pub(crate) fn from_bytes(data: Bytes) -> Self { + Self { + len: data.len() as i32, + data, + } + } } /// Parameter with encoded format. @@ -264,6 +272,13 @@ impl Bind { me } + pub(crate) fn set_binary_results(&mut self) { + const BINARY_FOR_ALL_COLUMNS: &[u8] = &1i16.to_be_bytes(); + + self.results = Bytes::from_static(BINARY_FOR_ALL_COLUMNS); + self.original = None; + } + pub(crate) fn set_param(&mut self, index: usize, param: Parameter) -> Option<()> { *self.params.get_mut(index)? = param; self.original = None;
^ permalink raw [nested|flat] 6+ messages in thread

* Re: [pgdogdev/pgdog] PR #2040: perf: skip decode -> re-encode of subquery rows (binary DataRow -> binary array)
@ 2026-11-15 00:17  "codecov[bot] (bot) (@codecov[bot])" <noreply+codecov[bot]@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: codecov[bot] (bot) (@codecov[bot]) @ 2026-11-15 00:17 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>

## [Codecov](https://app.codecov.io/gh/pgdogdev/pgdog/pull/2040?dropdown=coverage&src=pr&el=h1&utm_me...) Report
:x: Patch coverage is `98.85057%` with `1 line` in your changes missing coverage. Please review.
| [Files with missing lines](https://app.codecov.io/gh/pgdogdev/pgdog/pull/2040?dropdown=coverage&src=pr&el=tree&utm_...) | Patch % | Lines |
|---|---|---|
| [...end/client/query\_engine/multi\_step/subquery/mod.rs](https://app.codecov.io/gh/pgdogdev/pgdog/pull/2040?src=pr&el=tree&utm_medium=referral&ut...) | 85.71% | [1 Missing :warning: ](https://app.codecov.io/gh/pgdogdev/pgdog/pull/2040?src=pr&el=tree&utm_medium=referral&ut...) |

:loudspeaker: Thoughts on this report? [Let us know!](https://github.com/codecov/feedback/issues/255)

^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [pgdogdev/pgdog] PR #2040: perf: skip decode -> re-encode of subquery rows (binary DataRow -> binary array)
@ 2026-11-15 00:57  "github-actions[bot] (bot) (@github-actions[bot])" <noreply+github-actions[bot]@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: github-actions[bot] (bot) (@github-actions[bot]) @ 2026-11-15 00:57 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>

<!-- metal-bench -->

**Metal bench (arm64) passed.** All 520 measures within bounds.

| suite | throughput | cpu/txn | user cycles/txn | user instr/txn | kernel cycles/txn | kernel instr/txn | ctx/txn |
|---|---|---|---|---|---|---|---|
| pooler |  | 19.06 (+0.4% ± 0.4%) | 17,936 (-0.1% ± 0.4%) | 31,404 (-0.0% ± 0.03%) | 30,844 (+0.8% ± 1.2%) | 51,109 (-0.0% ± 0.3%) |  |
| lb |  | 19.5 (-0.7% ± 0.5%) | 18,568 (+0.8% ± 0.4%) | 32,321 (+0.0% ± 0.03%) | 31,132 (-1.5% ± 0.8%) | 52,255 (+0.1% ± 0.4%) |  |
| sharding-w2 |  | 32.33 (+0.4% ± 0.7%) | 43,351 (+0.2% ± 2.2%) | 94,899 (-0.0% ± 0.02%) | 40,706 (+0.8% ± 1.7%) | 53,719 (+0.0% ± 0.1%) | 1.549 (-0.0% ± 0.3%) |
| sharding-w8 | 244,588 (-0.3% ± 2.3%) | 29.27 (+0.5% ± 2.4%) | 44,500 (+0.4% ± 0.4%) | 50,471 (-0.0% ± 0.06%) | 36,357 (+0.6% ± 5.7%) | 42,371 (-0.0% ± 0.2%) | 0.168 (-0.6% ± 3.9%) |

<details><summary>Counters per txn</summary>

| suite | frontend stall | l1i refill | backend stall |
|---|---|---|---|
| pooler | 7,522 (-0.6% ± 1.1%) | 2,639 (-0.2% ± 0.5%) |  |
| lb | 7,915 (+1.8% ± 1.3%) | 2,697 (+0.6% ± 0.7%) |  |
| sharding-w2 | 17,603 (+0.3% ± 6.6%) | 4,125 (-0.1% ± 3.3%) |  |
| sharding-w8 | 19,961 (-0.7% ± 1.0%) | 4,111 (-0.7% ± 0.9%) |  |
</details>

Microbench: all 507 measures within bounds.

<details><summary>Hot code per txn</summary>

| path | base | head | change |
|---|---|---|---|
| pooler | 111.8 KB | 112.8 KB | **+1.1 KB** |
| sharding-w2 | 170.2 KB | 169.4 KB | **-0.8 KB** |

pooler:

| crate | base | head | change |
|---|---|---|---|
| pgdog::frontend::client::query_engine | 20.1 KB | 20.1 KB | +0.0 KB |
| tokio | 18.2 KB | 18.3 KB | +0.1 KB |
| pgdog::backend::pool | 17.6 KB | 17.8 KB | +0.2 KB |
| aws-lc (TLS crypto) | 9.6 KB | 10.1 KB | +0.5 KB |
| rustls (TLS) | 8.4 KB | 8.4 KB | +0.0 KB |
| pgdog::frontend (other) | 7.8 KB | 7.9 KB | +0.1 KB |
| pgdog::backend::server | 7.6 KB | 7.7 KB | +0.1 KB |
| other | 5.9 KB | 6.1 KB | +0.2 KB |
| everything else | 16.7 KB | 16.6 KB | -0.1 KB |

| function | head | change |
|---|---|---|
| `pgdog::frontend::client::Client::run::{{closure}}` | 5.6 KB | +0.1 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 5.3 KB | +0.1 KB |
| `pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}}` | 4.1 KB | +0.0 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 3.4 KB | +0.0 KB |
| `tokio::runtime::task::raw::poll` | 3.1 KB | +0.0 KB |

sharding-w2:

| crate | base | head | change |
|---|---|---|---|
| pgdog::frontend::router | 29.1 KB | 29.2 KB | +0.2 KB |
| pgdog::frontend::client::query_engine | 21.9 KB | 21.6 KB | -0.3 KB |
| tokio | 19.2 KB | 18.9 KB | -0.3 KB |
| pgdog::backend::pool | 18.6 KB | 18.5 KB | -0.1 KB |
| aws-lc (TLS crypto) | 12.7 KB | 12.9 KB | +0.2 KB |
| other | 10.2 KB | 10.1 KB | -0.1 KB |
| pgdog::frontend (other) | 9.1 KB | 9.0 KB | -0.1 KB |
| rustls (TLS) | 8.1 KB | 8.4 KB | +0.2 KB |
| everything else | 41.4 KB | 40.8 KB | -0.6 KB |

| function | head | change |
|---|---|---|
| `pgdog::frontend::client::Client::run::{{closure}}` | 6.5 KB | +0.0 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 5.1 KB | -0.1 KB |
| `pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}}` | 4.1 KB | -0.1 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 3.4 KB | -0.1 KB |
| `pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que` | 3.4 KB | +0.1 KB |

</details>

<details><summary>lb flamegraph vs 068e28fd</summary>

![lb](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...) for hover, zoom and search.

![lb removed](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...).
</details>
<details><summary>microbench flamegraph vs 068e28fd</summary>

![microbench](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...) for hover, zoom and search.

![microbench removed](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...).
</details>
<details><summary>pooler flamegraph vs 068e28fd</summary>

![pooler](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...) for hover, zoom and search.

![pooler removed](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...).
</details>
<details><summary>sharding-w2 flamegraph vs 068e28fd</summary>

![sharding-w2](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...) for hover, zoom and search.

![sharding-w2 removed](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...).
</details>
<details><summary>sharding-w8 flamegraph vs 068e28fd</summary>

![sharding-w8](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...) for hover, zoom and search.

![sharding-w8 removed](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results/jk-subquery-binary-conversion-subqueries/34ef3092...).
</details>

<details><summary>Logs</summary>

[lb](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results/jk-subquery-binary-conv...), [microbench](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results/jk-subquery-binary-conv...), [pooler](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results/jk-subquery-binary-conv...), [sharding-w2](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results/jk-subquery-binary-conv...), [sharding-w8](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results/jk-subquery-binary-conv...), [verdict.json](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results/jk-subquery-binary-conv...)
</details>

Compared 34ef3092 with 068e28fd on c8g.metal-24xl (on-demand).


^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [pgdogdev/pgdog] PR #2040: perf: skip decode -> re-encode of subquery rows (binary DataRow -> binary array)
@ 2026-11-15 00:59  "github-actions[bot] (bot) (@github-actions[bot])" <noreply+github-actions[bot]@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: github-actions[bot] (bot) (@github-actions[bot]) @ 2026-11-15 00:59 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>

<!-- metal-bench-x86 -->

**Metal bench (x86) passed.** All 520 measures within bounds.

| suite | throughput | cpu/txn | user cycles/txn | user instr/txn | kernel cycles/txn | kernel instr/txn | ctx/txn |
|---|---|---|---|---|---|---|---|
| pooler |  | 34.97 (-0.0% ± 0.3%) | 22,913 (-0.0% ± 0.9%) | 32,718 (+0.0% ± 0.02%) | 58,401 (-0.1% ± 0.4%) | 38,539 (+0.1% ± 0.2%) |  |
| lb |  | 35.88 (-0.1% ± 0.3%) | 23,854 (+0.0% ± 1.0%) | 33,682 (-0.0% ± 0.03%) | 59,243 (-0.2% ± 0.2%) | 39,219 (-0.0% ± 0.1%) |  |
| sharding-w2 |  | 56.96 (-0.1% ± 1.4%) | 53,331 (-0.2% ± 2.2%) | 98,600 (+0.0% ± 0.06%) | 73,610 (+0.0% ± 1.6%) | 43,203 (+0.0% ± 0.05%) | 1.39 (+0.0% ± 0.5%) |
| sharding-w8 | 147,015 (+0.5% ± 1.9%) | 48.67 (-0.1% ± 1.6%) | 58,129 (-0.3% ± 0.7%) | 54,041 (-0.1% ± 0.2%) | 65,399 (+0.0% ± 2.9%) | 34,283 (-0.1% ± 0.3%) | 0.1684 (-0.1% ± 3.1%) |

<details><summary>Counters per txn</summary>

| suite | frontend stall | l1i refill | backend stall |
|---|---|---|---|
| pooler | 74,838 (-0.2% ± 1.0%) | 3,594 (+0.0% ± 0.2%) |  |
| lb | 77,529 (+0.4% ± 0.8%) | 3,689 (+0.2% ± 0.2%) |  |
| sharding-w2 | 163,003 (-0.7% ± 4.5%) | 6,079 (-0.1% ± 1.1%) |  |
| sharding-w8 | 127,922 (-0.3% ± 1.9%) | 4,896 (-0.1% ± 0.3%) |  |
</details>

Microbench: all 507 measures within bounds.

<details><summary>Hot code per txn</summary>

| path | base | head | change |
|---|---|---|---|
| pooler | 107.3 KB | 111.9 KB | **+4.6 KB** |
| sharding-w2 | 164.9 KB | 166.9 KB | **+2.0 KB** |

pooler:

| crate | base | head | change |
|---|---|---|---|
| pgdog::frontend::client::query_engine | 20.8 KB | 21.8 KB | +0.9 KB |
| tokio | 17.4 KB | 17.9 KB | +0.5 KB |
| pgdog::backend::pool | 16.8 KB | 17.5 KB | +0.7 KB |
| pgdog::frontend (other) | 8.9 KB | 9.1 KB | +0.2 KB |
| pgdog::backend::server | 7.3 KB | 7.8 KB | +0.4 KB |
| aws-lc (TLS crypto) | 7.1 KB | 7.5 KB | +0.4 KB |
| rustls (TLS) | 7.1 KB | 7.3 KB | +0.2 KB |
| other | 5.6 KB | 5.8 KB | +0.2 KB |
| everything else | 16.3 KB | 17.2 KB | +0.9 KB |

| function | head | change |
|---|---|---|
| `pgdog::frontend::client::Client::run::{{closure}}` | 7.0 KB | +0.3 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 6.6 KB | +0.3 KB |
| `pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}}` | 4.6 KB | +0.4 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 3.8 KB | +0.1 KB |
| `tokio::runtime::task::raw::poll` | 3.6 KB | +0.1 KB |

sharding-w2:

| crate | base | head | change |
|---|---|---|---|
| pgdog::frontend::router | 26.7 KB | 26.8 KB | +0.1 KB |
| pgdog::frontend::client::query_engine | 23.1 KB | 23.2 KB | +0.1 KB |
| tokio | 18.5 KB | 18.4 KB | -0.1 KB |
| pgdog::backend::pool | 17.8 KB | 18.3 KB | +0.5 KB |
| aws-lc (TLS crypto) | 10.1 KB | 10.4 KB | +0.3 KB |
| other | 10.7 KB | 10.3 KB | -0.4 KB |
| pgdog::frontend (other) | 10.2 KB | 10.2 KB | +0.0 KB |
| jemalloc | 8.8 KB | 9.6 KB | +0.8 KB |
| everything else | 39.0 KB | 39.8 KB | +0.8 KB |

| function | head | change |
|---|---|---|
| `pgdog::frontend::client::Client::run::{{closure}}` | 7.8 KB | +0.0 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 6.3 KB | +0.2 KB |
| `pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}}` | 4.6 KB | +0.1 KB |
| `pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que` | 4.2 KB | +0.0 KB |
| `pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine:` | 3.9 KB | +0.0 KB |

</details>

<details><summary>lb flamegraph vs 068e28fd</summary>

![lb](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...) for hover, zoom and search.

![lb removed](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...).
</details>
<details><summary>microbench flamegraph vs 068e28fd</summary>

![microbench](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...) for hover, zoom and search.

![microbench removed](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...).
</details>
<details><summary>pooler flamegraph vs 068e28fd</summary>

![pooler](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...) for hover, zoom and search.

![pooler removed](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...).
</details>
<details><summary>sharding-w2 flamegraph vs 068e28fd</summary>

![sharding-w2](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...) for hover, zoom and search.

![sharding-w2 removed](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...).
</details>
<details><summary>sharding-w8 flamegraph vs 068e28fd</summary>

![sharding-w8](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...) for hover, zoom and search.

![sharding-w8 removed](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...)

[Open interactive](https://pgdog-metal-bench.s3.amazonaws.com/results-x86/jk-subquery-binary-conversion-subqueries/34ef...).
</details>

<details><summary>Logs</summary>

[lb](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results-x86/jk-subquery-binary-...), [microbench](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results-x86/jk-subquery-binary-...), [pooler](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results-x86/jk-subquery-binary-...), [sharding-w2](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results-x86/jk-subquery-binary-...), [sharding-w8](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results-x86/jk-subquery-binary-...), [verdict.json](https://s3.console.aws.amazon.com/s3/object/pgdog-metal-bench?prefix=results-x86/jk-subquery-binary-...)
</details>

Compared 34ef3092 with 068e28fd on c7a.metal-48xl (spot).


^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [pgdogdev/pgdog] PR #2040: perf: skip decode -> re-encode of subquery rows (binary DataRow -> binary array)
@ 2026-11-18 22:49  "jkaczman (@jkaczman)" <noreply+jkaczman@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: jkaczman (@jkaczman) @ 2026-11-18 22:49 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>

@jkaczman merged this (commit c20beb400956).

^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [pgdogdev/pgdog] PR #2040: perf: skip decode -> re-encode of subquery rows (binary DataRow -> binary array)
@ 2026-11-18 22:49  "jkaczman (@jkaczman)" <noreply+jkaczman@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: jkaczman (@jkaczman) @ 2026-11-18 22:49 UTC (permalink / raw)
  To: pgdogdev/pgdog <noreply+pgdogdev-pgdog@github.com>

@jkaczman closed this.

^ permalink  raw  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2026-11-18 22:49 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15 00:14 [pgdogdev/pgdog] PR #2040: perf: skip decode -> re-encode of subquery rows (binary DataRow -> binary array) "jkaczman (@jkaczman)" <noreply+jkaczman@github.com>
2026-11-15 00:17 ` "codecov[bot] (bot) (@codecov[bot])" <noreply+codecov[bot]@github.com>
2026-11-15 00:57 ` "github-actions[bot] (bot) (@github-actions[bot])" <noreply+github-actions[bot]@github.com>
2026-11-15 00:59 ` "github-actions[bot] (bot) (@github-actions[bot])" <noreply+github-actions[bot]@github.com>
2026-11-18 22:49 ` "jkaczman (@jkaczman)" <noreply+jkaczman@github.com>
2026-11-18 22:49 ` "jkaczman (@jkaczman)" <noreply+jkaczman@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox