Skip to content

Commit

Permalink
Postgres: set plan_cache_mode in transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
joeydewaal committed Oct 5, 2024
1 parent 4ceb879 commit 5bba30d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sqlx-postgres/src/connection/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::HashMap;
use crate::{PgColumn, PgConnection, PgTypeInfo};
use futures_core::future::BoxFuture;
use smallvec::SmallVec;
use sqlx_core::acquire::Acquire;
use sqlx_core::executor::Executor;
use sqlx_core::query_builder::QueryBuilder;
use std::sync::Arc;
Expand Down Expand Up @@ -522,9 +523,10 @@ WHERE rngtypid = $1

let mut explain = format!("EXPLAIN (VERBOSE, FORMAT JSON) EXECUTE {stmt_id_display}");
let mut comma = false;
let mut tx = self.begin().await?;

if params_len > 0 {
self.execute("set plan_cache_mode = force_generic_plan;")
tx.execute("set local plan_cache_mode = force_generic_plan;")
.await?;

explain += "(";
Expand All @@ -543,7 +545,9 @@ WHERE rngtypid = $1
}

let (Json(explains),): (Json<SmallVec<[Explain; 1]>>,) =
query_as(&explain).fetch_one(self).await?;
query_as(&explain).fetch_one(&mut *tx).await?;

tx.rollback().await?;

let mut nullables = Vec::new();

Expand Down

0 comments on commit 5bba30d

Please sign in to comment.