| 1105 | } |
| 1106 | |
| 1107 | Oid |
| 1108 | GetForeignServerSegByRelid(Oid relid) |
| 1109 | { |
| 1110 | Form_pg_foreign_table tableform; |
| 1111 | ForeignTable *ft; |
| 1112 | HeapTuple tp; |
| 1113 | Datum datum; |
| 1114 | bool isnull; |
| 1115 | Oid foreignServerId; |
| 1116 | |
| 1117 | if (Gp_role != GP_ROLE_EXECUTE) |
| 1118 | { |
| 1119 | tp = SearchSysCache1(FOREIGNTABLEREL, ObjectIdGetDatum(relid)); |
| 1120 | if (!HeapTupleIsValid(tp)) |
| 1121 | return InvalidOid; |
| 1122 | tableform = (Form_pg_foreign_table) GETSTRUCT(tp); |
| 1123 | |
| 1124 | ft = (ForeignTable *) palloc(sizeof(ForeignTable)); |
| 1125 | ft->relid = relid; |
| 1126 | ft->serverid = tableform->ftserver; |
| 1127 | |
| 1128 | /* Extract the ftoptions */ |
| 1129 | datum = SysCacheGetAttr(FOREIGNTABLEREL, |
| 1130 | tp, |
| 1131 | Anum_pg_foreign_table_ftoptions, |
| 1132 | &isnull); |
| 1133 | if (isnull) |
| 1134 | ft->options = NIL; |
| 1135 | else |
| 1136 | ft->options = untransformRelOptions(datum); |
| 1137 | |
| 1138 | ReleaseSysCache(tp); |
| 1139 | } |
| 1140 | else |
| 1141 | { |
| 1142 | ft = GetForeignTableOnSegment(relid); |
| 1143 | |
| 1144 | if (!ft) |
| 1145 | return InvalidOid; |
| 1146 | } |
| 1147 | |
| 1148 | foreignServerId = ft->serverid; |
| 1149 | pfree(ft); |
| 1150 | |
| 1151 | return foreignServerId; |
| 1152 | } |
| 1153 | |
| 1154 | Datum |
| 1155 | gp_foreign_server_id(PG_FUNCTION_ARGS) |
no test coverage detected