-
Notifications
You must be signed in to change notification settings - Fork 3
/
queries.proto
104 lines (90 loc) · 2.9 KB
/
queries.proto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
message SelectQuery {
required PlanNode plan = 1;
repeated RangeTable rtable = 2; // All the tables involved in the query
}
message RangeTable {
/*
* RangeTblEntry. For now this only references relations however RangeTblEntrys
* can also reference CTEs, constant values, subqueries, etc. They can also
* contain sampling info.
*/
required string name = 1;
}
message PlanNode {
repeated Expression target = 1; // projection, the cols which are returned
optional Expression qual = 2; // selection, the rows which are returned
oneof kind {
SequenceScan sscan = 3;
JoinNode join = 4;
Materialize materialize = 5;
SortNode sort = 6; // nb, if you use sort neither target nor qual are allowed
}
}
message SequenceScan {
required uint32 table = 1; // The index of the RangeTable to scan
}
/* saves rows from the subplan as they are requested, allowing for quick rescanning */
message Materialize {
required PlanNode plan = 1;
}
message JoinNode {
enum Kind {
HASH = 0; // Builds a hash table out of right and scans it for every row in left
MERGE = 1; // Sorts left and right on the join column then scans both
NESTED = 2; // Materializes right and scans it for every iteration
}
enum Type {
INNER = 0; // for every row in left, return it with every matching row of right
LEFT = 1; // inner join but also include rows which don't match any rows from right
FULL = 2; // inner join, but with all the extra results LEFT and RIGHT would add
RIGHT = 3; // left join but for every row of right
SEMI = 4; // returns left if a matching row exists in right
ANTI = 5; // returns left if no matching rows exist in right
}
required Kind kind = 1;
required Type type = 2; // not all types are supported for every kind
/*
* joinqual decides which rows match, which rows should be filled with NULLs
* qual (in the plan containing this JoinNode) chooses which of the joined rows to keep
*/
required Expression joinqual = 3;
required PlanNode left = 4; // the outer table
required PlanNode right = 5; // the inner table
}
message SortNode {
message SortCol {
required uint32 target = 1;
required bool ascending = 2;
}
repeated SortCol col = 1;
required PlanNode subplan = 2;
}
message Expression {
message ColumnRef { // Represents a Var
required uint32 table = 1; // The index of the RangeTable
required string column = 2; // The name of the attribute
}
message LeftRef {
required uint32 target = 1;
}
message RightRef {
required uint32 target = 2;
}
message Operation {
required string name = 1;
repeated Expression arg = 2;
}
message Constant {
oneof type {
uint32 uint = 1;
bool bool = 2;
}
}
oneof expr {
ColumnRef var = 1;
LeftRef leftRef = 2;
RightRef rightRef = 3;
Operation op = 4;
Constant const = 5;
}
}