mirror of
https://github.com/postgres/postgres.git
synced 2025-08-21 10:42:50 +03:00
tableam: Don't assume that every AM uses md.c style storage.
Previously various parts of the code routed size requests through RelationGetNumberOfBlocks[InFork]. That works if md.c is used by the AM, but not otherwise. Add a tableam callback to return the size of the table. As not every AM will use postgres' BLCKSZ, have it return bytes, and have RelationGetNumberOfBlocksInFork() round the byte size up into blocks. To allow code outside of the AM to determine the actual relation size map InvalidForkNumber the total size of a relation, as not every AM might just need the postgres defined forks. A few users of RelationGetNumberOfBlocks() ought to be converted away from that. One case, the use of it to determine whether a tid is valid, will be fixed in a follow up commit. Others will have to wait for v13. Author: Andres Freund Discussion: https://postgr.es/m/20190423225201.3bbv6tbqzkb5w7cw@alap3.anarazel.de
This commit is contained in:
@@ -540,6 +540,22 @@ typedef struct TableAmRoutine
|
||||
struct ValidateIndexState *state);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Miscellaneous functions.
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* See table_relation_size().
|
||||
*
|
||||
* Note that currently a few callers use the MAIN_FORKNUM size to vet the
|
||||
* validity of tids (e.g. nodeTidscans.c), and others use it to figure out
|
||||
* the range of potentially interesting blocks (brin, analyze). The
|
||||
* abstraction around this will need to be improved in the near future.
|
||||
*/
|
||||
uint64 (*relation_size) (Relation rel, ForkNumber forkNumber);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Planner related functions.
|
||||
* ------------------------------------------------------------------------
|
||||
@@ -550,6 +566,10 @@ typedef struct TableAmRoutine
|
||||
*
|
||||
* While block oriented, it shouldn't be too hard for an AM that doesn't
|
||||
* doesn't internally use blocks to convert into a usable representation.
|
||||
*
|
||||
* This differs from the relation_size callback by returning size
|
||||
* estimates (both relation size and tuple count) for planning purposes,
|
||||
* rather than returning a currently correct estimate.
|
||||
*/
|
||||
void (*relation_estimate_size) (Relation rel, int32 *attr_widths,
|
||||
BlockNumber *pages, double *tuples,
|
||||
@@ -1503,6 +1523,26 @@ table_index_validate_scan(Relation heap_rel,
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Miscellaneous functionality
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Return the current size of `rel` in bytes. If `forkNumber` is
|
||||
* InvalidForkNumber, return the relation's overall size, otherwise the size
|
||||
* for the indicated fork.
|
||||
*
|
||||
* Note that the overall size might not be the equivalent of the sum of sizes
|
||||
* for the individual forks for some AMs, e.g. because the AMs storage does
|
||||
* not neatly map onto the builtin types of forks.
|
||||
*/
|
||||
static inline uint64
|
||||
table_relation_size(Relation rel, ForkNumber forkNumber)
|
||||
{
|
||||
return rel->rd_tableam->relation_size(rel, forkNumber);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Planner related functionality
|
||||
* ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user