/** * Get the best plan for the given search mask. * * @param session the session * @param masks per-column comparison bit masks, null means 'always false', * see constants in IndexCondition * @param filter the table filter * @param sortOrder the sort order * @return the plan item */ public PlanItem getBestPlanItem(Session session, int[] masks, TableFilter filter) { PlanItem item = new PlanItem(); item.cost = 1; return item; }
/** * Set what plan item (index, cost) to use 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()); if (nestedJoin != null) { if (item.getNestedJoinPlan() != null) { nestedJoin.setPlanItem(item.getNestedJoinPlan()); } } if (join != null) { if (item.getJoinPlan() != null) { join.setPlanItem(item.getJoinPlan()); } } }
if (nestedJoin != null) { setEvaluatable(nestedJoin); item.setNestedJoinPlan(nestedJoin.getBestPlanItem(s, filters, filter)); item.cost += item.cost * item.getNestedJoinPlan().cost; filter++; } while (filters[filter] != join); item.setJoinPlan(join.getBestPlanItem(s, filters, filter)); item.cost += item.cost * item.getJoinPlan().cost;
public PlanItem getBestPlanItem(Session session, int[] masks, TableFilter[] filters, int filter) { PlanItem item = new PlanItem(); item.cost = Constants.COST_ROW_OFFSET; if (tableRule instanceof ShardedTableRule) { if (i == columns.length - 1) { item.cost = Constants.COST_ROW_OFFSET; item.scanningStrategyFor(ScanningStrategy.USE_SHARDINGKEY); break; if (i == columns.length - 1 && index.getIndexType().isUnique()) { item.cost = rowsCost * 0.25d; item.scanningStrategyFor(ScanningStrategy.USE_UNIQUEKEY); break; item.scanningStrategyFor(ScanningStrategy.USE_INDEXKEY); } else if ((mask & IndexCondition.RANGE) == IndexCondition.RANGE) { item.cost = item.cost * 0.70d; item.scanningStrategyFor(ScanningStrategy.USE_INDEXKEY); break; } else if ((mask & IndexCondition.START) == IndexCondition.START) { item.cost = item.cost * 0.75d; item.scanningStrategyFor(ScanningStrategy.USE_INDEXKEY); break; } else if ((mask & IndexCondition.END) == IndexCondition.END) { item.cost = item.cost * 0.75d; item.scanningStrategyFor(ScanningStrategy.USE_INDEXKEY); break; } else {
public void validationPlanItem(PlanItem item) { int priority = item.getScanningStrategy().priority; if (tableRule instanceof ShardedTableRule) { ShardedTableRule shardedTableRule = (ShardedTableRule) tableRule; switch (shardedTableRule.getScanLevel()) { case ShardedTableRule.SCANLEVEL_SHARDINGKEY: if (priority < ScanningStrategy.USE_SHARDINGKEY.priority) { throw DbException.get(ErrorCode.ALLOWED_SCANTABLE_ERROR, getName(), "shardingKey", "shardingKey"); } break; case ShardedTableRule.SCANLEVEL_UNIQUEINDEX: if (priority < ScanningStrategy.USE_UNIQUEKEY.priority) { throw DbException.get(ErrorCode.ALLOWED_SCANTABLE_ERROR, getName(), "uniqueIndex", "uniqueIndex"); } break; case ShardedTableRule.SCANLEVEL_ANYINDEX: if (priority < ScanningStrategy.USE_INDEXKEY.priority) { throw DbException.get(ErrorCode.ALLOWED_SCANTABLE_ERROR, getName(), "indexKey", "indexKey"); } break; case ShardedTableRule.SCANLEVEL_UNLIMITED: break; default: throw DbException.throwInternalError("invalid scanLevel"); } } } }
if (t.isDebugEnabled()) { t.debug("Plan : plan item cost {0} scanning strategy is {1}", item.cost, item.getScanningStrategy());
@Override public PlanItem getBestPlanItem(Session session, int[] masks, TableFilter filter) { PlanItem item = new PlanItem(); Query q = getCachedQuery(session, masks); item.cost = q.getCost(); return item; }