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; }
/** * 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); } }
/** * Remove all index conditions that can not be used. */ public void removeUnusableIndexConditions() { for (int i = 0; i < allFilters.length; i++) { TableFilter f = allFilters[i]; setEvaluatable(f, true); if (i < allFilters.length - 1 || f.getSession().getDatabase().getSettings().earlyFilter) { // the last table doesn't need the optimization, // otherwise the expression is calculated twice unnecessarily // (not that bad but not optimal) f.optimizeFullCondition(false); } f.removeUnusableIndexConditions(); } for (TableFilter f : allFilters) { setEvaluatable(f, false); } }
setEvaluatable(tableFilter, true); Expression on = tableFilter.getJoinCondition(); if (on != null) { setEvaluatable(f, false);
Plan part = new Plan(list, i + 1, condition); double costNow = part.calculateCost(session); if (costPart < 0 || costNow < costPart) { costPart = costNow;