diff --git a/src/test/modules/test_sort_perf/make-itemptr-tests.sh b/src/test/modules/test_sort_perf/make-itemptr-tests.sh index 9151ea703f..fd0048eba3 100755 --- a/src/test/modules/test_sort_perf/make-itemptr-tests.sh +++ b/src/test/modules/test_sort_perf/make-itemptr-tests.sh @@ -1,7 +1,7 @@ #!/bin/sh # different values to test for insertion sorts -THRESHOLDS="7 8 9 10 11 12 13" +THRESHOLDS="7 12 16 32" # amount of data to sort, in megabytes MEMORY=128 @@ -18,10 +18,9 @@ for threshold in $THRESHOLDS ; do echo "#define ST_DEFINE" echo "#include \"lib/sort_template.h\"" echo - echo "#define ST_SORT sort64_${threshold}_itemptr" + echo "#define ST_SORT sort_ids_${threshold}_itemptr" echo "#define ST_ELEMENT_TYPE ItemPointerData" - echo "#define ST_COMPARE(a, b) (itemptr_encode(a) - itemptr_encode(b))" - echo "#define ST_COMPARE_RET_TYPE int64" + echo "#define ST_COMPARE(a, b) itemptr_comparator_blockids(a, b)" echo "#define ST_SCOPE static" echo "#define ST_SORT_SMALL_THRESHOLD $threshold" echo "#define ST_CHECK_FOR_INTERRUPTS" @@ -76,7 +75,7 @@ for order in random increasing decreasing ; do echo " sort_${threshold}_itemptr(sorted, nobjects);" echo " INSTR_TIME_SET_CURRENT(end_time);" echo " INSTR_TIME_SUBTRACT(end_time, start_time);" - echo " elog(NOTICE, \"order=$order, threshold=$threshold, cmp=32, test=%d, time=%f\", i, INSTR_TIME_GET_DOUBLE(end_time));" + echo " elog(NOTICE, \"order=$order, threshold=$threshold, cmp=std, test=%d, time=%f\", i, INSTR_TIME_GET_DOUBLE(end_time));" echo " }" echo " for (int i = 0; i < 3; ++i)" echo " {" @@ -84,10 +83,10 @@ for order in random increasing decreasing ; do echo " memcpy(sorted, unsorted, sizeof(sorted[0]) * nobjects);" echo " INSTR_TIME_SET_CURRENT(start_time);" echo " memcpy(sorted, unsorted, sizeof(sorted[0]) * nobjects);" - echo " sort64_${threshold}_itemptr(sorted, nobjects);" + echo " sort_ids_${threshold}_itemptr(sorted, nobjects);" echo " INSTR_TIME_SET_CURRENT(end_time);" echo " INSTR_TIME_SUBTRACT(end_time, start_time);" - echo " elog(NOTICE, \"order=$order, threshold=$threshold, cmp=64, test=%d, time=%f\", i, INSTR_TIME_GET_DOUBLE(end_time));" + echo " elog(NOTICE, \"order=$order, threshold=$threshold, cmp=ids, test=%d, time=%f\", i, INSTR_TIME_GET_DOUBLE(end_time));" echo " }" done done diff --git a/src/test/modules/test_sort_perf/test_sort_perf.c b/src/test/modules/test_sort_perf/test_sort_perf.c index 05a10924f3..1ebaf41329 100644 --- a/src/test/modules/test_sort_perf/test_sort_perf.c +++ b/src/test/modules/test_sort_perf/test_sort_perf.c @@ -8,6 +8,44 @@ #include +/* + * ItemPointerGetBlockIdHiNoCheck + * Returns the high short of a disk item pointer blockid. + */ +#define ItemPointerGetBlockIdHiNoCheck(pointer) \ +( \ + (pointer)->ip_blkid.bi_hi \ +) + +/* + * ItemPointerGetBlockIdHi + * As above, but verifies that the item pointer looks valid. + */ +#define ItemPointerGetBlockIdHi(pointer) \ +( \ + AssertMacro(ItemPointerIsValid(pointer)), \ + ItemPointerGetBlockIdHiNoCheck(pointer) \ +) + +/* + * ItemPointerGetBlockIdLoNoCheck + * Returns the low short of a disk item pointer blockid. + */ +#define ItemPointerGetBlockIdLoNoCheck(pointer) \ +( \ + (pointer)->ip_blkid.bi_lo \ +) + +/* + * ItemPointerGetBlockIdLo + * As above, but verifies that the item pointer looks valid. + */ +#define ItemPointerGetBlockIdLo(pointer) \ +( \ + AssertMacro(ItemPointerIsValid(pointer)), \ + ItemPointerGetBlockIdHiNoCheck(pointer) \ +) + static int itemptr_comparator(const void *a, const void *b) { @@ -29,6 +67,38 @@ itemptr_comparator(const void *a, const void *b) return 0; } +static int +itemptr_comparator_blockids(const void *a, const void *b) +{ + const ItemPointerData *ipa = (const ItemPointerData *) a; + const ItemPointerData *ipb = (const ItemPointerData *) b; + + uint16 ba_hi = ItemPointerGetBlockIdHi(ipa); + uint16 bb_hi = ItemPointerGetBlockIdHi(ipb); + + if (ba_hi < bb_hi) + return -1; + if (ba_hi > bb_hi) + return 1; + + uint16 ba_lo = ItemPointerGetBlockIdLo(ipa); + uint16 bb_lo = ItemPointerGetBlockIdLo(ipb); + + if (ba_lo < bb_lo) + return -1; + if (ba_lo > bb_lo) + return 1; + + OffsetNumber oa = ItemPointerGetOffsetNumber(ipa); + OffsetNumber ob = ItemPointerGetOffsetNumber(ipb); + + if (oa < ob) + return -1; + if (oa > ob) + return 1; + return 0; +} + PG_MODULE_MAGIC; /* include the generated code */