Exemplo n.º 1
0
 private RoutingResult doRoute(Select prepare) {
   List<TableFilter> filters = filterNotTableMate(prepare.getTopTableFilter());
   List<TableFilter> shards = New.arrayList(filters.size());
   List<TableFilter> globals = New.arrayList(filters.size());
   List<TableFilter> fixeds = New.arrayList(filters.size());
   for (TableFilter tf : filters) {
     TableMate table = getTableMate(tf);
     switch (table.getTableRule().getType()) {
       case TableRule.SHARDED_NODE_TABLE:
         shards.add(tf);
         break;
       case TableRule.GLOBAL_NODE_TABLE:
         globals.add(tf);
         break;
       case TableRule.FIXED_NODE_TABLE:
         fixeds.add(tf);
         break;
       default:
         break;
     }
   }
   RoutingResult result = null;
   if (!shards.isEmpty()) {
     for (TableFilter f : shards) {
       f.setEvaluatable(f, false);
       if (f.isJoinOuter() || f.isJoinOuterIndirect()) {
         prepare.getCondition().createIndexConditions(session, f);
       }
       TableMate table = getTableMate(f);
       ConditionExtractor extractor = new ConditionExtractor(f);
       RoutingResult r =
           routingHandler.doRoute(
               table, extractor.getStart(), extractor.getEnd(), extractor.getInColumns());
       result = (result == null || r.compareTo(result) < 0) ? r : result;
     }
     for (TableFilter f : shards) {
       f.setEvaluatable(f, true);
     }
   } else if (!fixeds.isEmpty()) {
     for (TableFilter tf : shards) {
       TableMate table = getTableMate(tf);
       RoutingResult r = routingHandler.doRoute(table);
       result = r;
     }
   } else if (!globals.isEmpty()) {
     // 全部为全局表查询,随机取一个第一个表结点
     GlobalTableRule tableRule = (GlobalTableRule) getTableRule(globals.iterator().next());
     RoutingResult r = tableRule.getRandomRoutingResult();
     result = r;
   } else {
     throw DbException.throwInternalError("SQL_ROUTING_ERROR");
   }
   ObjectNode[] selectNodes = result.getSelectNodes();
   if (selectNodes.length == 0) {
     throw DbException.throwInternalError("SQL_ROUTING_ERROR,empty result");
   }
   setConsistencyTableNodes(selectNodes, filters);
   return result;
 }
Exemplo n.º 2
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");
     }
   }
 }
Exemplo n.º 3
0
 /**
  * Remove the row from the result set if it exists.
  *
  * @param values the row
  */
 public void removeDistinct(Value[] values) {
   if (!distinct) {
     DbException.throwInternalError();
   }
   ValueArray array = ValueArray.get(values);
   distinctRows.remove(array);
   rowCount = distinctRows.size();
 }
Exemplo n.º 4
0
 @Override
 public boolean previous() {
   throw DbException.throwInternalError();
 }