if (RT_VALUE_IS_EMBEDDABLE(value_p))
{
+ /* free the existing leaf */
+ if (found && !RT_CHILDPTR_IS_VALUE(*slot))
+ RT_FREE_LEAF(tree, *slot);
+
/* store value directly in child pointer slot */
memcpy(slot, value_p, value_sz);
{
RT_CHILD_PTR leaf;
- if (found)
+ if (found && !RT_CHILDPTR_IS_VALUE(*slot))
{
Assert(RT_PTR_ALLOC_IS_VALID(*slot));
leaf.alloc = *slot;
--- Note: The test code use an array of TIDs for verification similar
--- to vacuum's dead item array pre-PG17. To avoid adding duplicates,
--- each call to do_set_block_offsets() should use different block
--- numbers.
CREATE EXTENSION test_tidstore;
-- To hide the output of do_set_block_offsets()
CREATE TEMP TABLE hideblocks(blockno bigint);
(1 row)
+-- Test replacements crossing RT_CHILDPTR_IS_VALUE in both directions
+SELECT test_create(false);
+ test_create
+-------------
+
+(1 row)
+
+SELECT do_set_block_offsets(1, array[1]::int2[]); SELECT check_set_block_offsets();
+ do_set_block_offsets
+----------------------
+ 1
+(1 row)
+
+ check_set_block_offsets
+-------------------------
+
+(1 row)
+
+SELECT do_set_block_offsets(1, array[1,2]::int2[]); SELECT check_set_block_offsets();
+ do_set_block_offsets
+----------------------
+ 1
+(1 row)
+
+ check_set_block_offsets
+-------------------------
+
+(1 row)
+
+SELECT do_set_block_offsets(1, array[1,2,3]::int2[]); SELECT check_set_block_offsets();
+ do_set_block_offsets
+----------------------
+ 1
+(1 row)
+
+ check_set_block_offsets
+-------------------------
+
+(1 row)
+
+SELECT do_set_block_offsets(1, array[1,2,3,4]::int2[]); SELECT check_set_block_offsets();
+ do_set_block_offsets
+----------------------
+ 1
+(1 row)
+
+ check_set_block_offsets
+-------------------------
+
+(1 row)
+
+SELECT do_set_block_offsets(1, array[1,2,3,4,100]::int2[]); SELECT check_set_block_offsets();
+ do_set_block_offsets
+----------------------
+ 1
+(1 row)
+
+ check_set_block_offsets
+-------------------------
+
+(1 row)
+
+SELECT do_set_block_offsets(1, array[1,2,3,4]::int2[]); SELECT check_set_block_offsets();
+ do_set_block_offsets
+----------------------
+ 1
+(1 row)
+
+ check_set_block_offsets
+-------------------------
+
+(1 row)
+
+SELECT do_set_block_offsets(1, array[1,2,3]::int2[]); SELECT check_set_block_offsets();
+ do_set_block_offsets
+----------------------
+ 1
+(1 row)
+
+ check_set_block_offsets
+-------------------------
+
+(1 row)
+
+SELECT do_set_block_offsets(1, array[1,2]::int2[]); SELECT check_set_block_offsets();
+ do_set_block_offsets
+----------------------
+ 1
+(1 row)
+
+ check_set_block_offsets
+-------------------------
+
+(1 row)
+
+SELECT do_set_block_offsets(1, array[1]::int2[]); SELECT check_set_block_offsets();
+ do_set_block_offsets
+----------------------
+ 1
+(1 row)
+
+ check_set_block_offsets
+-------------------------
+
+(1 row)
+
+SELECT test_destroy();
+ test_destroy
+--------------
+
+(1 row)
+
-- Use shared memory this time. We can't do that in test_radixtree.sql,
-- because unused static functions would raise warnings there.
SELECT test_create(true);
--- Note: The test code use an array of TIDs for verification similar
--- to vacuum's dead item array pre-PG17. To avoid adding duplicates,
--- each call to do_set_block_offsets() should use different block
--- numbers.
-
CREATE EXTENSION test_tidstore;
-- To hide the output of do_set_block_offsets()
-- Re-create the TID store for randommized tests.
SELECT test_destroy();
+
+
+-- Test replacements crossing RT_CHILDPTR_IS_VALUE in both directions
+SELECT test_create(false);
+SELECT do_set_block_offsets(1, array[1]::int2[]); SELECT check_set_block_offsets();
+SELECT do_set_block_offsets(1, array[1,2]::int2[]); SELECT check_set_block_offsets();
+SELECT do_set_block_offsets(1, array[1,2,3]::int2[]); SELECT check_set_block_offsets();
+SELECT do_set_block_offsets(1, array[1,2,3,4]::int2[]); SELECT check_set_block_offsets();
+SELECT do_set_block_offsets(1, array[1,2,3,4,100]::int2[]); SELECT check_set_block_offsets();
+SELECT do_set_block_offsets(1, array[1,2,3,4]::int2[]); SELECT check_set_block_offsets();
+SELECT do_set_block_offsets(1, array[1,2,3]::int2[]); SELECT check_set_block_offsets();
+SELECT do_set_block_offsets(1, array[1,2]::int2[]); SELECT check_set_block_offsets();
+SELECT do_set_block_offsets(1, array[1]::int2[]); SELECT check_set_block_offsets();
+SELECT test_destroy();
+
+
-- Use shared memory this time. We can't do that in test_radixtree.sql,
-- because unused static functions would raise warnings there.
SELECT test_create(true);
errmsg("argument must be empty or one-dimensional array")));
}
+static void
+purge_from_verification_array(BlockNumber blkno)
+{
+ int dst = 0;
+
+ for (int src = 0; src < items.num_tids; src++)
+ if (ItemPointerGetBlockNumber(&items.insert_tids[src]) != blkno)
+ items.insert_tids[dst++] = items.insert_tids[src];
+ items.num_tids = dst;
+}
+
+
/* Set the given block and offsets pairs */
Datum
do_set_block_offsets(PG_FUNCTION_ARGS)
TidStoreSetBlockOffsets(tidstore, blkno, offs, noffs);
TidStoreUnlock(tidstore);
+ /* Remove the existing items of blkno from the verification array */
+ purge_from_verification_array(blkno);
+
/* Set TIDs in verification array */
for (int i = 0; i < noffs; i++)
{