Skip to content

Commit

Permalink
update base on comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kysshsy committed Oct 13, 2024
1 parent 92a7786 commit 76003c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/hooks/utility/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,21 @@ pub fn execute_query<T: pgbox::WhoAllocated>(
return Ok(true);
}

// we need to make Duckdb replan the `PREPARE` statement when search path changed.
// We need to ensure that DuckDB replans the PREPARE statement when the search path changes,
// in order to match PostgreSQL’s default behavior.

#[cfg(not(feature = "pg17"))]
let need_replan = !pg_sys::OverrideSearchPathMatchesCurrent((*plan_source).search_path);

#[cfg(feature = "pg17")]
let need_replan = !pg_sys::SearchPathMatchesCurrentEnvironment((*plan_source).search_path);

// For PostgreSQL 13
#[cfg(feature = "pg13")]
let cached_plan = pg_sys::GetCachedPlan(plan_source, null_mut(), false, null_mut());

// For PostgreSQL 14 and above
#[cfg(not(feature = "pg13"))]
let cached_plan = pg_sys::GetCachedPlan(plan_source, null_mut(), null_mut(), null_mut());

if cached_plan.is_null() || (*cached_plan).stmt_list.is_null() {
return Ok(true);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,5 +644,8 @@ async fn test_prepare_search_path(mut conn: PgConnection, tempdir: TempDir) -> R
let result: Vec<(bool,)> = "EXECUTE q1(true)".fetch_collect(&mut conn);
assert_eq!(result.len(), 1);

"DEALLOCATE q1".execute(&mut conn);
assert!("EXECUTE q1(true)".execute_result(&mut conn).is_err());

Ok(())
}

0 comments on commit 76003c0

Please sign in to comment.