예제 #1
0
 private boolean isGropTableFilter(TableFilter filter) {
   TableMate table1 = (TableMate) filter.getTable();
   for (TableFilter item : filters) {
     if (item == filter || isNestedJoinTable(item)) {
       continue;
     }
     TableMate table2 = (TableMate) item.getTable();
     TableRule rule1 = table1.getTableRule();
     TableRule rule2 = table2.getTableRule();
     if (!rule1.isNodeComparable(rule2)) {
       return false;
     }
   }
   return true;
 }
예제 #2
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;
 }
예제 #3
0
 private void setConsistencyTableNodes(ObjectNode[] selectNodes, List<TableFilter> filters) {
   this.consistencyTableNodes = New.hashMapNonRehash(selectNodes.length);
   for (ObjectNode target : selectNodes) {
     HashMap<TableFilter, ObjectNode> tableNodeMapping = New.hashMapNonRehash(filters.size());
     for (TableFilter tf : filters) {
       TableMate table = getTableMate(tf);
       ObjectNode consistencyNode = getConsistencyNode(table.getTableRule(), target);
       tableNodeMapping.put(tf, consistencyNode);
     }
     consistencyTableNodes.put(target, tableNodeMapping);
   }
 }