From 936744dfd6054d986ea784bd1e4acc4472684992 Mon Sep 17 00:00:00 2001 From: Jesse Wang Date: Fri, 15 Mar 2024 08:05:44 +1300 Subject: [PATCH] Fix describe on PostgreSQL views with rules (#2736) * fix postgres describe on multiple explains * inline the first explain using smallvec * fix: regenerate `Cargo.lock` --------- Co-authored-by: Austin Bonander --- Cargo.lock | 19 +++++++++++-------- sqlx-postgres/Cargo.toml | 2 +- sqlx-postgres/src/connection/describe.rs | 10 ++++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 130a38c602..6b9f185918 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,9 +136,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" [[package]] name = "argon2" @@ -479,9 +479,9 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "basic-toml" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2db21524cad41c5591204d22d75e1970a2d1f71060214ca931dc7d5afe2c14e5" +checksum = "823388e228f614e9558c6804262db37960ec8821856535f5c3f59913140558f8" dependencies = [ "serde", ] @@ -3098,6 +3098,9 @@ name = "smallvec" version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +dependencies = [ + "serde", +] [[package]] name = "socket2" @@ -3708,18 +3711,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", diff --git a/sqlx-postgres/Cargo.toml b/sqlx-postgres/Cargo.toml index 77cc0e2403..ffa40471fc 100644 --- a/sqlx-postgres/Cargo.toml +++ b/sqlx-postgres/Cargo.toml @@ -57,7 +57,7 @@ log = "0.4.17" memchr = { version = "2.4.1", default-features = false } num-bigint = { version = "0.4.3", optional = true } once_cell = "1.9.0" -smallvec = "1.7.0" +smallvec = { version = "1.7.0", features = ["serde"] } stringprep = "0.1.2" thiserror = "1.0.35" tracing = { version = "0.1.37", features = ["log"] } diff --git a/sqlx-postgres/src/connection/describe.rs b/sqlx-postgres/src/connection/describe.rs index 1cd28a8b54..189ae3389b 100644 --- a/sqlx-postgres/src/connection/describe.rs +++ b/sqlx-postgres/src/connection/describe.rs @@ -10,6 +10,7 @@ use crate::types::Oid; use crate::HashMap; use crate::{PgArguments, PgColumn, PgConnection, PgTypeInfo}; use futures_core::future::BoxFuture; +use smallvec::SmallVec; use std::fmt::Write; use std::sync::Arc; @@ -447,20 +448,21 @@ WHERE rngtypid = $1 explain += ")"; } - let (Json([explain]),): (Json<[Explain; 1]>,) = query_as(&explain).fetch_one(self).await?; + let (Json(explains),): (Json>,) = + query_as(&explain).fetch_one(self).await?; let mut nullables = Vec::new(); - if let Explain::Plan { + if let Some(Explain::Plan { plan: plan @ Plan { output: Some(ref outputs), .. }, - } = &explain + }) = explains.first() { nullables.resize(outputs.len(), None); - visit_plan(plan, outputs, &mut nullables); + visit_plan(&plan, outputs, &mut nullables); } Ok(nullables)