1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

pgindent run for 9.5

This commit is contained in:
Bruce Momjian
2015-05-23 21:35:49 -04:00
parent 225892552b
commit 807b9e0dff
414 changed files with 5810 additions and 5308 deletions

View File

@ -35,16 +35,17 @@ PG_MODULE_MAGIC;
typedef struct
{
SamplerRandomState randstate;
uint32 seed; /* random seed */
BlockNumber nblocks; /* number of block in relation */
int32 time; /* time limit for sampling */
TimestampTz start_time; /* start time of sampling */
TimestampTz end_time; /* end time of sampling */
OffsetNumber lt; /* last tuple returned from current block */
BlockNumber step; /* step size */
BlockNumber lb; /* last block visited */
BlockNumber estblocks; /* estimated number of returned blocks (moving) */
BlockNumber doneblocks; /* number of already returned blocks */
uint32 seed; /* random seed */
BlockNumber nblocks; /* number of block in relation */
int32 time; /* time limit for sampling */
TimestampTz start_time; /* start time of sampling */
TimestampTz end_time; /* end time of sampling */
OffsetNumber lt; /* last tuple returned from current block */
BlockNumber step; /* step size */
BlockNumber lb; /* last block visited */
BlockNumber estblocks; /* estimated number of returned blocks
* (moving) */
BlockNumber doneblocks; /* number of already returned blocks */
} SystemSamplerData;
@ -63,11 +64,11 @@ static uint32 random_relative_prime(uint32 n, SamplerRandomState randstate);
Datum
tsm_system_time_init(PG_FUNCTION_ARGS)
{
TableSampleDesc *tsdesc = (TableSampleDesc *) PG_GETARG_POINTER(0);
uint32 seed = PG_GETARG_UINT32(1);
int32 time = PG_ARGISNULL(2) ? -1 : PG_GETARG_INT32(2);
HeapScanDesc scan = tsdesc->heapScan;
SystemSamplerData *sampler;
TableSampleDesc *tsdesc = (TableSampleDesc *) PG_GETARG_POINTER(0);
uint32 seed = PG_GETARG_UINT32(1);
int32 time = PG_ARGISNULL(2) ? -1 : PG_GETARG_INT32(2);
HeapScanDesc scan = tsdesc->heapScan;
SystemSamplerData *sampler;
if (time < 1)
ereport(ERROR,
@ -92,6 +93,7 @@ tsm_system_time_init(PG_FUNCTION_ARGS)
/* Find relative prime as step size for linear probing. */
sampler->step = random_relative_prime(sampler->nblocks, sampler->randstate);
/*
* Randomize start position so that blocks close to step size don't have
* higher probability of being chosen on very short scan.
@ -111,8 +113,8 @@ tsm_system_time_init(PG_FUNCTION_ARGS)
Datum
tsm_system_time_nextblock(PG_FUNCTION_ARGS)
{
TableSampleDesc *tsdesc = (TableSampleDesc *) PG_GETARG_POINTER(0);
SystemSamplerData *sampler = (SystemSamplerData *) tsdesc->tsmdata;
TableSampleDesc *tsdesc = (TableSampleDesc *) PG_GETARG_POINTER(0);
SystemSamplerData *sampler = (SystemSamplerData *) tsdesc->tsmdata;
sampler->lb = (sampler->lb + sampler->step) % sampler->nblocks;
sampler->doneblocks++;
@ -125,16 +127,16 @@ tsm_system_time_nextblock(PG_FUNCTION_ARGS)
* Update the estimations for time limit at least 10 times per estimated
* number of returned blocks to handle variations in block read speed.
*/
if (sampler->doneblocks % Max(sampler->estblocks/10, 1) == 0)
if (sampler->doneblocks % Max(sampler->estblocks / 10, 1) == 0)
{
TimestampTz now = GetCurrentTimestamp();
long secs;
int usecs;
TimestampTz now = GetCurrentTimestamp();
long secs;
int usecs;
int usecs_remaining;
int time_per_block;
TimestampDifference(sampler->start_time, now, &secs, &usecs);
usecs += (int) secs * 1000000;
usecs += (int) secs *1000000;
time_per_block = usecs / sampler->doneblocks;
@ -144,7 +146,7 @@ tsm_system_time_nextblock(PG_FUNCTION_ARGS)
PG_RETURN_UINT32(InvalidBlockNumber);
/* Remaining microseconds */
usecs_remaining = usecs + (int) secs * 1000000;
usecs_remaining = usecs + (int) secs *1000000;
/* Recalculate estimated returned number of blocks */
if (time_per_block < usecs_remaining && time_per_block > 0)
@ -161,10 +163,10 @@ tsm_system_time_nextblock(PG_FUNCTION_ARGS)
Datum
tsm_system_time_nexttuple(PG_FUNCTION_ARGS)
{
TableSampleDesc *tsdesc = (TableSampleDesc *) PG_GETARG_POINTER(0);
OffsetNumber maxoffset = PG_GETARG_UINT16(2);
SystemSamplerData *sampler = (SystemSamplerData *) tsdesc->tsmdata;
OffsetNumber tupoffset = sampler->lt;
TableSampleDesc *tsdesc = (TableSampleDesc *) PG_GETARG_POINTER(0);
OffsetNumber maxoffset = PG_GETARG_UINT16(2);
SystemSamplerData *sampler = (SystemSamplerData *) tsdesc->tsmdata;
OffsetNumber tupoffset = sampler->lt;
if (tupoffset == InvalidOffsetNumber)
tupoffset = FirstOffsetNumber;
@ -198,8 +200,8 @@ tsm_system_time_end(PG_FUNCTION_ARGS)
Datum
tsm_system_time_reset(PG_FUNCTION_ARGS)
{
TableSampleDesc *tsdesc = (TableSampleDesc *) PG_GETARG_POINTER(0);
SystemSamplerData *sampler = (SystemSamplerData *) tsdesc->tsmdata;
TableSampleDesc *tsdesc = (TableSampleDesc *) PG_GETARG_POINTER(0);
SystemSamplerData *sampler = (SystemSamplerData *) tsdesc->tsmdata;
sampler->lt = InvalidOffsetNumber;
sampler->start_time = GetCurrentTimestamp();
@ -221,18 +223,18 @@ tsm_system_time_reset(PG_FUNCTION_ARGS)
Datum
tsm_system_time_cost(PG_FUNCTION_ARGS)
{
PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
Path *path = (Path *) PG_GETARG_POINTER(1);
RelOptInfo *baserel = (RelOptInfo *) PG_GETARG_POINTER(2);
List *args = (List *) PG_GETARG_POINTER(3);
BlockNumber *pages = (BlockNumber *) PG_GETARG_POINTER(4);
double *tuples = (double *) PG_GETARG_POINTER(5);
Node *limitnode;
int32 time;
BlockNumber relpages;
double reltuples;
double density;
double spc_random_page_cost;
PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
Path *path = (Path *) PG_GETARG_POINTER(1);
RelOptInfo *baserel = (RelOptInfo *) PG_GETARG_POINTER(2);
List *args = (List *) PG_GETARG_POINTER(3);
BlockNumber *pages = (BlockNumber *) PG_GETARG_POINTER(4);
double *tuples = (double *) PG_GETARG_POINTER(5);
Node *limitnode;
int32 time;
BlockNumber relpages;
double reltuples;
double density;
double spc_random_page_cost;
limitnode = linitial(args);
limitnode = estimate_expression_value(root, limitnode);
@ -269,10 +271,10 @@ tsm_system_time_cost(PG_FUNCTION_ARGS)
/*
* Assumption here is that we'll never read less than 1% of table pages,
* this is here mainly because it is much less bad to overestimate than
* underestimate and using just spc_random_page_cost will probably lead
* to underestimations in general.
* underestimate and using just spc_random_page_cost will probably lead to
* underestimations in general.
*/
*pages = Min(baserel->pages, Max(time/spc_random_page_cost, baserel->pages/100));
*pages = Min(baserel->pages, Max(time / spc_random_page_cost, baserel->pages / 100));
*tuples = rint(density * (double) *pages * path->rows / baserel->tuples);
path->rows = *tuples;
@ -280,9 +282,9 @@ tsm_system_time_cost(PG_FUNCTION_ARGS)
}
static uint32
gcd (uint32 a, uint32 b)
gcd(uint32 a, uint32 b)
{
uint32 c;
uint32 c;
while (a != 0)
{
@ -298,8 +300,8 @@ static uint32
random_relative_prime(uint32 n, SamplerRandomState randstate)
{
/* Pick random starting number, with some limits on what it can be. */
uint32 r = (uint32) sampler_random_fract(randstate) * n/2 + n/4,
t;
uint32 r = (uint32) sampler_random_fract(randstate) * n / 2 + n / 4,
t;
/*
* This should only take 2 or 3 iterations as the probability of 2 numbers