Skip to content

Commit 10ede30

Browse files
author
Marina Polyakova
committed
PGPRO-6828: fix tuplesort15.c due to changes in PostgreSQL 15
See the commits 27b77ecf9f4d5be211900eda54d8155ada50d696 and 94aa7cc5f707712f592885995a28e018c7c80488 in PostgreSQL 15.
1 parent d9cc86f commit 10ede30

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/tuplesort15.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
* produce exactly one output run from their partial input.
8888
*
8989
*
90-
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
90+
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
9191
* Portions Copyright (c) 1994, Regents of the University of California
9292
*
9393
* IDENTIFICATION
@@ -459,6 +459,7 @@ struct Tuplesortstate
459459

460460
/* These are specific to the index_btree subcase: */
461461
bool enforceUnique; /* complain if we find duplicate tuples */
462+
bool uniqueNullsNotDistinct; /* unique constraint null treatment */
462463

463464
/* These are specific to the index_hash subcase: */
464465
uint32 high_mask; /* masks for sortable part of hash code */
@@ -1065,6 +1066,7 @@ Tuplesortstate *
10651066
tuplesort_begin_index_btree(Relation heapRel,
10661067
Relation indexRel,
10671068
bool enforceUnique,
1069+
bool uniqueNullsNotDistinct,
10681070
int workMem,
10691071
SortCoordinate coordinate,
10701072
bool randomAccess)
@@ -1103,6 +1105,7 @@ tuplesort_begin_index_btree(Relation heapRel,
11031105
state->heapRel = heapRel;
11041106
state->indexRel = indexRel;
11051107
state->enforceUnique = enforceUnique;
1108+
state->uniqueNullsNotDistinct = uniqueNullsNotDistinct;
11061109

11071110
indexScanKey = _bt_mkscankey(indexRel, NULL);
11081111

@@ -4200,14 +4203,15 @@ comparetup_index_btree(const SortTuple *a, const SortTuple *b,
42004203

42014204
/*
42024205
* If btree has asked us to enforce uniqueness, complain if two equal
4203-
* tuples are detected (unless there was at least one NULL field).
4206+
* tuples are detected (unless there was at least one NULL field and NULLS
4207+
* NOT DISTINCT was not set).
42044208
*
42054209
* It is sufficient to make the test here, because if two tuples are equal
42064210
* they *must* get compared at some stage of the sort --- otherwise the
42074211
* sort algorithm wouldn't have checked whether one must appear before the
42084212
* other.
42094213
*/
4210-
if (state->enforceUnique && !equal_hasnull)
4214+
if (state->enforceUnique && !(!state->uniqueNullsNotDistinct && equal_hasnull))
42114215
{
42124216
Datum values[INDEX_MAX_KEYS];
42134217
bool isnull[INDEX_MAX_KEYS];

0 commit comments

Comments
 (0)