]> granicus.if.org Git - postgresql/commitdiff
Fix a bunch more portability bugs in commit 08bf6e529.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 3 Feb 2017 04:11:08 +0000 (23:11 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 3 Feb 2017 04:11:08 +0000 (23:11 -0500)
It seems like somebody used a dartboard while choosing integer widths
for the various values taken and returned by these functions ... and
then threw a fresh set of darts while writing the SQL declarations.

This patch brings the C code into line with what the SQL declarations
say, which is enough to make it not dump core on the particular 32-bit
machine I'm testing on.  But I think we could do with another round
of looking at what the datum widths *should* be.  For instance, it's
not all that sensible that hash_bitmap_info decided to use int64 to
represent a BlockNumber input when get_raw_page doesn't do it that way.

There's also a remaining problem that the expected outputs from the
test script are platform-dependent, but I'll leave that issue for
somebody else.

Per buildfarm.

contrib/pageinspect/hashfuncs.c

index fd0ef08d553b4ae6968095067b0378e87196e31d..83b469864a9c11cec7345ddd63298548414c4ee5 100644 (file)
@@ -360,7 +360,7 @@ hash_page_items(PG_FUNCTION_ARGS)
                values[j++] = PointerGetDatum(&itup->t_tid);
 
                hashkey = _hash_get_indextuple_hashkey(itup);
-               values[j] = UInt32GetDatum(hashkey);
+               values[j] = UInt64GetDatum((uint64) hashkey);
 
                tuple = heap_form_tuple(fctx->attinmeta->tupdesc, values, nulls);
                result = HeapTupleGetDatum(tuple);
@@ -388,7 +388,7 @@ Datum
 hash_bitmap_info(PG_FUNCTION_ARGS)
 {
        Oid                     indexRelid = PG_GETARG_OID(0);
-       BlockNumber ovflblkno = (BlockNumber) PG_GETARG_INT64(1);
+       uint64          ovflblkno = PG_GETARG_INT64(1);
        HashMetaPage metap;
        Buffer          buf,
                                metabuf;
@@ -422,13 +422,14 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                                 errmsg("cannot access temporary tables of other sessions")));
 
-       if (RelationGetNumberOfBlocks(indexRel) <= (BlockNumber) (ovflblkno))
+       if (ovflblkno >= RelationGetNumberOfBlocks(indexRel))
                ereport(ERROR,
                                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                                errmsg("block number %u is out of range for relation \"%s\"",
+                                errmsg("block number " UINT64_FORMAT " is out of range for relation \"%s\"",
                                                ovflblkno, RelationGetRelationName(indexRel))));
 
-       buf = ReadBufferExtended(indexRel, MAIN_FORKNUM, ovflblkno, RBM_NORMAL, NULL);
+       buf = ReadBufferExtended(indexRel, MAIN_FORKNUM, (BlockNumber) ovflblkno,
+                                                        RBM_NORMAL, NULL);
        LockBuffer(buf, BUFFER_LOCK_SHARE);
        _hash_checkpage(indexRel, buf, LH_PAGE_TYPE);
        page = BufferGetPage(buf);
@@ -451,7 +452,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
        metap = HashPageGetMeta(BufferGetPage(metabuf));
 
        /* Identify overflow bit number */
-       ovflbitno = _hash_ovflblkno_to_bitno(metap, ovflblkno);
+       ovflbitno = _hash_ovflblkno_to_bitno(metap, (BlockNumber) ovflblkno);
 
        bitmappage = ovflbitno >> BMPG_SHIFT(metap);
        bitmapbit = ovflbitno & BMPG_MASK(metap);
@@ -475,7 +476,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS)
        MemSet(nulls, 0, sizeof(nulls));
 
        j = 0;
-       values[j++] = UInt32GetDatum(bitmapblkno);
+       values[j++] = UInt64GetDatum((uint64) bitmapblkno);
        values[j++] = Int32GetDatum(bitmapbit);
        values[j++] = BoolGetDatum(bit);
 
@@ -524,34 +525,34 @@ hash_metapage_info(PG_FUNCTION_ARGS)
        MemSet(nulls, 0, sizeof(nulls));
 
        j = 0;
-       values[j++] = UInt32GetDatum(metad->hashm_magic);
-       values[j++] = UInt32GetDatum(metad->hashm_version);
+       values[j++] = UInt64GetDatum(metad->hashm_magic);
+       values[j++] = UInt64GetDatum(metad->hashm_version);
        values[j++] = Float8GetDatum(metad->hashm_ntuples);
-       values[j++] = UInt16GetDatum(metad->hashm_ffactor);
-       values[j++] = UInt16GetDatum(metad->hashm_bsize);
-       values[j++] = UInt16GetDatum(metad->hashm_bmsize);
-       values[j++] = UInt16GetDatum(metad->hashm_bmshift);
-       values[j++] = UInt32GetDatum(metad->hashm_maxbucket);
-       values[j++] = UInt32GetDatum(metad->hashm_highmask);
-       values[j++] = UInt32GetDatum(metad->hashm_lowmask);
-       values[j++] = UInt32GetDatum(metad->hashm_ovflpoint);
-       values[j++] = UInt32GetDatum(metad->hashm_firstfree);
-       values[j++] = UInt32GetDatum(metad->hashm_nmaps);
-       values[j++] = UInt16GetDatum(metad->hashm_procid);
+       values[j++] = UInt32GetDatum(metad->hashm_ffactor);
+       values[j++] = UInt32GetDatum(metad->hashm_bsize);
+       values[j++] = UInt32GetDatum(metad->hashm_bmsize);
+       values[j++] = UInt32GetDatum(metad->hashm_bmshift);
+       values[j++] = UInt64GetDatum(metad->hashm_maxbucket);
+       values[j++] = UInt64GetDatum(metad->hashm_highmask);
+       values[j++] = UInt64GetDatum(metad->hashm_lowmask);
+       values[j++] = UInt64GetDatum(metad->hashm_ovflpoint);
+       values[j++] = UInt64GetDatum(metad->hashm_firstfree);
+       values[j++] = UInt64GetDatum(metad->hashm_nmaps);
+       values[j++] = UInt32GetDatum(metad->hashm_procid);
 
        for (i = 0; i < HASH_MAX_SPLITPOINTS; i++)
-               spares[i] = UInt32GetDatum(metad->hashm_spares[i]);
+               spares[i] = UInt64GetDatum(metad->hashm_spares[i]);
        values[j++] = PointerGetDatum(construct_array(spares,
                                                                                                  HASH_MAX_SPLITPOINTS,
                                                                                                  INT8OID,
-                                                                                                 8, true, 'd'));
+                                                                                                 8, FLOAT8PASSBYVAL, 'd'));
 
        for (i = 0; i < HASH_MAX_BITMAPS; i++)
-               mapp[i] = UInt32GetDatum(metad->hashm_mapp[i]);
+               mapp[i] = UInt64GetDatum(metad->hashm_mapp[i]);
        values[j++] = PointerGetDatum(construct_array(mapp,
                                                                                                  HASH_MAX_BITMAPS,
                                                                                                  INT8OID,
-                                                                                                 8, true, 'd'));
+                                                                                                 8, FLOAT8PASSBYVAL, 'd'));
 
        tuple = heap_form_tuple(tupleDesc, values, nulls);