Esempio n. 1
0
 private void checkNullable() {
   for (Index index : table.getIndexes()) {
     if (index.getColumnIndex(oldColumn) < 0) {
       continue;
     }
     IndexType indexType = index.getIndexType();
     if (indexType.isPrimaryKey() || indexType.isHash()) {
       throw DbException.get(ErrorCode.COLUMN_IS_PART_OF_INDEX_1, index.getSQL());
     }
   }
 }
Esempio n. 2
0
  public MergedResult(List<Result> results, Select newSelect, Select oldSelect) {
    // 1. 结果集串行化,为合并做准备
    SerializedResult serializedResult = new SerializedResult(results, oldSelect.getLimitRows());
    Table table = newSelect.getTopTableFilter().getTable();
    newSelect
        .getTopTableFilter()
        .setIndex(
            new MergedIndex(
                serializedResult,
                table,
                -1,
                IndexColumn.wrap(table.getColumns()),
                IndexType.createScan(false)));

    // 2. 把多个结果集合并
    Result mergedResult = newSelect.queryGroupMerge();

    // 3. 计算合并后的结果集,
    // 例如oldSelect="select avg"时,在分布式环境要转成newSelect="select count, sum",
    // 此时就由count, sum来算出avg
    Result calculatedResult = oldSelect.calculate(mergedResult, newSelect);

    // 4. 如果不存在avg、stddev这类需要拆分为count、sum的计算,
    // 此时mergedResult和calculatedResult是同一个实例,否则就是不同实例
    if (mergedResult != calculatedResult) {
      mergedResult.close();
      result = calculatedResult;
    } else {
      result = mergedResult;
    }
  }