@@ -21,7 +21,7 @@ public class QueryPlanner {
21
21
private QueryIndexer indexer ;
22
22
private List <PlanTable > planTables = new ArrayList <>();
23
23
24
- private List <String > nodes = new ArrayList <>();
24
+ private Set <String > nodes = new HashSet <>();
25
25
private List <RelationEdge > edges = new ArrayList <>();
26
26
27
27
public QueryPlanner (Map <String , QueryConstraints > varToConstraint ,
@@ -64,9 +64,27 @@ private void constructLeafPlan() {
64
64
//TODO: Change this to selecting the optimal plan.
65
65
// Just pick the first and use others as filters.
66
66
QueryConstraints constraints = varToConstraint .get (node );
67
- Constraint constraint = constraints .getConstraints ().get (0 );
67
+ List <Constraint > constraintsList = new ArrayList <>();
68
+ for (Constraint constraint : constraints .getConstraints ()){
69
+ if (constraint .name .contains ("id" )){
70
+ constraintsList .add (constraint );
71
+ }
72
+ }
73
+ for (Constraint constraint : constraints .getConstraints ()){
74
+ if (constraint .name .contains ("nodeLabels" )){
75
+ constraintsList .add (constraint );
76
+ }
77
+ }
78
+ for (Constraint constraint : constraints .getConstraints ()){
79
+ if (!constraint .name .contains ("id" ) && !constraint .name .contains ("nodeLabels" )){
80
+ constraintsList .add (constraint );
81
+ }
82
+ }
83
+ Constraint constraint = constraintsList .get (0 );
84
+
68
85
switch (constraint .name ) {
69
86
case "nodeLabels" :
87
+ assert constraint .value .type .contains ("List" );
70
88
List <String > labels = ((List <String >) constraint .value .val );
71
89
ScanByLabelPlan scanByLabelPlan = new ScanByLabelPlan (indexer , node , labels );
72
90
scanByLabelPlan .applyTo (table );
@@ -87,8 +105,8 @@ private void constructLeafPlan() {
87
105
break ;
88
106
}
89
107
90
- for (int i = 1 , size = constraints . getConstraints () .size (); i < size ; i ++) {
91
- Constraint cons = constraints . getConstraints () .get (i );
108
+ for (int i = 1 , size = constraintsList .size (); i < size ; i ++) {
109
+ Constraint cons = constraintsList .get (i );
92
110
FilterConstraintPlan filterConstraintPlan = new FilterConstraintPlan (indexer , node , cons , table );
93
111
filterConstraintPlan .applyTo (table );
94
112
}
@@ -102,7 +120,7 @@ private void constructLeafPlan() {
102
120
103
121
private List <PlanTable > candidates = new ArrayList <>();
104
122
public void plan () {
105
-
123
+ System . out . println ( "Generating Plan..." );
106
124
init ();
107
125
108
126
// Find start point
@@ -139,7 +157,11 @@ public void plan() {
139
157
planTables .removeIf (table -> covers (best , table ));
140
158
141
159
planTables .add (best );
142
- removeRelated (best .plans .get (best .plans .size () - 1 ));
160
+
161
+ for (Plan plan : best .plans ){
162
+ removeRelated (plan );
163
+ }
164
+
143
165
144
166
145
167
}while (candidates .size () > 0 );
@@ -153,13 +175,30 @@ public void plan() {
153
175
private void removeRelated (Plan plan ){
154
176
if (plan instanceof ExpandAllPlan || plan instanceof ExpandIntoPlan ){
155
177
for (RelationEdge edge : edges ){
156
- if (edge .name .equals (plan .getParams ())){
157
- edge .used = true ;
178
+ if (plan instanceof ExpandAllPlan ){
179
+ String name = ((ExpandAllPlan ) plan ).getRelationEdge ().name ;
180
+ if (edge .name .equals (name )){
181
+ edge .used = true ;
182
+ break ;
183
+ }
184
+ }
185
+
186
+ if (plan instanceof ExpandIntoPlan ){
187
+ String name = ((ExpandIntoPlan ) plan ).getRelationEdge ().name ;
188
+ if (edge .name .equals (name )){
189
+ edge .used = true ;
190
+ break ;
191
+ }
158
192
}
159
193
}
160
194
}else if (plan instanceof NodeHashJoinPlan ||
161
195
plan instanceof FilterRelationEqualityPlan ){
162
- equalityList .removeAll (((NodeHashJoinPlan ) plan ).getEquality ());
196
+ if (plan instanceof NodeHashJoinPlan ){
197
+ equalityList .removeAll (((NodeHashJoinPlan ) plan ).getEquality ());
198
+ }else {
199
+ equalityList .removeAll (((FilterRelationEqualityPlan ) plan ).getEquality ());
200
+ }
201
+
163
202
}
164
203
165
204
}
@@ -245,8 +284,9 @@ private void constructExpand(PlanTable table){
245
284
}
246
285
PlanTable newTable ;
247
286
if (table .nodes .contains (edge .start ) && table .nodes .contains (edge .end )){
287
+ QueryConstraints constraints = varToConstraint .get (edge .name );
248
288
ExpandIntoPlan plan = new ExpandIntoPlan (indexer ,edge ,
249
- varToConstraint . get ( edge . name ) ,
289
+ constraints ,
250
290
table );
251
291
newTable = new PlanTable (table );
252
292
plan .applyTo (newTable );
@@ -259,6 +299,13 @@ private void constructExpand(PlanTable table){
259
299
newTable = new PlanTable (table );
260
300
plan .applyTo (newTable );
261
301
newTable = addAdditionalFilter (newTable );
302
+ String addedNode = plan .getExpandedNode ();
303
+ if (varToConstraint .get (addedNode ).getConstraints ().size () > 0 ){
304
+ for (Constraint constraint : varToConstraint .get (addedNode ).getConstraints ()){
305
+ FilterConstraintPlan plan1 = new FilterConstraintPlan (indexer , addedNode , constraint , newTable );
306
+ plan1 .applyTo (newTable );
307
+ }
308
+ }
262
309
candidates .add (newTable );
263
310
}
264
311
0 commit comments