feophantlib/engine/objects/
query_tree.rs

1//! Is the result of the parse tree post validation
2//! See here: https://www.postgresql.org/docs/current/querytree.html
3use super::types::SqlTypeDefinition;
4use super::SqlTuple;
5use super::Table;
6use std::sync::Arc;
7
8//Note the comments below are based on my current understanding of how Postgres works,
9//I'm sure these comments will age poorly
10//
11//Its important to note that postgres heavily uses references in these structs I'm not sure
12//if that makes sense in Rust. My focus is understanding the data relationships.
13#[derive(Clone, Debug)]
14pub struct QueryTree {
15    //the command type
16    pub command_type: CommandType,
17
18    //the target list of columns to be affected
19    pub targets: Arc<SqlTypeDefinition>,
20
21    //These are tables being used as inputs for the query.
22    //They could be a table, view, static data, or even a sub query.
23    //How to represent some of this is TBD
24    pub range_tables: Vec<RangeRelation>,
25
26    //the qualification - Don't really understand this yet
27    //pub qualification: Vec<WhereEntry>,
28
29    //the join tree is to relate entries in the range tables to each other
30    pub joins: Vec<(JoinType, RangeRelation, RangeRelation)>,
31    //the others
32    //pub sorts: Vec<(SortType, TargetEntry)>,
33}
34
35#[derive(Clone, Copy, Debug)]
36pub enum CommandType {
37    Select,
38    Insert,
39    Update,
40    Delete,
41    Utility,
42}
43
44#[derive(Clone, Debug)]
45pub enum RangeRelation {
46    Table(RangeRelationTable),
47    //View(RangeRelationTable),
48    //SubQuery(Option<QueryTree>),
49    AnonymousTable(Arc<Vec<SqlTuple>>), //Used for inserts
50}
51
52#[derive(Clone, Debug)]
53pub struct RangeRelationTable {
54    pub table: Arc<Table>,
55    pub alias: Option<String>,
56}
57
58//Every entry in the target list contains an expression that can be a
59//constant value, a variable pointing to a column of one of the
60//relations in the range table, a parameter, or an expression tree
61//made of function calls, constants, variables, operators, etc.
62//#[derive(Clone, Debug)]
63//pub enum TargetEntry {
64//    Parameter(Attribute),
65//}
66
67#[derive(Clone, Debug)]
68pub enum WhereEntry {}
69
70#[derive(Clone, Copy, Debug)]
71pub enum JoinType {
72    Inner,
73    OuterLeft,
74    OuterRight,
75    OuterFull,
76}
77
78//#[derive(Clone, Copy, Debug)]
79//pub enum SortType {
80//    Ascending,
81//   Descending,
82//}