Teach pgxc_exec_sizefunc() to use pg_my_temp_schema() to get temp schema
authorPavan Deolasee <[email protected]>
Thu, 19 Jul 2018 09:31:07 +0000 (15:01 +0530)
committerPavan Deolasee <[email protected]>
Fri, 27 Jul 2018 08:01:29 +0000 (13:31 +0530)
Similar to what we did in e688c0c23c962d425b82fdfad014bace4207af1d, we must not
rely on the temporary namespace on the coordinator since it may change on the
remote nodes. Instead we use the pg_my_temp_schema() function to find the
currently active temporary schema on the remote node.

src/backend/utils/adt/dbsize.c

index 5bf80a26a942587909f168e98e396e5828b7d488..6d5fe23c5f6720883bb7c14710144894b23bed3b 100644 (file)
@@ -1356,18 +1356,28 @@ pgxc_exec_sizefunc(Oid relOid, char *funcname, char *extra_arg)
        char           *relname = NULL;
        StringInfoData  buf;
        Relation        rel;
+       bool                    istemp;
 
        rel = relation_open(relOid, AccessShareLock);
+       istemp = (rel->rd_rel->relpersistence == RELPERSISTENCE_TEMP);
 
-       if (rel->rd_locator_info)
-       /* get relation name including any needed schema prefix and quoting */
-       relname = quote_qualified_identifier(get_namespace_name(rel->rd_rel->relnamespace),
-                                            RelationGetRelationName(rel));
        initStringInfo(&buf);
+       /* get relation name including any needed schema prefix and quoting */
        if (!extra_arg)
-               appendStringInfo(&buf, "SELECT pg_catalog.%s('%s')", funcname, relname);
+               appendStringInfo(&buf, "SELECT pg_catalog.%s(c.oid) "
+                               "FROM pg_class c JOIN pg_namespace nc "
+                               "       ON c.oid = nc.oid ", funcname);
+       else
+               appendStringInfo(&buf, "SELECT pg_catalog.%s(c.oid, '%s') "
+                               "FROM pg_class c JOIN pg_namespace nc "
+                               "       ON c.oid = nc.oid ", funcname, extra_arg);
+
+       if (!istemp)
+               appendStringInfo(&buf, "WHERE relname = '%s' AND nc.nspname = '%s'",
+                               relname, get_namespace_name(rel->rd_rel->relnamespace));
        else
-               appendStringInfo(&buf, "SELECT pg_catalog.%s('%s', '%s')", funcname, relname, extra_arg);
+               appendStringInfo(&buf, "WHERE relname = '%s' AND "
+                               "       nc.oid = pg_my_temp_schema()", relname);
 
        numnodes = get_pgxc_classnodes(RelationGetRelid(rel), &nodelist);