Skip to content

Commit 3a0781f

Browse files
authored
Merge pull request #22 from mbakli/develop
Improved query planning
2 parents 01c22b1 + 4e98040 commit 3a0781f

42 files changed

Lines changed: 778 additions & 130 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 129 additions & 85 deletions
Large diffs are not rendered by default.

include/catalog/nodes.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@
1717
#include "postgres.h"
1818
#include "executor/executor_tasks.h"
1919

20+
/* Name of the database the current backend is connected to. */
2021
extern Datum GetDBName();
22+
23+
/* Coordinator/worker node info (host, port, role) for the local backend. */
2124
extern TaskNode *GetNodeInfo();
25+
26+
/* Table id of the tile assigned to a randomly-picked worker for relationId. */
2227
extern char* GetRandomTileId(Oid relationId, ExecTaskType taskType, int rand_tile);
28+
29+
/* Looks up the tiling method used to distribute relationId; -1 if not distributed. */
2330
extern int TilingSearch(Oid relationId);
31+
32+
/* Number of tiles the given distributed relation was split into. */
2433
extern int GetNumTiles(Oid relationId);
2534
#endif /* NODESS_H */

include/catalog/pg_dist_spatiotemporal_dist_functions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
/* ----------------
1919
* pg_dist_spatiotemporal_dist_functions: Compiler constants
20+
*
21+
* Catalog table that maps a distributable aggregate/function (id) to the
22+
* three-phase function set used to run it across the cluster: the
23+
* per-tile `worker` function, the `combiner` that merges partial results,
24+
* and the `final` function that produces the end result. `sexec_id` ties
25+
* the row to the pg_execution_run entry for the query that registered it.
2026
* ----------------
2127
*/
2228

include/catalog/pg_dist_spatiotemporal_tables.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
/* ----------------
1919
* pg_dist_spatiotemporal_tables: Compiler constants
20+
*
21+
* Catalog table holding one row per table that has been distributed via
22+
* create_spatiotemporal_distributed_table(). Records the source relation
23+
* (tbloid/tablename), how it was tiled (numtiles, tilingmethod,
24+
* tilingtype, granularity, disjoint, tilekey), and which column drives
25+
* the distribution (distcol/distcoltype/ismobilitydb/shapesegmented/srid).
2026
* ----------------
2127
*/
2228

include/catalog/pg_dist_spatiotemporal_tiles.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
/* ----------------
1919
* pg_dist_spatiotemporal_tiles: Compiler constants
20+
*
21+
* Catalog table with one row per tile produced for a distributed table
22+
* (table_id references pg_dist_spatiotemporal_tables). Stores the tile's
23+
* key and its bounding boxes in both MobilityDB (mobdb_bbox) and PostGIS
24+
* (postgis_bbox) representations, plus per-tile cardinality used by the
25+
* planner for load balancing (num_shapes, num_points).
2026
* ----------------
2127
*/
2228

include/catalog/pg_execution_run.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
/* ----------------
1919
* pg_execution_run: Compiler constants
20+
*
21+
* Catalog table that assigns a unique execution id (id) to each
22+
* distributed query run, paired with its serialized executor state
23+
* (sexec) so distributed_functions rows can be traced back to the run
24+
* that produced them.
2025
* ----------------
2126
*/
2227

include/catalog/table_ops.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,32 @@
1717

1818
#include "postgres.h"
1919

20-
21-
2220
/* constants for columnar.options */
2321
#define Anum_pg_spatiotemporal_join_operations_oid 3
2422
#define Anum_pg_spatiotemporal_join_operations_distance 4
2523

24+
/* Full pg_dist_spatiotemporal_tables row for relationId, as a Datum array. */
2625
extern Datum * GetDistributedTableMetadata(Oid relationId);
26+
27+
/* True if relationId's tiles have been rebalanced/reshuffled since creation. */
2728
extern bool IsReshuffledTable(Oid relationId);
29+
30+
/* PostgreSQL type oid of the column driving relationId's distribution. */
2831
extern int DistributedColumnType(Oid relationId);
32+
33+
/* Name of the spatiotemporal (MobilityDB) column used to distribute relationId. */
2934
extern char * GetSpatiotemporalCol(Oid relationId);
35+
36+
/* Serialized global (cross-tile) index metadata for relid. */
3037
extern char * GetGlobalIndexInfo(Oid relid);
38+
39+
/* Resolves a relation oid from its (possibly schema-qualified) name. */
3140
extern Oid RelationId(const char *relationName);
41+
42+
/* True if relationId is registered in pg_dist_spatiotemporal_tables. */
3243
extern bool IsDistributedSpatiotemporalTable(Oid relationId);
44+
45+
/* Name of the geometry/shape column used to distribute relationId. */
3346
char *GetShapeCol(Oid relationId);
3447

3548
#endif /* TABLE_OPS_H */

include/distributed_functions/coordinator_operations.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
#ifndef COORDINATOR_OPERATIONS_H
1616
#define COORDINATOR_OPERATIONS_H
1717

18+
/*
19+
* CoordinatorOperation
20+
*
21+
* The coordinator-side half of a distributed aggregate/expression: the
22+
* `intermediate_op` combines the per-tile results collected from the
23+
* workers, and `final_op` transforms that combined result into the value
24+
* returned to the client.
25+
*/
1826
typedef struct CoordinatorOperation
1927
{
2028
Datum intermediate_op;

include/distributed_functions/distributed_function.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,41 @@
2626
#define Anum_DistFun_combiner 3
2727
#define Anum_DistFun_final 4
2828

29-
29+
/*
30+
* QOperation
31+
*
32+
* A single query operation (e.g. an aggregate call) being rewritten for
33+
* distributed execution: `op` is the operation's Datum representation,
34+
* `col` the column/argument it applies to, and `alias` the output alias
35+
* it must be projected under in the rewritten targetlist.
36+
*/
3037
typedef struct QOperation
3138
{
3239
Datum op;
3340
Alias *alias;
3441
Datum col;
3542
} QOperation;
3643

44+
/*
45+
* DistributedFunction
46+
*
47+
* Binds a query targetlist entry to the worker/coordinator function pair
48+
* (looked up via pg_dist_spatiotemporal_dist_functions) that implements it
49+
* across the distributed plan.
50+
*/
3751
typedef struct DistributedFunction
3852
{
3953
CoordinatorOperation *coordinatorOp;
4054
WorkerOperation *workerOp;
4155
TargetEntry *targetEntry;
4256
} DistributedFunction;
4357

58+
/* Resolves and attaches the worker/coordinator functions for a targetlist entry. */
4459
extern DistributedFunction *addDistributedFunction(TargetEntry *operation);
60+
61+
/* True if targetEntry's expression is a registered distributable function. */
4562
extern bool IsDistFunc(TargetEntry *targetEntry);
63+
64+
/* Builds a QOperation pairing a distributed op (des) with its argument column (cur). */
4665
extern QOperation * AddQOperation(Datum des, Datum cur);
4766
#endif /* DISTRIBUTED_FUNCTION_H */

include/distributed_functions/worker_operations.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
#ifndef WORKER_OPERATIONS_H
1616
#define WORKER_OPERATIONS_H
1717

18+
/*
19+
* WorkerOperation
20+
*
21+
* The worker-side half of a distributed aggregate/expression: `op` is the
22+
* per-tile computation run on each worker before its partial result is
23+
* shipped back to the coordinator for combination (see CoordinatorOperation).
24+
*/
1825
typedef struct WorkerOperation
1926
{
2027
Datum op;

0 commit comments

Comments
 (0)