From 70313e2fa267a22c9046f828aa92f484f2bbbe02 Mon Sep 17 00:00:00 2001 From: Philippe Bourdon Date: Thu, 19 Mar 2026 04:44:39 +0000 Subject: [PATCH] Fix get_table_stats row counts --- src/tools/performance.ts | 4 ++-- tests/integration/container.test.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tools/performance.ts b/src/tools/performance.ts index d0b2910..baef6fb 100644 --- a/src/tools/performance.ts +++ b/src/tools/performance.ts @@ -109,7 +109,7 @@ export async function getTableStatsTool( SELECT schemaname as schema_name, relname as table_name, - (COALESCE(n_tup_ins, 0) + COALESCE(n_tup_upd, 0) + COALESCE(n_tup_del, 0))::bigint as row_count, + COALESCE(n_live_tup, 0)::bigint as row_count, pg_relation_size(schemaname||'.'||relname) as table_size_bytes, pg_size_pretty(pg_relation_size(schemaname||'.'||relname)) as table_size_pretty, pg_indexes_size(schemaname||'.'||relname) as index_size_bytes, @@ -129,7 +129,7 @@ export async function getTableStatsTool( SELECT schemaname as schema_name, relname as table_name, - (COALESCE(n_tup_ins, 0) + COALESCE(n_tup_upd, 0) + COALESCE(n_tup_del, 0))::bigint as row_count, + COALESCE(n_live_tup, 0)::bigint as row_count, pg_relation_size(schemaname||'.'||relname) as table_size_bytes, pg_size_pretty(pg_relation_size(schemaname||'.'||relname)) as table_size_pretty, pg_indexes_size(schemaname||'.'||relname) as index_size_bytes, diff --git a/tests/integration/container.test.ts b/tests/integration/container.test.ts index 40f567d..f3bebd5 100644 --- a/tests/integration/container.test.ts +++ b/tests/integration/container.test.ts @@ -292,7 +292,7 @@ describe("Testcontainer Integration Tests", () => { (s) => s.table_name === "users" ); expect(userStats).toBeDefined(); - expect(userStats!.row_count).toBeGreaterThanOrEqual(0); + expect(userStats!.row_count).toBe(3); expect(userStats!.table_size_bytes).toBeGreaterThan(0); // Test 12: Get table stats for specific table @@ -304,6 +304,7 @@ describe("Testcontainer Integration Tests", () => { expect(userStatsResult.stats).toBeDefined(); expect(userStatsResult.stats!.length).toBe(1); expect(userStatsResult.stats![0].table_name).toBe("users"); + expect(userStatsResult.stats![0].row_count).toBe(3); // Test 13: List views const viewsResult = await listViewsTool({ schema: "testschema" });