Run pgindent on code

This commit is contained in:
Matvey Arye 2017-06-21 14:00:00 -04:00 committed by Erik Nordström
parent 9489d06595
commit ce3d630b6d
22 changed files with 232 additions and 190 deletions

View File

@ -53,7 +53,8 @@ chunk_create_new(Hyperspace *hs, Point *p)
} }
Chunk * Chunk *
chunk_create_stub(int32 id, int16 num_constraints) { chunk_create_stub(int32 id, int16 num_constraints)
{
Chunk *chunk; Chunk *chunk;
chunk = palloc0(CHUNK_SIZE(num_constraints)); chunk = palloc0(CHUNK_SIZE(num_constraints));
@ -68,6 +69,7 @@ static bool
chunk_tuple_found(TupleInfo *ti, void *arg) chunk_tuple_found(TupleInfo *ti, void *arg)
{ {
Chunk *chunk = arg; Chunk *chunk = arg;
chunk_fill(chunk, ti->tuple); chunk_fill(chunk, ti->tuple);
return false; return false;
} }
@ -203,7 +205,8 @@ chunk_find(Hyperspace *hs, Point *p)
Chunk *chunk; Chunk *chunk;
ChunkScanCtx ctx; ChunkScanCtx ctx;
int16 num_dimensions = HYPERSPACE_NUM_DIMENSIONS(hs); int16 num_dimensions = HYPERSPACE_NUM_DIMENSIONS(hs);
int i, j; int i,
j;
/* The scan context will keep the state accumulated during the scan */ /* The scan context will keep the state accumulated during the scan */
chunk_scan_ctx_init(&ctx, num_dimensions); chunk_scan_ctx_init(&ctx, num_dimensions);
@ -216,8 +219,11 @@ chunk_find(Hyperspace *hs, Point *p)
vec = dimension_slice_scan(hs->dimensions[i].fd.id, p->coordinates[i]); vec = dimension_slice_scan(hs->dimensions[i].fd.id, p->coordinates[i]);
for (j = 0; j < vec->num_slices; j++) for (j = 0; j < vec->num_slices; j++)
/* For each dimension slice, find matching constraints. These will
* be saved in the scan context */ /*
* For each dimension slice, find matching constraints. These will
* be saved in the scan context
*/
chunk_constraint_scan_by_dimension_slice_id(vec->slices[j], &ctx); chunk_constraint_scan_by_dimension_slice_id(vec->slices[j], &ctx);
} }

View File

@ -27,8 +27,8 @@ typedef struct Chunk
/* /*
* The hypercube defines the chunks position in the N-dimensional space. * The hypercube defines the chunks position in the N-dimensional space.
* Each of the N slices in the cube corresponds to a constraint on the chunk * Each of the N slices in the cube corresponds to a constraint on the
* table. * chunk table.
*/ */
Hypercube *cube; Hypercube *cube;
int16 capacity; int16 capacity;

View File

@ -10,6 +10,7 @@ static inline ChunkConstraint *
chunk_constraint_from_form_data(Form_chunk_constraint fd) chunk_constraint_from_form_data(Form_chunk_constraint fd)
{ {
ChunkConstraint *cc; ChunkConstraint *cc;
cc = palloc0(sizeof(ChunkConstraint)); cc = palloc0(sizeof(ChunkConstraint));
memcpy(&cc->fd, fd, sizeof(FormData_chunk_constraint)); memcpy(&cc->fd, fd, sizeof(FormData_chunk_constraint));
return cc; return cc;
@ -103,14 +104,18 @@ chunk_constraint_dimension_id_tuple_found(TupleInfo *ti, void *data)
{ {
chunk = chunk_create_stub(constraint.fd.chunk_id, ctx->num_dimensions); chunk = chunk_create_stub(constraint.fd.chunk_id, ctx->num_dimensions);
entry->chunk = chunk; entry->chunk = chunk;
} else { }
else
{
chunk = entry->chunk; chunk = entry->chunk;
} }
chunk_add_constraint(chunk, &constraint); chunk_add_constraint(chunk, &constraint);
/* If the chunk has N constraints, it is the chunk we are looking for and /*
* can abort the scan */ * If the chunk has N constraints, it is the chunk we are looking for and
* can abort the scan
*/
if (chunk->num_constraints == ctx->num_dimensions) if (chunk->num_constraints == ctx->num_dimensions)
return false; return false;

View File

@ -38,6 +38,7 @@ static Hyperspace *
hyperspace_create(int32 hypertable_id, Oid main_table_relid, uint16 num_dimensions) hyperspace_create(int32 hypertable_id, Oid main_table_relid, uint16 num_dimensions)
{ {
Hyperspace *hs = palloc0(HYPERSPACE_SIZE(num_dimensions)); Hyperspace *hs = palloc0(HYPERSPACE_SIZE(num_dimensions));
hs->hypertable_id = hypertable_id; hs->hypertable_id = hypertable_id;
hs->main_table_relid = main_table_relid; hs->main_table_relid = main_table_relid;
hs->capacity = num_dimensions; hs->capacity = num_dimensions;
@ -93,6 +94,7 @@ static Point *
point_create(int16 num_dimensions) point_create(int16 num_dimensions)
{ {
Point *p = palloc0(POINT_SIZE(num_dimensions)); Point *p = palloc0(POINT_SIZE(num_dimensions));
p->cardinality = num_dimensions; p->cardinality = num_dimensions;
p->num_closed = p->num_open = 0; p->num_closed = p->num_open = 0;
return p; return p;
@ -102,7 +104,8 @@ const char *
point_to_string(Point *p) point_to_string(Point *p)
{ {
char *buf = palloc(100); char *buf = palloc(100);
int i, j = 1; int i,
j = 1;
buf[0] = '('; buf[0] = '(';

View File

@ -15,6 +15,7 @@ static inline DimensionSlice *
dimension_slice_from_form_data(Form_dimension_slice fd) dimension_slice_from_form_data(Form_dimension_slice fd)
{ {
DimensionSlice *ds; DimensionSlice *ds;
ds = palloc0(sizeof(DimensionSlice)); ds = palloc0(sizeof(DimensionSlice));
memcpy(&ds->fd, fd, sizeof(FormData_dimension_slice)); memcpy(&ds->fd, fd, sizeof(FormData_dimension_slice));
ds->storage_free = NULL; ds->storage_free = NULL;
@ -32,6 +33,7 @@ static inline Hypercube *
hypercube_alloc(int16 num_dimensions) hypercube_alloc(int16 num_dimensions)
{ {
Hypercube *hc = palloc0(HYPERCUBE_SIZE(num_dimensions)); Hypercube *hc = palloc0(HYPERCUBE_SIZE(num_dimensions));
hc->capacity = num_dimensions; hc->capacity = num_dimensions;
return hc; return hc;
} }
@ -68,6 +70,7 @@ dimension_vec_tuple_found(TupleInfo *ti, void *data)
{ {
DimensionVec **vecptr = data; DimensionVec **vecptr = data;
DimensionSlice *slice = dimension_slice_from_tuple(ti->tuple); DimensionSlice *slice = dimension_slice_from_tuple(ti->tuple);
dimension_vec_add_slice(vecptr, slice); dimension_vec_add_slice(vecptr, slice);
return true; return true;
} }
@ -90,8 +93,10 @@ dimension_slice_scan(int32 dimension_id, int64 coordinate)
.scandirection = ForwardScanDirection, .scandirection = ForwardScanDirection,
}; };
/* Perform an index scan for slice matching the dimension's ID and which /*
* encloses the coordinate */ * Perform an index scan for slice matching the dimension's ID and which
* encloses the coordinate
*/
ScanKeyInit(&scankey[0], Anum_dimension_slice_dimension_id_range_start_range_end_idx_dimension_id, ScanKeyInit(&scankey[0], Anum_dimension_slice_dimension_id_range_start_range_end_idx_dimension_id,
BTEqualStrategyNumber, F_INT4EQ, Int32GetDatum(dimension_id)); BTEqualStrategyNumber, F_INT4EQ, Int32GetDatum(dimension_id));
ScanKeyInit(&scankey[1], Anum_dimension_slice_dimension_id_range_start_range_end_idx_range_start, ScanKeyInit(&scankey[1], Anum_dimension_slice_dimension_id_range_start_range_end_idx_range_start,
@ -108,6 +113,7 @@ static bool
dimension_slice_tuple_found(TupleInfo *ti, void *data) dimension_slice_tuple_found(TupleInfo *ti, void *data)
{ {
DimensionSlice **slice = data; DimensionSlice **slice = data;
*slice = dimension_slice_from_tuple(ti->tuple); *slice = dimension_slice_from_tuple(ti->tuple);
return false; return false;
} }
@ -141,6 +147,7 @@ DimensionSlice *
dimension_slice_copy(const DimensionSlice *original) dimension_slice_copy(const DimensionSlice *original)
{ {
DimensionSlice *new = palloc(sizeof(DimensionSlice)); DimensionSlice *new = palloc(sizeof(DimensionSlice));
memcpy(new, original, sizeof(DimensionSlice)); memcpy(new, original, sizeof(DimensionSlice));
return new; return new;
} }
@ -174,6 +181,7 @@ hypercube_from_constraints(ChunkConstraint constraints[], int16 num_constraints)
for (i = 0; i < num_constraints; i++) for (i = 0; i < num_constraints; i++)
{ {
DimensionSlice *slice = dimension_slice_scan_by_id(constraints[i].fd.dimension_slice_id); DimensionSlice *slice = dimension_slice_scan_by_id(constraints[i].fd.dimension_slice_id);
Assert(slice != NULL); Assert(slice != NULL);
hc->slices[hc->num_slices++] = slice; hc->slices[hc->num_slices++] = slice;
} }
@ -182,7 +190,8 @@ hypercube_from_constraints(ChunkConstraint constraints[], int16 num_constraints)
return hc; return hc;
} }
void dimension_slice_free(DimensionSlice *slice) void
dimension_slice_free(DimensionSlice *slice)
{ {
if (slice->storage_free != NULL) if (slice->storage_free != NULL)
slice->storage_free(slice->storage); slice->storage_free(slice->storage);
@ -247,6 +256,7 @@ DimensionVec *
dimension_vec_create(int32 initial_num_slices) dimension_vec_create(int32 initial_num_slices)
{ {
DimensionVec *vec = dimension_vec_expand(NULL, initial_num_slices); DimensionVec *vec = dimension_vec_expand(NULL, initial_num_slices);
vec->capacity = initial_num_slices; vec->capacity = initial_num_slices;
vec->num_slices = 0; vec->num_slices = 0;
return vec; return vec;
@ -269,6 +279,7 @@ DimensionVec *
dimension_vec_add_slice_sort(DimensionVec **vecptr, DimensionSlice *slice) dimension_vec_add_slice_sort(DimensionVec **vecptr, DimensionSlice *slice)
{ {
DimensionVec *vec = *vecptr; DimensionVec *vec = *vecptr;
*vecptr = vec = dimension_vec_add_slice(vecptr, slice); *vecptr = vec = dimension_vec_add_slice(vecptr, slice);
qsort(vec->slices, vec->num_slices, sizeof(DimensionSlice *), cmp_slices); qsort(vec->slices, vec->num_slices, sizeof(DimensionSlice *), cmp_slices);
return vec; return vec;
@ -279,13 +290,15 @@ dimension_vec_find_slice(DimensionVec *vec, int64 coordinate)
{ {
DimensionSlice **res = bsearch(&coordinate, vec->slices, vec->num_slices, DimensionSlice **res = bsearch(&coordinate, vec->slices, vec->num_slices,
sizeof(DimensionSlice *), cmp_coordinate_and_slice); sizeof(DimensionSlice *), cmp_coordinate_and_slice);
if (res == NULL) if (res == NULL)
return NULL; return NULL;
return *res; return *res;
} }
void dimension_vec_free(DimensionVec *vec) void
dimension_vec_free(DimensionVec *vec)
{ {
int i; int i;

View File

@ -13,7 +13,8 @@ typedef struct DimensionSlice
FormData_dimension_slice fd; FormData_dimension_slice fd;
DimensionType type; DimensionType type;
void (*storage_free) (void *); void (*storage_free) (void *);
void *storage; //used in the cache void *storage;
//used in the cache
} DimensionSlice; } DimensionSlice;
/* /*
@ -23,7 +24,8 @@ typedef struct DimensionSlice
typedef struct Hypercube typedef struct Hypercube
{ {
int16 capacity; /* capacity of slices[] */ int16 capacity; /* capacity of slices[] */
int16 num_slices; /* actual number of slices (should equal num_dimensions after create) */ int16 num_slices; /* actual number of slices (should equal
* num_dimensions after create) */
/* Open slices are stored before closed slices */ /* Open slices are stored before closed slices */
DimensionSlice *slices[0]; DimensionSlice *slices[0];
} Hypercube; } Hypercube;
@ -38,7 +40,8 @@ typedef struct Hypercube
typedef struct DimensionVec typedef struct DimensionVec
{ {
int32 capacity; /* The capacity of the slices array */ int32 capacity; /* The capacity of the slices array */
int32 num_slices; /* The current number of slices in slices array */ int32 num_slices; /* The current number of slices in slices
* array */
DimensionSlice *slices[0]; DimensionSlice *slices[0];
} DimensionVec; } DimensionVec;

View File

@ -26,7 +26,8 @@ hypertable_from_tuple(HeapTuple tuple)
return h; return h;
} }
Chunk *hypertable_get_chunk(Hypertable *h, Point *point) Chunk *
hypertable_get_chunk(Hypertable *h, Point *point)
{ {
Chunk *chunk = subspace_store_get(h->chunk_cache, point); Chunk *chunk = subspace_store_get(h->chunk_cache, point);
@ -35,8 +36,8 @@ Chunk *hypertable_get_chunk(Hypertable *h, Point *point)
MemoryContext old; MemoryContext old;
/* /*
chunk_find() must execute on the transaction memory context since it * chunk_find() must execute on the transaction memory context since
allocates a lot of transient data. * it allocates a lot of transient data.
*/ */
chunk = chunk_find(h->space, point); chunk = chunk_find(h->space, point);

View File

@ -78,6 +78,7 @@ static bool
hypertable_tuple_found(TupleInfo *ti, void *data) hypertable_tuple_found(TupleInfo *ti, void *data)
{ {
HypertableNameCacheEntry *entry = data; HypertableNameCacheEntry *entry = data;
entry->hypertable = hypertable_from_tuple(ti->tuple); entry->hypertable = hypertable_from_tuple(ti->tuple);
return false; return false;
} }

View File

@ -155,6 +155,7 @@ insert_chunk_state_destroy(InsertChunkState *state)
foreach(lc, state->replica_states) foreach(lc, state->replica_states)
{ {
InsertChunkStateRel *rel_state = lfirst(lc); InsertChunkStateRel *rel_state = lfirst(lc);
insert_chunk_state_rel_destroy(rel_state); insert_chunk_state_rel_destroy(rel_state);
} }
} }
@ -167,6 +168,7 @@ insert_chunk_state_insert_tuple(InsertChunkState *state, HeapTuple tup)
foreach(lc, state->replica_states) foreach(lc, state->replica_states)
{ {
InsertChunkStateRel *rel_state = lfirst(lc); InsertChunkStateRel *rel_state = lfirst(lc);
insert_chunk_state_rel_insert_tuple(rel_state, tup); insert_chunk_state_rel_insert_tuple(rel_state, tup);
} }
} }

View File

@ -50,9 +50,11 @@ insert_statement_state_destroy(InsertStatementState *state)
MemoryContextDelete(state->mctx); MemoryContextDelete(state->mctx);
} }
static void destroy_insert_chunk_state(void *ics_ptr) static void
destroy_insert_chunk_state(void *ics_ptr)
{ {
InsertChunkState *ics = ics_ptr; InsertChunkState *ics = ics_ptr;
insert_chunk_state_destroy(ics); insert_chunk_state_destroy(ics);
} }

View File

@ -66,7 +66,8 @@ DEFINE_PLAN(create_chunk_plan, CHUNK_CREATE, 2, CHUNK_CREATE_ARGS)
static HeapTuple static HeapTuple
chunk_tuple_create_spi_connected(Hyperspace *hs, Point *p, SPIPlanPtr plan) chunk_tuple_create_spi_connected(Hyperspace *hs, Point *p, SPIPlanPtr plan)
{ {
int i, ret; int i,
ret;
HeapTuple tuple; HeapTuple tuple;
Datum dimension_ids[HYPERSPACE_NUM_DIMENSIONS(hs)]; Datum dimension_ids[HYPERSPACE_NUM_DIMENSIONS(hs)];
Datum dimension_values[HYPERSPACE_NUM_DIMENSIONS(hs)]; Datum dimension_values[HYPERSPACE_NUM_DIMENSIONS(hs)];
@ -99,7 +100,8 @@ spi_chunk_create(Hyperspace *hs, Point *p)
{ {
HeapTuple tuple; HeapTuple tuple;
Chunk *chunk; Chunk *chunk;
MemoryContext old, top = CurrentMemoryContext; MemoryContext old,
top = CurrentMemoryContext;
SPIPlanPtr plan = create_chunk_plan(); SPIPlanPtr plan = create_chunk_plan();
if (SPI_connect() < 0) if (SPI_connect() < 0)

View File

@ -200,8 +200,7 @@ add_partitioning_func_qual_mutator(Node *node, AddPartFuncQualCtx *context)
/* /*
* Detect partitioning_column = const. If not fall-thru. If detected, * Detect partitioning_column = const. If not fall-thru. If detected,
* replace with partitioning_column = const AND * replace with partitioning_column = const AND
* partitioning_func(partition_column) = * partitioning_func(partition_column) = partitioning_func(const)
* partitioning_func(const)
*/ */
if (IsA(node, OpExpr)) if (IsA(node, OpExpr))
{ {

View File

@ -4,7 +4,8 @@
#include "dimension_slice.h" #include "dimension_slice.h"
#include "subspace_store.h" #include "subspace_store.h"
typedef struct SubspaceStore { typedef struct SubspaceStore
{
MemoryContext mcxt; MemoryContext mcxt;
int16 num_dimensions; int16 num_dimensions;
DimensionVec *origin; /* origin of the tree */ DimensionVec *origin; /* origin of the tree */
@ -21,6 +22,7 @@ subspace_store_init(int16 num_dimensions, MemoryContext mcxt)
{ {
MemoryContext old = MemoryContextSwitchTo(mcxt); MemoryContext old = MemoryContextSwitchTo(mcxt);
SubspaceStore *sst = palloc(sizeof(SubspaceStore)); SubspaceStore *sst = palloc(sizeof(SubspaceStore));
sst->origin = subspace_store_dimension_create(); sst->origin = subspace_store_dimension_create();
sst->num_dimensions = num_dimensions; sst->num_dimensions = num_dimensions;
sst->mcxt = mcxt; sst->mcxt = mcxt;
@ -34,7 +36,8 @@ subspace_store_free_internal_node(void * node)
dimension_vec_free((DimensionVec *) node); dimension_vec_free((DimensionVec *) node);
} }
void subspace_store_add(SubspaceStore *cache, const Hypercube *hc, void
subspace_store_add(SubspaceStore *cache, const Hypercube *hc,
void *end_store, void (*end_store_free) (void *)) void *end_store, void (*end_store_free) (void *))
{ {
DimensionVec **vecptr = &cache->origin; DimensionVec **vecptr = &cache->origin;
@ -69,6 +72,7 @@ void subspace_store_add(SubspaceStore *cache, const Hypercube *hc,
if (match == NULL) if (match == NULL)
{ {
DimensionSlice *copy = dimension_slice_copy(target); DimensionSlice *copy = dimension_slice_copy(target);
dimension_vec_add_slice_sort(vecptr, copy); dimension_vec_add_slice_sort(vecptr, copy);
match = copy; match = copy;
} }
@ -112,7 +116,8 @@ subspace_store_free(SubspaceStore *cache)
pfree(cache); pfree(cache);
} }
MemoryContext subspace_store_mcxt(SubspaceStore *cache) MemoryContext
subspace_store_mcxt(SubspaceStore *cache)
{ {
return cache->mcxt; return cache->mcxt;
} }