-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
RelSubset.java
759 lines (676 loc) · 23 KB
/
RelSubset.java
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.calcite.plan.volcano;
import org.apache.calcite.linq4j.Linq4j;
import org.apache.calcite.plan.RelOptCluster;
import org.apache.calcite.plan.RelOptCost;
import org.apache.calcite.plan.RelOptListener;
import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.plan.RelTrait;
import org.apache.calcite.plan.RelTraitSet;
import org.apache.calcite.plan.hep.HepRelVertex;
import org.apache.calcite.rel.AbstractRelNode;
import org.apache.calcite.rel.PhysicalNode;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.RelWriter;
import org.apache.calcite.rel.core.CorrelationId;
import org.apache.calcite.rel.externalize.RelWriterImpl;
import org.apache.calcite.rel.metadata.RelMetadataQuery;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.sql.SqlExplainLevel;
import org.apache.calcite.util.Pair;
import org.apache.calcite.util.Util;
import org.apache.calcite.util.trace.CalciteTrace;
import com.google.common.collect.Sets;
import org.apiguardian.api.API;
import org.checkerframework.checker.initialization.qual.UnderInitialization;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.apache.calcite.linq4j.Nullness.castNonNull;
import static java.util.Objects.requireNonNull;
/**
* Subset of an equivalence class where all relational expressions have the
* same physical properties.
*
* <p>Physical properties are instances of the {@link RelTraitSet}, and consist
* of traits such as calling convention and collation (sort-order).
*
* <p>For some traits, a relational expression can have more than one instance.
* For example, R can be sorted on both [X] and [Y, Z]. In which case, R would
* belong to the sub-sets for [X] and [Y, Z]; and also the leading edges [Y] and
* [].
*
* @see RelNode
* @see RelSet
* @see RelTrait
*/
public class RelSubset extends AbstractRelNode {
//~ Static fields/initializers ---------------------------------------------
private static final Logger LOGGER = CalciteTrace.getPlannerTracer();
private static final int DELIVERED = 1;
private static final int REQUIRED = 2;
//~ Instance fields --------------------------------------------------------
/** Optimization task state. */
@Nullable OptimizeState taskState;
/** Cost of best known plan (it may have improved since). */
RelOptCost bestCost;
/** The set this subset belongs to. */
final RelSet set;
/** Best known plan. */
@Nullable RelNode best;
/** Timestamp for metadata validity. */
long timestamp;
/**
* Physical property state of current subset. Values:
*
* <ul>
* <li>0: logical operators, NONE convention is neither DELIVERED nor REQUIRED
* <li>1: traitSet DELIVERED from child operators or itself
* <li>2: traitSet REQUIRED from parent operators
* <li>3: both DELIVERED and REQUIRED
* </ul>
*/
private int state = 0;
/**
* This subset should trigger rules when it becomes delivered.
*/
boolean triggerRule = false;
/**
* When the subset state is REQUIRED, whether enable property enforcing
* between this subset and other delivered subsets. When it is true,
* no enforcer operators will be added even if the other subset can't
* satisfy current subset's required traitSet.
*/
private boolean enforceDisabled = false;
/**
* The upper bound of the last OptimizeGroup call.
*/
RelOptCost upperBound;
/**
* A cache that recognize which RelNode has invoked the passThrough method
* so as to avoid duplicate invocation.
*/
@Nullable Set<RelNode> passThroughCache;
//~ Constructors -----------------------------------------------------------
RelSubset(
RelOptCluster cluster,
RelSet set,
RelTraitSet traits) {
super(cluster, traits);
this.set = set;
assert traits.allSimple();
computeBestCost(cluster, cluster.getPlanner());
upperBound = bestCost;
}
//~ Methods ----------------------------------------------------------------
/**
* Computes the best {@link RelNode} in this subset.
*
* <p>Only necessary when a subset is created in a set that has subsets that
* subsume it. Rationale:
*
* <ol>
* <li>If the are no subsuming subsets, the subset is initially empty.</li>
* <li>After creation, {@code best} and {@code bestCost} are maintained
* incrementally by {@link VolcanoPlanner#propagateCostImprovements} and
* {@link RelSet#mergeWith(VolcanoPlanner, RelSet)}.</li>
* </ol>
*/
@EnsuresNonNull("bestCost")
private void computeBestCost(
@UnderInitialization RelSubset this,
RelOptCluster cluster,
RelOptPlanner planner) {
bestCost = planner.getCostFactory().makeInfiniteCost();
final RelMetadataQuery mq = cluster.getMetadataQuery();
@SuppressWarnings("method.invocation.invalid")
Iterable<RelNode> rels = getRels();
for (RelNode rel : rels) {
final RelOptCost cost = planner.getCost(rel, mq);
if (cost == null) {
continue;
}
if (cost.isLt(bestCost)) {
bestCost = cost;
best = rel;
}
}
}
void setDelivered() {
triggerRule = !isDelivered();
state |= DELIVERED;
}
void setRequired() {
triggerRule = false;
state |= REQUIRED;
}
@API(since = "1.23", status = API.Status.EXPERIMENTAL)
public boolean isDelivered() {
return (state & DELIVERED) == DELIVERED;
}
@API(since = "1.23", status = API.Status.EXPERIMENTAL)
public boolean isRequired() {
return (state & REQUIRED) == REQUIRED;
}
void disableEnforcing() {
assert isDelivered();
enforceDisabled = true;
}
boolean isEnforceDisabled() {
return enforceDisabled;
}
public @Nullable RelNode getBest() {
return best;
}
public @Nullable RelNode getOriginal() {
return set.rel;
}
@API(since = "1.27", status = API.Status.INTERNAL)
public RelNode getBestOrOriginal() {
RelNode result = getBest();
if (result != null) {
return result;
}
return requireNonNull(getOriginal(), "both best and original nodes are null");
}
@Override public RelNode stripped() {
return getBestOrOriginal();
}
@Override public RelNode copy(RelTraitSet traitSet, List<RelNode> inputs) {
if (inputs.isEmpty()) {
final RelTraitSet traitSet1 = traitSet.simplify();
if (traitSet1.equals(this.traitSet)) {
return this;
}
return set.getOrCreateSubset(getCluster(), traitSet1, isRequired());
}
throw new UnsupportedOperationException();
}
@Override public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner,
RelMetadataQuery mq) {
return planner.getCostFactory().makeZeroCost();
}
@Override public double estimateRowCount(RelMetadataQuery mq) {
if (best != null) {
return mq.getRowCount(best);
} else {
return mq.getRowCount(castNonNull(set.rel));
}
}
@Override public void explain(RelWriter pw) {
// Not a typical implementation of "explain". We don't gather terms &
// values to be printed later. We actually do the work.
pw.item("subset", toString());
final AbstractRelNode input =
(@Nullable AbstractRelNode) Util.first(getBest(), getOriginal());
if (input == null) {
return;
}
input.explainTerms(pw);
pw.done(input);
}
@Override public boolean deepEquals(@Nullable Object obj) {
return this == obj;
}
@Override public int deepHashCode() {
return this.hashCode();
}
@Override protected RelDataType deriveRowType() {
return castNonNull(set.rel).getRowType();
}
/**
* Returns the collection of RelNodes one of whose inputs is in this
* subset.
*/
Set<RelNode> getParents() {
final Set<RelNode> list = new LinkedHashSet<>();
for (RelNode parent : set.getParentRels()) {
for (RelSubset rel : inputSubsets(parent)) {
// see usage of this method in propagateCostImprovements0()
if (rel == this) {
list.add(parent);
break;
}
}
}
return list;
}
/**
* Returns the collection of distinct subsets that contain a RelNode one
* of whose inputs is in this subset.
*/
Set<RelSubset> getParentSubsets(VolcanoPlanner planner) {
final Set<RelSubset> list = new LinkedHashSet<>();
for (RelNode parent : set.getParentRels()) {
for (RelSubset rel : inputSubsets(parent)) {
if (rel.set == set && rel.getTraitSet().equals(traitSet)) {
list.add(planner.getSubsetNonNull(parent));
break;
}
}
}
return list;
}
private static List<RelSubset> inputSubsets(RelNode parent) {
//noinspection unchecked
return (List<RelSubset>) (List) parent.getInputs();
}
/**
* Returns a list of relational expressions one of whose children is this
* subset. The elements of the list are distinct.
*/
public Collection<RelNode> getParentRels() {
final Set<RelNode> list = new LinkedHashSet<>();
parentLoop:
for (RelNode parent : set.getParentRels()) {
for (RelSubset rel : inputSubsets(parent)) {
if (rel.set == set && traitSet.satisfies(rel.getTraitSet())) {
list.add(parent);
continue parentLoop;
}
}
}
return list;
}
RelSet getSet() {
return set;
}
/**
* Adds expression <code>rel</code> to this subset.
*/
void add(RelNode rel) {
assert !(rel instanceof HepRelVertex);
if (set.rels.contains(rel)) {
return;
}
VolcanoPlanner planner = (VolcanoPlanner) rel.getCluster().getPlanner();
if (planner.getListener() != null) {
RelOptListener.RelEquivalenceEvent event =
new RelOptListener.RelEquivalenceEvent(
planner,
rel,
this,
true);
planner.getListener().relEquivalenceFound(event);
}
set.addInternal(rel);
if (false) {
Set<CorrelationId> variablesSet = RelOptUtil.getVariablesSet(rel);
Set<CorrelationId> variablesStopped = rel.getVariablesSet();
Set<CorrelationId> variablesPropagated =
Util.minus(variablesSet, variablesStopped);
assert set.variablesPropagated.containsAll(variablesPropagated);
Set<CorrelationId> variablesUsed = RelOptUtil.getVariablesUsed(rel);
assert set.variablesUsed.containsAll(variablesUsed);
}
}
/**
* Recursively builds a tree consisting of the cheapest plan at each node.
*/
RelNode buildCheapestPlan(VolcanoPlanner planner) {
CheapestPlanReplacer replacer = new CheapestPlanReplacer(planner);
final RelNode cheapest = replacer.visit(this, -1, null);
if (planner.getListener() != null) {
RelOptListener.RelChosenEvent event =
new RelOptListener.RelChosenEvent(
planner,
null);
planner.getListener().relChosen(event);
}
return cheapest;
}
@Override public void collectVariablesUsed(Set<CorrelationId> variableSet) {
variableSet.addAll(set.variablesUsed);
}
@Override public void collectVariablesSet(Set<CorrelationId> variableSet) {
variableSet.addAll(set.variablesPropagated);
}
/**
* Returns the rel nodes in this rel subset. All rels must have the same
* traits and are logically equivalent.
*
* @return all the rels in the subset
*/
public Iterable<RelNode> getRels() {
return () -> Linq4j.asEnumerable(set.rels)
.where(v1 -> v1.getTraitSet().satisfies(traitSet))
.iterator();
}
/**
* As {@link #getRels()} but returns a list.
*/
public List<RelNode> getRelList() {
final List<RelNode> list = new ArrayList<>();
for (RelNode rel : set.rels) {
if (rel.getTraitSet().satisfies(traitSet)) {
list.add(rel);
}
}
return list;
}
/**
* Returns whether this subset contains the specified relational expression.
*/
public boolean contains(RelNode node) {
return set.rels.contains(node) && node.getTraitSet().satisfies(traitSet);
}
/**
* Returns stream of subsets whose traitset satisfies
* current subset's traitset.
*/
@API(since = "1.23", status = API.Status.EXPERIMENTAL)
public Stream<RelSubset> getSubsetsSatisfyingThis() {
return set.subsets.stream()
.filter(s -> s.getTraitSet().satisfies(traitSet));
}
/**
* Returns stream of subsets whose traitset is satisfied
* by current subset's traitset.
*/
@API(since = "1.23", status = API.Status.EXPERIMENTAL)
public Stream<RelSubset> getSatisfyingSubsets() {
return set.subsets.stream()
.filter(s -> traitSet.satisfies(s.getTraitSet()));
}
/**
* Returns the best cost if this subset is fully optimized
* or null if the subset is not fully optimized.
*/
@API(since = "1.24", status = API.Status.INTERNAL)
public @Nullable RelOptCost getWinnerCost() {
if (taskState == OptimizeState.COMPLETED && bestCost.isLe(upperBound)) {
return bestCost;
}
// if bestCost != upperBound, it means optimize failed
return null;
}
void startOptimize(RelOptCost ub) {
assert getWinnerCost() == null : this + " is already optimized";
if (upperBound.isLt(ub)) {
upperBound = ub;
if (bestCost.isLt(upperBound)) {
upperBound = bestCost;
}
}
taskState = OptimizeState.OPTIMIZING;
}
void setOptimized() {
taskState = OptimizeState.COMPLETED;
}
boolean resetTaskState() {
boolean optimized = taskState != null;
taskState = null;
upperBound = bestCost;
return optimized;
}
@Nullable RelNode passThrough(RelNode rel) {
if (!(rel instanceof PhysicalNode)) {
return null;
}
if (passThroughCache == null) {
passThroughCache = Sets.newIdentityHashSet();
passThroughCache.add(rel);
} else if (!passThroughCache.add(rel)) {
return null;
}
return ((PhysicalNode) rel).passThrough(this.getTraitSet());
}
boolean isExplored() {
return set.exploringState == RelSet.ExploringState.EXPLORED;
}
boolean explore() {
if (set.exploringState != null) {
return false;
}
set.exploringState = RelSet.ExploringState.EXPLORING;
return true;
}
void setExplored() {
set.exploringState = RelSet.ExploringState.EXPLORED;
}
//~ Inner Classes ----------------------------------------------------------
/**
* Identifies the leaf-most non-implementable nodes.
*/
static class DeadEndFinder {
final Set<RelSubset> deadEnds = new HashSet<>();
// To save time
private final Set<RelNode> visitedNodes = new HashSet<>();
// For cycle detection
private final Set<RelNode> activeNodes = new HashSet<>();
private boolean visit(RelNode p) {
if (p instanceof RelSubset) {
visitSubset((RelSubset) p);
return false;
}
return visitRel(p);
}
private void visitSubset(RelSubset subset) {
RelNode cheapest = subset.getBest();
if (cheapest != null) {
// Subset is implementable, and we are looking for bad ones, so stop here
return;
}
boolean isEmpty = true;
for (RelNode rel : subset.getRels()) {
if (rel instanceof AbstractConverter) {
// Converters are not implementable
continue;
}
if (!activeNodes.add(rel)) {
continue;
}
boolean res = visit(rel);
isEmpty &= res;
activeNodes.remove(rel);
}
if (isEmpty) {
deadEnds.add(subset);
}
}
/**
* Returns true when input {@code RelNode} is cyclic.
*/
private boolean visitRel(RelNode p) {
// If one of the inputs is in "active" set, that means the rel forms a cycle,
// then we just ignore it. Cyclic rels are not implementable.
for (RelNode oldInput : p.getInputs()) {
if (activeNodes.contains(oldInput)) {
return true;
}
}
// The same subset can be used multiple times (e.g. union all with the same inputs),
// so it is important to perform "contains" and "add" in different loops
activeNodes.addAll(p.getInputs());
for (RelNode oldInput : p.getInputs()) {
if (!visitedNodes.add(oldInput)) {
// We don't want to explore the same subset twice
continue;
}
visit(oldInput);
}
activeNodes.removeAll(p.getInputs());
return false;
}
}
@Override public String getDigest() {
return "RelSubset#" + set.id + '.' + getTraitSet();
}
/**
* Visitor which walks over a tree of {@link RelSet}s, replacing each node
* with the cheapest implementation of the expression.
*/
static class CheapestPlanReplacer {
VolcanoPlanner planner;
final Map<Integer, RelNode> visited = new HashMap<>();
CheapestPlanReplacer(VolcanoPlanner planner) {
super();
this.planner = planner;
}
private static String traitDiff(RelTraitSet original, RelTraitSet desired) {
return Pair.zip(original, desired)
.stream()
.filter(p -> !p.left.satisfies(p.right))
.map(p -> p.left.getTraitDef().getSimpleName() + ": " + p.left + " -> " + p.right)
.collect(Collectors.joining(", ", "[", "]"));
}
public RelNode visit(
RelNode p,
int ordinal,
@Nullable RelNode parent) {
final int pId = p.getId();
RelNode prevVisit = visited.get(pId);
if (prevVisit != null) {
// return memoized result of previous visit if available
return prevVisit;
}
if (p instanceof RelSubset) {
RelSubset subset = (RelSubset) p;
RelNode cheapest = subset.best;
if (cheapest == null) {
// Dump the planner's expression pool so we can figure
// out why we reached impasse.
StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
pw.print("There are not enough rules to produce a node with desired properties");
RelTraitSet desiredTraits = subset.getTraitSet();
String sep = ": ";
for (RelTrait trait : desiredTraits) {
pw.print(sep);
pw.print(trait.getTraitDef().getSimpleName());
pw.print("=");
pw.print(trait);
sep = ", ";
}
pw.print(".");
DeadEndFinder finder = new DeadEndFinder();
finder.visit(subset);
if (finder.deadEnds.isEmpty()) {
pw.print(" All the inputs have relevant nodes, however the cost is still infinite.");
} else {
Map<String, Long> problemCounts =
finder.deadEnds.stream()
.filter(deadSubset -> deadSubset.getOriginal() != null)
.map(x -> {
RelNode original = castNonNull(x.getOriginal());
return original.getClass().getSimpleName()
+ traitDiff(original.getTraitSet(), x.getTraitSet());
})
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
// Sort problems from most often to less often ones
String problems = problemCounts.entrySet().stream()
.sorted(Comparator.comparingLong(Map.Entry<String, Long>::getValue).reversed())
.map(e -> e.getKey() + (e.getValue() > 1 ? " (" + e.getValue() + " cases)" : ""))
.collect(Collectors.joining(", "));
pw.println();
pw.print("Missing conversion");
pw.print(finder.deadEnds.size() == 1 ? " is " : "s are ");
pw.print(problems);
pw.println();
if (finder.deadEnds.size() == 1) {
pw.print("There is 1 empty subset: ");
}
if (finder.deadEnds.size() > 1) {
pw.println("There are " + finder.deadEnds.size() + " empty subsets:");
}
int i = 0;
int rest = finder.deadEnds.size();
for (RelSubset deadEnd : finder.deadEnds) {
if (finder.deadEnds.size() > 1) {
pw.print("Empty subset ");
pw.print(i);
pw.print(": ");
}
pw.print(deadEnd);
pw.println(", the relevant part of the original plan is as follows");
RelNode original = deadEnd.getOriginal();
if (original != null) {
original.explain(
new RelWriterImpl(pw, SqlExplainLevel.EXPPLAN_ATTRIBUTES, true));
}
i++;
rest--;
if (rest > 0) {
pw.println();
}
if (i >= 10 && rest > 1) {
pw.print("The rest ");
pw.print(rest);
pw.println(" leafs are omitted.");
break;
}
}
}
pw.println();
planner.dump(pw);
pw.flush();
final String dump = sw.toString();
RuntimeException e =
new RelOptPlanner.CannotPlanException(dump);
LOGGER.trace("Caught exception in class={}, method=visit", getClass().getName(), e);
throw e;
}
p = cheapest;
}
if (ordinal != -1) {
if (planner.getListener() != null) {
RelOptListener.RelChosenEvent event =
new RelOptListener.RelChosenEvent(
planner,
p);
planner.getListener().relChosen(event);
}
}
List<RelNode> oldInputs = p.getInputs();
List<RelNode> inputs = new ArrayList<>();
for (int i = 0; i < oldInputs.size(); i++) {
RelNode oldInput = oldInputs.get(i);
RelNode input = visit(oldInput, i, p);
inputs.add(input);
}
if (!inputs.equals(oldInputs)) {
final RelNode pOld = p;
p = p.copy(p.getTraitSet(), inputs);
planner.provenanceMap.put(
p, new VolcanoPlanner.DirectProvenance(pOld));
}
visited.put(pId, p); // memoize result for pId
return p;
}
}
/** State of optimizer. */
enum OptimizeState {
OPTIMIZING,
COMPLETED
}
}