pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: pageinspect: Try to fix some bugs in previous commit.
22+ messages / 5 participants
[nested] [flat]

* pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 03:32  Robert Haas <rhaas@postgresql.org>
  0 siblings, 1 reply; 22+ messages in thread

From: Robert Haas @ 2017-02-03 03:32 UTC (permalink / raw)
  To: pgsql-committers

pageinspect: Try to fix some bugs in previous commit.

Commit 08bf6e529587e1e9075d013d859af2649c32a511 seems not to have
used the correct *GetDatum and PG_GETARG_* macros for the SQL types
in some cases, and some of the SQL types seem to have been poorly
chosen, too.  Try to fix it.  I'm not sure if this is the reason
why the buildfarm is currently unhappy with this code, but it
seems like a good place to start.

Buildfarm unhappiness reported by Tom Lane.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/ed807fda6d5102537daa5d725e716555cbc49f44

Modified Files
--------------
contrib/pageinspect/hashfuncs.c               | 28 +++++++++++++--------------
contrib/pageinspect/pageinspect--1.5--1.6.sql | 10 +++++-----
2 files changed, 19 insertions(+), 19 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 03:40  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Robert Haas <rhaas@postgresql.org>
  0 siblings, 1 reply; 22+ messages in thread

From: Tom Lane @ 2017-02-03 03:40 UTC (permalink / raw)
  To: Robert Haas <rhaas@postgresql.org>; +Cc: pgsql-committers

Robert Haas <rhaas@postgresql.org> writes:
> pageinspect: Try to fix some bugs in previous commit.

This is a first step, but there's more :-(.  Poking at it now on
dromedary.

			regards, tom lane


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 03:49  Robert Haas <robertmhaas@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 22+ messages in thread

From: Robert Haas @ 2017-02-03 03:49 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers

On Thu, Feb 2, 2017 at 10:40 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Robert Haas <rhaas@postgresql.org> writes:
>> pageinspect: Try to fix some bugs in previous commit.
>
> This is a first step, but there's more :-(.  Poking at it now on
> dromedary.

Ugh, yes.  Sorry, I should have checked this more carefully before
commit.  I mentioned the problem in a previous review and failed to
notice that it hadn't been fixed.  Are you taking care of it at this
point or should I keep at it?

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 04:00  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 22+ messages in thread

From: Tom Lane @ 2017-02-03 04:00 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: pgsql-committers

Robert Haas <robertmhaas@gmail.com> writes:
> Ugh, yes.  Sorry, I should have checked this more carefully before
> commit.  I mentioned the problem in a previous review and failed to
> notice that it hadn't been fixed.  Are you taking care of it at this
> point or should I keep at it?

I'm about to push a fix that removes the crashes (or at least the ones
I see on dromedary), but there is still a problem, which is that the
expected output seems inherently platform-dependent:

inline patch 1: /Users/tgl/pgsql/contrib/pageinspect/results/hash.out Thu Feb 2 22:55:43 2017 (+2/-2 lines) download inline-1.patch*** /Users/tgl/pgsql/contrib/pageinspect/expected/hash.out Thu Feb 2 21:30:54 2017 --- /Users/tgl/pgsql/contrib/pageinspect/results/hash.out Thu Feb 2 22:55:43 2017 *************** *** 52,58 **** magic | 105121344 version | 2 ntuples | 1 ! ffactor | 307 bsize | 8152 bmsize | 4096 bmshift | 15 --- 52,58 ---- magic | 105121344 version | 2 ntuples | 1 ! ffactor | 384 bsize | 8152 bmsize | 4096 bmshift | 15 *************** *** 107,113 **** live_items | 1 dead_items | 0 page_size | 8192 ! free_size | 8128 hasho_prevblkno | 4294967295 hasho_nextblkno | 4294967295 hasho_bucket | 2 --- 107,113 ---- live_items | 1 dead_items | 0 page_size | 8192 ! free_size | 8132 hasho_prevblkno | 4294967295 hasho_nextblkno | 4294967295 hasho_bucket | 2
====================================================================== I think probably both of those are unavoidable 32-bit v 64-bit differences due to available space on a page changing with MAXALIGN. What do you want to do about those? regards, tom lane -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 22+ messages in thread

* Re: pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 04:03  Robert Haas <robertmhaas@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 22+ messages in thread

From: Robert Haas @ 2017-02-03 04:03 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers

On Thu, Feb 2, 2017 at 11:00 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Robert Haas <robertmhaas@gmail.com> writes:
>> Ugh, yes.  Sorry, I should have checked this more carefully before
>> commit.  I mentioned the problem in a previous review and failed to
>> notice that it hadn't been fixed.  Are you taking care of it at this
>> point or should I keep at it?
>
> I'm about to push a fix that removes the crashes (or at least the ones
> I see on dromedary),

For comparison, a patch I wrote by inspection is attached.

> but there is still a problem, which is that the
> expected output seems inherently platform-dependent:
>
> I think probably both of those are unavoidable 32-bit v 64-bit
> differences due to available space on a page changing with MAXALIGN.
> What do you want to do about those?

How about we have the test just select a named list of fields instead
of selecting *?

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

Attachments:

fixes.patch (application/octet-stream, 3.6K) download diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c index fd0ef08..8538fa3 100644 --- a/contrib/pageinspect/hashfuncs.c +++ b/contrib/pageinspect/hashfuncs.c @@ -356,11 +356,11 @@ hash_page_items(PG_FUNCTION_ARGS) MemSet(nulls, 0, sizeof(nulls)); j = 0; - values[j++] = UInt16GetDatum(uargs->offset); + values[j++] = Int32GetDatum((int32) uargs->offset); values[j++] = PointerGetDatum(&itup->t_tid); hashkey = _hash_get_indextuple_hashkey(itup); - values[j] = UInt32GetDatum(hashkey); + values[j] = Int64GetDatum((int64) hashkey); tuple = heap_form_tuple(fctx->attinmeta->tupdesc, values, nulls); result = HeapTupleGetDatum(tuple); @@ -475,7 +475,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS) MemSet(nulls, 0, sizeof(nulls)); j = 0; - values[j++] = UInt32GetDatum(bitmapblkno); + values[j++] = Int64GetDatum((int64) bitmapblkno); values[j++] = Int32GetDatum(bitmapbit); values[j++] = BoolGetDatum(bit); @@ -524,30 +524,30 @@ 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++] = Int64GetDatum((int64) metad->hashm_magic); + values[j++] = Int64GetDatum((int64) 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++] = Int32GetDatum((int32) metad->hashm_ffactor); + values[j++] = Int32GetDatum((int32) metad->hashm_bsize); + values[j++] = Int32GetDatum((int32) metad->hashm_bmsize); + values[j++] = Int32GetDatum((int32) metad->hashm_bmshift); + values[j++] = Int64GetDatum((int64) metad->hashm_maxbucket); + values[j++] = Int64GetDatum((int64) metad->hashm_highmask); + values[j++] = Int64GetDatum((int64) metad->hashm_lowmask); + values[j++] = Int64GetDatum((int64) metad->hashm_ovflpoint); + values[j++] = Int64GetDatum((int64) metad->hashm_firstfree); + values[j++] = Int64GetDatum((int64) metad->hashm_nmaps); + values[j++] = ObjectIdGetDatum((Oid) metad->hashm_procid); for (i = 0; i < HASH_MAX_SPLITPOINTS; i++) - spares[i] = UInt32GetDatum(metad->hashm_spares[i]); + spares[i] = Int64GetDatum((int8) metad->hashm_spares[i]); values[j++] = PointerGetDatum(construct_array(spares, HASH_MAX_SPLITPOINTS, INT8OID, 8, true, 'd')); for (i = 0; i < HASH_MAX_BITMAPS; i++) - mapp[i] = UInt32GetDatum(metad->hashm_mapp[i]); + mapp[i] = Int64GetDatum((int64) metad->hashm_mapp[i]); values[j++] = PointerGetDatum(construct_array(mapp, HASH_MAX_BITMAPS, INT8OID, diff --git a/contrib/pageinspect/pageinspect--1.5--1.6.sql b/contrib/pageinspect/pageinspect--1.5--1.6.sql index a22438d..8199682 100644 --- a/contrib/pageinspect/pageinspect--1.5--1.6.sql +++ b/contrib/pageinspect/pageinspect--1.5--1.6.sql @@ -35,7 +35,7 @@ LANGUAGE C STRICT PARALLEL SAFE; -- hash_page_items() -- CREATE FUNCTION hash_page_items(IN page bytea, - OUT itemoffset smallint, + OUT itemoffset int4, OUT ctid tid, OUT data int8) RETURNS SETOF record
^ permalink raw reply [nested|flat] 22+ messages in thread

* Re: pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 04:16  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 2 replies; 22+ messages in thread

From: Tom Lane @ 2017-02-03 04:16 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: pgsql-committers

Robert Haas <robertmhaas@gmail.com> writes:
> On Thu, Feb 2, 2017 at 11:00 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I'm about to push a fix that removes the crashes (or at least the ones
>> I see on dromedary),

> For comparison, a patch I wrote by inspection is attached.

Hm, some of what you have here matches what I just pushed, but not all.

I just made the C code agree with what the SQL declarations for the
functions say.  I'm pretty dubious that the SQL declarations are entirely
sensible as to which values need to be of what width, but I'll leave that
decision for somebody who's been paying closer attention to the hash code.

>> I think probably both of those are unavoidable 32-bit v 64-bit
>> differences due to available space on a page changing with MAXALIGN.
>> What do you want to do about those?

> How about we have the test just select a named list of fields instead
> of selecting *?

Yeah, that's one possible answer.  We could also maintain two
expected-files for 32 bit v 64 bit, but I'm not sure it's worth
the trouble.

			regards, tom lane


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 11:06  Amit Kapila <amit.kapila16@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 2 replies; 22+ messages in thread

From: Amit Kapila @ 2017-02-03 11:06 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Robert Haas <robertmhaas@gmail.com>; pgsql-committers

On Fri, Feb 3, 2017 at 9:46 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Robert Haas <robertmhaas@gmail.com> writes:
>> On Thu, Feb 2, 2017 at 11:00 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> I'm about to push a fix that removes the crashes (or at least the ones
>>> I see on dromedary),
>
>> For comparison, a patch I wrote by inspection is attached.
>
> Hm, some of what you have here matches what I just pushed, but not all.
>
> I just made the C code agree with what the SQL declarations for the
> functions say.  I'm pretty dubious that the SQL declarations are entirely
> sensible as to which values need to be of what width, but I'll leave that
> decision for somebody who's been paying closer attention to the hash code.
>

I have gone through all the of the SQL declarations and it seems
hash_metapage_info(...,OUT procid int4,..) is not consistent.  procid
is unsigned int, so isn't it better to use the corresponding datatype
as int8 in SQL function hash_metapage_info then use Int64GetDatum?

The other inconsistency in the code appears to be in the usage of
UInt64GetDatum and Int64GetDatum for same SQL datatype.  For ex. SQL
declaration of hasho_prevblkno is int8 (hash_page_stats(.. , OUT
hasho_prevblkno int8,..)) and we use Int64GetDatum to fill the
corresponding C value.  However for SQL declaration of maxbucket is
int8 (hash_metapage_info(..,OUT maxbucket int8,)) and we use
UInt64GetDatum() to fetch the value.  I think it is better to be
consistent here.

>>> I think probably both of those are unavoidable 32-bit v 64-bit
>>> differences due to available space on a page changing with MAXALIGN.
>>> What do you want to do about those?
>
>> How about we have the test just select a named list of fields instead
>> of selecting *?
>
> Yeah, that's one possible answer.  We could also maintain two
> expected-files for 32 bit v 64 bit, but I'm not sure it's worth
> the trouble.
>

I think for now selecting named fields is sufficient.

-- 
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 12:41  Ashutosh Sharma <ashu.coek88@gmail.com>
  parent: Amit Kapila <amit.kapila16@gmail.com>
  1 sibling, 2 replies; 22+ messages in thread

From: Ashutosh Sharma @ 2017-02-03 12:41 UTC (permalink / raw)
  To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Robert Haas <robertmhaas@gmail.com>; pgsql-committers

On Fri, Feb 3, 2017 at 4:36 PM, Amit Kapila <amit.kapila16@gmail.com> wrote:
> On Fri, Feb 3, 2017 at 9:46 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Robert Haas <robertmhaas@gmail.com> writes:
>>> On Thu, Feb 2, 2017 at 11:00 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>>> I'm about to push a fix that removes the crashes (or at least the ones
>>>> I see on dromedary),
>>
>>> For comparison, a patch I wrote by inspection is attached.
>>
>> Hm, some of what you have here matches what I just pushed, but not all.
>>
>> I just made the C code agree with what the SQL declarations for the
>> functions say.  I'm pretty dubious that the SQL declarations are entirely
>> sensible as to which values need to be of what width, but I'll leave that
>> decision for somebody who's been paying closer attention to the hash code.
>>

I think UInt32GetDatum(metad->hashm_procid) looks fine, the reason
being 'hashm_procid' is defined as 32-bit unsigned integer but then we
may have to define procid as int8 in SQL function.

>
> I have gone through all the of the SQL declarations and it seems
> hash_metapage_info(...,OUT procid int4,..) is not consistent.  procid
> is unsigned int, so isn't it better to use the corresponding datatype
> as int8 in SQL function hash_metapage_info then use Int64GetDatum?
>
> The other inconsistency in the code appears to be in the usage of
> UInt64GetDatum and Int64GetDatum for same SQL datatype.  For ex. SQL
> declaration of hasho_prevblkno is int8 (hash_page_stats(.. , OUT
> hasho_prevblkno int8,..)) and we use Int64GetDatum to fill the
> corresponding C value.  However for SQL declaration of maxbucket is
> int8 (hash_metapage_info(..,OUT maxbucket int8,)) and we use
> UInt64GetDatum() to fetch the value.  I think it is better to be
> consistent here.

I am sorry but I am not quite able to understand the purpose of
typecasting unsigned integer to signed type at few places and then
using corresponding macros to represent it as Datum. I mean at few
places we have done typecasting of unsigned inetgers to signed type
whereas at some places we have kept it as it is.

>
>>>> I think probably both of those are unavoidable 32-bit v 64-bit
>>>> differences due to available space on a page changing with MAXALIGN.
>>>> What do you want to do about those?
>>
>>> How about we have the test just select a named list of fields instead
>>> of selecting *?
>>
>> Yeah, that's one possible answer.  We could also maintain two
>> expected-files for 32 bit v 64 bit, but I'm not sure it's worth
>> the trouble.
>>
>
> I think for now selecting named fields is sufficient.

+1. Attached is the patch that has this changes.

Note: I am extremely sorry for wrongly choosing some of the SQL types
in the patch for pageinspect. I think there were few platform specific
things that too should have been addressed by me. Moreover, I feel
being the owner of this project I should have participated in this
discussion a bit earlier but as I was not subscribed to
pgsql-committers list I could not be on time.

-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

Attachments:

Removed_platform_specific_fields_metapagege_info_func.patch (invalid/octet-stream, 5.0K) download diff --git a/contrib/pageinspect/expected/hash.out b/contrib/pageinspect/expected/hash.out index 3abc887..8ff5969 100644 --- a/contrib/pageinspect/expected/hash.out +++ b/contrib/pageinspect/expected/hash.out @@ -47,12 +47,13 @@ DETAIL: Expected 00000001, got 00000002. SELECT * FROM hash_bitmap_info('test_hash_a_idx', 5); ERROR: page is not an overflow page DETAIL: Expected 00000001, got 00000004. -SELECT * FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 0)); +SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, +lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM +hash_metapage_info(get_raw_page('test_hash_a_idx', 0)); -[ RECORD 1 ]---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- magic | 105121344 version | 2 ntuples | 1 -ffactor | 307 bsize | 8152 bmsize | 4096 bmshift | 15 @@ -66,15 +67,25 @@ procid | 450 spares | {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} mapp | {5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -SELECT * FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 1)); +SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, +lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM +hash_metapage_info(get_raw_page('test_hash_a_idx', 1)); ERROR: page is not a hash meta page -SELECT * FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 2)); +SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, +lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM +hash_metapage_info(get_raw_page('test_hash_a_idx', 2)); ERROR: page is not a hash meta page -SELECT * FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 3)); +SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, +lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM +hash_metapage_info(get_raw_page('test_hash_a_idx', 3)); ERROR: page is not a hash meta page -SELECT * FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 4)); +SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, +lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM +hash_metapage_info(get_raw_page('test_hash_a_idx', 4)); ERROR: page is not a hash meta page -SELECT * FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 5)); +SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, +lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM +hash_metapage_info(get_raw_page('test_hash_a_idx', 5)); ERROR: page is not a hash meta page SELECT * FROM hash_page_stats(get_raw_page('test_hash_a_idx', 0)); ERROR: page is not a hash bucket or overflow page diff --git a/contrib/pageinspect/sql/hash.sql b/contrib/pageinspect/sql/hash.sql index 9e7635e..617c3bb 100644 --- a/contrib/pageinspect/sql/hash.sql +++ b/contrib/pageinspect/sql/hash.sql @@ -21,13 +21,29 @@ SELECT * FROM hash_bitmap_info('test_hash_a_idx', 4); SELECT * FROM hash_bitmap_info('test_hash_a_idx', 5); +SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, +lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM +hash_metapage_info(get_raw_page('test_hash_a_idx', 0)); -SELECT * FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 0)); -SELECT * FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 1)); -SELECT * FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 2)); -SELECT * FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 3)); -SELECT * FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 4)); -SELECT * FROM hash_metapage_info(get_raw_page('test_hash_a_idx', 5)); +SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, +lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM +hash_metapage_info(get_raw_page('test_hash_a_idx', 1)); + +SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, +lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM +hash_metapage_info(get_raw_page('test_hash_a_idx', 2)); + +SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, +lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM +hash_metapage_info(get_raw_page('test_hash_a_idx', 3)); + +SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, +lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM +hash_metapage_info(get_raw_page('test_hash_a_idx', 4)); + +SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask, +lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM +hash_metapage_info(get_raw_page('test_hash_a_idx', 5)); SELECT * FROM hash_page_stats(get_raw_page('test_hash_a_idx', 0));
^ permalink raw reply [nested|flat] 22+ messages in thread

* Re: pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 14:43  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Amit Kapila <amit.kapila16@gmail.com>
  1 sibling, 1 reply; 22+ messages in thread

From: Tom Lane @ 2017-02-03 14:43 UTC (permalink / raw)
  To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Robert Haas <robertmhaas@gmail.com>; pgsql-committers

Amit Kapila <amit.kapila16@gmail.com> writes:
> I have gone through all the of the SQL declarations and it seems
> hash_metapage_info(...,OUT procid int4,..) is not consistent.  procid
> is unsigned int, so isn't it better to use the corresponding datatype
> as int8 in SQL function hash_metapage_info then use Int64GetDatum?

Isn't procid an OID?  I'd use OID or maybe even regprocedure on
the SQL side.

			regards, tom lane


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 14:49  Robert Haas <robertmhaas@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 22+ messages in thread

From: Robert Haas @ 2017-02-03 14:49 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers

 On Thu, Feb 2, 2017 at 11:16 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Robert Haas <robertmhaas@gmail.com> writes:
>> On Thu, Feb 2, 2017 at 11:00 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> I'm about to push a fix that removes the crashes (or at least the ones
>>> I see on dromedary),
>
>> For comparison, a patch I wrote by inspection is attached.
>
> Hm, some of what you have here matches what I just pushed, but not all.
>
> I just made the C code agree with what the SQL declarations for the
> functions say.

Doesn't look like it to me.  You changed a bunch of places that say
UInt32GetDatum to UInt64GetDatum, but the SQL type certainly isn't
unsigned.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 14:50  Amit Kapila <amit.kapila16@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 22+ messages in thread

From: Amit Kapila @ 2017-02-03 14:50 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Robert Haas <robertmhaas@gmail.com>; pgsql-committers

On Fri, Feb 3, 2017 at 8:13 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Amit Kapila <amit.kapila16@gmail.com> writes:
>> I have gone through all the of the SQL declarations and it seems
>> hash_metapage_info(...,OUT procid int4,..) is not consistent.  procid
>> is unsigned int, so isn't it better to use the corresponding datatype
>> as int8 in SQL function hash_metapage_info then use Int64GetDatum?
>
> Isn't procid an OID?
>

It is RegProcedure.

>  I'd use OID or maybe even regprocedure on
> the SQL side.
>

I think we can use either one of those.

-- 
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: [COMMITTERS] pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 14:59  Robert Haas <robertmhaas@gmail.com>
  parent: Ashutosh Sharma <ashu.coek88@gmail.com>
  1 sibling, 1 reply; 22+ messages in thread

From: Robert Haas @ 2017-02-03 14:59 UTC (permalink / raw)
  To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

On Fri, Feb 3, 2017 at 7:41 AM, Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
> I think UInt32GetDatum(metad->hashm_procid) looks fine, the reason
> being 'hashm_procid' is defined as 32-bit unsigned integer but then we
> may have to define procid as int8 in SQL function.

No, you're wrong.  The GetDatum you choose macro has to match the SQL
type, not the type of the variable that you're passing to it.  For
example, if you've got an "int" in the code and the SQL type is
"int8", you have to use Int64GetDatum, not Int32GetDatum.  Otherwise,
stuff breaks, because on some systems 64-bit integers are passed by
reference, not by value, so the representation that Int32GetDatum
produces isn't valid when interpreted by DatumGetInt64 later on.  The
latter is expecting a pointer, but the former didn't produce one.

> Note: I am extremely sorry for wrongly choosing some of the SQL types
> in the patch for pageinspect. I think there were few platform specific
> things that too should have been addressed by me. Moreover, I feel
> being the owner of this project I should have participated in this
> discussion a bit earlier but as I was not subscribed to
> pgsql-committers list I could not be on time.

It might be a good idea to subscribe to pgsql-committers; that way you
can follow what's getting committed, whether it is your patch or
otherwise.  But we also should perhaps have migrated this discussion
to pgsql-hackers.  Adjusting recipient list.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 15:28  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 22+ messages in thread

From: Tom Lane @ 2017-02-03 15:28 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: pgsql-committers

Robert Haas <robertmhaas@gmail.com> writes:
>  On Thu, Feb 2, 2017 at 11:16 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I just made the C code agree with what the SQL declarations for the
>> functions say.

> Doesn't look like it to me.  You changed a bunch of places that say
> UInt32GetDatum to UInt64GetDatum, but the SQL type certainly isn't
> unsigned.

The machines don't care about that.  They do care about the width of
the datum.  Particularly on 32-bit hardware, where one width is
pass-by-val and the other isn't.  (Also, if your point is that you
wish we had a uint64 SQL type, I doubt we're going there.)

What needs to be resolved to decide if any of this is actually sane is to
figure out which of these values need to be int64 on the SQL side because
(a) they could practically exceed the range of signed int32 and (b) it
would bother us to show such values as negative rather than large
positive.  I suspect that not all the things currently declared as int64
really need to be.  I also remain unhappy that we can't manage to be
consistent about what a BlockNumber parameter is represented as.

			regards, tom lane


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: [COMMITTERS] pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 15:54  Robert Haas <robertmhaas@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 22+ messages in thread

From: Robert Haas @ 2017-02-03 15:54 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

On Fri, Feb 3, 2017 at 10:28 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Robert Haas <robertmhaas@gmail.com> writes:
>>  On Thu, Feb 2, 2017 at 11:16 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> I just made the C code agree with what the SQL declarations for the
>>> functions say.
>
>> Doesn't look like it to me.  You changed a bunch of places that say
>> UInt32GetDatum to UInt64GetDatum, but the SQL type certainly isn't
>> unsigned.
>
> The machines don't care about that.  They do care about the width of
> the datum.  Particularly on 32-bit hardware, where one width is
> pass-by-val and the other isn't.  (Also, if your point is that you
> wish we had a uint64 SQL type, I doubt we're going there.)

I know the machines don't care about that, but I still think it'd be a
better idea to be consistent with the SQL types throughout rather than
only in places where failing to do so actually breaks something.  It's
not much of an abstraction layer if we're only kinda-sorta rigorous
about using it correctly.  If nothing else, it obscures best practice
for new patch authors.

> What needs to be resolved to decide if any of this is actually sane is to
> figure out which of these values need to be int64 on the SQL side because
> (a) they could practically exceed the range of signed int32 and (b) it
> would bother us to show such values as negative rather than large
> positive.  I suspect that not all the things currently declared as int64
> really need to be.  I also remain unhappy that we can't manage to be
> consistent about what a BlockNumber parameter is represented as.

The existing usage is mixed.  For example, gin_metapage_info() returns
pending_head and pending_tail as bigint, and those are BlockNumber at
the C level. But bt_metap returns fastroot as int4, and that's also a
BlockNumber at the C level.  For my money, int8 is a better choice
because I don't like the idea of the block number rolling over to a
negative value for a large relation, but I probably wouldn't bother
breaking compatibility for the existing cases where it's been done
otherwise, because relations of at least 16TB in size are not yet very
common.  At some point we may have to bite that bullet but maybe not
today.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: [COMMITTERS] pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 16:18  Robert Haas <robertmhaas@gmail.com>
  parent: Ashutosh Sharma <ashu.coek88@gmail.com>
  1 sibling, 1 reply; 22+ messages in thread

From: Robert Haas @ 2017-02-03 16:18 UTC (permalink / raw)
  To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

On Fri, Feb 3, 2017 at 7:41 AM, Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
>> I think for now selecting named fields is sufficient.
>
> +1. Attached is the patch that has this changes.

Thanks for the patch, but you only handled one of the two cases Tom
reported upthread.  Added a fix for the other one and committed the
result as 29e312bc1301061ae9f897ff39f3b230c421a5fb.

Hopefully that will turn the buildfarm green again, but we'll see.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: [COMMITTERS] pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 16:35  Robert Haas <robertmhaas@gmail.com>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 22+ messages in thread

From: Robert Haas @ 2017-02-03 16:35 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

On Fri, Feb 3, 2017 at 10:54 AM, Robert Haas <robertmhaas@gmail.com> wrote:
>> What needs to be resolved to decide if any of this is actually sane is to
>> figure out which of these values need to be int64 on the SQL side because
>> (a) they could practically exceed the range of signed int32 and (b) it
>> would bother us to show such values as negative rather than large
>> positive.  I suspect that not all the things currently declared as int64
>> really need to be.  I also remain unhappy that we can't manage to be
>> consistent about what a BlockNumber parameter is represented as.
>
> The existing usage is mixed.  For example, gin_metapage_info() returns
> pending_head and pending_tail as bigint, and those are BlockNumber at
> the C level. But bt_metap returns fastroot as int4, and that's also a
> BlockNumber at the C level.  For my money, int8 is a better choice
> because I don't like the idea of the block number rolling over to a
> negative value for a large relation, but I probably wouldn't bother
> breaking compatibility for the existing cases where it's been done
> otherwise, because relations of at least 16TB in size are not yet very
> common.  At some point we may have to bite that bullet but maybe not
> today.

So based on that theory, here's a patch.

- In hash_page_items, the returned columns are declared as itemoffset
int2, ctid tid, and data int8 at the SQL level.  There's existing
precedent for returning itemoffset as either int2 or int4, but since
at the C level it is uint16 it seems best to stick with int4, so the
patch changes that.  The other types seem OK: data is an int8 because
it's reporting the hash code, and that's uint32 at the C level.

- In hash_bitmap_info, the returned columns are declared as
bitmapblkno int8, bitmapbit int4, and bitstatus bool.  Since a block
number is a uint32 at the C level, it seems right to use int8 at the
SQL level per the above, because of signedness.  The other two return
columns are fine also.  The BlahGetDatum macros mostly match the
types, although in the case of bitmapblkno it differs in signedness
(UInt64GetDatum rather than Int64GetDatum).

- hash_metapage_info() returns a whole bunch of columns, all of which
are unsigned quantities, except for hashm_ntuples, which is a double.
With the attached patch, all of those unsigned quantities get promoted
to the next larger signed type at the SQL level (uint32 -> int8,
uint16 -> int4); exceptionally, hashm_procid is reported as an OID,
since it is.

In short, this patch makes hashfuncs.c consistent about (1) using the
next wider signed type to report unsigned values and (2) using the
GetDatum macro that matches the SQL return type in width and
signedness.  Objections?

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

pageinspect-more-hash-fixes.patch (application/octet-stream, 3.9K) download diff --git a/contrib/pageinspect/hashfuncs.c b/contrib/pageinspect/hashfuncs.c index 83b4698..b67a988 100644 --- a/contrib/pageinspect/hashfuncs.c +++ b/contrib/pageinspect/hashfuncs.c @@ -356,11 +356,11 @@ hash_page_items(PG_FUNCTION_ARGS) MemSet(nulls, 0, sizeof(nulls)); j = 0; - values[j++] = UInt16GetDatum(uargs->offset); + values[j++] = Int32GetDatum((int32) uargs->offset); values[j++] = PointerGetDatum(&itup->t_tid); hashkey = _hash_get_indextuple_hashkey(itup); - values[j] = UInt64GetDatum((uint64) hashkey); + values[j] = Int64GetDatum((int64) hashkey); tuple = heap_form_tuple(fctx->attinmeta->tupdesc, values, nulls); result = HeapTupleGetDatum(tuple); @@ -476,7 +476,7 @@ hash_bitmap_info(PG_FUNCTION_ARGS) MemSet(nulls, 0, sizeof(nulls)); j = 0; - values[j++] = UInt64GetDatum((uint64) bitmapblkno); + values[j++] = Int64GetDatum((int64) bitmapblkno); values[j++] = Int32GetDatum(bitmapbit); values[j++] = BoolGetDatum(bit); @@ -525,30 +525,30 @@ hash_metapage_info(PG_FUNCTION_ARGS) MemSet(nulls, 0, sizeof(nulls)); j = 0; - values[j++] = UInt64GetDatum(metad->hashm_magic); - values[j++] = UInt64GetDatum(metad->hashm_version); + values[j++] = Int64GetDatum((int64) metad->hashm_magic); + values[j++] = Int64GetDatum((int64) metad->hashm_version); values[j++] = Float8GetDatum(metad->hashm_ntuples); - 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); + values[j++] = Int32GetDatum((int32) metad->hashm_ffactor); + values[j++] = Int32GetDatum((int32) metad->hashm_bsize); + values[j++] = Int32GetDatum((int32) metad->hashm_bmsize); + values[j++] = Int32GetDatum((int32) metad->hashm_bmshift); + values[j++] = Int64GetDatum((int64) metad->hashm_maxbucket); + values[j++] = Int64GetDatum((int64) metad->hashm_highmask); + values[j++] = Int64GetDatum((int64) metad->hashm_lowmask); + values[j++] = Int64GetDatum((int64) metad->hashm_ovflpoint); + values[j++] = Int64GetDatum((int64) metad->hashm_firstfree); + values[j++] = Int64GetDatum((int64) metad->hashm_nmaps); + values[j++] = ObjectIdGetDatum((Oid) metad->hashm_procid); for (i = 0; i < HASH_MAX_SPLITPOINTS; i++) - spares[i] = UInt64GetDatum(metad->hashm_spares[i]); + spares[i] = Int64GetDatum((int8) metad->hashm_spares[i]); values[j++] = PointerGetDatum(construct_array(spares, HASH_MAX_SPLITPOINTS, INT8OID, 8, FLOAT8PASSBYVAL, 'd')); for (i = 0; i < HASH_MAX_BITMAPS; i++) - mapp[i] = UInt64GetDatum(metad->hashm_mapp[i]); + mapp[i] = Int64GetDatum((int64) metad->hashm_mapp[i]); values[j++] = PointerGetDatum(construct_array(mapp, HASH_MAX_BITMAPS, INT8OID, diff --git a/contrib/pageinspect/pageinspect--1.5--1.6.sql b/contrib/pageinspect/pageinspect--1.5--1.6.sql index a22438d..ac39568 100644 --- a/contrib/pageinspect/pageinspect--1.5--1.6.sql +++ b/contrib/pageinspect/pageinspect--1.5--1.6.sql @@ -35,7 +35,7 @@ LANGUAGE C STRICT PARALLEL SAFE; -- hash_page_items() -- CREATE FUNCTION hash_page_items(IN page bytea, - OUT itemoffset smallint, + OUT itemoffset int4, OUT ctid tid, OUT data int8) RETURNS SETOF record @@ -70,7 +70,7 @@ CREATE FUNCTION hash_metapage_info(IN page bytea, OUT ovflpoint int8, OUT firstfree int8, OUT nmaps int8, - OUT procid int4, + OUT procid oid, OUT spares int8[], OUT mapp int8[]) AS 'MODULE_PATHNAME', 'hash_metapage_info'
^ permalink raw reply [nested|flat] 22+ messages in thread

* Re: [COMMITTERS] pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 16:36  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 0 replies; 22+ messages in thread

From: Tom Lane @ 2017-02-03 16:36 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Ashutosh Sharma <ashu.coek88@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

Robert Haas <robertmhaas@gmail.com> writes:
> Hopefully that will turn the buildfarm green again, but we'll see.

It won't make the unhappy 64-bit machines happy, but I just pushed
a change that should deal with those problems.  With a little luck
we're over the hump now.

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: [COMMITTERS] pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 17:04  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 22+ messages in thread

From: Tom Lane @ 2017-02-03 17:04 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

Robert Haas <robertmhaas@gmail.com> writes:
> So based on that theory, here's a patch.
> ...
> In short, this patch makes hashfuncs.c consistent about (1) using the
> next wider signed type to report unsigned values and (2) using the
> GetDatum macro that matches the SQL return type in width and
> signedness.  Objections?

I haven't actually reviewed the patch, but your description of it sounds
sane.

One thing to think about is what will happen if someday we want to use
64-bit hash codes (a day I think is not that far away).  It sounds like
you've already chosen bigint for any output field that represents a
hash code or a related value such as a mask ... but it wouldn't hurt
to look through the fields with that in mind.

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: [COMMITTERS] pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-03 21:35  Robert Haas <robertmhaas@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 22+ messages in thread

From: Robert Haas @ 2017-02-03 21:35 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

On Fri, Feb 3, 2017 at 12:04 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> One thing to think about is what will happen if someday we want to use
> 64-bit hash codes (a day I think is not that far away).  It sounds like
> you've already chosen bigint for any output field that represents a
> hash code or a related value such as a mask ... but it wouldn't hurt
> to look through the fields with that in mind.

Yeah, I think we're fine on that score.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: [COMMITTERS] pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-04 02:14  Ashutosh Sharma <ashu.coek88@gmail.com>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 1 reply; 22+ messages in thread

From: Ashutosh Sharma @ 2017-02-04 02:14 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

On Fri, Feb 3, 2017 at 8:29 PM, Robert Haas <robertmhaas@gmail.com> wrote:
> On Fri, Feb 3, 2017 at 7:41 AM, Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
>> I think UInt32GetDatum(metad->hashm_procid) looks fine, the reason
>> being 'hashm_procid' is defined as 32-bit unsigned integer but then we
>> may have to define procid as int8 in SQL function.
>
> No, you're wrong.  The GetDatum you choose macro has to match the SQL
> type, not the type of the variable that you're passing to it.  For
> example, if you've got an "int" in the code and the SQL type is
> "int8", you have to use Int64GetDatum, not Int32GetDatum.  Otherwise,
> stuff breaks, because on some systems 64-bit integers are passed by
> reference, not by value, so the representation that Int32GetDatum
> produces isn't valid when interpreted by DatumGetInt64 later on.  The
> latter is expecting a pointer, but the former didn't produce one.
>

Thank you very much for detailed information and explanation. It is
really very helpful and understandable. But, As per your explanation,
GetDatum we choose need to match the SQL type, not the type of the
variable used in code and I do not see any unsigned integer SQL type
in PostgreSQL then I am just wondering on why do we have
UInt32GetDatum or UInt64GetDatum macros.

>> Note: I am extremely sorry for wrongly choosing some of the SQL types
>> in the patch for pageinspect. I think there were few platform specific
>> things that too should have been addressed by me. Moreover, I feel
>> being the owner of this project I should have participated in this
>> discussion a bit earlier but as I was not subscribed to
>> pgsql-committers list I could not be on time.
>
> It might be a good idea to subscribe to pgsql-committers; that way you
> can follow what's getting committed, whether it is your patch or
> otherwise.  But we also should perhaps have migrated this discussion
> to pgsql-hackers.  Adjusting recipient list.
>
> --
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: [COMMITTERS] pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-05 23:50  Robert Haas <robertmhaas@gmail.com>
  parent: Ashutosh Sharma <ashu.coek88@gmail.com>
  0 siblings, 1 reply; 22+ messages in thread

From: Robert Haas @ 2017-02-05 23:50 UTC (permalink / raw)
  To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

On Fri, Feb 3, 2017 at 9:14 PM, Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
> On Fri, Feb 3, 2017 at 8:29 PM, Robert Haas <robertmhaas@gmail.com> wrote:
>> On Fri, Feb 3, 2017 at 7:41 AM, Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
>>> I think UInt32GetDatum(metad->hashm_procid) looks fine, the reason
>>> being 'hashm_procid' is defined as 32-bit unsigned integer but then we
>>> may have to define procid as int8 in SQL function.
>>
>> No, you're wrong.  The GetDatum you choose macro has to match the SQL
>> type, not the type of the variable that you're passing to it.  For
>> example, if you've got an "int" in the code and the SQL type is
>> "int8", you have to use Int64GetDatum, not Int32GetDatum.  Otherwise,
>> stuff breaks, because on some systems 64-bit integers are passed by
>> reference, not by value, so the representation that Int32GetDatum
>> produces isn't valid when interpreted by DatumGetInt64 later on.  The
>> latter is expecting a pointer, but the former didn't produce one.
>>
>
> Thank you very much for detailed information and explanation. It is
> really very helpful and understandable. But, As per your explanation,
> GetDatum we choose need to match the SQL type, not the type of the
> variable used in code and I do not see any unsigned integer SQL type
> in PostgreSQL then I am just wondering on why do we have
> UInt32GetDatum or UInt64GetDatum macros.

That's a pretty good question.  UInt64GetDatum is used in exactly one
place (exec_stmt_getdiag) and there's really no reason why
Int64GetDatum wouldn't be more appropriate.  UInt32GetDatum is used in
a few more places, and some of those are used for hash values which
are not exposed at the SQL level so they might be legitimate, but
others like the ones in pageinspect look like fuzzy thinking that has
only survived because it happens not to break anything.  I suppose if
we wanted to be really rigorous about this sort of thing, we should
change UInt32GetDatum to do something tangibly different from
Int32GetDatum, like negate all the bits.  Then if somebody picked the
wrong macro it would actually fail.  I'm not sure that's really the
best place to spend our effort, though.  The moral of this episode is
that it's important to at least get the right width.  Currently,
getting the wrong signedness doesn't actually break anything.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread

* Re: [COMMITTERS] pgsql: pageinspect: Try to fix some bugs in previous commit.
@ 2017-02-06 05:02  Ashutosh Sharma <ashu.coek88@gmail.com>
  parent: Robert Haas <robertmhaas@gmail.com>
  0 siblings, 0 replies; 22+ messages in thread

From: Ashutosh Sharma @ 2017-02-06 05:02 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>

>>>> I think UInt32GetDatum(metad->hashm_procid) looks fine, the reason
>>>> being 'hashm_procid' is defined as 32-bit unsigned integer but then we
>>>> may have to define procid as int8 in SQL function.
>>>
>>> No, you're wrong.  The GetDatum you choose macro has to match the SQL
>>> type, not the type of the variable that you're passing to it.  For
>>> example, if you've got an "int" in the code and the SQL type is
>>> "int8", you have to use Int64GetDatum, not Int32GetDatum.  Otherwise,
>>> stuff breaks, because on some systems 64-bit integers are passed by
>>> reference, not by value, so the representation that Int32GetDatum
>>> produces isn't valid when interpreted by DatumGetInt64 later on.  The
>>> latter is expecting a pointer, but the former didn't produce one.
>>>
>>
>> Thank you very much for detailed information and explanation. It is
>> really very helpful and understandable. But, As per your explanation,
>> GetDatum we choose need to match the SQL type, not the type of the
>> variable used in code and I do not see any unsigned integer SQL type
>> in PostgreSQL then I am just wondering on why do we have
>> UInt32GetDatum or UInt64GetDatum macros.
>
> That's a pretty good question.  UInt64GetDatum is used in exactly one
> place (exec_stmt_getdiag) and there's really no reason why
> Int64GetDatum wouldn't be more appropriate.  UInt32GetDatum is used in
> a few more places, and some of those are used for hash values which
> are not exposed at the SQL level so they might be legitimate, but
> others like the ones in pageinspect look like fuzzy thinking that has
> only survived because it happens not to break anything.  I suppose if
> we wanted to be really rigorous about this sort of thing, we should
> change UInt32GetDatum to do something tangibly different from
> Int32GetDatum, like negate all the bits.  Then if somebody picked the
> wrong macro it would actually fail.  I'm not sure that's really the
> best place to spend our effort, though.  The moral of this episode is
> that it's important to at least get the right width.  Currently,
> getting the wrong signedness doesn't actually break anything.

Okay, understood. Thank you very much !

--
With Regards,
Ashutosh Sharma
EnterpriseDB:http://www.enterprisedb.com


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 22+ messages in thread


end of thread, other threads:[~2017-02-06 05:02 UTC | newest]

Thread overview: 22+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-02-03 03:32 pgsql: pageinspect: Try to fix some bugs in previous commit. Robert Haas <rhaas@postgresql.org>
2017-02-03 03:40 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-02-03 03:49   ` Robert Haas <robertmhaas@gmail.com>
2017-02-03 04:00     ` Tom Lane <tgl@sss.pgh.pa.us>
2017-02-03 04:03       ` Robert Haas <robertmhaas@gmail.com>
2017-02-03 04:16         ` Tom Lane <tgl@sss.pgh.pa.us>
2017-02-03 11:06           ` Amit Kapila <amit.kapila16@gmail.com>
2017-02-03 12:41             ` Ashutosh Sharma <ashu.coek88@gmail.com>
2017-02-03 14:59               ` Robert Haas <robertmhaas@gmail.com>
2017-02-04 02:14                 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2017-02-05 23:50                   ` Robert Haas <robertmhaas@gmail.com>
2017-02-06 05:02                     ` Ashutosh Sharma <ashu.coek88@gmail.com>
2017-02-03 16:18               ` Robert Haas <robertmhaas@gmail.com>
2017-02-03 16:36                 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-02-03 14:43             ` Tom Lane <tgl@sss.pgh.pa.us>
2017-02-03 14:50               ` Amit Kapila <amit.kapila16@gmail.com>
2017-02-03 14:49           ` Robert Haas <robertmhaas@gmail.com>
2017-02-03 15:28             ` Tom Lane <tgl@sss.pgh.pa.us>
2017-02-03 15:54               ` Robert Haas <robertmhaas@gmail.com>
2017-02-03 16:35                 ` Robert Haas <robertmhaas@gmail.com>
2017-02-03 17:04                   ` Tom Lane <tgl@sss.pgh.pa.us>
2017-02-03 21:35                     ` Robert Haas <robertmhaas@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox