示例#1
0
 private boolean testPlan(TableFilter[] list) {
   Plan p = new Plan(list, list.length, condition);
   double costNow = p.calculateCost(session);
   if (cost < 0 || costNow < cost) {
     cost = costNow;
     bestPlan = p;
     return true;
   }
   return false;
 }
示例#2
0
 /** Calculate the best query plan to use. */
 void optimize() {
   calculateBestPlan();
   bestPlan.removeUnusableIndexConditions();
   TableFilter[] f2 = bestPlan.getFilters();
   topFilter = f2[0];
   for (int i = 0; i < f2.length - 1; i++) {
     f2[i].addJoin(f2[i + 1], false, false, null);
   }
   for (TableFilter f : f2) {
     PlanItem item = bestPlan.getItem(f);
     f.setPlanItem(item);
   }
 }
示例#3
0
 private void calculateBruteForceSome() {
   int bruteForce = getMaxBruteForceFilters(filters.length);
   TableFilter[] list = new TableFilter[filters.length];
   Permutations<TableFilter> p = Permutations.create(filters, list, bruteForce);
   for (int x = 0; !canStop(x) && p.next(); x++) {
     // find out what filters are not used yet
     for (TableFilter f : filters) {
       f.setUsed(false);
     }
     for (int i = 0; i < bruteForce; i++) {
       list[i].setUsed(true);
     }
     // fill the remaining elements with the unused elements (greedy)
     for (int i = bruteForce; i < filters.length; i++) {
       double costPart = -1.0;
       int bestPart = -1;
       for (int j = 0; j < filters.length; j++) {
         if (!filters[j].isUsed()) {
           if (i == filters.length - 1) {
             bestPart = j;
             break;
           }
           list[i] = filters[j];
           Plan part = new Plan(list, i + 1, condition);
           double costNow = part.calculateCost(session);
           if (costPart < 0 || costNow < costPart) {
             costPart = costNow;
             bestPart = j;
           }
         }
       }
       filters[bestPart].setUsed(true);
       list[i] = filters[bestPart];
     }
     testPlan(list);
   }
 }