Skip to main content

pg_extras/queries/
null_indexes.rs

1use crate::{queries::shared::Query, PgStatsVersion};
2use sqlx::postgres::types::Oid;
3use sqlx::{postgres::PgRow, Row};
4
5#[derive(Debug, Clone, serde::Serialize)]
6pub struct NullIndexes {
7    pub oid: Oid,
8    pub index: String,
9    pub index_size: String,
10    pub unique: bool,
11    pub indexed_column: String,
12    pub table: String,
13    pub null_frac: String,
14    pub expected_saving: String,
15    pub schema: String,
16}
17
18impl Query for NullIndexes {
19    fn new(row: &PgRow) -> Self {
20        Self {
21            oid: row.try_get("oid").unwrap_or_default(),
22            index: row.try_get("index").unwrap_or_default(),
23            index_size: row.try_get("index_size").unwrap_or_default(),
24            unique: row.try_get("unique").unwrap_or_default(),
25            indexed_column: row.try_get("indexed_column").unwrap_or_default(),
26            table: row.try_get("table").unwrap_or_default(),
27            null_frac: row.try_get("null_frac").unwrap_or_default(),
28            expected_saving: row.try_get("expected_saving").unwrap_or_default(),
29            schema: row.try_get("schema").unwrap_or_default(),
30        }
31    }
32
33    fn to_row(&self) -> prettytable::Row {
34        row![
35            format!("{:?}", self.oid),
36            self.index,
37            self.index_size,
38            self.unique,
39            self.indexed_column,
40            self.table,
41            self.null_frac,
42            self.expected_saving,
43            self.schema
44        ]
45    }
46
47    fn headers() -> prettytable::Row {
48        row![
49            "oid",
50            "index",
51            "index_size",
52            "unique",
53            "indexed_column",
54            "table",
55            "null_frac",
56            "expected_saving",
57            "schema"
58        ]
59    }
60
61    fn read_file(_pg_statement_version: Option<PgStatsVersion>) -> String {
62        include_str!("../sql/null_indexes.sql").to_string()
63    }
64}