Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7657f6a

Browse files
committed
Merge branch 'REL9_6_STABLE' into PGPRO9_6
2 parents 531615e + 8b1bf31 commit 7657f6a

Some content is hidden

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

88 files changed

+2002
-1037
lines changed

COPYRIGHT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PostgreSQL Database Management System
22
(formerly known as Postgres, then as Postgres95)
33

4-
Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
4+
Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
55

66
Portions Copyright (c) 1994, The Regents of the University of California
77

contrib/dblink/dblink.c

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "access/reloptions.h"
4141
#include "catalog/indexing.h"
4242
#include "catalog/namespace.h"
43+
#include "catalog/pg_foreign_data_wrapper.h"
4344
#include "catalog/pg_foreign_server.h"
4445
#include "catalog/pg_type.h"
4546
#include "catalog/pg_user_mapping.h"
@@ -112,7 +113,8 @@ static Relation get_rel_from_relname(text *relname_text, LOCKMODE lockmode, AclM
112113
static char *generate_relation_name(Relation rel);
113114
static void dblink_connstr_check(const char *connstr);
114115
static void dblink_security_check(PGconn *conn, remoteConn *rconn);
115-
static void dblink_res_error(const char *conname, PGresult *res, const char *dblink_context_msg, bool fail);
116+
static void dblink_res_error(PGconn *conn, const char *conname, PGresult *res,
117+
const char *dblink_context_msg, bool fail);
116118
static char *get_connect_string(const char *servername);
117119
static char *escape_param_str(const char *from);
118120
static void validate_pkattnums(Relation rel,
@@ -427,7 +429,7 @@ dblink_open(PG_FUNCTION_ARGS)
427429
res = PQexec(conn, buf.data);
428430
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
429431
{
430-
dblink_res_error(conname, res, "could not open cursor", fail);
432+
dblink_res_error(conn, conname, res, "could not open cursor", fail);
431433
PG_RETURN_TEXT_P(cstring_to_text("ERROR"));
432434
}
433435

@@ -496,7 +498,7 @@ dblink_close(PG_FUNCTION_ARGS)
496498
res = PQexec(conn, buf.data);
497499
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
498500
{
499-
dblink_res_error(conname, res, "could not close cursor", fail);
501+
dblink_res_error(conn, conname, res, "could not close cursor", fail);
500502
PG_RETURN_TEXT_P(cstring_to_text("ERROR"));
501503
}
502504

@@ -599,7 +601,8 @@ dblink_fetch(PG_FUNCTION_ARGS)
599601
(PQresultStatus(res) != PGRES_COMMAND_OK &&
600602
PQresultStatus(res) != PGRES_TUPLES_OK))
601603
{
602-
dblink_res_error(conname, res, "could not fetch from cursor", fail);
604+
dblink_res_error(conn, conname, res,
605+
"could not fetch from cursor", fail);
603606
return (Datum) 0;
604607
}
605608
else if (PQresultStatus(res) == PGRES_COMMAND_OK)
@@ -750,8 +753,8 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
750753
if (PQresultStatus(res) != PGRES_COMMAND_OK &&
751754
PQresultStatus(res) != PGRES_TUPLES_OK)
752755
{
753-
dblink_res_error(conname, res, "could not execute query",
754-
fail);
756+
dblink_res_error(conn, conname, res,
757+
"could not execute query", fail);
755758
/* if fail isn't set, we'll return an empty query result */
756759
}
757760
else
@@ -996,7 +999,8 @@ materializeQueryResult(FunctionCallInfo fcinfo,
996999
PGresult *res1 = res;
9971000

9981001
res = NULL;
999-
dblink_res_error(conname, res1, "could not execute query", fail);
1002+
dblink_res_error(conn, conname, res1,
1003+
"could not execute query", fail);
10001004
/* if fail isn't set, we'll return an empty query result */
10011005
}
10021006
else if (PQresultStatus(res) == PGRES_COMMAND_OK)
@@ -1431,7 +1435,8 @@ dblink_exec(PG_FUNCTION_ARGS)
14311435
(PQresultStatus(res) != PGRES_COMMAND_OK &&
14321436
PQresultStatus(res) != PGRES_TUPLES_OK))
14331437
{
1434-
dblink_res_error(conname, res, "could not execute command", fail);
1438+
dblink_res_error(conn, conname, res,
1439+
"could not execute command", fail);
14351440

14361441
/*
14371442
* and save a copy of the command status string to return as our
@@ -2662,7 +2667,8 @@ dblink_connstr_check(const char *connstr)
26622667
}
26632668

26642669
static void
2665-
dblink_res_error(const char *conname, PGresult *res, const char *dblink_context_msg, bool fail)
2670+
dblink_res_error(PGconn *conn, const char *conname, PGresult *res,
2671+
const char *dblink_context_msg, bool fail)
26662672
{
26672673
int level;
26682674
char *pg_diag_sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
@@ -2696,6 +2702,14 @@ dblink_res_error(const char *conname, PGresult *res, const char *dblink_context_
26962702
xpstrdup(message_hint, pg_diag_message_hint);
26972703
xpstrdup(message_context, pg_diag_context);
26982704

2705+
/*
2706+
* If we don't get a message from the PGresult, try the PGconn. This
2707+
* is needed because for connection-level failures, PQexec may just
2708+
* return NULL, not a PGresult at all.
2709+
*/
2710+
if (message_primary == NULL)
2711+
message_primary = PQerrorMessage(conn);
2712+
26992713
if (res)
27002714
PQclear(res);
27012715

@@ -2705,7 +2719,7 @@ dblink_res_error(const char *conname, PGresult *res, const char *dblink_context_
27052719
ereport(level,
27062720
(errcode(sqlstate),
27072721
message_primary ? errmsg_internal("%s", message_primary) :
2708-
errmsg("unknown error"),
2722+
errmsg("could not obtain message string for remote error"),
27092723
message_detail ? errdetail_internal("%s", message_detail) : 0,
27102724
message_hint ? errhint("%s", message_hint) : 0,
27112725
message_context ? errcontext("%s", message_context) : 0,
@@ -2727,6 +2741,25 @@ get_connect_string(const char *servername)
27272741
AclResult aclresult;
27282742
char *srvname;
27292743

2744+
static const PQconninfoOption *options = NULL;
2745+
2746+
/*
2747+
* Get list of valid libpq options.
2748+
*
2749+
* To avoid unnecessary work, we get the list once and use it throughout
2750+
* the lifetime of this backend process. We don't need to care about
2751+
* memory context issues, because PQconndefaults allocates with malloc.
2752+
*/
2753+
if (!options)
2754+
{
2755+
options = PQconndefaults();
2756+
if (!options) /* assume reason for failure is OOM */
2757+
ereport(ERROR,
2758+
(errcode(ERRCODE_FDW_OUT_OF_MEMORY),
2759+
errmsg("out of memory"),
2760+
errdetail("could not get libpq's default connection options")));
2761+
}
2762+
27302763
/* first gather the server connstr options */
27312764
srvname = pstrdup(servername);
27322765
truncate_identifier(srvname, strlen(srvname), false);
@@ -2750,25 +2783,28 @@ get_connect_string(const char *servername)
27502783
{
27512784
DefElem *def = lfirst(cell);
27522785

2753-
appendStringInfo(buf, "%s='%s' ", def->defname,
2754-
escape_param_str(strVal(def->arg)));
2786+
if (is_valid_dblink_option(options, def->defname, ForeignDataWrapperRelationId))
2787+
appendStringInfo(buf, "%s='%s' ", def->defname,
2788+
escape_param_str(strVal(def->arg)));
27552789
}
27562790

27572791
foreach(cell, foreign_server->options)
27582792
{
27592793
DefElem *def = lfirst(cell);
27602794

2761-
appendStringInfo(buf, "%s='%s' ", def->defname,
2762-
escape_param_str(strVal(def->arg)));
2795+
if (is_valid_dblink_option(options, def->defname, ForeignServerRelationId))
2796+
appendStringInfo(buf, "%s='%s' ", def->defname,
2797+
escape_param_str(strVal(def->arg)));
27632798
}
27642799

27652800
foreach(cell, user_mapping->options)
27662801
{
27672802

27682803
DefElem *def = lfirst(cell);
27692804

2770-
appendStringInfo(buf, "%s='%s' ", def->defname,
2771-
escape_param_str(strVal(def->arg)));
2805+
if (is_valid_dblink_option(options, def->defname, UserMappingRelationId))
2806+
appendStringInfo(buf, "%s='%s' ", def->defname,
2807+
escape_param_str(strVal(def->arg)));
27722808
}
27732809

27742810
return buf->data;

contrib/postgres_fdw/connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ pgfdw_report_error(int elevel, PGresult *res, PGconn *conn,
567567
ereport(elevel,
568568
(errcode(sqlstate),
569569
message_primary ? errmsg_internal("%s", message_primary) :
570-
errmsg("unknown error"),
570+
errmsg("could not obtain message string for remote error"),
571571
message_detail ? errdetail_internal("%s", message_detail) : 0,
572572
message_hint ? errhint("%s", message_hint) : 0,
573573
message_context ? errcontext("%s", message_context) : 0,

contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,12 +2479,100 @@ EXECUTE st5('foo', 1);
24792479
1 | 1 | 00001 | Fri Jan 02 00:00:00 1970 PST | Fri Jan 02 00:00:00 1970 | 1 | 1 | foo
24802480
(1 row)
24812481

2482+
-- altering FDW options requires replanning
2483+
PREPARE st6 AS SELECT * FROM ft1 t1 WHERE t1.c1 = t1.c2;
2484+
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st6;
2485+
QUERY PLAN
2486+
----------------------------------------------------------------------------------------------
2487+
Foreign Scan on public.ft1 t1
2488+
Output: c1, c2, c3, c4, c5, c6, c7, c8
2489+
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE (("C 1" = c2))
2490+
(3 rows)
2491+
2492+
PREPARE st7 AS INSERT INTO ft1 (c1,c2,c3) VALUES (1001,101,'foo');
2493+
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st7;
2494+
QUERY PLAN
2495+
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2496+
Insert on public.ft1
2497+
Remote SQL: INSERT INTO "S 1"."T 1"("C 1", c2, c3, c4, c5, c6, c7, c8) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
2498+
-> Result
2499+
Output: NULL::integer, 1001, 101, 'foo'::text, NULL::timestamp with time zone, NULL::timestamp without time zone, NULL::character varying, 'ft1 '::character(10), NULL::user_enum
2500+
(4 rows)
2501+
2502+
ALTER TABLE "S 1"."T 1" RENAME TO "T 0";
2503+
ALTER FOREIGN TABLE ft1 OPTIONS (SET table_name 'T 0');
2504+
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st6;
2505+
QUERY PLAN
2506+
----------------------------------------------------------------------------------------------
2507+
Foreign Scan on public.ft1 t1
2508+
Output: c1, c2, c3, c4, c5, c6, c7, c8
2509+
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 0" WHERE (("C 1" = c2))
2510+
(3 rows)
2511+
2512+
EXECUTE st6;
2513+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
2514+
----+----+-------+------------------------------+--------------------------+----+------------+-----
2515+
1 | 1 | 00001 | Fri Jan 02 00:00:00 1970 PST | Fri Jan 02 00:00:00 1970 | 1 | 1 | foo
2516+
2 | 2 | 00002 | Sat Jan 03 00:00:00 1970 PST | Sat Jan 03 00:00:00 1970 | 2 | 2 | foo
2517+
3 | 3 | 00003 | Sun Jan 04 00:00:00 1970 PST | Sun Jan 04 00:00:00 1970 | 3 | 3 | foo
2518+
4 | 4 | 00004 | Mon Jan 05 00:00:00 1970 PST | Mon Jan 05 00:00:00 1970 | 4 | 4 | foo
2519+
5 | 5 | 00005 | Tue Jan 06 00:00:00 1970 PST | Tue Jan 06 00:00:00 1970 | 5 | 5 | foo
2520+
6 | 6 | 00006 | Wed Jan 07 00:00:00 1970 PST | Wed Jan 07 00:00:00 1970 | 6 | 6 | foo
2521+
7 | 7 | 00007 | Thu Jan 08 00:00:00 1970 PST | Thu Jan 08 00:00:00 1970 | 7 | 7 | foo
2522+
8 | 8 | 00008 | Fri Jan 09 00:00:00 1970 PST | Fri Jan 09 00:00:00 1970 | 8 | 8 | foo
2523+
9 | 9 | 00009 | Sat Jan 10 00:00:00 1970 PST | Sat Jan 10 00:00:00 1970 | 9 | 9 | foo
2524+
(9 rows)
2525+
2526+
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st7;
2527+
QUERY PLAN
2528+
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2529+
Insert on public.ft1
2530+
Remote SQL: INSERT INTO "S 1"."T 0"("C 1", c2, c3, c4, c5, c6, c7, c8) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
2531+
-> Result
2532+
Output: NULL::integer, 1001, 101, 'foo'::text, NULL::timestamp with time zone, NULL::timestamp without time zone, NULL::character varying, 'ft1 '::character(10), NULL::user_enum
2533+
(4 rows)
2534+
2535+
ALTER TABLE "S 1"."T 0" RENAME TO "T 1";
2536+
ALTER FOREIGN TABLE ft1 OPTIONS (SET table_name 'T 1');
2537+
PREPARE st8 AS SELECT count(c3) FROM ft1 t1 WHERE t1.c1 === t1.c2;
2538+
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st8;
2539+
QUERY PLAN
2540+
----------------------------------------------------------------------------------------
2541+
Aggregate
2542+
Output: count(c3)
2543+
-> Foreign Scan on public.ft1 t1
2544+
Output: c3
2545+
Remote SQL: SELECT c3 FROM "S 1"."T 1" WHERE (("C 1" OPERATOR(public.===) c2))
2546+
(5 rows)
2547+
2548+
ALTER SERVER loopback OPTIONS (DROP extensions);
2549+
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st8;
2550+
QUERY PLAN
2551+
-----------------------------------------------------------
2552+
Aggregate
2553+
Output: count(c3)
2554+
-> Foreign Scan on public.ft1 t1
2555+
Output: c3
2556+
Filter: (t1.c1 === t1.c2)
2557+
Remote SQL: SELECT "C 1", c2, c3 FROM "S 1"."T 1"
2558+
(6 rows)
2559+
2560+
EXECUTE st8;
2561+
count
2562+
-------
2563+
9
2564+
(1 row)
2565+
2566+
ALTER SERVER loopback OPTIONS (ADD extensions 'postgres_fdw');
24822567
-- cleanup
24832568
DEALLOCATE st1;
24842569
DEALLOCATE st2;
24852570
DEALLOCATE st3;
24862571
DEALLOCATE st4;
24872572
DEALLOCATE st5;
2573+
DEALLOCATE st6;
2574+
DEALLOCATE st7;
2575+
DEALLOCATE st8;
24882576
-- System columns, except ctid, should not be sent to remote
24892577
EXPLAIN (VERBOSE, COSTS OFF)
24902578
SELECT * FROM ft1 t1 WHERE t1.tableoid = 'pg_class'::regclass LIMIT 1;

contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,35 @@ EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st5('foo', 1);
570570
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st5('foo', 1);
571571
EXECUTE st5('foo', 1);
572572

573+
-- altering FDW options requires replanning
574+
PREPARE st6 AS SELECT * FROM ft1 t1 WHERE t1.c1 = t1.c2;
575+
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st6;
576+
PREPARE st7 AS INSERT INTO ft1 (c1,c2,c3) VALUES (1001,101,'foo');
577+
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st7;
578+
ALTER TABLE "S 1"."T 1" RENAME TO "T 0";
579+
ALTER FOREIGN TABLE ft1 OPTIONS (SET table_name 'T 0');
580+
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st6;
581+
EXECUTE st6;
582+
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st7;
583+
ALTER TABLE "S 1"."T 0" RENAME TO "T 1";
584+
ALTER FOREIGN TABLE ft1 OPTIONS (SET table_name 'T 1');
585+
586+
PREPARE st8 AS SELECT count(c3) FROM ft1 t1 WHERE t1.c1 === t1.c2;
587+
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st8;
588+
ALTER SERVER loopback OPTIONS (DROP extensions);
589+
EXPLAIN (VERBOSE, COSTS OFF) EXECUTE st8;
590+
EXECUTE st8;
591+
ALTER SERVER loopback OPTIONS (ADD extensions 'postgres_fdw');
592+
573593
-- cleanup
574594
DEALLOCATE st1;
575595
DEALLOCATE st2;
576596
DEALLOCATE st3;
577597
DEALLOCATE st4;
578598
DEALLOCATE st5;
599+
DEALLOCATE st6;
600+
DEALLOCATE st7;
601+
DEALLOCATE st8;
579602

580603
-- System columns, except ctid, should not be sent to remote
581604
EXPLAIN (VERBOSE, COSTS OFF)

contrib/uuid-ossp/uuid-ossp.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include "utils/builtins.h"
1818
#include "utils/uuid.h"
1919

20+
/* for ntohl/htonl */
21+
#include <netinet/in.h>
22+
#include <arpa/inet.h>
23+
2024
/*
2125
* It's possible that there's more than one uuid.h header file present.
2226
* We expect configure to set the HAVE_ symbol for only the one we want.
@@ -26,14 +30,14 @@
2630
*/
2731
#define uuid_hash bsd_uuid_hash
2832

29-
#ifdef HAVE_UUID_H
33+
#if defined(HAVE_UUID_H)
3034
#include <uuid.h>
31-
#endif
32-
#ifdef HAVE_OSSP_UUID_H
35+
#elif defined(HAVE_OSSP_UUID_H)
3336
#include <ossp/uuid.h>
34-
#endif
35-
#ifdef HAVE_UUID_UUID_H
37+
#elif defined(HAVE_UUID_UUID_H)
3638
#include <uuid/uuid.h>
39+
#else
40+
#error "please use configure's --with-uuid switch to select a UUID library"
3741
#endif
3842

3943
#undef uuid_hash

doc/src/sgml/catalogs.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@
566566

567567
<row>
568568
<entry><structfield>amhandler</structfield></entry>
569-
<entry><type>oid</type></entry>
569+
<entry><type>regproc</type></entry>
570570
<entry><literal><link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.oid</literal></entry>
571571
<entry>
572572
OID of a handler function that is responsible for supplying information

doc/src/sgml/datatype.sgml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,15 +3959,7 @@ SELECT 'fat &amp; rat &amp; ! cat'::tsquery;
39593959
tsquery
39603960
------------------------
39613961
'fat' &amp; 'rat' &amp; !'cat'
3962-
3963-
SELECT '(fat | rat) &lt;-&gt; cat'::tsquery;
3964-
tsquery
3965-
-----------------------------------
3966-
'fat' &lt;-&gt; 'cat' | 'rat' &lt;-&gt; 'cat'
39673962
</programlisting>
3968-
3969-
The last example demonstrates that <type>tsquery</type> sometimes
3970-
rearranges nested operators into a logically equivalent formulation.
39713963
</para>
39723964

39733965
<para>

0 commit comments

Comments
 (0)