Esempio n. 1
0
 public Pos createPosFromNode(int row, int col) {
   List<PlanItem> roads = getRoads();
   for (PlanItem pi : roads) {
     Pos p = pi.getPos();
     if (getRow(p) == row && getCol(p) == col) return p;
   }
   return null;
 }
Esempio n. 2
0
 public Index getScanIndex(Session session) {
   if (createException != null) {
     String msg = createException.getMessage();
     throw DbException.get(ErrorCode.VIEW_IS_INVALID_2, createException, getSQL(), msg);
   }
   PlanItem item = getBestPlanItem(session, null);
   return item.getIndex();
 }
Esempio n. 3
0
 public PlanItem getBestPlanItem(Session session, int[] masks) {
   PlanItem item = new PlanItem();
   item.cost = index.getCost(session, masks);
   IntArray masksArray = new IntArray(masks == null ? Utils.EMPTY_INT_ARRAY : masks);
   ViewIndex i2 = 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;
 }
Esempio n. 4
0
 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");
     }
   }
 }
Esempio n. 5
0
 /**
  * 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 sortOrder the sort order
  * @return the plan item
  */
 public PlanItem getBestPlanItem(Session session, int[] masks, SortOrder sortOrder) {
   PlanItem item = new PlanItem();
   item.setIndex(getScanIndex(session));
   item.cost = item.getIndex().getCost(session, null, null);
   ArrayList<Index> indexes = getIndexes();
   if (indexes != null && masks != null) {
     for (int i = 1, size = indexes.size(); i < size; i++) {
       Index index = indexes.get(i);
       double cost = index.getCost(session, masks, sortOrder);
       if (cost < item.cost) {
         item.cost = cost;
         item.setIndex(index);
       }
     }
   }
   return item;
 }
Esempio n. 6
0
  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) {
      ShardedTableRule shardedTableRule = (ShardedTableRule) tableRule;
      int nodeCount = shardedTableRule.getObjectNodes().length;
      item.cost = Constants.COST_ROW_OFFSET * nodeCount;
    }

    Column[] columns = getRuleColumns();
    if (columns != null && masks != null) {
      for (int i = 0, len = columns.length; i < len; i++) {
        Column column = columns[i];
        int index = column.getColumnId();
        int mask = masks[index];
        if ((mask & IndexCondition.EQUALITY) == IndexCondition.EQUALITY) {
          if (i == columns.length - 1) {
            item.cost = Constants.COST_ROW_OFFSET;
            item.scanningStrategyFor(ScanningStrategy.USE_SHARDINGKEY);
            break;
          }
        } else {
          break;
        }
      }
    }
    double rowsCost = item.cost;
    ArrayList<Index> indexes = getIndexes();
    if (indexes != null && masks != null) {
      for (Index index : indexes) {
        columns = index.getColumns();
        for (int i = 0, len = columns.length; i < len; i++) {
          Column column = columns[i];
          int columnId = column.getColumnId();
          int mask = masks[columnId];
          if ((mask & IndexCondition.EQUALITY) == IndexCondition.EQUALITY) {
            if (i == columns.length - 1 && index.getIndexType().isUnique()) {
              item.cost = rowsCost * 0.25d;
              item.scanningStrategyFor(ScanningStrategy.USE_UNIQUEKEY);
              break;
            }
            item.cost = Math.max(rowsCost * 0.5d, item.cost * 0.5d);
            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 {
            break;
          }
        }
      }
    }
    // validationPlanItem(item);
    return item;
  }