Skip to content

Commit e97bc2f

Browse files
committed
Merge branch 'REL9_5_STABLE' into PGPRO9_5
Fix conflicts: src/backend/optimizer/util/plancat.c
2 parents 2dca94c + e504d91 commit e97bc2f

File tree

18 files changed

+167
-64
lines changed

18 files changed

+167
-64
lines changed

contrib/btree_gist/expected/not_equal.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ INSERT INTO test_ne SELECT '2009-01-01', 10.7 FROM generate_series(1,1000);
99
INSERT INTO test_ne VALUES('2007-02-03', -91.3);
1010
INSERT INTO test_ne VALUES('2011-09-01', 43.7);
1111
INSERT INTO test_ne SELECT '2009-01-01', 10.7 FROM generate_series(1,1000);
12+
SET enable_indexscan to false;
1213
EXPLAIN (COSTS OFF) SELECT * FROM test_ne WHERE a <> '2009-01-01' AND b <> 10.7;
1314
QUERY PLAN
1415
------------------------------------------------------------------------------------------------------
@@ -25,6 +26,7 @@ SELECT * FROM test_ne WHERE a <> '2009-01-01' AND b <> 10.7;
2526
Thu Sep 01 00:00:00 2011 | 43.7
2627
(2 rows)
2728

29+
RESET enable_indexscan;
2830
-- test search for "not equals" using an exclusion constraint
2931
CREATE TABLE zoo (
3032
cage INTEGER,

contrib/btree_gist/sql/not_equal.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ INSERT INTO test_ne VALUES('2007-02-03', -91.3);
1414
INSERT INTO test_ne VALUES('2011-09-01', 43.7);
1515
INSERT INTO test_ne SELECT '2009-01-01', 10.7 FROM generate_series(1,1000);
1616

17+
SET enable_indexscan to false;
18+
1719
EXPLAIN (COSTS OFF) SELECT * FROM test_ne WHERE a <> '2009-01-01' AND b <> 10.7;
1820

1921
SELECT * FROM test_ne WHERE a <> '2009-01-01' AND b <> 10.7;
2022

23+
RESET enable_indexscan;
24+
2125
-- test search for "not equals" using an exclusion constraint
2226

2327
CREATE TABLE zoo (

doc/src/sgml/gin.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@
539539
<function>extractQuery</> to pass additional data to the
540540
<function>consistent</> and <function>comparePartial</> methods.
541541
To use it, <function>extractQuery</> must allocate
542-
an array of <literal>*nkeys</> Pointers and store its address at
542+
an array of <literal>*nkeys</> pointers and store its address at
543543
<literal>*extra_data</>, then store whatever it wants to into the
544544
individual pointers. The variable is initialized to <symbol>NULL</symbol> before
545545
call, so this argument can simply be ignored by operator classes that

doc/src/sgml/ref/pg_dump.sgml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,16 @@ doc/src/sgml/ref/pg_dump.sgml
817817
<term><option>--quote-all-identifiers</></term>
818818
<listitem>
819819
<para>
820-
Force quoting of all identifiers. This may be useful when dumping a
821-
database for migration to a future version that may have introduced
822-
additional keywords.
820+
Force quoting of all identifiers. This option is recommended when
821+
dumping a database from a server whose <productname>PostgreSQL</>
822+
major version is different from <application>pg_dump</>'s, or when
823+
the output is intended to be loaded into a server of a different
824+
major version. By default, <application>pg_dump</> quotes only
825+
identifiers that are reserved words in its own major version.
826+
This sometimes results in compatibility issues when dealing with
827+
servers of other versions that may have slightly different sets
828+
of reserved words. Using <option>--quote-all-identifiers</> prevents
829+
such issues, at the price of a harder-to-read dump script.
823830
</para>
824831
</listitem>
825832
</varlistentry>
@@ -1150,6 +1157,9 @@ CREATE DATABASE foo WITH TEMPLATE template0;
11501157
dump was taken from a server of that version. Loading a dump file
11511158
into an older server may require manual editing of the dump file
11521159
to remove syntax not understood by the older server.
1160+
Use of the <option>--quote-all-identifiers</option> option is recommended
1161+
in cross-version cases, as it can prevent problems arising from varying
1162+
reserved-word lists in different <productname>PostgreSQL</> versions.
11531163
</para>
11541164
</refsect1>
11551165

doc/src/sgml/ref/pg_dumpall.sgml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,16 @@ doc/src/sgml/ref/pg_dumpall.sgml
368368
<term><option>--quote-all-identifiers</></term>
369369
<listitem>
370370
<para>
371-
Force quoting of all identifiers. This may be useful when dumping a
372-
database for migration to a future version that may have introduced
373-
additional keywords.
371+
Force quoting of all identifiers. This option is recommended when
372+
dumping a database from a server whose <productname>PostgreSQL</>
373+
major version is different from <application>pg_dumpall</>'s, or when
374+
the output is intended to be loaded into a server of a different
375+
major version. By default, <application>pg_dumpall</> quotes only
376+
identifiers that are reserved words in its own major version.
377+
This sometimes results in compatibility issues when dealing with
378+
servers of other versions that may have slightly different sets
379+
of reserved words. Using <option>--quote-all-identifiers</> prevents
380+
such issues, at the price of a harder-to-read dump script.
374381
</para>
375382
</listitem>
376383
</varlistentry>

src/backend/access/heap/heapam.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6752,8 +6752,8 @@ heap_tuple_needs_freeze(HeapTupleHeader tuple, TransactionId cutoff_xid,
67526752

67536753
/*
67546754
* The considerations for multixacts are complicated; look at
6755-
* heap_freeze_tuple for justifications. This routine had better be in
6756-
* sync with that one!
6755+
* heap_prepare_freeze_tuple for justifications. This routine had better
6756+
* be in sync with that one!
67576757
*/
67586758
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
67596759
{
@@ -7611,8 +7611,8 @@ heap_xlog_visible(XLogReaderState *record)
76117611
PageInit(vmpage, BLCKSZ, 0);
76127612

76137613
/*
7614-
* XLogReplayBufferExtended locked the buffer. But visibilitymap_set
7615-
* will handle locking itself.
7614+
* XLogReadBufferForRedoExtended locked the buffer. But
7615+
* visibilitymap_set will handle locking itself.
76167616
*/
76177617
LockBuffer(vmbuffer, BUFFER_LOCK_UNLOCK);
76187618

src/backend/access/transam/xlogutils.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,10 @@ XLogReadBufferForRedoExtended(XLogReaderState *record,
422422
* to imply that the page should be dropped or truncated later.
423423
*
424424
* NB: A redo function should normally not call this directly. To get a page
425-
* to modify, use XLogReplayBuffer instead. It is important that all pages
426-
* modified by a WAL record are registered in the WAL records, or they will be
427-
* invisible to tools that that need to know which pages are modified.
425+
* to modify, use XLogReadBufferForRedoExtended instead. It is important that
426+
* all pages modified by a WAL record are registered in the WAL records, or
427+
* they will be invisible to tools that that need to know which pages are
428+
* modified.
428429
*/
429430
Buffer
430431
XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum,

src/backend/catalog/dependency.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,15 @@ find_expr_references_walker(Node *node,
17771777
add_object_address(OCLASS_TYPE, cd->resulttype, 0,
17781778
context->addrs);
17791779
}
1780+
else if (IsA(node, OnConflictExpr))
1781+
{
1782+
OnConflictExpr *onconflict = (OnConflictExpr *) node;
1783+
1784+
if (OidIsValid(onconflict->constraint))
1785+
add_object_address(OCLASS_CONSTRAINT, onconflict->constraint, 0,
1786+
context->addrs);
1787+
/* fall through to examine arguments */
1788+
}
17801789
else if (IsA(node, SortGroupClause))
17811790
{
17821791
SortGroupClause *sgc = (SortGroupClause *) node;

src/backend/executor/execTuples.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,33 +1325,32 @@ do_tup_output(TupOutputState *tstate, Datum *values, bool *isnull)
13251325
* Should only be used with a single-TEXT-attribute tupdesc.
13261326
*/
13271327
void
1328-
do_text_output_multiline(TupOutputState *tstate, char *text)
1328+
do_text_output_multiline(TupOutputState *tstate, const char *txt)
13291329
{
13301330
Datum values[1];
13311331
bool isnull[1] = {false};
13321332

1333-
while (*text)
1333+
while (*txt)
13341334
{
1335-
char *eol;
1335+
const char *eol;
13361336
int len;
13371337

1338-
eol = strchr(text, '\n');
1338+
eol = strchr(txt, '\n');
13391339
if (eol)
13401340
{
1341-
len = eol - text;
1342-
1341+
len = eol - txt;
13431342
eol++;
13441343
}
13451344
else
13461345
{
1347-
len = strlen(text);
1348-
eol += len;
1346+
len = strlen(txt);
1347+
eol = txt + len;
13491348
}
13501349

1351-
values[0] = PointerGetDatum(cstring_to_text_with_len(text, len));
1350+
values[0] = PointerGetDatum(cstring_to_text_with_len(txt, len));
13521351
do_tup_output(tstate, values, isnull);
13531352
pfree(DatumGetPointer(values[0]));
1354-
text = eol;
1353+
txt = eol;
13551354
}
13561355
}
13571356

src/backend/nodes/nodeFuncs.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,6 +3365,15 @@ raw_expression_tree_walker(Node *node,
33653365
/* for now, constraints are ignored */
33663366
}
33673367
break;
3368+
case T_IndexElem:
3369+
{
3370+
IndexElem *indelem = (IndexElem *) node;
3371+
3372+
if (walker(indelem->expr, context))
3373+
return true;
3374+
/* collation and opclass names are deemed uninteresting */
3375+
}
3376+
break;
33683377
case T_GroupingSet:
33693378
return walker(((GroupingSet *) node)->content, context);
33703379
case T_LockingClause:

src/backend/optimizer/plan/planner.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ planner_hook_type planner_hook = NULL;
6565
#define EXPRKIND_APPINFO 7
6666
#define EXPRKIND_PHV 8
6767
#define EXPRKIND_TABLESAMPLE 9
68+
#define EXPRKIND_ARBITER_ELEM 10
6869

6970
/* Passthrough data for standard_qp_callback */
7071
typedef struct
@@ -483,13 +484,23 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
483484

484485
if (parse->onConflict)
485486
{
487+
parse->onConflict->arbiterElems = (List *)
488+
preprocess_expression(root,
489+
(Node *) parse->onConflict->arbiterElems,
490+
EXPRKIND_ARBITER_ELEM);
491+
parse->onConflict->arbiterWhere =
492+
preprocess_expression(root,
493+
parse->onConflict->arbiterWhere,
494+
EXPRKIND_QUAL);
486495
parse->onConflict->onConflictSet = (List *)
487-
preprocess_expression(root, (Node *) parse->onConflict->onConflictSet,
496+
preprocess_expression(root,
497+
(Node *) parse->onConflict->onConflictSet,
488498
EXPRKIND_TARGET);
489-
490499
parse->onConflict->onConflictWhere =
491-
preprocess_expression(root, (Node *) parse->onConflict->onConflictWhere,
500+
preprocess_expression(root,
501+
parse->onConflict->onConflictWhere,
492502
EXPRKIND_QUAL);
503+
/* exclRelTlist contains only Vars, so no preprocessing needed */
493504
}
494505

495506
root->append_rel_list = (List *)

src/backend/optimizer/plan/subselect.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,7 @@ finalize_plan(PlannerInfo *root, Plan *plan, Bitmapset *valid_params,
24262426
&context);
24272427
finalize_primnode((Node *) mtplan->onConflictWhere,
24282428
&context);
2429+
/* exclRelTlist contains only Vars, doesn't need examination */
24292430
foreach(l, mtplan->plans)
24302431
{
24312432
context.paramids =

src/backend/optimizer/prep/prepjointree.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,19 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte,
10311031
parse->returningList = (List *)
10321032
pullup_replace_vars((Node *) parse->returningList, &rvcontext);
10331033
if (parse->onConflict)
1034+
{
10341035
parse->onConflict->onConflictSet = (List *)
1035-
pullup_replace_vars((Node *) parse->onConflict->onConflictSet, &rvcontext);
1036+
pullup_replace_vars((Node *) parse->onConflict->onConflictSet,
1037+
&rvcontext);
1038+
parse->onConflict->onConflictWhere =
1039+
pullup_replace_vars(parse->onConflict->onConflictWhere,
1040+
&rvcontext);
1041+
1042+
/*
1043+
* We assume ON CONFLICT's arbiterElems, arbiterWhere, exclRelTlist
1044+
* can't contain any references to a subquery
1045+
*/
1046+
}
10361047
replace_vars_in_jointree((Node *) parse->jointree, &rvcontext,
10371048
lowest_nulling_outer_join);
10381049
Assert(parse->setOperations == NULL);
@@ -1625,8 +1636,19 @@ pull_up_simple_values(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte)
16251636
parse->returningList = (List *)
16261637
pullup_replace_vars((Node *) parse->returningList, &rvcontext);
16271638
if (parse->onConflict)
1639+
{
16281640
parse->onConflict->onConflictSet = (List *)
1629-
pullup_replace_vars((Node *) parse->onConflict->onConflictSet, &rvcontext);
1641+
pullup_replace_vars((Node *) parse->onConflict->onConflictSet,
1642+
&rvcontext);
1643+
parse->onConflict->onConflictWhere =
1644+
pullup_replace_vars(parse->onConflict->onConflictWhere,
1645+
&rvcontext);
1646+
1647+
/*
1648+
* We assume ON CONFLICT's arbiterElems, arbiterWhere, exclRelTlist
1649+
* can't contain any references to a subquery
1650+
*/
1651+
}
16301652
replace_vars_in_jointree((Node *) parse->jointree, &rvcontext, NULL);
16311653
Assert(parse->setOperations == NULL);
16321654
parse->havingQual = pullup_replace_vars(parse->havingQual, &rvcontext);

0 commit comments

Comments
 (0)