Skip to content

Commit 1d13184

Browse files
committed
Merge branch 'REL9_5_STABLE' into PGPRO9_5
2 parents 5e48363 + a7aa61f commit 1d13184

File tree

22 files changed

+765
-314
lines changed

22 files changed

+765
-314
lines changed

contrib/btree_gist/expected/interval.out

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,21 @@ SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21
8989
@ 220 days 19 hours 5 mins 42 secs | @ 21 days -2 hours -15 mins -41 secs
9090
(3 rows)
9191

92+
SET enable_indexonlyscan=off;
93+
EXPLAIN (COSTS OFF)
94+
SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;
95+
QUERY PLAN
96+
---------------------------------------------------------------------------
97+
Limit
98+
-> Index Scan using intervalidx on intervaltmp
99+
Order By: (a <-> '@ 199 days 21 hours 21 mins 23 secs'::interval)
100+
(3 rows)
101+
102+
SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;
103+
a | ?column?
104+
-------------------------------------+--------------------------------------
105+
@ 199 days 21 hours 21 mins 23 secs | @ 0
106+
@ 183 days 6 hours 52 mins 48 secs | @ 16 days 14 hours 28 mins 35 secs
107+
@ 220 days 19 hours 5 mins 42 secs | @ 21 days -2 hours -15 mins -41 secs
108+
(3 rows)
109+

contrib/btree_gist/sql/interval.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ SELECT count(*) FROM intervaltmp WHERE a > '199 days 21:21:23'::interval;
3535
EXPLAIN (COSTS OFF)
3636
SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;
3737
SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;
38+
39+
SET enable_indexonlyscan=off;
40+
41+
EXPLAIN (COSTS OFF)
42+
SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;
43+
SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21:21:23' LIMIT 3;

src/backend/access/nbtree/nbtree.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -592,25 +592,6 @@ btrestrpos(PG_FUNCTION_ARGS)
592592
*/
593593
so->currPos.itemIndex = so->markItemIndex;
594594
}
595-
else if (so->currPos.currPage == so->markPos.currPage)
596-
{
597-
/*
598-
* so->markItemIndex < 0 but mark and current positions are on the
599-
* same page. This would be an unusual case, where the scan moved to
600-
* a new index page after the mark, restored, and later restored again
601-
* without moving off the marked page. It is not clear that this code
602-
* can currently be reached, but it seems better to make this function
603-
* robust for this case than to Assert() or elog() that it can't
604-
* happen.
605-
*
606-
* We neither want to set so->markItemIndex >= 0 (because that could
607-
* cause a later move to a new page to redo the memcpy() executions)
608-
* nor re-execute the memcpy() functions for a restore within the same
609-
* page. The previous restore to this page already set everything
610-
* except markPos as it should be.
611-
*/
612-
so->currPos.itemIndex = so->markPos.itemIndex;
613-
}
614595
else
615596
{
616597
/*

src/backend/access/nbtree/nbtsearch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
10021002
so->currPos.moreRight = false;
10031003
}
10041004
so->numKilled = 0; /* just paranoia */
1005-
so->markItemIndex = -1; /* ditto */
1005+
Assert(so->markItemIndex == -1);
10061006

10071007
/* position to the precise item on the page */
10081008
offnum = _bt_binsrch(rel, buf, keysCount, scankeys, nextkey);

src/backend/executor/execQual.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5333,15 +5333,24 @@ ExecCleanTargetListLength(List *targetlist)
53335333
* of *isDone = ExprMultipleResult signifies a set element, and a return
53345334
* of *isDone = ExprEndResult signifies end of the set of tuple.
53355335
* We assume that *isDone has been initialized to ExprSingleResult by caller.
5336+
*
5337+
* Since fields of the result tuple might be multiply referenced in higher
5338+
* plan nodes, we have to force any read/write expanded values to read-only
5339+
* status. It's a bit annoying to have to do that for every projected
5340+
* expression; in the future, consider teaching the planner to detect
5341+
* actually-multiply-referenced Vars and insert an expression node that
5342+
* would do that only where really required.
53365343
*/
53375344
static bool
53385345
ExecTargetList(List *targetlist,
5346+
TupleDesc tupdesc,
53395347
ExprContext *econtext,
53405348
Datum *values,
53415349
bool *isnull,
53425350
ExprDoneCond *itemIsDone,
53435351
ExprDoneCond *isDone)
53445352
{
5353+
Form_pg_attribute *att = tupdesc->attrs;
53455354
MemoryContext oldContext;
53465355
ListCell *tl;
53475356
bool haveDoneSets;
@@ -5367,6 +5376,10 @@ ExecTargetList(List *targetlist,
53675376
&isnull[resind],
53685377
&itemIsDone[resind]);
53695378

5379+
values[resind] = MakeExpandedObjectReadOnly(values[resind],
5380+
isnull[resind],
5381+
att[resind]->attlen);
5382+
53705383
if (itemIsDone[resind] != ExprSingleResult)
53715384
{
53725385
/* We have a set-valued expression in the tlist */
@@ -5420,6 +5433,10 @@ ExecTargetList(List *targetlist,
54205433
&isnull[resind],
54215434
&itemIsDone[resind]);
54225435

5436+
values[resind] = MakeExpandedObjectReadOnly(values[resind],
5437+
isnull[resind],
5438+
att[resind]->attlen);
5439+
54235440
if (itemIsDone[resind] == ExprEndResult)
54245441
{
54255442
/*
@@ -5453,6 +5470,7 @@ ExecTargetList(List *targetlist,
54535470
econtext,
54545471
&isnull[resind],
54555472
&itemIsDone[resind]);
5473+
/* no need for MakeExpandedObjectReadOnly */
54565474
}
54575475
}
54585476

@@ -5578,6 +5596,7 @@ ExecProject(ProjectionInfo *projInfo, ExprDoneCond *isDone)
55785596
if (projInfo->pi_targetlist)
55795597
{
55805598
if (!ExecTargetList(projInfo->pi_targetlist,
5599+
slot->tts_tupleDescriptor,
55815600
econtext,
55825601
slot->tts_values,
55835602
slot->tts_isnull,

src/backend/executor/execTuples.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
#include "nodes/nodeFuncs.h"
8989
#include "storage/bufmgr.h"
9090
#include "utils/builtins.h"
91-
#include "utils/expandeddatum.h"
9291
#include "utils/lsyscache.h"
9392
#include "utils/typcache.h"
9493

@@ -813,52 +812,6 @@ ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
813812
return ExecStoreTuple(newTuple, dstslot, InvalidBuffer, true);
814813
}
815814

816-
/* --------------------------------
817-
* ExecMakeSlotContentsReadOnly
818-
* Mark any R/W expanded datums in the slot as read-only.
819-
*
820-
* This is needed when a slot that might contain R/W datum references is to be
821-
* used as input for general expression evaluation. Since the expression(s)
822-
* might contain more than one Var referencing the same R/W datum, we could
823-
* get wrong answers if functions acting on those Vars thought they could
824-
* modify the expanded value in-place.
825-
*
826-
* For notational reasons, we return the same slot passed in.
827-
* --------------------------------
828-
*/
829-
TupleTableSlot *
830-
ExecMakeSlotContentsReadOnly(TupleTableSlot *slot)
831-
{
832-
/*
833-
* sanity checks
834-
*/
835-
Assert(slot != NULL);
836-
Assert(slot->tts_tupleDescriptor != NULL);
837-
Assert(!slot->tts_isempty);
838-
839-
/*
840-
* If the slot contains a physical tuple, it can't contain any expanded
841-
* datums, because we flatten those when making a physical tuple. This
842-
* might change later; but for now, we need do nothing unless the slot is
843-
* virtual.
844-
*/
845-
if (slot->tts_tuple == NULL)
846-
{
847-
Form_pg_attribute *att = slot->tts_tupleDescriptor->attrs;
848-
int attnum;
849-
850-
for (attnum = 0; attnum < slot->tts_nvalid; attnum++)
851-
{
852-
slot->tts_values[attnum] =
853-
MakeExpandedObjectReadOnly(slot->tts_values[attnum],
854-
slot->tts_isnull[attnum],
855-
att[attnum]->attlen);
856-
}
857-
}
858-
859-
return slot;
860-
}
861-
862815

863816
/* ----------------------------------------------------------------
864817
* convenience initialization routines

src/backend/executor/nodeIndexscan.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,9 +966,20 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
966966
Oid orderbyop = lfirst_oid(lco);
967967
Node *orderbyexpr = (Node *) lfirst(lcx);
968968
Oid orderbyType = exprType(orderbyexpr);
969+
Oid orderbyColl = exprCollation(orderbyexpr);
970+
SortSupport orderbysort = &indexstate->iss_SortSupport[i];
971+
972+
/* Initialize sort support */
973+
orderbysort->ssup_cxt = CurrentMemoryContext;
974+
orderbysort->ssup_collation = orderbyColl;
975+
/* See cmp_orderbyvals() comments on NULLS LAST */
976+
orderbysort->ssup_nulls_first = false;
977+
/* ssup_attno is unused here and elsewhere */
978+
orderbysort->ssup_attno = 0;
979+
/* No abbreviation */
980+
orderbysort->abbreviate = false;
981+
PrepareSortSupportFromOrderingOp(orderbyop, orderbysort);
969982

970-
PrepareSortSupportFromOrderingOp(orderbyop,
971-
&indexstate->iss_SortSupport[i]);
972983
get_typlenbyval(orderbyType,
973984
&indexstate->iss_OrderByTypLens[i],
974985
&indexstate->iss_OrderByTypByVals[i]);

src/backend/executor/nodeSubqueryscan.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,7 @@ SubqueryNext(SubqueryScanState *node)
5656
* We just return the subplan's result slot, rather than expending extra
5757
* cycles for ExecCopySlot(). (Our own ScanTupleSlot is used only for
5858
* EvalPlanQual rechecks.)
59-
*
60-
* We do need to mark the slot contents read-only to prevent interference
61-
* between different functions reading the same datum from the slot. It's
62-
* a bit hokey to do this to the subplan's slot, but should be safe
63-
* enough.
6459
*/
65-
if (!TupIsNull(slot))
66-
slot = ExecMakeSlotContentsReadOnly(slot);
67-
6860
return slot;
6961
}
7062

src/backend/executor/nodeValuesscan.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "executor/executor.h"
2727
#include "executor/nodeValuesscan.h"
28+
#include "utils/expandeddatum.h"
2829

2930

3031
static TupleTableSlot *ValuesNext(ValuesScanState *node);
@@ -94,6 +95,7 @@ ValuesNext(ValuesScanState *node)
9495
List *exprstatelist;
9596
Datum *values;
9697
bool *isnull;
98+
Form_pg_attribute *att;
9799
ListCell *lc;
98100
int resind;
99101

@@ -129,6 +131,7 @@ ValuesNext(ValuesScanState *node)
129131
*/
130132
values = slot->tts_values;
131133
isnull = slot->tts_isnull;
134+
att = slot->tts_tupleDescriptor->attrs;
132135

133136
resind = 0;
134137
foreach(lc, exprstatelist)
@@ -139,6 +142,17 @@ ValuesNext(ValuesScanState *node)
139142
econtext,
140143
&isnull[resind],
141144
NULL);
145+
146+
/*
147+
* We must force any R/W expanded datums to read-only state, in
148+
* case they are multiply referenced in the plan node's output
149+
* expressions, or in case we skip the output projection and the
150+
* output column is multiply referenced in higher plan nodes.
151+
*/
152+
values[resind] = MakeExpandedObjectReadOnly(values[resind],
153+
isnull[resind],
154+
att[resind]->attlen);
155+
142156
resind++;
143157
}
144158

src/backend/parser/gram.y

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14537,10 +14537,16 @@ doNegateFloat(Value *v)
1453714537
static Node *
1453814538
makeAndExpr(Node *lexpr, Node *rexpr, int location)
1453914539
{
14540+
Node *lexp = lexpr;
14541+
14542+
/* Look through AEXPR_PAREN nodes so they don't affect flattening */
14543+
while (IsA(lexp, A_Expr) &&
14544+
((A_Expr *) lexp)->kind == AEXPR_PAREN)
14545+
lexp = ((A_Expr *) lexp)->lexpr;
1454014546
/* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
14541-
if (IsA(lexpr, BoolExpr))
14547+
if (IsA(lexp, BoolExpr))
1454214548
{
14543-
BoolExpr *blexpr = (BoolExpr *) lexpr;
14549+
BoolExpr *blexpr = (BoolExpr *) lexp;
1454414550

1454514551
if (blexpr->boolop == AND_EXPR)
1454614552
{
@@ -14554,10 +14560,16 @@ makeAndExpr(Node *lexpr, Node *rexpr, int location)
1455414560
static Node *
1455514561
makeOrExpr(Node *lexpr, Node *rexpr, int location)
1455614562
{
14563+
Node *lexp = lexpr;
14564+
14565+
/* Look through AEXPR_PAREN nodes so they don't affect flattening */
14566+
while (IsA(lexp, A_Expr) &&
14567+
((A_Expr *) lexp)->kind == AEXPR_PAREN)
14568+
lexp = ((A_Expr *) lexp)->lexpr;
1455714569
/* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
14558-
if (IsA(lexpr, BoolExpr))
14570+
if (IsA(lexp, BoolExpr))
1455914571
{
14560-
BoolExpr *blexpr = (BoolExpr *) lexpr;
14572+
BoolExpr *blexpr = (BoolExpr *) lexp;
1456114573

1456214574
if (blexpr->boolop == OR_EXPR)
1456314575
{

src/bin/pg_dump/compress_io.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
#include "postgres_fe.h"
5555

5656
#include "compress_io.h"
57-
#include "parallel.h"
5857
#include "pg_backup_utils.h"
5958

6059
/*----------------------
@@ -184,9 +183,6 @@ void
184183
WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs,
185184
const void *data, size_t dLen)
186185
{
187-
/* Are we aborting? */
188-
checkAborting(AH);
189-
190186
switch (cs->comprAlg)
191187
{
192188
case COMPR_ALG_LIBZ:
@@ -351,9 +347,6 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF)
351347
/* no minimal chunk size for zlib */
352348
while ((cnt = readF(AH, &buf, &buflen)))
353349
{
354-
/* Are we aborting? */
355-
checkAborting(AH);
356-
357350
zp->next_in = (void *) buf;
358351
zp->avail_in = cnt;
359352

@@ -414,9 +407,6 @@ ReadDataFromArchiveNone(ArchiveHandle *AH, ReadFunc readF)
414407

415408
while ((cnt = readF(AH, &buf, &buflen)))
416409
{
417-
/* Are we aborting? */
418-
checkAborting(AH);
419-
420410
ahwrite(buf, 1, cnt, AH);
421411
}
422412

0 commit comments

Comments
 (0)