From 22ece6e571df08e520fe1d4701b95f5624abd7b0 Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Mon, 9 Jan 2017 13:35:26 -0800 Subject: [PATCH] Issue a WARNING for external tables with too many URIs External tables with protocols file or http which specify more URIs than segments won't be allowed to query until the cluster has been extended. Rather than silently allow creation, issue a warning and hint to the user to assist troubleshooting. Writable tables error out for the same problem but avoiding to change behavior this late in the release cycle seems like a good idea. --- src/backend/commands/exttablecmds.c | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/backend/commands/exttablecmds.c b/src/backend/commands/exttablecmds.c index 9d0f0c14bc..db20ee26ec 100644 --- a/src/backend/commands/exttablecmds.c +++ b/src/backend/commands/exttablecmds.c @@ -369,6 +369,36 @@ DefineExternalRelation(CreateExternalStmt *createExtStmt) if (encoding < 0) encoding = pg_get_client_encoding(); + /* + * If the number of locations (file or http URIs) exceed the number of + * segments in the cluster, then all queries against the table will fail + * since locations must be mapped at most one per segment. Allow the + * creation since this is old pre-existing behavior but throw a WARNING + * that the user must expand the cluster in order to use it (or alter + * the table). + */ + if (exttypeDesc->exttabletype == EXTTBL_TYPE_LOCATION) + { + if (Gp_role == GP_ROLE_DISPATCH) + { + Value *loc = lfirst(list_head(exttypeDesc->location_list)); + Uri *uri = ParseExternalTableUri(loc->val.str); + + if (uri->protocol == URI_FILE || uri->protocol == URI_HTTP) + { + if (getgpsegmentCount() < list_length(exttypeDesc->location_list)) + ereport(WARNING, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("number of locations (%) exceeds the number " + "of segments (%d)", + list_length(exttypeDesc->location_list), + getgpsegmentCount()), + errhint("The table cannot be queried until cluster " + "is expanded so that there are at least as " + "many segments as locations."))); + } + } + } /* * First, create the pg_class and other regular relation catalog entries. -- GitLab