本文整理汇总了Java中com.taobao.tddl.optimizer.costbased.esitimater.stat.KVIndexStat类的典型用法代码示例。如果您正苦于以下问题:Java KVIndexStat类的具体用法?Java KVIndexStat怎么用?Java KVIndexStat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KVIndexStat类属于com.taobao.tddl.optimizer.costbased.esitimater.stat包,在下文中一共展示了KVIndexStat类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKVIndex
import com.taobao.tddl.optimizer.costbased.esitimater.stat.KVIndexStat; //导入依赖的package包/类
@Override
public KVIndexStat getKVIndex(String indexName) {
TargetDB targetDB = rule.shardAny(indexName);
if (targetDB.getDbIndex() == null) {
// 没有对应的规则,也没有default group,则可能是一个不存在的表
// 尝试找一下local
return local.getKVIndex(indexName);
} else {
Group group = matrix.getGroup(targetDB.getDbIndex()); // 先找到group
if (group == null) {
throw new TddlRuntimeException(ErrorCode.ERR_CONFIG, "not found groupName : " + targetDB.getDbIndex());
}
try {
return repos.get(group).getKVIndex(targetDB.getTableNames().iterator().next());
} catch (ExecutionException e) {
throw new OptimizerException(e);
}
}
}
示例2: parseKVIndexStat
import com.taobao.tddl.optimizer.costbased.esitimater.stat.KVIndexStat; //导入依赖的package包/类
private static KVIndexStat parseKVIndexStat(Node node) {
NodeList list = node.getChildNodes();
KVIndexStat stat = new KVIndexStat();
for (int i = 0; i < list.getLength(); i++) {
Node item = list.item(i);
if ("indexName".equals(item.getNodeName())) {
stat.setIndexName(StringUtils.upperCase(item.getFirstChild().getNodeValue()));
} else if ("indexType".equals(item.getNodeName())) {
stat.setIndexType(Integer.valueOf(item.getFirstChild().getNodeValue()));
} else if ("distinctKeys".equals(item.getNodeName())) {
stat.setDistinctKeys(Integer.valueOf(item.getFirstChild().getNodeValue()));
} else if ("numRows".equals(item.getNodeName())) {
stat.setNumRows(Integer.valueOf(item.getFirstChild().getNodeValue()));
} else if ("factor".equals(item.getNodeName())) {
stat.setFactor(Double.valueOf(item.getFirstChild().getNodeValue()));
}
}
return stat;
}
示例3: getKVIndex
import com.taobao.tddl.optimizer.costbased.esitimater.stat.KVIndexStat; //导入依赖的package包/类
public KVIndexStat getKVIndex(String indexName) {
TargetDB targetDB = rule.shardAny(indexName);
if (targetDB.getDbIndex() == null) {
// 没有对应的规则,也没有default group,则可能是一个不存在的表
// 尝试找一下local
return local.getKVIndex(indexName);
} else {
Group group = matrix.getGroup(targetDB.getDbIndex()); // 先找到group
try {
return repos.get(group).getKVIndex(targetDB.getTableNames().iterator().next());
} catch (ExecutionException e) {
throw new OptimizerException(e);
}
}
}
示例4: findBestIndex
import com.taobao.tddl.optimizer.costbased.esitimater.stat.KVIndexStat; //导入依赖的package包/类
public static IndexMeta findBestIndex(TableMeta tableMeta, List<ISelectable> columns, List<IFilter> filters,
String tablename, Map<String, Object> extraCmd) {
if (!chooseIndex(extraCmd)) {
return null;
}
List<IndexMeta> indexs = tableMeta.getIndexs();
if (indexs.isEmpty()) {
return null;
}
Map<Object, List<IFilter>> columnFilters = FilterUtils.toColumnFiltersMap(filters);
int scores[] = new int[indexs.size()];
for (int i = 0; i < scores.length; i++) {
scores[i] = initialScore;
}
for (int i = 0; i < indexs.size(); i++) {
// 目前不使用弱一致索引
if (!indexs.get(i).isStronglyConsistent()) {
scores[i] = Integer.MAX_VALUE;
continue;
}
KVIndexStat kvIndexStat = OptimizerContext.getContext()
.getStatManager()
.getKVIndex(indexs.get(i).getName());
List<ISelectable> indexColumns = OptimizerUtils.columnMetaListToIColumnList(indexs.get(i).getKeyColumns(),
tablename);
for (int j = 0; j < indexColumns.size(); j++) {
boolean isContain = false;
if (columnFilters.isEmpty()) {// 此时以columns为准
isContain = columns.contains(indexColumns.get(j));
} else {
isContain = columnFilters.containsKey(indexColumns.get(j));
}
if (isContain) {
scores[i] = (int) CostEsitimaterFactory.estimateRowCount(scores[i],
columnFilters.get((indexColumns.get(j))),
indexs.get(i),
kvIndexStat);
scores[i] -= 1; // 命中一个主键字段
} else {
break;
}
}
}
for (int i = 0; i < scores.length; i++) {
scores[i] = initialScore - scores[i];
}
int maxIndex = 0;
int maxScore = scores[maxIndex];
for (int i = 1; i < scores.length; i++) {
if (scores[i] > maxScore) {
maxIndex = i;
maxScore = scores[i];
}
}
if (maxScore == 0) {
return null;
}
return indexs.get(maxIndex);
}
示例5: estimateRowCount
import com.taobao.tddl.optimizer.costbased.esitimater.stat.KVIndexStat; //导入依赖的package包/类
/**
* 根据索引和查询的filter条件,估算记录数
*
* @param tableRowCount 表记录数
* @param filters 查询条件
* @param index 选择的索引
* @param indexStat 索引的统计信息,如果为null则按照经验值预算
* @return
*/
public static long estimateRowCount(long tableRowCount, List<IFilter> filters, IndexMeta index,
KVIndexStat indexStat) {
// indexMeta
if (filters == null || filters.isEmpty()) {
return tableRowCount;
}
Map<String, Double> columnAndColumnCountItSelectivity = new HashMap();
if (index != null && indexStat != null) {
Double columnCountEveryKeyColumnSelect = (index.getKeyColumns().size())
* (1.0 / indexStat.getDistinctKeys());
for (ColumnMeta cm : index.getKeyColumns()) {
columnAndColumnCountItSelectivity.put(cm.getName(), columnCountEveryKeyColumnSelect);
}
}
long count = tableRowCount;
// 每出现一个运算符,都把现在的行数乘上一个系数
for (IFilter f : filters) {
if (f == null) {
break;
}
if (f instanceof IGroupFilter) {
continue;
}
IBooleanFilter filter = (IBooleanFilter) f;
Double selectivity = null;
if (filter.getColumn() instanceof IColumn) {
String columnName = ((IColumn) filter.getColumn()).getColumnName();
if (columnAndColumnCountItSelectivity.containsKey(columnName)) {
selectivity = columnAndColumnCountItSelectivity.get(columnName);
}
}
if (selectivity == null) {
selectivity = CostEsitimaterFactory.selectivity(filter.getOperation());
}
count *= selectivity;
}
return count;
}
示例6: estimateRowCount
import com.taobao.tddl.optimizer.costbased.esitimater.stat.KVIndexStat; //导入依赖的package包/类
/**
* 根据索引和查询的filter条件,估算记录数
*
* @param tableRowCount 表记录数
* @param filters 查询条件
* @param index 选择的索引
* @param indexStat 索引的统计信息,如果为null则按照经验值预算
* @return
*/
public static long estimateRowCount(long tableRowCount, List<IFilter> filters, IndexMeta index,
KVIndexStat indexStat) {
// indexMeta
if (filters == null || filters.isEmpty()) {
return tableRowCount;
}
Map<String, Double> columnAndColumnCountItSelectivity = new HashMap();
if (index != null && indexStat != null) {
Double columnCountEveryKeyColumnSelect = ((double) index.getKeyColumns().size())
* (1.0 / indexStat.getDistinctKeys());
for (ColumnMeta cm : index.getKeyColumns()) {
columnAndColumnCountItSelectivity.put(cm.getName(), columnCountEveryKeyColumnSelect);
}
}
long count = tableRowCount;
// 每出现一个运算符,都把现在的行数乘上一个系数
for (IFilter f : filters) {
if (f == null) {
break;
}
IBooleanFilter filter = (IBooleanFilter) f;
Double selectivity = null;
if (filter.getColumn() instanceof IColumn) {
String columnName = ((IColumn) filter.getColumn()).getColumnName();
if (columnAndColumnCountItSelectivity.containsKey(columnName)) {
selectivity = columnAndColumnCountItSelectivity.get(columnName);
}
}
if (selectivity == null) {
selectivity = CostEsitimaterFactory.selectivity(filter.getOperation());
}
count *= selectivity;
}
return count;
}