Skip to content

Commit

Permalink
Fix describe on PostgreSQL views with rules (#2736)
Browse files Browse the repository at this point in the history
* fix postgres describe on multiple explains

* inline the first explain using smallvec

* fix: regenerate `Cargo.lock`

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
  • Loading branch information
jwangnz and abonander authored Mar 14, 2024
1 parent 4c68302 commit 936744d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
19 changes: 11 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sqlx-postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
10 changes: 6 additions & 4 deletions sqlx-postgres/src/connection/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<SmallVec<[Explain; 1]>>,) =
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)
Expand Down

0 comments on commit 936744d

Please sign in to comment.