MCPcopy Create free account
hub / github.com/apache/cloudberry / postgresAnalyzeForeignTable

Function postgresAnalyzeForeignTable

contrib/postgres_fdw/postgres_fdw.c:4936–4992  ·  view source on GitHub ↗

* postgresAnalyzeForeignTable * Test whether analyzing this foreign table is supported */

Source from the content-addressed store, hash-verified

4934 * Test whether analyzing this foreign table is supported
4935 */
4936static bool
4937postgresAnalyzeForeignTable(Relation relation,
4938 AcquireSampleRowsFunc *func,
4939 BlockNumber *totalpages)
4940{
4941 ForeignTable *table;
4942 UserMapping *user;
4943 PGconn *conn;
4944 StringInfoData sql;
4945 PGresult *volatile res = NULL;
4946
4947 /* Return the row-analysis function pointer */
4948 *func = postgresAcquireSampleRowsFunc;
4949
4950 /*
4951 * Now we have to get the number of pages. It's annoying that the ANALYZE
4952 * API requires us to return that now, because it forces some duplication
4953 * of effort between this routine and postgresAcquireSampleRowsFunc. But
4954 * it's probably not worth redefining that API at this point.
4955 */
4956
4957 /*
4958 * Get the connection to use. We do the remote access as the table's
4959 * owner, even if the ANALYZE was started by some other user.
4960 */
4961 table = GetForeignTable(RelationGetRelid(relation));
4962 user = GetUserMapping(relation->rd_rel->relowner, table->serverid);
4963 conn = GetConnection(user, false, NULL);
4964
4965 /*
4966 * Construct command to get page count for relation.
4967 */
4968 initStringInfo(&sql);
4969 deparseAnalyzeSizeSql(&sql, relation);
4970
4971 /* In what follows, do not risk leaking any PGresults. */
4972 PG_TRY();
4973 {
4974 res = pgfdw_exec_query(conn, sql.data, NULL);
4975 if (PQresultStatus(res) != PGRES_TUPLES_OK)
4976 pgfdw_report_error(ERROR, res, conn, false, sql.data);
4977
4978 if (PQntuples(res) != 1 || PQnfields(res) != 1)
4979 elog(ERROR, "unexpected result from deparseAnalyzeSizeSql query");
4980 *totalpages = strtoul(PQgetvalue(res, 0, 0), NULL, 10);
4981 }
4982 PG_FINALLY();
4983 {
4984 if (res)
4985 PQclear(res);
4986 }
4987 PG_END_TRY();
4988
4989 ReleaseConnection(conn);
4990
4991 return true;
4992}
4993

Callers

nothing calls this directly

Calls 13

GetForeignTableFunction · 0.85
GetUserMappingFunction · 0.85
initStringInfoFunction · 0.85
deparseAnalyzeSizeSqlFunction · 0.85
pgfdw_exec_queryFunction · 0.85
PQresultStatusFunction · 0.85
pgfdw_report_errorFunction · 0.85
PQntuplesFunction · 0.85
PQnfieldsFunction · 0.85
PQgetvalueFunction · 0.85
PQclearFunction · 0.85
ReleaseConnectionFunction · 0.85

Tested by

no test coverage detected