Skip to main content

pg_extras/queries/
index_usage.rs

1use crate::{queries::shared::Query, PgStatsVersion};
2use sqlx::{postgres::PgRow, Row};
3
4#[derive(Debug, Clone, serde::Serialize)]
5pub struct IndexUsage {
6    pub relname: String,
7    pub percent_of_times_index_used: String,
8    pub rows_in_table: i64,
9}
10
11impl Query for IndexUsage {
12    fn new(row: &PgRow) -> Self {
13        Self {
14            relname: row.try_get("relname").unwrap_or_default(),
15            percent_of_times_index_used: row
16                .try_get("percent_of_times_index_used")
17                .unwrap_or_default(),
18            rows_in_table: row.try_get("rows_in_table").unwrap_or_default(),
19        }
20    }
21
22    fn to_row(&self) -> prettytable::Row {
23        row![
24            self.relname,
25            self.percent_of_times_index_used,
26            self.rows_in_table.to_string()
27        ]
28    }
29
30    fn headers() -> prettytable::Row {
31        row!["relname", "percent_of_times_index_used", "rows_in_table"]
32    }
33
34    fn read_file(_pg_statement_version: Option<PgStatsVersion>) -> String {
35        include_str!("../sql/index_usage.sql").to_string()
36    }
37}