submit code to openGauss-server

Offering: openGaussDev

More detail: fix owner for fdw

Signed-off-by:chenbobo <chenbobo3@huawei.com>

Match-id-0cdd43e2bf4f91363b42dec95cd648e902b88bd5
This commit is contained in:
openGaussDev 2022-03-04 15:57:38 +08:00 committed by yanghao
parent a4da772704
commit d28a571efd
1 changed files with 25 additions and 23 deletions

View File

@ -1151,7 +1151,6 @@ static void deparseRelation(StringInfo buf, Relation rel)
const char *nspname = NULL;
const char *relname = NULL;
ListCell *lc;
char parttype = PARTTYPE_NON_PARTITIONED_RELATION;
/* obtain additional catalog information. */
ForeignTable* table = GetForeignTable(RelationGetRelid(rel));
@ -1180,31 +1179,34 @@ static void deparseRelation(StringInfo buf, Relation rel)
relname = RelationGetRelationName(rel);
}
/* foreign table could not be built from a partitioned table */
UserMapping* user = GetUserMapping(rel->rd_rel->relowner, table->serverid);
ForeignServer *server = GetForeignServer(table->serverid);
PGconn* conn = GetConnection(server, user, false);
/* In current version, there are some unpredictable operations (delete/update, etc.) of foreign table built on
* partitioned table. We forbid all operations in this condition by default. */
if (!ENABLE_SQL_BETA_FEATURE(PARTITION_FDW_ON)) {
char parttype = PARTTYPE_NON_PARTITIONED_RELATION;
UserMapping* user = GetUserMapping(GetUserId(), table->serverid);
ForeignServer *server = GetForeignServer(table->serverid);
PGconn* conn = GetConnection(server, user, false);
PQExpBuffer query = createPQExpBuffer();
appendPQExpBuffer(query,
"SELECT c.parttype FROM pg_class c, pg_namespace n "
"WHERE c.relname = '%s' and c.relnamespace = n.oid and n.nspname = '%s'",
quote_identifier(relname), quote_identifier(nspname));
PQExpBuffer query = createPQExpBuffer();
appendPQExpBuffer(query,
"SELECT c.parttype FROM pg_class c, pg_namespace n "
"WHERE c.relname = '%s' and c.relnamespace = n.oid and n.nspname = '%s'",
quote_identifier(relname), quote_identifier(nspname));
PGresult* res = pgfdw_exec_query(conn, query->data);
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
pgfdw_report_error(ERROR, res, conn, true, query->data);
}
/* res may be empty as the relname/nspname validation is not checked */
if (PQntuples(res) > 0) {
parttype = *PQgetvalue(res, 0, 0);
}
PQclear(res);
destroyPQExpBuffer(query);
PGresult* res = pgfdw_exec_query(conn, query->data);
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
pgfdw_report_error(ERROR, res, conn, true, query->data);
}
/* res may be empty as the relname/nspname validation is not checked */
if (PQntuples(res) > 0) {
parttype = *PQgetvalue(res, 0, 0);
}
PQclear(res);
destroyPQExpBuffer(query);
if (!ENABLE_SQL_BETA_FEATURE(PARTITION_FDW_ON) &&
(parttype == PARTTYPE_PARTITIONED_RELATION || parttype == PARTTYPE_SUBPARTITIONED_RELATION)) {
ereport(ERROR, (errmsg("could not operate foreign table on partitioned table")));
if ((parttype == PARTTYPE_PARTITIONED_RELATION || parttype == PARTTYPE_SUBPARTITIONED_RELATION)) {
ereport(ERROR, (errmsg("could not operate foreign table on partitioned table")));
}
}
appendStringInfo(buf, "%s.%s", quote_identifier(nspname), quote_identifier(relname));