From b5b9f6d6c5deb3b3d5a580d0dd37ff3e4080ae53 Mon Sep 17 00:00:00 2001 From: Leonardo Yvens Date: Mon, 4 Mar 2024 18:23:37 +0100 Subject: [PATCH] fix(pruning): Fix version stats for huge number of versions --- graph/src/components/store/mod.rs | 4 ++-- store/postgres/src/catalog.rs | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/graph/src/components/store/mod.rs b/graph/src/components/store/mod.rs index 43a32a04489..5ec11c69d7b 100644 --- a/graph/src/components/store/mod.rs +++ b/graph/src/components/store/mod.rs @@ -1054,8 +1054,8 @@ impl ReadStore for EmptyStore { /// in a database table #[derive(Clone, Debug)] pub struct VersionStats { - pub entities: i32, - pub versions: i32, + pub entities: i64, + pub versions: i64, pub tablename: String, /// The ratio `entities / versions` pub ratio: f64, diff --git a/store/postgres/src/catalog.rs b/store/postgres/src/catalog.rs index cc448b9fd1d..2d6a8a9712f 100644 --- a/store/postgres/src/catalog.rs +++ b/store/postgres/src/catalog.rs @@ -3,7 +3,7 @@ use diesel::{connection::SimpleConnection, prelude::RunQueryDsl, select}; use diesel::{insert_into, OptionalExtension}; use diesel::{pg::PgConnection, sql_query}; use diesel::{ - sql_types::{Array, Double, Nullable, Text}, + sql_types::{Array, BigInt, Double, Nullable, Text}, ExpressionMethods, QueryDsl, }; use graph::components::store::VersionStats; @@ -700,10 +700,10 @@ pub(crate) fn drop_index( pub fn stats(conn: &PgConnection, site: &Site) -> Result, StoreError> { #[derive(Queryable, QueryableByName)] pub struct DbStats { - #[sql_type = "Integer"] - pub entities: i32, - #[sql_type = "Integer"] - pub versions: i32, + #[sql_type = "BigInt"] + pub entities: i64, + #[sql_type = "BigInt"] + pub versions: i64, #[sql_type = "Text"] pub tablename: String, /// The ratio `entities / versions` @@ -730,10 +730,10 @@ pub fn stats(conn: &PgConnection, site: &Site) -> Result, Stor // values there are in the `id` column) See the [Postgres // docs](https://www.postgresql.org/docs/current/view-pg-stats.html) for // the precise meaning of n_distinct - let query = "select case when s.n_distinct < 0 then (- s.n_distinct * c.reltuples)::int4 - else s.n_distinct::int4 + let query = "select case when s.n_distinct < 0 then (- s.n_distinct * c.reltuples)::int8 + else s.n_distinct::int8 end as entities, - c.reltuples::int4 as versions, + c.reltuples::int8 as versions, c.relname as tablename, case when c.reltuples = 0 then 0::float8 when s.n_distinct < 0 then (-s.n_distinct)::float8