Skip to content

Commit 57416b4

Browse files
committed
Merge branch 'PGPRO9_6_covering_update' into PGPRO9_6
2 parents 6c8bb1f + 535db01 commit 57416b4

File tree

5 files changed

+56
-47
lines changed

5 files changed

+56
-47
lines changed

src/backend/access/common/indextuple.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ CopyIndexTuple(IndexTuple source)
449449
IndexTuple
450450
index_truncate_tuple(Relation idxrel, IndexTuple olditup)
451451
{
452-
TupleDesc itupdesc = RelationGetDescr(idxrel);
452+
TupleDesc itupdesc = CreateTupleDescCopyConstr(RelationGetDescr(idxrel));
453453
Datum values[INDEX_MAX_KEYS];
454454
bool isnull[INDEX_MAX_KEYS];
455455
IndexTuple newitup;
@@ -467,8 +467,7 @@ index_truncate_tuple(Relation idxrel, IndexTuple olditup)
467467
newitup = index_form_tuple(itupdesc, values, isnull);
468468
newitup->t_tid = olditup->t_tid;
469469

470-
itupdesc->natts = indnatts;
471-
470+
FreeTupleDesc(itupdesc);
472471
Assert(IndexTupleSize(newitup) <= IndexTupleSize(olditup));
473472
return newitup;
474473
}

src/backend/access/nbtree/nbtinsert.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,20 +1330,16 @@ _bt_split(Relation rel, Buffer buf, Buffer cbuf, OffsetNumber firstright,
13301330
if (newitemonleft)
13311331
XLogRegisterBufData(0, (char *) newitem, MAXALIGN(newitemsz));
13321332

1333-
/* Log left page */
1334-
if (!isleaf)
1335-
{
1336-
/*
1337-
* We must also log the left page's high key, because the right
1338-
* page's leftmost key is suppressed on non-leaf levels. Show it
1339-
* as belonging to the left page buffer, so that it is not stored
1340-
* if XLogInsert decides it needs a full-page image of the left
1341-
* page.
1342-
*/
1343-
itemid = PageGetItemId(origpage, P_HIKEY);
1344-
item = (IndexTuple) PageGetItem(origpage, itemid);
1345-
XLogRegisterBufData(0, (char *) item, MAXALIGN(IndexTupleSize(item)));
1346-
}
1333+
/*
1334+
* We must also log the left page's high key, because the right
1335+
* page's leftmost key is suppressed on non-leaf levels. Show it
1336+
* as belonging to the left page buffer, so that it is not stored
1337+
* if XLogInsert decides it needs a full-page image of the left
1338+
* page.
1339+
*/
1340+
itemid = PageGetItemId(origpage, P_HIKEY);
1341+
item = (IndexTuple) PageGetItem(origpage, itemid);
1342+
XLogRegisterBufData(0, (char *) item, MAXALIGN(IndexTupleSize(item)));
13471343

13481344
/*
13491345
* Log the contents of the right page in the format understood by

src/backend/access/nbtree/nbtsort.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,14 +550,13 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
550550
if (indnkeyatts != indnatts && P_ISLEAF(opageop))
551551
{
552552
/*
553-
* It's essential to truncate High key here.
554-
* The purpose is not just to save more space on this particular page,
555-
* but to keep whole b-tree structure consistent. Subsequent insertions
556-
* assume that hikey is already truncated, and so they should not
557-
* worry about it, when copying the high key into the parent page
558-
* as a downlink.
559-
* NOTE It is not crutial for reliability in present,
560-
* but maybe it will be that in the future.
553+
* We truncate included attributes of High key here.
554+
* Subsequent insertions assume that hikey is already truncated,
555+
* and so they need not worry about it, when copying the high key
556+
* into the parent page as a downlink.
557+
* NOTE: It is not crucial for reliability in present, but maybe
558+
* it will be that in the future. Now the purpose is just to save
559+
* more space on inner pages of btree.
561560
*/
562561
keytup = index_truncate_tuple(wstate->index, oitup);
563562

src/backend/access/nbtree/nbtxlog.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,11 @@ btree_xlog_split(bool onleft, bool isroot, XLogReaderState *record)
307307
}
308308

309309
/* Extract left hikey and its size (assuming 16-bit alignment) */
310-
if (!isleaf)
311-
{
312-
left_hikey = (Item) datapos;
313-
left_hikeysz = MAXALIGN(IndexTupleSize(left_hikey));
314-
datapos += left_hikeysz;
315-
datalen -= left_hikeysz;
316-
}
310+
left_hikey = (Item) datapos;
311+
left_hikeysz = MAXALIGN(IndexTupleSize(left_hikey));
312+
datapos += left_hikeysz;
313+
datalen -= left_hikeysz;
314+
317315
Assert(datalen == 0);
318316

319317
newlpage = PageGetTempPageCopySpecial(lpage);

src/backend/catalog/index.c

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -424,31 +424,48 @@ ConstructTupleDescriptor(Relation heapRelation,
424424
namestrcpy(&to->attname, (const char *) lfirst(colnames_item));
425425
colnames_item = lnext(colnames_item);
426426

427+
/*
428+
* Check the opclass and index AM to see if either provides a keytype
429+
* (overriding the attribute type). Opclass (if exists) takes precedence.
430+
*/
431+
keyType = amroutine->amkeytype;
432+
427433
/*
428434
* Code below is concerned to the opclasses which are not used
429435
* with the included columns.
430436
*/
431-
if (i >= indexInfo->ii_NumIndexKeyAttrs)
432-
continue;
437+
if (i < indexInfo->ii_NumIndexKeyAttrs)
438+
{
439+
tuple = SearchSysCache1(CLAOID, ObjectIdGetDatum(classObjectId[i]));
440+
if (!HeapTupleIsValid(tuple))
441+
elog(ERROR, "cache lookup failed for opclass %u",
442+
classObjectId[i]);
443+
opclassTup = (Form_pg_opclass) GETSTRUCT(tuple);
444+
if (OidIsValid(opclassTup->opckeytype))
445+
keyType = opclassTup->opckeytype;
446+
447+
ReleaseSysCache(tuple);
448+
}
433449

434450
/*
435-
* Check the opclass and index AM to see if either provides a keytype
436-
* (overriding the attribute type). Opclass takes precedence.
451+
* If keytype is specified as ANYELEMENT, and opcintype is ANYARRAY,
452+
* then the attribute type must be an array (else it'd not have
453+
* matched this opclass); use its element type.
437454
*/
438-
tuple = SearchSysCache1(CLAOID, ObjectIdGetDatum(classObjectId[i]));
439-
if (!HeapTupleIsValid(tuple))
440-
elog(ERROR, "cache lookup failed for opclass %u",
441-
classObjectId[i]);
442-
opclassTup = (Form_pg_opclass) GETSTRUCT(tuple);
443-
if (OidIsValid(opclassTup->opckeytype))
444-
keyType = opclassTup->opckeytype;
445-
else
446-
keyType = amroutine->amkeytype;
447-
ReleaseSysCache(tuple);
455+
if (keyType == ANYELEMENTOID && opclassTup->opcintype == ANYARRAYOID)
456+
{
457+
keyType = get_base_element_type(to->atttypid);
458+
if (!OidIsValid(keyType))
459+
elog(ERROR, "could not get element type of array type %u",
460+
to->atttypid);
461+
}
448462

463+
/*
464+
* If a key type different from the heap value is specified, update
465+
* the type-related fields in the index tupdesc.
466+
*/
449467
if (OidIsValid(keyType) && keyType != to->atttypid)
450468
{
451-
/* index value and heap value have different types */
452469
tuple = SearchSysCache1(TYPEOID, ObjectIdGetDatum(keyType));
453470
if (!HeapTupleIsValid(tuple))
454471
elog(ERROR, "cache lookup failed for type %u", keyType);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy