|
| 1 | +# Internal Query Algebra |
| 2 | + |
| 3 | +This document defines the operators and structures for the internal query algebra of ArgusDB. This algebra represents the intermediate representation of queries that will be executed against the database. |
| 4 | + |
| 5 | +## Query Plan |
| 6 | + |
| 7 | +A query plan is a tree of operators. The execution engine evaluates this tree, typically starting from the leaves (data sources) and processing data up to the root. |
| 8 | + |
| 9 | +## Operators |
| 10 | + |
| 11 | +The following operators are defined: |
| 12 | + |
| 13 | +### 1. Scan |
| 14 | + |
| 15 | +* **Description**: Scans the database for documents. It produces a stream of documents. |
| 16 | +* **Parameters**: |
| 17 | + * `collection`: (Implicitly the whole DB for now, or filtered by some criteria if we add collections later). |
| 18 | +* **Output**: A stream of `(DocumentID, Document)` pairs. |
| 19 | + |
| 20 | +### 2. Project (Select) |
| 21 | + |
| 22 | +* **Description**: Transforms each document in the input stream by selecting a subset of fields or computing new fields. |
| 23 | +* **Parameters**: |
| 24 | + * `projections`: A list of expressions defining the output fields. |
| 25 | +* **Input**: A stream of documents. |
| 26 | +* **Output**: A stream of modified documents. |
| 27 | + |
| 28 | +### 3. Filter (Where) |
| 29 | + |
| 30 | +* **Description**: Filters the input stream, passing only documents that satisfy a predicate. |
| 31 | +* **Parameters**: |
| 32 | + * `predicate`: A boolean expression that is evaluated against each document. |
| 33 | +* **Input**: A stream of documents. |
| 34 | +* **Output**: A stream of documents satisfying the predicate. |
| 35 | + |
| 36 | +### 4. Limit |
| 37 | + |
| 38 | +* **Description**: Limits the number of documents returned. |
| 39 | +* **Parameters**: |
| 40 | + * `limit`: The maximum number of documents to return. |
| 41 | +* **Input**: A stream of documents. |
| 42 | +* **Output**: A stream of at most `limit` documents. |
| 43 | + |
| 44 | +### 5. Offset |
| 45 | + |
| 46 | +* **Description**: Skips a specified number of documents from the beginning of the stream. |
| 47 | +* **Parameters**: |
| 48 | + * `offset`: The number of documents to skip. |
| 49 | +* **Input**: A stream of documents. |
| 50 | +* **Output**: The input stream minus the first `offset` documents. |
| 51 | + |
| 52 | +## Expressions |
| 53 | + |
| 54 | +Operators like `Project` and `Filter` rely on expressions. |
| 55 | + |
| 56 | +* **FieldReference**: Refers to a field in the document (e.g., `a.b`). |
| 57 | +* **Literal**: A constant value (e.g., `1`, `"hello"`, `true`). |
| 58 | +* **BinaryExpression**: Combines two expressions with an operator (e.g., `a > 5`, `b == "test"`). |
| 59 | + * Supported operators: `=`, `!=`, `<`, `<=`, `>`, `>=`. |
| 60 | +* **LogicalExpression**: Combines boolean expressions. |
| 61 | + * Supported operators: `AND`, `OR`, `NOT`. |
| 62 | + |
| 63 | +## Execution Model |
| 64 | + |
| 65 | +The query engine will execute the plan by pulling data from the root operator. Each operator pulls data from its child, processes it, and returns it to its parent. This is a standard iterator (Volcano) model. |
0 commit comments