mirror of https://github.com/citusdata/citus.git
PG15: Use RelationGetSmgr() instead of RelationOpenSmgr().
Handle PG commit f10f0ae420.pull/5920/head
parent
518fb0873e
commit
f944722c6a
|
@ -115,8 +115,6 @@ columnar_storage_info(PG_FUNCTION_ARGS)
|
|||
RelationGetRelationName(rel))));
|
||||
}
|
||||
|
||||
RelationOpenSmgr(rel);
|
||||
|
||||
Datum values[STORAGE_INFO_NATTS] = { 0 };
|
||||
bool nulls[STORAGE_INFO_NATTS] = { 0 };
|
||||
|
||||
|
|
|
@ -1738,11 +1738,10 @@ ColumnarStorageUpdateIfNeeded(Relation rel, bool isUpgrade)
|
|||
return;
|
||||
}
|
||||
|
||||
RelationOpenSmgr(rel);
|
||||
BlockNumber nblocks = smgrnblocks(rel->rd_smgr, MAIN_FORKNUM);
|
||||
BlockNumber nblocks = smgrnblocks(RelationGetSmgr(rel), MAIN_FORKNUM);
|
||||
if (nblocks < 2)
|
||||
{
|
||||
ColumnarStorageInit(rel->rd_smgr, ColumnarMetadataNewStorageId());
|
||||
ColumnarStorageInit(RelationGetSmgr(rel), ColumnarMetadataNewStorageId());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,8 @@
|
|||
#include "storage/bufmgr.h"
|
||||
#include "storage/lmgr.h"
|
||||
|
||||
#include "pg_version_compat.h"
|
||||
|
||||
#include "columnar/columnar.h"
|
||||
#include "columnar/columnar_storage.h"
|
||||
|
||||
|
@ -354,8 +356,7 @@ ColumnarStorageGetReservedOffset(Relation rel, bool force)
|
|||
bool
|
||||
ColumnarStorageIsCurrent(Relation rel)
|
||||
{
|
||||
RelationOpenSmgr(rel);
|
||||
BlockNumber nblocks = smgrnblocks(rel->rd_smgr, MAIN_FORKNUM);
|
||||
BlockNumber nblocks = smgrnblocks(RelationGetSmgr(rel), MAIN_FORKNUM);
|
||||
|
||||
if (nblocks < 2)
|
||||
{
|
||||
|
@ -439,8 +440,7 @@ ColumnarStorageReserveData(Relation rel, uint64 amount)
|
|||
PhysicalAddr final = LogicalToPhysical(nextReservation - 1);
|
||||
|
||||
/* extend with new pages */
|
||||
RelationOpenSmgr(rel);
|
||||
BlockNumber nblocks = smgrnblocks(rel->rd_smgr, MAIN_FORKNUM);
|
||||
BlockNumber nblocks = smgrnblocks(RelationGetSmgr(rel), MAIN_FORKNUM);
|
||||
|
||||
while (nblocks <= final.blockno)
|
||||
{
|
||||
|
@ -547,8 +547,7 @@ ColumnarStorageTruncate(Relation rel, uint64 newDataReservation)
|
|||
rel->rd_id, newDataReservation);
|
||||
}
|
||||
|
||||
RelationOpenSmgr(rel);
|
||||
BlockNumber old_rel_pages = smgrnblocks(rel->rd_smgr, MAIN_FORKNUM);
|
||||
BlockNumber old_rel_pages = smgrnblocks(RelationGetSmgr(rel), MAIN_FORKNUM);
|
||||
if (old_rel_pages == 0)
|
||||
{
|
||||
/* nothing to do */
|
||||
|
@ -627,8 +626,7 @@ ColumnarOverwriteMetapage(Relation relation, ColumnarMetapage columnarMetapage)
|
|||
static ColumnarMetapage
|
||||
ColumnarMetapageRead(Relation rel, bool force)
|
||||
{
|
||||
RelationOpenSmgr(rel);
|
||||
BlockNumber nblocks = smgrnblocks(rel->rd_smgr, MAIN_FORKNUM);
|
||||
BlockNumber nblocks = smgrnblocks(RelationGetSmgr(rel), MAIN_FORKNUM);
|
||||
if (nblocks == 0)
|
||||
{
|
||||
/*
|
||||
|
|
|
@ -913,8 +913,7 @@ columnar_relation_nontransactional_truncate(Relation rel)
|
|||
RelationTruncate(rel, 0);
|
||||
|
||||
uint64 storageId = ColumnarMetadataNewStorageId();
|
||||
RelationOpenSmgr(rel);
|
||||
ColumnarStorageInit(rel->rd_smgr, storageId);
|
||||
ColumnarStorageInit(RelationGetSmgr(rel), storageId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1136,8 +1135,7 @@ LogRelationStats(Relation rel, int elevel)
|
|||
totalStripeLength += stripe->dataLength;
|
||||
}
|
||||
|
||||
RelationOpenSmgr(rel);
|
||||
uint64 relPages = smgrnblocks(rel->rd_smgr, MAIN_FORKNUM);
|
||||
uint64 relPages = smgrnblocks(RelationGetSmgr(rel), MAIN_FORKNUM);
|
||||
RelationCloseSmgr(rel);
|
||||
|
||||
Datum storageId = DirectFunctionCall1(columnar_relation_storageid,
|
||||
|
@ -1239,8 +1237,7 @@ TruncateColumnar(Relation rel, int elevel)
|
|||
uint64 newDataReservation = Max(GetHighestUsedAddress(rel->rd_node) + 1,
|
||||
ColumnarFirstLogicalOffset);
|
||||
|
||||
RelationOpenSmgr(rel);
|
||||
BlockNumber old_rel_pages = smgrnblocks(rel->rd_smgr, MAIN_FORKNUM);
|
||||
BlockNumber old_rel_pages = smgrnblocks(RelationGetSmgr(rel), MAIN_FORKNUM);
|
||||
|
||||
if (!ColumnarStorageTruncate(rel, newDataReservation))
|
||||
{
|
||||
|
@ -1248,8 +1245,7 @@ TruncateColumnar(Relation rel, int elevel)
|
|||
return;
|
||||
}
|
||||
|
||||
RelationOpenSmgr(rel);
|
||||
BlockNumber new_rel_pages = smgrnblocks(rel->rd_smgr, MAIN_FORKNUM);
|
||||
BlockNumber new_rel_pages = smgrnblocks(RelationGetSmgr(rel), MAIN_FORKNUM);
|
||||
|
||||
/*
|
||||
* We can release the exclusive lock as soon as we have truncated.
|
||||
|
@ -1784,20 +1780,17 @@ columnar_relation_size(Relation rel, ForkNumber forkNumber)
|
|||
|
||||
uint64 nblocks = 0;
|
||||
|
||||
/* Open it at the smgr level if not already done */
|
||||
RelationOpenSmgr(rel);
|
||||
|
||||
/* InvalidForkNumber indicates returning the size for all forks */
|
||||
if (forkNumber == InvalidForkNumber)
|
||||
{
|
||||
for (int i = 0; i < MAX_FORKNUM; i++)
|
||||
{
|
||||
nblocks += smgrnblocks(rel->rd_smgr, i);
|
||||
nblocks += smgrnblocks(RelationGetSmgr(rel), i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nblocks = smgrnblocks(rel->rd_smgr, forkNumber);
|
||||
nblocks = smgrnblocks(RelationGetSmgr(rel), forkNumber);
|
||||
}
|
||||
|
||||
return nblocks * BLCKSZ;
|
||||
|
@ -1819,8 +1812,7 @@ columnar_estimate_rel_size(Relation rel, int32 *attr_widths,
|
|||
double *allvisfrac)
|
||||
{
|
||||
CheckCitusColumnarVersion(ERROR);
|
||||
RelationOpenSmgr(rel);
|
||||
*pages = smgrnblocks(rel->rd_smgr, MAIN_FORKNUM);
|
||||
*pages = smgrnblocks(RelationGetSmgr(rel), MAIN_FORKNUM);
|
||||
*tuples = ColumnarTableRowCount(rel);
|
||||
|
||||
/*
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "postgres.h"
|
||||
|
||||
#include "distributed/pg_version_constants.h"
|
||||
#include "pg_version_compat.h"
|
||||
|
||||
|
||||
#include "access/amapi.h"
|
||||
|
@ -446,20 +447,17 @@ fake_relation_size(Relation rel, ForkNumber forkNumber)
|
|||
|
||||
uint64 nblocks = 0;
|
||||
|
||||
/* Open it at the smgr level if not already done */
|
||||
RelationOpenSmgr(rel);
|
||||
|
||||
/* InvalidForkNumber indicates returning the size for all forks */
|
||||
if (forkNumber == InvalidForkNumber)
|
||||
{
|
||||
for (int i = 0; i < MAX_FORKNUM; i++)
|
||||
{
|
||||
nblocks += smgrnblocks(rel->rd_smgr, i);
|
||||
nblocks += smgrnblocks(RelationGetSmgr(rel), i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nblocks = smgrnblocks(rel->rd_smgr, forkNumber);
|
||||
nblocks = smgrnblocks(RelationGetSmgr(rel), forkNumber);
|
||||
}
|
||||
|
||||
return nblocks * BLCKSZ;
|
||||
|
|
|
@ -13,6 +13,25 @@
|
|||
|
||||
#include "distributed/pg_version_constants.h"
|
||||
|
||||
#if PG_VERSION_NUM >= PG_VERSION_15
|
||||
#else
|
||||
|
||||
#include "storage/smgr.h"
|
||||
#include "utils/rel.h"
|
||||
|
||||
static inline SMgrRelation
|
||||
RelationGetSmgr(Relation rel)
|
||||
{
|
||||
if (unlikely(rel->rd_smgr == NULL))
|
||||
{
|
||||
smgrsetowner(&(rel->rd_smgr), smgropen(rel->rd_node, rel->rd_backend));
|
||||
}
|
||||
return rel->rd_smgr;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM >= PG_VERSION_14
|
||||
#define AlterTableStmtObjType_compat(a) ((a)->objtype)
|
||||
#define getObjectTypeDescription_compat(a, b) getObjectTypeDescription(a, b)
|
||||
|
|
Loading…
Reference in New Issue