item1 = new PlanItem(); item1.setIndex(table.getScanIndex(s, null, filters, filter, sortOrder, allColumnsSet)); item1.cost = item1.getIndex().getCost(s, null, filters, filter, sortOrder, allColumnsSet); item.setMasks(masks); item.setNestedJoinPlan(nestedJoin.getBestPlanItem(s, filters, filter, allColumnsSet)); item.cost += item.cost * item.getNestedJoinPlan().cost; filter++; } while (filters[filter] != join); item.setJoinPlan(join.getBestPlanItem(s, filters, filter, allColumnsSet)); item.cost += item.cost * item.getJoinPlan().cost;
/** * Set what plan item (index, cost, masks) to use. * * @param item the plan item */ public void setPlanItem(PlanItem item) { if (item == null) { // invalid plan, most likely because a column wasn't found // this will result in an exception later on return; } setIndex(item.getIndex()); masks = item.getMasks(); if (nestedJoin != null) { if (item.getNestedJoinPlan() != null) { nestedJoin.setPlanItem(item.getNestedJoinPlan()); } else { nestedJoin.setScanIndexes(); } } if (join != null) { if (item.getJoinPlan() != null) { join.setPlanItem(item.getJoinPlan()); } else { join.setScanIndexes(); } } }
@Override public PlanItem getBestPlanItem(Session session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) { final CacheKey cacheKey = new CacheKey(masks, this); Map<Object, ViewIndex> indexCache = session.getViewIndexCache(topQuery != null); ViewIndex i = indexCache.get(cacheKey); if (i == null || i.isExpired()) { i = new ViewIndex(this, index, session, masks, filters, filter, sortOrder); indexCache.put(cacheKey, i); } PlanItem item = new PlanItem(); item.cost = i.getCost(session, masks, filters, filter, sortOrder, allColumnsSet); item.setIndex(i); return item; }
TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) { PlanItem item = new PlanItem(); item.setIndex(getScanIndex(session)); item.cost = item.getIndex().getCost(session, null, filters, filter, null, allColumnsSet); Trace t = session.getTrace(); if (t.isDebugEnabled()) { t.debug("Table : potential plan item cost {0} index {1}", item.cost, item.getIndex().getPlanSQL()); item.setIndex(index);
public PlanItem getBestPlanItem(Session session) throws SQLException { PlanItem item; if (indexConditions.size() == 0) { item = new PlanItem(); item.setIndex(table.getScanIndex(session)); item.cost = item.getIndex().getCost(session, null); } else { int len = table.getColumns().length; item.setJoinPlan(join.getBestPlanItem(session)); item.cost += item.cost * item.getJoinPlan().cost;
@Override public Index getScanIndex(Session session) { return getBestPlanItem(session, null, null, -1, null, null).getIndex(); }
public void setPlanItem(PlanItem item) { setIndex(item.getIndex()); if (join != null) { if (item.getJoinPlan() != null) { join.setPlanItem(item.getJoinPlan()); } } }
/** * Get the best plan for the given search mask. * * @param masks - null means 'always false' */ public PlanItem getBestPlanItem(Session session, int[] masks) throws SQLException { PlanItem item = new PlanItem(); item.setIndex(getScanIndex(session)); item.cost = item.getIndex().getCost(session, null); ObjectArray indexes = getIndexes(); for (int i = 1; indexes != null && masks != null && i < indexes.size(); i++) { Index index = (Index) indexes.get(i); double cost = index.getCost(session, masks); if (cost < item.cost) { item.cost = cost; item.setIndex(index); } } return item; }
@Override public PlanItem getBestPlanItem(Session session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) { final CacheKey cacheKey = new CacheKey(masks, this); Map<Object, ViewIndex> indexCache = session.getViewIndexCache(topQuery != null); ViewIndex i = indexCache.get(cacheKey); if (i == null || i.isExpired()) { i = new ViewIndex(this, index, session, masks, filters, filter, sortOrder); indexCache.put(cacheKey, i); } PlanItem item = new PlanItem(); item.cost = i.getCost(session, masks, filters, filter, sortOrder, allColumnsSet); item.setIndex(i); return item; }
@Override public Index getScanIndex(Session session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) { if (createException != null) { String msg = createException.getMessage(); throw DbException.get(ErrorCode.VIEW_IS_INVALID_2, createException, getSQL(), msg); } PlanItem item = getBestPlanItem(session, masks, filters, filter, sortOrder, allColumnsSet); return item.getIndex(); }
item1 = new PlanItem(); item1.setIndex(table.getScanIndex(s, null, filters, filter, sortOrder, allColumnsSet)); item1.cost = item1.getIndex().getCost(s, null, filters, filter, sortOrder, allColumnsSet); item.setMasks(masks); item.setNestedJoinPlan(nestedJoin.getBestPlanItem(s, filters, filter, allColumnsSet)); item.cost += item.cost * item.getNestedJoinPlan().cost; filter++; } while (filters[filter] != join); item.setJoinPlan(join.getBestPlanItem(s, filters, filter, allColumnsSet)); item.cost += item.cost * item.getJoinPlan().cost;
/** * Set what plan item (index, cost, masks) to use. * * @param item the plan item */ public void setPlanItem(PlanItem item) { if (item == null) { // invalid plan, most likely because a column wasn't found // this will result in an exception later on return; } setIndex(item.getIndex()); masks = item.getMasks(); if (nestedJoin != null) { if (item.getNestedJoinPlan() != null) { nestedJoin.setPlanItem(item.getNestedJoinPlan()); } } if (join != null) { if (item.getJoinPlan() != null) { join.setPlanItem(item.getJoinPlan()); } } }
TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) { PlanItem item = new PlanItem(); item.setIndex(getScanIndex(session)); item.cost = item.getIndex().getCost(session, null, filters, filter, null, allColumnsSet); Trace t = session.getTrace(); if (t.isDebugEnabled()) { t.debug("Table : potential plan item cost {0} index {1}", item.cost, item.getIndex().getPlanSQL()); item.setIndex(index);
@Override public PlanItem getBestPlanItem(Session session, int[] masks, TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) { final CacheKey cacheKey = new CacheKey(masks, this); Map<Object, ViewIndex> indexCache = session.getViewIndexCache(topQuery != null); ViewIndex i = indexCache.get(cacheKey); if (i == null || i.isExpired()) { i = new ViewIndex(this, index, session, masks, filters, filter, sortOrder); indexCache.put(cacheKey, i); } PlanItem item = new PlanItem(); item.cost = i.getCost(session, masks, filters, filter, sortOrder, allColumnsSet); item.setIndex(i); return item; }
if (t.isDebugEnabled()) { t.debug("Plan : best plan item cost {0} index {1}", item.cost, item.getIndex().getPlanSQL());
item1 = new PlanItem(); item1.setIndex(table.getScanIndex(s, null, filters, filter, sortOrder, allColumnsSet)); item1.cost = item1.getIndex().getCost(s, null, filters, filter, sortOrder, allColumnsSet); item.setMasks(masks); item.setNestedJoinPlan(nestedJoin.getBestPlanItem(s, filters, filter, allColumnsSet)); item.cost += item.cost * item.getNestedJoinPlan().cost; filter++; } while (filters[filter] != join); item.setJoinPlan(join.getBestPlanItem(s, filters, filter, allColumnsSet)); item.cost += item.cost * item.getJoinPlan().cost;
/** * Set what plan item (index, cost, masks) to use. * * @param item the plan item */ public void setPlanItem(PlanItem item) { if (item == null) { // invalid plan, most likely because a column wasn't found // this will result in an exception later on return; } setIndex(item.getIndex()); masks = item.getMasks(); if (nestedJoin != null) { if (item.getNestedJoinPlan() != null) { nestedJoin.setPlanItem(item.getNestedJoinPlan()); } } if (join != null) { if (item.getJoinPlan() != null) { join.setPlanItem(item.getJoinPlan()); } } }
TableFilter[] filters, int filter, SortOrder sortOrder, HashSet<Column> allColumnsSet) { PlanItem item = new PlanItem(); item.setIndex(getScanIndex(session)); item.cost = item.getIndex().getCost(session, null, filters, filter, null, allColumnsSet); Trace t = session.getTrace(); if (t.isDebugEnabled()) { t.debug("Table : potential plan item cost {0} index {1}", item.cost, item.getIndex().getPlanSQL()); item.setIndex(index);
public PlanItem getBestPlanItem(Session session, int[] masks) throws SQLException { PlanItem item = new PlanItem(); item.cost = index.getCost(session, masks); IntArray masksArray = new IntArray(masks == null ? new int[0] : masks); ViewIndex i2 = (ViewIndex) indexCache.get(masksArray); if (i2 == null || i2.getSession() != session) { i2 = new ViewIndex(this, index, session, masks); indexCache.put(masksArray, i2); } item.setIndex(i2); return item; }
private int generateInsertValues(int count, Table table) throws IOException { PlanItem plan = table.getBestPlanItem(session, null, null, -1, null, null); Index index = plan.getIndex(); Cursor cursor = index.find(session, null, null); Column[] columns = table.getColumns();