Mis-use of type BlockNumber? - Mailing list pgsql-hackers

From Chao Li
Subject Mis-use of type BlockNumber?
Date
Msg-id 96FF4104-7891-4ED7-90E3-47FF1CD6F34D@gmail.com
Whole thread Raw
Responses Re: Mis-use of type BlockNumber?
Re: Mis-use of type BlockNumber?
List pgsql-hackers
Hi,

While reviewing [1], I noticed several cases where BlockNumber seems to be misused.

Although BlockNumber is currently underlying defined as uint32, it has a special meaning. For example:
```
#define InvalidBlockNumber ((BlockNumber) 0xFFFFFFFF)
#define MaxBlockNumber ((BlockNumber) 0xFFFFFFFE)
```
So my understanding is that BlockNumber should only be used to identify a block.

However, I saw several places where variables of type BlockNumber are actually used as counts. For example:
```
typedef struct LVRelState
{

    BlockNumber blkno;   <== correct usage

    BlockNumber rel_pages; /* total number of pages */  <== mis-use
```
In this example, rel_pages is actually a count. In theory it could just be an int (or some other count type).

Another example:
```
static void
system_time_samplescangetsamplesize(PlannerInfo *root,
                                    RelOptInfo *baserel,
                                    List *paramexprs,
                                    BlockNumber *pages,
                                    double *tuples)
```
Here the parameter pages is also a count indicating the number of pages.

So I want to confirm whether my understanding is correct that these are misuses of BlockNumber. If so, would it be
wortha cleanup patch to fix such cases? 

[1] https://postgr.es/m/81DAFACF-7D55-4A84-ACB0-0425D1669DB4@gmail.com

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/







pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Skipping schema changes in publication
Next
From: Michael Paquier
Date:
Subject: Re: Add pg_stat_recovery system view