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

Function postgresExecForeignTruncate

contrib/postgres_fdw/postgres_fdw.c:2974–3064  ·  view source on GitHub ↗

* postgresExecForeignTruncate * Truncate one or more foreign tables */

Source from the content-addressed store, hash-verified

2972 * Truncate one or more foreign tables
2973 */
2974static void
2975postgresExecForeignTruncate(List *rels,
2976 DropBehavior behavior,
2977 bool restart_seqs)
2978{
2979 Oid serverid = InvalidOid;
2980 UserMapping *user = NULL;
2981 PGconn *conn = NULL;
2982 StringInfoData sql;
2983 ListCell *lc;
2984 bool server_truncatable = true;
2985
2986 /*
2987 * By default, all postgres_fdw foreign tables are assumed truncatable.
2988 * This can be overridden by a per-server setting, which in turn can be
2989 * overridden by a per-table setting.
2990 */
2991 foreach(lc, rels)
2992 {
2993 ForeignServer *server = NULL;
2994 Relation rel = lfirst(lc);
2995 ForeignTable *table = GetForeignTable(RelationGetRelid(rel));
2996 ListCell *cell;
2997 bool truncatable;
2998
2999 /*
3000 * First time through, determine whether the foreign server allows
3001 * truncates. Since all specified foreign tables are assumed to belong
3002 * to the same foreign server, this result can be used for other
3003 * foreign tables.
3004 */
3005 if (!OidIsValid(serverid))
3006 {
3007 serverid = table->serverid;
3008 server = GetForeignServer(serverid);
3009
3010 foreach(cell, server->options)
3011 {
3012 DefElem *defel = (DefElem *) lfirst(cell);
3013
3014 if (strcmp(defel->defname, "truncatable") == 0)
3015 {
3016 server_truncatable = defGetBoolean(defel);
3017 break;
3018 }
3019 }
3020 }
3021
3022 /*
3023 * Confirm that all specified foreign tables belong to the same
3024 * foreign server.
3025 */
3026 Assert(table->serverid == serverid);
3027
3028 /* Determine whether this foreign table allows truncations */
3029 truncatable = server_truncatable;
3030 foreach(cell, table->options)
3031 {

Callers

nothing calls this directly

Calls 13

GetForeignTableFunction · 0.85
GetForeignServerFunction · 0.85
defGetBooleanFunction · 0.85
GetUserMappingFunction · 0.85
GetUserIdFunction · 0.85
initStringInfoFunction · 0.85
deparseTruncateSqlFunction · 0.85
do_sql_commandFunction · 0.85
GetConnectionFunction · 0.70
foreachFunction · 0.50
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected