From 5691fb0fe442f2f11a55c555b4373710ec345cdf Mon Sep 17 00:00:00 2001 From: dpage Date: Wed, 15 Apr 2009 09:06:29 +0000 Subject: [PATCH] Greenplum stores the number of rows per segmentDatabase (actually the max of any of the segDBs) in pg_class.reltuples, not the total number of tuples. This causes the stats to display wrong values, and causes pgAdmin to warn that Analyze is needed when it is not. This simple patch multiplies the reltuples x gp_segments, so that we get a better value. Of course, it only does this for Greenplum connections. [Chuck McDevitt] git-svn-id: svn://svn.pgadmin.org/trunk/pgadmin3@7807 a7884b65-44f6-0310-8a51-81a127f17b15 --- pgadmin/schema/gpPartition.cpp | 12 +++++++++++- pgadmin/schema/pgTable.cpp | 13 ++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pgadmin/schema/gpPartition.cpp b/pgadmin/schema/gpPartition.cpp index 028a68854..958f4572e 100644 --- a/pgadmin/schema/gpPartition.cpp +++ b/pgadmin/schema/gpPartition.cpp @@ -96,6 +96,16 @@ pgObject *gpPartitionFactory::CreateObjects(pgCollection *coll, ctlTree *browser wxString query; gpPartition *table=0; + // Greenplum returns reltuples and relpages as tuples per segmentDB and pages per segmentDB, + // so we need to multiply them by the number of segmentDBs to get reasonable values. + long gp_segments =1; + + query = wxT("SELECT count(*) AS gp_segments from pg_catalog.gp_configuration where definedprimary = 't' and content >= 0"); + gp_segments = StrToLong(collection->GetDatabase()->ExecuteScalar(query)); + if (gp_segments <= 1) + gp_segments = 1; + + pgSet *tables; query= wxT("SELECT rel.oid, relname, rel.reltablespace AS spcoid, spcname, pg_get_userbyid(relowner) AS relowner, relacl, relhasoids, ") @@ -152,7 +162,7 @@ pgObject *gpPartitionFactory::CreateObjects(pgCollection *coll, ctlTree *browser table->iSetComment(tables->GetVal(wxT("description"))); table->iSetHasOids(tables->GetBool(wxT("relhasoids"))); - table->iSetEstimatedRows(tables->GetDouble(wxT("reltuples"))); + table->iSetEstimatedRows(tables->GetDouble(wxT("reltuples")) * gp_segments); table->iSetFillFactor(tables->GetVal(wxT("fillfactor"))); diff --git a/pgadmin/schema/pgTable.cpp b/pgadmin/schema/pgTable.cpp index 81e557571..cf60da36f 100644 --- a/pgadmin/schema/pgTable.cpp +++ b/pgadmin/schema/pgTable.cpp @@ -1194,6 +1194,17 @@ pgObject *pgTableFactory::CreateObjects(pgCollection *collection, ctlTree *brows wxString query; pgTable *table=0; + // Greenplum returns reltuples and relpages as tuples per segmentDB and pages per segmentDB, + // so we need to multiply them by the number of segmentDBs to get reasonable values. + long gp_segments =1; + if (collection->GetConnection()->GetIsGreenplum()) + { + query = wxT("SELECT count(*) AS gp_segments from pg_catalog.gp_configuration where definedprimary = 't' and content >= 0"); + gp_segments = StrToLong(collection->GetDatabase()->ExecuteScalar(query)); + if (gp_segments <= 1) + gp_segments = 1; + } + pgSet *tables; if (collection->GetConnection()->BackendMinimumVersion(8, 0)) { @@ -1291,7 +1302,7 @@ pgObject *pgTableFactory::CreateObjects(pgCollection *collection, ctlTree *brows } table->iSetComment(tables->GetVal(wxT("description"))); table->iSetHasOids(tables->GetBool(wxT("relhasoids"))); - table->iSetEstimatedRows(tables->GetDouble(wxT("reltuples"))); + table->iSetEstimatedRows(tables->GetDouble(wxT("reltuples")) * gp_segments); if (collection->GetConnection()->BackendMinimumVersion(8, 2)) { table->iSetFillFactor(tables->GetVal(wxT("fillfactor"))); } -- 2.39.5