Greenplum stores the number of rows per segmentDatabase (actually the max of any...
authordpage <dpage@a7884b65-44f6-0310-8a51-81a127f17b15>
Wed, 15 Apr 2009 09:06:29 +0000 (09:06 +0000)
committerdpage <dpage@a7884b65-44f6-0310-8a51-81a127f17b15>
Wed, 15 Apr 2009 09:06:29 +0000 (09:06 +0000)
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
pgadmin/schema/pgTable.cpp

index 028a6885474533d3ee864f77b9ee85b9770f9b99..958f4572e30767e6664bee9bb7ab4d7dbe88b664 100644 (file)
@@ -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")));
 
index 81e55757101fa72e3e8c26eaac09229248ebceee..cf60da36f68bc5252fcce2b21b25d91ea2ac4a97 100644 (file)
@@ -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")));
             }