mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-17 11:03:36 +08:00
Run pgindent on code
This commit is contained in:
parent
9489d06595
commit
ce3d630b6d
14
src/chunk.c
14
src/chunk.c
@ -53,7 +53,8 @@ chunk_create_new(Hyperspace *hs, Point *p)
|
||||
}
|
||||
|
||||
Chunk *
|
||||
chunk_create_stub(int32 id, int16 num_constraints) {
|
||||
chunk_create_stub(int32 id, int16 num_constraints)
|
||||
{
|
||||
Chunk *chunk;
|
||||
|
||||
chunk = palloc0(CHUNK_SIZE(num_constraints));
|
||||
@ -68,6 +69,7 @@ static bool
|
||||
chunk_tuple_found(TupleInfo *ti, void *arg)
|
||||
{
|
||||
Chunk *chunk = arg;
|
||||
|
||||
chunk_fill(chunk, ti->tuple);
|
||||
return false;
|
||||
}
|
||||
@ -203,7 +205,8 @@ chunk_find(Hyperspace *hs, Point *p)
|
||||
Chunk *chunk;
|
||||
ChunkScanCtx ctx;
|
||||
int16 num_dimensions = HYPERSPACE_NUM_DIMENSIONS(hs);
|
||||
int i, j;
|
||||
int i,
|
||||
j;
|
||||
|
||||
/* The scan context will keep the state accumulated during the scan */
|
||||
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]);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,8 @@ typedef struct Chunk
|
||||
|
||||
/*
|
||||
* 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
|
||||
* table.
|
||||
* Each of the N slices in the cube corresponds to a constraint on the
|
||||
* chunk table.
|
||||
*/
|
||||
Hypercube *cube;
|
||||
int16 capacity;
|
||||
|
@ -10,6 +10,7 @@ static inline ChunkConstraint *
|
||||
chunk_constraint_from_form_data(Form_chunk_constraint fd)
|
||||
{
|
||||
ChunkConstraint *cc;
|
||||
|
||||
cc = palloc0(sizeof(ChunkConstraint));
|
||||
memcpy(&cc->fd, fd, sizeof(FormData_chunk_constraint));
|
||||
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);
|
||||
entry->chunk = chunk;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
chunk = entry->chunk;
|
||||
}
|
||||
|
||||
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)
|
||||
return false;
|
||||
|
||||
|
@ -38,6 +38,7 @@ static Hyperspace *
|
||||
hyperspace_create(int32 hypertable_id, Oid main_table_relid, uint16 num_dimensions)
|
||||
{
|
||||
Hyperspace *hs = palloc0(HYPERSPACE_SIZE(num_dimensions));
|
||||
|
||||
hs->hypertable_id = hypertable_id;
|
||||
hs->main_table_relid = main_table_relid;
|
||||
hs->capacity = num_dimensions;
|
||||
@ -93,6 +94,7 @@ static Point *
|
||||
point_create(int16 num_dimensions)
|
||||
{
|
||||
Point *p = palloc0(POINT_SIZE(num_dimensions));
|
||||
|
||||
p->cardinality = num_dimensions;
|
||||
p->num_closed = p->num_open = 0;
|
||||
return p;
|
||||
@ -102,7 +104,8 @@ const char *
|
||||
point_to_string(Point *p)
|
||||
{
|
||||
char *buf = palloc(100);
|
||||
int i, j = 1;
|
||||
int i,
|
||||
j = 1;
|
||||
|
||||
buf[0] = '(';
|
||||
|
||||
|
@ -15,6 +15,7 @@ static inline DimensionSlice *
|
||||
dimension_slice_from_form_data(Form_dimension_slice fd)
|
||||
{
|
||||
DimensionSlice *ds;
|
||||
|
||||
ds = palloc0(sizeof(DimensionSlice));
|
||||
memcpy(&ds->fd, fd, sizeof(FormData_dimension_slice));
|
||||
ds->storage_free = NULL;
|
||||
@ -32,6 +33,7 @@ static inline Hypercube *
|
||||
hypercube_alloc(int16 num_dimensions)
|
||||
{
|
||||
Hypercube *hc = palloc0(HYPERCUBE_SIZE(num_dimensions));
|
||||
|
||||
hc->capacity = num_dimensions;
|
||||
return hc;
|
||||
}
|
||||
@ -68,6 +70,7 @@ dimension_vec_tuple_found(TupleInfo *ti, void *data)
|
||||
{
|
||||
DimensionVec **vecptr = data;
|
||||
DimensionSlice *slice = dimension_slice_from_tuple(ti->tuple);
|
||||
|
||||
dimension_vec_add_slice(vecptr, slice);
|
||||
return true;
|
||||
}
|
||||
@ -90,8 +93,10 @@ dimension_slice_scan(int32 dimension_id, int64 coordinate)
|
||||
.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,
|
||||
BTEqualStrategyNumber, F_INT4EQ, Int32GetDatum(dimension_id));
|
||||
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)
|
||||
{
|
||||
DimensionSlice **slice = data;
|
||||
|
||||
*slice = dimension_slice_from_tuple(ti->tuple);
|
||||
return false;
|
||||
}
|
||||
@ -141,6 +147,7 @@ DimensionSlice *
|
||||
dimension_slice_copy(const DimensionSlice *original)
|
||||
{
|
||||
DimensionSlice *new = palloc(sizeof(DimensionSlice));
|
||||
|
||||
memcpy(new, original, sizeof(DimensionSlice));
|
||||
return new;
|
||||
}
|
||||
@ -174,6 +181,7 @@ hypercube_from_constraints(ChunkConstraint constraints[], int16 num_constraints)
|
||||
for (i = 0; i < num_constraints; i++)
|
||||
{
|
||||
DimensionSlice *slice = dimension_slice_scan_by_id(constraints[i].fd.dimension_slice_id);
|
||||
|
||||
Assert(slice != NULL);
|
||||
hc->slices[hc->num_slices++] = slice;
|
||||
}
|
||||
@ -182,7 +190,8 @@ hypercube_from_constraints(ChunkConstraint constraints[], int16 num_constraints)
|
||||
return hc;
|
||||
}
|
||||
|
||||
void dimension_slice_free(DimensionSlice *slice)
|
||||
void
|
||||
dimension_slice_free(DimensionSlice *slice)
|
||||
{
|
||||
if (slice->storage_free != NULL)
|
||||
slice->storage_free(slice->storage);
|
||||
@ -247,6 +256,7 @@ DimensionVec *
|
||||
dimension_vec_create(int32 initial_num_slices)
|
||||
{
|
||||
DimensionVec *vec = dimension_vec_expand(NULL, initial_num_slices);
|
||||
|
||||
vec->capacity = initial_num_slices;
|
||||
vec->num_slices = 0;
|
||||
return vec;
|
||||
@ -269,6 +279,7 @@ DimensionVec *
|
||||
dimension_vec_add_slice_sort(DimensionVec **vecptr, DimensionSlice *slice)
|
||||
{
|
||||
DimensionVec *vec = *vecptr;
|
||||
|
||||
*vecptr = vec = dimension_vec_add_slice(vecptr, slice);
|
||||
qsort(vec->slices, vec->num_slices, sizeof(DimensionSlice *), cmp_slices);
|
||||
return vec;
|
||||
@ -279,13 +290,15 @@ dimension_vec_find_slice(DimensionVec *vec, int64 coordinate)
|
||||
{
|
||||
DimensionSlice **res = bsearch(&coordinate, vec->slices, vec->num_slices,
|
||||
sizeof(DimensionSlice *), cmp_coordinate_and_slice);
|
||||
|
||||
if (res == NULL)
|
||||
return NULL;
|
||||
|
||||
return *res;
|
||||
}
|
||||
|
||||
void dimension_vec_free(DimensionVec *vec)
|
||||
void
|
||||
dimension_vec_free(DimensionVec *vec)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -13,7 +13,8 @@ typedef struct DimensionSlice
|
||||
FormData_dimension_slice fd;
|
||||
DimensionType type;
|
||||
void (*storage_free) (void *);
|
||||
void *storage; //used in the cache
|
||||
void *storage;
|
||||
//used in the cache
|
||||
} DimensionSlice;
|
||||
|
||||
/*
|
||||
@ -23,7 +24,8 @@ typedef struct DimensionSlice
|
||||
typedef struct Hypercube
|
||||
{
|
||||
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 */
|
||||
DimensionSlice *slices[0];
|
||||
} Hypercube;
|
||||
@ -38,7 +40,8 @@ typedef struct Hypercube
|
||||
typedef struct DimensionVec
|
||||
{
|
||||
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];
|
||||
} DimensionVec;
|
||||
|
||||
|
@ -26,7 +26,8 @@ hypertable_from_tuple(HeapTuple tuple)
|
||||
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);
|
||||
|
||||
@ -35,8 +36,8 @@ Chunk *hypertable_get_chunk(Hypertable *h, Point *point)
|
||||
MemoryContext old;
|
||||
|
||||
/*
|
||||
chunk_find() must execute on the transaction memory context since it
|
||||
allocates a lot of transient data.
|
||||
* chunk_find() must execute on the transaction memory context since
|
||||
* it allocates a lot of transient data.
|
||||
*/
|
||||
chunk = chunk_find(h->space, point);
|
||||
|
||||
|
@ -78,6 +78,7 @@ static bool
|
||||
hypertable_tuple_found(TupleInfo *ti, void *data)
|
||||
{
|
||||
HypertableNameCacheEntry *entry = data;
|
||||
|
||||
entry->hypertable = hypertable_from_tuple(ti->tuple);
|
||||
return false;
|
||||
}
|
||||
|
@ -155,6 +155,7 @@ insert_chunk_state_destroy(InsertChunkState *state)
|
||||
foreach(lc, state->replica_states)
|
||||
{
|
||||
InsertChunkStateRel *rel_state = lfirst(lc);
|
||||
|
||||
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)
|
||||
{
|
||||
InsertChunkStateRel *rel_state = lfirst(lc);
|
||||
|
||||
insert_chunk_state_rel_insert_tuple(rel_state, tup);
|
||||
}
|
||||
}
|
||||
|
@ -50,9 +50,11 @@ insert_statement_state_destroy(InsertStatementState *state)
|
||||
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;
|
||||
|
||||
insert_chunk_state_destroy(ics);
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,8 @@ DEFINE_PLAN(create_chunk_plan, CHUNK_CREATE, 2, CHUNK_CREATE_ARGS)
|
||||
static HeapTuple
|
||||
chunk_tuple_create_spi_connected(Hyperspace *hs, Point *p, SPIPlanPtr plan)
|
||||
{
|
||||
int i, ret;
|
||||
int i,
|
||||
ret;
|
||||
HeapTuple tuple;
|
||||
Datum dimension_ids[HYPERSPACE_NUM_DIMENSIONS(hs)];
|
||||
Datum dimension_values[HYPERSPACE_NUM_DIMENSIONS(hs)];
|
||||
@ -99,7 +100,8 @@ spi_chunk_create(Hyperspace *hs, Point *p)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
Chunk *chunk;
|
||||
MemoryContext old, top = CurrentMemoryContext;
|
||||
MemoryContext old,
|
||||
top = CurrentMemoryContext;
|
||||
SPIPlanPtr plan = create_chunk_plan();
|
||||
|
||||
if (SPI_connect() < 0)
|
||||
|
@ -200,8 +200,7 @@ add_partitioning_func_qual_mutator(Node *node, AddPartFuncQualCtx *context)
|
||||
/*
|
||||
* Detect partitioning_column = const. If not fall-thru. If detected,
|
||||
* replace with partitioning_column = const AND
|
||||
* partitioning_func(partition_column) =
|
||||
* partitioning_func(const)
|
||||
* partitioning_func(partition_column) = partitioning_func(const)
|
||||
*/
|
||||
if (IsA(node, OpExpr))
|
||||
{
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include "dimension_slice.h"
|
||||
#include "subspace_store.h"
|
||||
|
||||
typedef struct SubspaceStore {
|
||||
typedef struct SubspaceStore
|
||||
{
|
||||
MemoryContext mcxt;
|
||||
int16 num_dimensions;
|
||||
DimensionVec *origin; /* origin of the tree */
|
||||
@ -21,6 +22,7 @@ subspace_store_init(int16 num_dimensions, MemoryContext mcxt)
|
||||
{
|
||||
MemoryContext old = MemoryContextSwitchTo(mcxt);
|
||||
SubspaceStore *sst = palloc(sizeof(SubspaceStore));
|
||||
|
||||
sst->origin = subspace_store_dimension_create();
|
||||
sst->num_dimensions = num_dimensions;
|
||||
sst->mcxt = mcxt;
|
||||
@ -34,7 +36,8 @@ subspace_store_free_internal_node(void * 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 *))
|
||||
{
|
||||
DimensionVec **vecptr = &cache->origin;
|
||||
@ -69,6 +72,7 @@ void subspace_store_add(SubspaceStore *cache, const Hypercube *hc,
|
||||
if (match == NULL)
|
||||
{
|
||||
DimensionSlice *copy = dimension_slice_copy(target);
|
||||
|
||||
dimension_vec_add_slice_sort(vecptr, copy);
|
||||
match = copy;
|
||||
}
|
||||
@ -112,7 +116,8 @@ subspace_store_free(SubspaceStore *cache)
|
||||
pfree(cache);
|
||||
}
|
||||
|
||||
MemoryContext subspace_store_mcxt(SubspaceStore *cache)
|
||||
MemoryContext
|
||||
subspace_store_mcxt(SubspaceStore *cache)
|
||||
{
|
||||
return cache->mcxt;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user