Skip to content

Commit 6a69977

Browse files
authored
Merge pull request #162 from postgres/master
Sync Fork from Upstream
2 parents a797af7 + e757080 commit 6a69977

File tree

242 files changed

+4332
-2088
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+4332
-2088
lines changed

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ b5bce6c1ec6061c8a4f730d927e162db7e2ce365 # 2016-08-15 13:42:51 -0400
104104
de94e2af184e25576b13cbda8cf825118835d1cd # 2016-04-06 11:34:02 -0400
105105
# Run pgindent on a batch of (mostly-planner-related) source files.
106106

107+
be060cbcd42737693f6fd425db4c139121181cce # 2016-03-09 13:51:11 -0500
108+
# Re-pgindent vacuumlazy.c.
109+
107110
d0cd7bda97a626049aa7d247374909c52399c413 # 2016-02-04 22:30:08 -0500
108111
# postgres_fdw: pgindent run.
109112

contrib/amcheck/verify_heapam.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ verify_heapam(PG_FUNCTION_ARGS)
395395
{
396396
OffsetNumber maxoff;
397397

398+
CHECK_FOR_INTERRUPTS();
399+
398400
/* Optionally skip over all-frozen or all-visible blocks */
399401
if (skip_option != SKIP_PAGES_NONE)
400402
{

contrib/intarray/_int_tool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ inner_int_contains(ArrayType *a, ArrayType *b)
4141
break; /* db[j] is not in da */
4242
}
4343

44-
return (n == nb) ? true : false;
44+
return (n == nb);
4545
}
4646

4747
/* arguments are assumed sorted */

contrib/intarray/bench/create_test.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
else
5252
{
5353
print $msg "$i\t{" . join(',', @sect) . "}\n";
54-
map { print $map "$i\t$_\n" } @sect;
54+
print $map "$i\t$_\n" foreach @sect;
5555
}
5656
}
5757
close $map;

contrib/ltree/ltree_gist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ ltree_same(PG_FUNCTION_ARGS)
137137
PG_RETURN_POINTER(result);
138138

139139
if (LTG_ISONENODE(a))
140-
*result = (ISEQ(LTG_NODE(a), LTG_NODE(b))) ? true : false;
140+
*result = ISEQ(LTG_NODE(a), LTG_NODE(b));
141141
else
142142
{
143143
int32 i;

contrib/postgres_fdw/connection.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,11 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
353353
/*
354354
* Construct connection params from generic options of ForeignServer
355355
* and UserMapping. (Some of them might not be libpq options, in
356-
* which case we'll just waste a few array slots.) Add 3 extra slots
357-
* for fallback_application_name, client_encoding, end marker.
356+
* which case we'll just waste a few array slots.) Add 4 extra slots
357+
* for application_name, fallback_application_name, client_encoding,
358+
* end marker.
358359
*/
359-
n = list_length(server->options) + list_length(user->options) + 3;
360+
n = list_length(server->options) + list_length(user->options) + 4;
360361
keywords = (const char **) palloc(n * sizeof(char *));
361362
values = (const char **) palloc(n * sizeof(char *));
362363

@@ -366,7 +367,23 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
366367
n += ExtractConnectionOptions(user->options,
367368
keywords + n, values + n);
368369

369-
/* Use "postgres_fdw" as fallback_application_name. */
370+
/*
371+
* Use pgfdw_application_name as application_name if set.
372+
*
373+
* PQconnectdbParams() processes the parameter arrays from start to
374+
* end. If any key word is repeated, the last value is used. Therefore
375+
* note that pgfdw_application_name must be added to the arrays after
376+
* options of ForeignServer are, so that it can override
377+
* application_name set in ForeignServer.
378+
*/
379+
if (pgfdw_application_name && *pgfdw_application_name != '\0')
380+
{
381+
keywords[n] = "application_name";
382+
values[n] = pgfdw_application_name;
383+
n++;
384+
}
385+
386+
/* Use "postgres_fdw" as fallback_application_name */
370387
keywords[n] = "fallback_application_name";
371388
values[n] = "postgres_fdw";
372389
n++;

contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9428,7 +9428,7 @@ $d$;
94289428
-- But creation of user mappings for non-superusers should fail
94299429
CREATE USER MAPPING FOR public SERVER loopback_nopw;
94309430
CREATE USER MAPPING FOR CURRENT_USER SERVER loopback_nopw;
9431-
CREATE FOREIGN TABLE ft1_nopw (
9431+
CREATE FOREIGN TABLE pg_temp.ft1_nopw (
94329432
c1 int NOT NULL,
94339433
c2 int NOT NULL,
94349434
c3 text,

contrib/postgres_fdw/option.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*-------------------------------------------------------------------------
22
*
33
* option.c
4-
* FDW option handling for postgres_fdw
4+
* FDW and GUC option handling for postgres_fdw
55
*
66
* Portions Copyright (c) 2012-2021, PostgreSQL Global Development Group
77
*
@@ -45,6 +45,13 @@ static PgFdwOption *postgres_fdw_options;
4545
*/
4646
static PQconninfoOption *libpq_options;
4747

48+
/*
49+
* GUC parameters
50+
*/
51+
char *pgfdw_application_name = NULL;
52+
53+
void _PG_init(void);
54+
4855
/*
4956
* Helper functions
5057
*/
@@ -435,3 +442,29 @@ ExtractExtensionList(const char *extensionsString, bool warnOnMissing)
435442
list_free(extlist);
436443
return extensionOids;
437444
}
445+
446+
/*
447+
* Module load callback
448+
*/
449+
void
450+
_PG_init(void)
451+
{
452+
/*
453+
* Unlike application_name GUC, don't set GUC_IS_NAME flag nor check_hook
454+
* to allow postgres_fdw.application_name to be any string more than
455+
* NAMEDATALEN characters and to include non-ASCII characters. Instead,
456+
* remote server truncates application_name of remote connection to less
457+
* than NAMEDATALEN and replaces any non-ASCII characters in it with a '?'
458+
* character.
459+
*/
460+
DefineCustomStringVariable("postgres_fdw.application_name",
461+
"Sets the application name to be used on the remote server.",
462+
NULL,
463+
&pgfdw_application_name,
464+
NULL,
465+
PGC_USERSET,
466+
0,
467+
NULL,
468+
NULL,
469+
NULL);
470+
}

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ enum FdwModifyPrivateIndex
101101
FdwModifyPrivateUpdateSql,
102102
/* Integer list of target attribute numbers for INSERT/UPDATE */
103103
FdwModifyPrivateTargetAttnums,
104-
/* Length till the end of VALUES clause (as an integer Value node) */
104+
/* Length till the end of VALUES clause (as an Integer node) */
105105
FdwModifyPrivateLen,
106-
/* has-returning flag (as an integer Value node) */
106+
/* has-returning flag (as an Integer node) */
107107
FdwModifyPrivateHasReturning,
108108
/* Integer list of attribute numbers retrieved by RETURNING */
109109
FdwModifyPrivateRetrievedAttrs
@@ -122,11 +122,11 @@ enum FdwDirectModifyPrivateIndex
122122
{
123123
/* SQL statement to execute remotely (as a String node) */
124124
FdwDirectModifyPrivateUpdateSql,
125-
/* has-returning flag (as an integer Value node) */
125+
/* has-returning flag (as an Integer node) */
126126
FdwDirectModifyPrivateHasReturning,
127127
/* Integer list of attribute numbers retrieved by RETURNING */
128128
FdwDirectModifyPrivateRetrievedAttrs,
129-
/* set-processed flag (as an integer Value node) */
129+
/* set-processed flag (as an Integer node) */
130130
FdwDirectModifyPrivateSetProcessed
131131
};
132132

@@ -280,9 +280,9 @@ typedef struct PgFdwAnalyzeState
280280
*/
281281
enum FdwPathPrivateIndex
282282
{
283-
/* has-final-sort flag (as an integer Value node) */
283+
/* has-final-sort flag (as an Integer node) */
284284
FdwPathPrivateHasFinalSort,
285-
/* has-limit flag (as an integer Value node) */
285+
/* has-limit flag (as an Integer node) */
286286
FdwPathPrivateHasLimit
287287
};
288288

@@ -5287,45 +5287,41 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
52875287
"SELECT relname, "
52885288
" attname, "
52895289
" format_type(atttypid, atttypmod), "
5290-
" attnotnull, ");
5290+
" attnotnull, "
5291+
" pg_get_expr(adbin, adrelid), ");
52915292

52925293
/* Generated columns are supported since Postgres 12 */
52935294
if (PQserverVersion(conn) >= 120000)
52945295
appendStringInfoString(&buf,
5295-
" attgenerated, "
5296-
" pg_get_expr(adbin, adrelid), ");
5296+
" attgenerated, ");
52975297
else
52985298
appendStringInfoString(&buf,
5299-
" NULL, "
5300-
" pg_get_expr(adbin, adrelid), ");
5299+
" NULL, ");
53015300

53025301
if (import_collate)
53035302
appendStringInfoString(&buf,
53045303
" collname, "
5305-
" collnsp.nspname "
5306-
"FROM pg_class c "
5307-
" JOIN pg_namespace n ON "
5308-
" relnamespace = n.oid "
5309-
" LEFT JOIN pg_attribute a ON "
5310-
" attrelid = c.oid AND attnum > 0 "
5311-
" AND NOT attisdropped "
5312-
" LEFT JOIN pg_attrdef ad ON "
5313-
" adrelid = c.oid AND adnum = attnum "
5304+
" collnsp.nspname ");
5305+
else
5306+
appendStringInfoString(&buf,
5307+
" NULL, NULL ");
5308+
5309+
appendStringInfoString(&buf,
5310+
"FROM pg_class c "
5311+
" JOIN pg_namespace n ON "
5312+
" relnamespace = n.oid "
5313+
" LEFT JOIN pg_attribute a ON "
5314+
" attrelid = c.oid AND attnum > 0 "
5315+
" AND NOT attisdropped "
5316+
" LEFT JOIN pg_attrdef ad ON "
5317+
" adrelid = c.oid AND adnum = attnum ");
5318+
5319+
if (import_collate)
5320+
appendStringInfoString(&buf,
53145321
" LEFT JOIN pg_collation coll ON "
53155322
" coll.oid = attcollation "
53165323
" LEFT JOIN pg_namespace collnsp ON "
53175324
" collnsp.oid = collnamespace ");
5318-
else
5319-
appendStringInfoString(&buf,
5320-
" NULL, NULL "
5321-
"FROM pg_class c "
5322-
" JOIN pg_namespace n ON "
5323-
" relnamespace = n.oid "
5324-
" LEFT JOIN pg_attribute a ON "
5325-
" attrelid = c.oid AND attnum > 0 "
5326-
" AND NOT attisdropped "
5327-
" LEFT JOIN pg_attrdef ad ON "
5328-
" adrelid = c.oid AND adnum = attnum ");
53295325

53305326
appendStringInfoString(&buf,
53315327
"WHERE c.relkind IN ("
@@ -5405,9 +5401,9 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
54055401
attname = PQgetvalue(res, i, 1);
54065402
typename = PQgetvalue(res, i, 2);
54075403
attnotnull = PQgetvalue(res, i, 3);
5408-
attgenerated = PQgetisnull(res, i, 4) ? (char *) NULL :
5404+
attdefault = PQgetisnull(res, i, 4) ? (char *) NULL :
54095405
PQgetvalue(res, i, 4);
5410-
attdefault = PQgetisnull(res, i, 5) ? (char *) NULL :
5406+
attgenerated = PQgetisnull(res, i, 5) ? (char *) NULL :
54115407
PQgetvalue(res, i, 5);
54125408
collname = PQgetisnull(res, i, 6) ? (char *) NULL :
54135409
PQgetvalue(res, i, 6);

contrib/postgres_fdw/postgres_fdw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ extern int ExtractConnectionOptions(List *defelems,
158158
const char **values);
159159
extern List *ExtractExtensionList(const char *extensionsString,
160160
bool warnOnMissing);
161+
extern char *pgfdw_application_name;
161162

162163
/* in deparse.c */
163164
extern void classifyConditions(PlannerInfo *root,

0 commit comments

Comments
 (0)