Assorted code improvements for table partitioning.
authorRobert Haas <rhaas@postgresql.org>
Wed, 4 Jan 2017 20:59:00 +0000 (15:59 -0500)
committerRobert Haas <rhaas@postgresql.org>
Wed, 4 Jan 2017 20:59:00 +0000 (15:59 -0500)
Michael Paquier, per Coverity.

src/backend/catalog/heap.c
src/backend/catalog/partition.c
src/bin/pg_dump/pg_dump.c

index d407b8c243d5df89b529c3e39911349e028da30f..72aa0dd6c84b532937942e5019272f11c5550e40 100644 (file)
@@ -3248,6 +3248,10 @@ StorePartitionBound(Relation rel, Relation parent, Node *bound)
    classRel = heap_open(RelationRelationId, RowExclusiveLock);
    tuple = SearchSysCacheCopy1(RELOID,
                                ObjectIdGetDatum(RelationGetRelid(rel)));
+   if (!HeapTupleIsValid(tuple))
+       elog(ERROR, "cache lookup failed for relation %u",
+            RelationGetRelid(rel));
+
 #ifdef USE_ASSERT_CHECKING
    {
        Form_pg_class   classForm;
index 1542c122f18d44338b86a8224ddca94214d104ba..f54e1bdf3fb52cefed9b0d2fe7ab2a169231579d 100644 (file)
@@ -200,6 +200,8 @@ RelationBuildPartitionDesc(Relation rel)
        Node       *boundspec;
 
        tuple = SearchSysCache1(RELOID, inhrelid);
+       if (!HeapTupleIsValid(tuple))
+           elog(ERROR, "cache lookup failed for relation %u", inhrelid);
 
        /*
         * It is possible that the pg_class tuple of a partition has not been
@@ -1516,6 +1518,10 @@ generate_partition_qual(Relation rel)
        elog(ERROR, "relation \"%s\" has relispartition = false",
             RelationGetRelationName(rel));
    tuple = SearchSysCache1(RELOID, RelationGetRelid(rel));
+   if (!HeapTupleIsValid(tuple))
+       elog(ERROR, "cache lookup failed for relation %u",
+            RelationGetRelid(rel));
+
    boundDatum = SysCacheGetAttr(RELOID, tuple,
                                 Anum_pg_class_relpartbound,
                                 &isnull);
index 359402dd2a7dbdfc8b3eb40e000b5cb78603ef38..6a53a051294ebe2395452c40a868df1066a5399f 100644 (file)
@@ -5736,7 +5736,7 @@ getPartitions(Archive *fout, int *numPartitions)
    PGresult   *res;
    int         ntups;
    int         i;
-   PQExpBuffer query = createPQExpBuffer();
+   PQExpBuffer query;
    PartInfo    *partinfo;
 
    int         i_partrelid;
@@ -5750,6 +5750,8 @@ getPartitions(Archive *fout, int *numPartitions)
        return NULL;
    }
 
+   query = createPQExpBuffer();
+
    /* Make sure we are in proper schema */
    selectSourceSchema(fout, "pg_catalog");
 
@@ -7067,7 +7069,7 @@ getTransforms(Archive *fout, int *numTransforms)
 void
 getTablePartitionKeyInfo(Archive *fout, TableInfo *tblinfo, int numTables)
 {
-   PQExpBuffer q = createPQExpBuffer();
+   PQExpBuffer q;
    int         i;
    PGresult   *res;
 
@@ -7075,6 +7077,8 @@ getTablePartitionKeyInfo(Archive *fout, TableInfo *tblinfo, int numTables)
    if (fout->remoteVersion < 100000)
        return;
 
+   q = createPQExpBuffer();
+
    for (i = 0; i < numTables; i++)
    {
        TableInfo  *tbinfo = &(tblinfo[i]);
@@ -7094,6 +7098,8 @@ getTablePartitionKeyInfo(Archive *fout, TableInfo *tblinfo, int numTables)
        Assert(PQntuples(res) == 1);
        tbinfo->partkeydef = pg_strdup(PQgetvalue(res, 0, 0));
    }
+
+   destroyPQExpBuffer(q);
 }
 
 /*