|
18 | 18 | #include "catalog/pg_foreign_server.h" |
19 | 19 | #include "catalog/pg_foreign_table.h" |
20 | 20 | #include "catalog/pg_user_mapping.h" |
| 21 | +#include "cdb/cdbutil.h" |
21 | 22 | #include "commands/defrem.h" |
22 | 23 | #include "foreign/fdwapi.h" |
23 | 24 | #include "foreign/foreign.h" |
@@ -74,6 +75,41 @@ SeparateOutMppExecute(List **options) |
74 | 75 | return exec_location; |
75 | 76 | } |
76 | 77 |
|
| 78 | +/* Get and separate out the num_segments option */ |
| 79 | +int32 |
| 80 | +SeparateOutNumSegments(List **options) |
| 81 | +{ |
| 82 | + ListCell *lc = NULL; |
| 83 | + ListCell *prev = NULL; |
| 84 | + char *num_segments_str = NULL; |
| 85 | + int32 num_segments = 0; |
| 86 | + |
| 87 | + foreach(lc, *options) |
| 88 | + { |
| 89 | + DefElem *def = (DefElem *) lfirst(lc); |
| 90 | + |
| 91 | + if (strcmp(def->defname, "num_segments") == 0) |
| 92 | + { |
| 93 | + num_segments_str = defGetString(def); |
| 94 | + num_segments = pg_atoi(num_segments_str, sizeof(int32), 0); |
| 95 | + |
| 96 | + if (num_segments <= 0) |
| 97 | + { |
| 98 | + ereport(ERROR, |
| 99 | + (errcode(ERRCODE_SYNTAX_ERROR), |
| 100 | + errmsg("\"%d\" is not a valid num_segments value", |
| 101 | + num_segments))); |
| 102 | + } |
| 103 | + |
| 104 | + *options = list_delete_cell(*options, lc, prev); |
| 105 | + break; |
| 106 | + } |
| 107 | + |
| 108 | + prev = lc; |
| 109 | + } |
| 110 | + return num_segments; |
| 111 | +} |
| 112 | + |
77 | 113 | /* |
78 | 114 | * GetForeignDataWrapper - look up the foreign-data wrapper by OID. |
79 | 115 | */ |
@@ -224,6 +260,12 @@ GetForeignServerExtended(Oid serverid, bits16 flags) |
224 | 260 | server->exec_location = fdw->exec_location; |
225 | 261 | } |
226 | 262 |
|
| 263 | + server->num_segments = SeparateOutNumSegments(&server->options); |
| 264 | + if (server->num_segments <= 0) |
| 265 | + { |
| 266 | + server->num_segments = getgpsegmentCount(); |
| 267 | + } |
| 268 | + |
227 | 269 | ReleaseSysCache(tp); |
228 | 270 |
|
229 | 271 | return server; |
@@ -329,13 +371,20 @@ GetForeignTable(Oid relid) |
329 | 371 | else |
330 | 372 | ft->options = untransformRelOptions(datum); |
331 | 373 |
|
| 374 | + ForeignServer *server = GetForeignServer(ft->serverid); |
| 375 | + |
332 | 376 | ft->exec_location = SeparateOutMppExecute(&ft->options); |
333 | 377 | if (ft->exec_location == FTEXECLOCATION_NOT_DEFINED) |
334 | 378 | { |
335 | | - ForeignServer *server = GetForeignServer(ft->serverid); |
336 | 379 | ft->exec_location = server->exec_location; |
337 | 380 | } |
338 | 381 |
|
| 382 | + ft->num_segments = SeparateOutNumSegments(&ft->options); |
| 383 | + if (ft->num_segments <= 0) |
| 384 | + { |
| 385 | + ft->num_segments = server->num_segments; |
| 386 | + } |
| 387 | + |
339 | 388 | ReleaseSysCache(tp); |
340 | 389 |
|
341 | 390 | return ft; |
|
0 commit comments