Run the optimizer. This method attempts to match each of the Rules against the plan. If a Rule matches, it then calls the check method of the associated Transformer to give the it a chance to check whether it really wants to do the optimization. If that returns true as well, then Transformer.tran
()
| 93 | * @throws FrontendException |
| 94 | */ |
| 95 | public void optimize() throws FrontendException { |
| 96 | |
| 97 | for (Set<Rule> rs : ruleSets) { |
| 98 | boolean sawMatch = false; |
| 99 | int numIterations = 0; |
| 100 | do { |
| 101 | sawMatch = false; |
| 102 | for (Rule rule : rs) { |
| 103 | List<OperatorPlan> matches = rule.match(plan); |
| 104 | if (matches != null) { |
| 105 | Transformer transformer = rule.getNewTransformer(); |
| 106 | for (OperatorPlan m : matches) { |
| 107 | try { |
| 108 | if (transformer.check(m)) { |
| 109 | sawMatch = true; |
| 110 | transformer.transform(m); |
| 111 | OperatorPlan change = transformer.reportChanges(); |
| 112 | if (change == null) { |
| 113 | sawMatch = false; |
| 114 | } else if (!rule.isSkipListener()) { |
| 115 | for(PlanTransformListener l: listeners) { |
| 116 | l.transformed(plan, change); |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } catch (Exception e) { |
| 121 | StringBuffer message = new StringBuffer("Error processing rule " + rule.name); |
| 122 | if (!rule.isMandatory()) { |
| 123 | message.append(". Try -t " + rule.name); |
| 124 | } |
| 125 | throw new FrontendException(message.toString(), 2000, e); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | } while(sawMatch && ++numIterations < maxIter); |
| 131 | } |
| 132 | } |
| 133 | } |