@@ -39,7 +39,8 @@ typedef struct
39
39
*/
40
40
static BlockNumber
41
41
createPostingTree (RumState * rumstate , OffsetNumber attnum , Relation index ,
42
- ItemPointerData * items , Datum * addInfo , bool * addInfoIsNull , uint32 nitems )
42
+ ItemPointerData * items ,
43
+ Datum * addInfo , bool * addInfoIsNull , uint32 nitems )
43
44
{
44
45
BlockNumber blkno ;
45
46
Buffer buffer = RumNewBuffer (index );
@@ -64,7 +65,7 @@ createPostingTree(RumState *rumstate, OffsetNumber attnum, Relation index,
64
65
if (i > 0 )
65
66
prev_iptr = items [i - 1 ];
66
67
ptr = rumPlaceToDataPageLeaf (ptr , attnum , & items [i ], addInfo [i ],
67
- addInfoIsNull [i ], & prev_iptr , rumstate );
68
+ addInfoIsNull [i ], & prev_iptr , rumstate );
68
69
}
69
70
freespace = RumDataPageFreeSpacePre (page , ptr );
70
71
Assert (freespace >= 0 );
@@ -150,14 +151,18 @@ RumFormTuple(RumState *rumstate,
150
151
if (nipd > 0 )
151
152
{
152
153
newsize = rumCheckPlaceToDataPageLeaf (attnum , & ipd [0 ], addInfo [0 ],
153
- addInfoIsNull [0 ], & nullItemPointer , rumstate , newsize );
154
+ addInfoIsNull [0 ],
155
+ & nullItemPointer ,
156
+ rumstate , newsize );
154
157
for (i = 1 ; i < nipd ; i ++ )
155
158
{
156
159
newsize = rumCheckPlaceToDataPageLeaf (attnum , & ipd [i ], addInfo [i ],
157
- addInfoIsNull [i ], & ipd [i - 1 ], rumstate , newsize );
160
+ addInfoIsNull [i ], & ipd [i - 1 ],
161
+ rumstate , newsize );
158
162
}
159
163
}
160
164
165
+
161
166
if (category != RUM_CAT_NORM_KEY )
162
167
{
163
168
Assert (IndexTupleHasNulls (itup ));
@@ -198,12 +203,18 @@ RumFormTuple(RumState *rumstate,
198
203
{
199
204
char * ptr = RumGetPosting (itup );
200
205
ptr = rumPlaceToDataPageLeaf (ptr , attnum , & ipd [0 ], addInfo [0 ],
201
- addInfoIsNull [0 ], & nullItemPointer , rumstate );
206
+ addInfoIsNull [0 ], & nullItemPointer ,
207
+ rumstate );
202
208
for (i = 1 ; i < nipd ; i ++ )
203
209
{
204
210
ptr = rumPlaceToDataPageLeaf (ptr , attnum , & ipd [i ], addInfo [i ],
205
- addInfoIsNull [i ], & ipd [i - 1 ], rumstate );
211
+ addInfoIsNull [i ], & ipd [i - 1 ],
212
+ rumstate );
206
213
}
214
+
215
+ Assert (MAXALIGN ((ptr - ((char * )itup )) +
216
+ ((category == RUM_CAT_NORM_KEY ) ? 0 : sizeof (RumNullCategory )))
217
+ == newsize );
207
218
}
208
219
209
220
/*
@@ -214,6 +225,7 @@ RumFormTuple(RumState *rumstate,
214
225
Assert (IndexTupleHasNulls (itup ));
215
226
RumSetNullCategory (itup , rumstate , category );
216
227
}
228
+
217
229
return itup ;
218
230
}
219
231
@@ -341,20 +353,24 @@ buildFreshLeafTuple(RumState *rumstate,
341
353
do
342
354
{
343
355
size = rumCheckPlaceToDataPageLeaf (attnum , & items [itemsCount ],
344
- addInfo [itemsCount ], addInfoIsNull [itemsCount ], & prevIptr ,
345
- rumstate , size );
356
+ addInfo [itemsCount ],
357
+ addInfoIsNull [itemsCount ],
358
+ & prevIptr , rumstate , size );
346
359
prevIptr = items [itemsCount ];
347
360
itemsCount ++ ;
348
361
}
349
362
while (itemsCount < nitem && size < RumDataPageSize );
350
- itemsCount -- ;
363
+
364
+ if (size >= RumDataPageSize )
365
+ itemsCount -- ;
351
366
352
367
353
368
/*
354
369
* Build posting-tree-only result tuple. We do this first so as to
355
370
* fail quickly if the key is too big.
356
371
*/
357
- res = RumFormTuple (rumstate , attnum , key , category , NULL , NULL , NULL , 0 , true);
372
+ res = RumFormTuple (rumstate , attnum , key , category ,
373
+ NULL , NULL , NULL , 0 , true);
358
374
359
375
/*
360
376
* Initialize posting tree with as many TIDs as will fit on the first
@@ -377,7 +393,8 @@ buildFreshLeafTuple(RumState *rumstate,
377
393
{
378
394
RumPostingTreeScan * gdi ;
379
395
380
- gdi = rumPrepareScanPostingTree (rumstate -> index , postingRoot , FALSE, attnum , rumstate );
396
+ gdi = rumPrepareScanPostingTree (rumstate -> index , postingRoot , FALSE,
397
+ attnum , rumstate );
381
398
gdi -> btree .isBuild = (buildStats != NULL );
382
399
383
400
rumInsertItemPointers (rumstate ,
@@ -457,25 +474,29 @@ rumEntryInsert(RumState *rumstate,
457
474
freeRumBtreeStack (stack );
458
475
459
476
/* insert into posting tree */
460
- gdi = rumPrepareScanPostingTree (rumstate -> index , rootPostingTree , FALSE, attnum , rumstate );
477
+ gdi = rumPrepareScanPostingTree (rumstate -> index , rootPostingTree ,
478
+ FALSE, attnum , rumstate );
461
479
gdi -> btree .isBuild = (buildStats != NULL );
462
- rumInsertItemPointers (rumstate , attnum , gdi , items , addInfo , addInfoIsNull , nitem , buildStats );
480
+ rumInsertItemPointers (rumstate , attnum , gdi , items , addInfo ,
481
+ addInfoIsNull , nitem , buildStats );
463
482
pfree (gdi );
464
483
465
484
return ;
466
485
}
467
486
468
487
/* modify an existing leaf entry */
469
488
itup = addItemPointersToLeafTuple (rumstate , itup ,
470
- items , addInfo , addInfoIsNull , nitem , buildStats );
489
+ items , addInfo , addInfoIsNull , nitem ,
490
+ buildStats );
471
491
472
492
btree .isDelete = TRUE;
473
493
}
474
494
else
475
495
{
476
496
/* no match, so construct a new leaf entry */
477
497
itup = buildFreshLeafTuple (rumstate , attnum , key , category ,
478
- items , addInfo , addInfoIsNull , nitem , buildStats );
498
+ items , addInfo , addInfoIsNull , nitem ,
499
+ buildStats );
479
500
}
480
501
481
502
/* Insert the new or modified leaf tuple */
0 commit comments