本文整理汇总了Java中com.taobao.tddl.optimizer.core.ast.query.TableNode.useIndex方法的典型用法代码示例。如果您正苦于以下问题:Java TableNode.useIndex方法的具体用法?Java TableNode.useIndex怎么用?Java TableNode.useIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.taobao.tddl.optimizer.core.ast.query.TableNode
的用法示例。
在下文中一共展示了TableNode.useIndex方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //导入方法依赖的package包/类
private void build(TableNode table) {
table.build();
Map<String, Object> extraCmd = new HashMap<String, Object>();
extraCmd.put(ConnectionProperties.CHOOSE_INDEX, true);
IndexMeta index = IndexChooser.findBestIndex(table.getTableMeta(),
new ArrayList<ISelectable>(),
FilterUtils.toDNFNode(table.getWhereFilter()),
table.getTableName(),
extraCmd);
table.useIndex(index);
Map<FilterType, IFilter> result = FilterSpliter.splitByIndex(FilterUtils.toDNFNode(table.getWhereFilter()),
table);
table.setKeyFilter(result.get(FilterType.IndexQueryKeyFilter));
table.setIndexQueryValueFilter(result.get(FilterType.IndexQueryValueFilter));
table.setResultFilter(result.get(FilterType.ResultFilter));
}
示例2: build
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //导入方法依赖的package包/类
private void build(TableNode table) {
table.build();
Map<String, Object> extraCmd = new HashMap<String, Object>();
extraCmd.put(ExtraCmd.CHOOSE_INDEX, true);
IndexMeta index = IndexChooser.findBestIndex(table.getTableMeta(),
new ArrayList<ISelectable>(),
FilterUtils.toDNFNode(table.getWhereFilter()),
table.getTableName(),
extraCmd);
table.useIndex(index);
Map<FilterType, IFilter> result = FilterSpliter.splitByIndex(FilterUtils.toDNFNode(table.getWhereFilter()),
table);
table.setKeyFilter(result.get(FilterType.IndexQueryKeyFilter));
table.setIndexQueryValueFilter(result.get(FilterType.IndexQueryValueFilter));
table.setResultFilter(result.get(FilterType.ResultFilter));
}
示例3: build
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //导入方法依赖的package包/类
private void build(TableNode table) {
table.build();
Map<String, Object> extraCmd = new HashMap<String, Object>();
extraCmd.put(ConnectionProperties.CHOOSE_INDEX, true);
IndexMeta index = IndexChooser.findBestIndex(table.getTableMeta(),
new ArrayList<ISelectable>(),
FilterUtils.toDNFNode(table.getWhereFilter()),
table.getTableName(),
extraCmd);
table.useIndex(index);
}
示例4: TableNode
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //导入方法依赖的package包/类
@Test
public void testChooseIndex手动指定索引() {
TableNode table = new TableNode("TABLE9");
table.build();
table.useIndex(table.getTableMeta().getIndexs().get(0));
table.build();
System.out.println(table.toDataNodeExecutor());
}
示例5: build
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //导入方法依赖的package包/类
private void build(TableNode table) {
table.build();
Map<String, Object> extraCmd = new HashMap<String, Object>();
extraCmd.put(ExtraCmd.CHOOSE_INDEX, true);
IndexMeta index = IndexChooser.findBestIndex(table.getTableMeta(),
new ArrayList<ISelectable>(),
FilterUtils.toDNFNode(table.getWhereFilter()),
table.getTableName(),
extraCmd);
table.useIndex(index);
}
示例6: TableNode
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //导入方法依赖的package包/类
@Test
public void testChooseIndex手动指定索引() throws QueryException {
TableNode table = new TableNode("TABLE9");
table.build();
table.useIndex(table.getTableMeta().getIndexs().get(0));
table.build();
System.out.println(table.toDataNodeExecutor());
}
示例7: splitByDNF
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //导入方法依赖的package包/类
/**
* 根据where中的所有条件按照or进行分隔,生成多个query请求. (主要考虑部分存储引擎不支持or语法)
*/
public static List<QueryTreeNode> splitByDNF(TableNode node, Map<String, Object> extraCmd) {
if (node.getWhereFilter() == null) {
return new LinkedList<QueryTreeNode>();
}
if (!FilterUtils.isDNF(node.getWhereFilter())) {
throw new IllegalArgumentException("not dnf!!! fuck!!\n" + node.getWhereFilter());
}
List<QueryTreeNode> subQueries = new LinkedList<QueryTreeNode>();
List<List<IFilter>> DNFNodes = FilterUtils.toDNFNodesArray(node.getWhereFilter());
// 判断是否要处理OR转化为index merge,比如mysql可以push
// 比如hbase/bdb这一类,OR条件目前只能是主键索引,由执行器层面去解决
// 如果涉及多字段时就需要拆分为index merge,同时做uniq
boolean needCopy = (DNFNodes.size() > 1);
if (isOptimizeIndexMerge(extraCmd) || DNFNodes.size() == 1) {
for (List<IFilter> DNFNode : DNFNodes) {
List columns = Arrays.asList(FilterUtils.toColumnFiltersMap(DNFNode).keySet().toArray());
String tablename = node.getTableName();
IndexMeta index = IndexChooser.findBestIndex(node.getTableMeta(), columns, DNFNode, tablename, extraCmd);
if (index == null) {
index = node.getTableMeta().getPrimaryIndex();
}
// 如果找不到对应条件的主键,可能需要全表扫描
TableNode subQuery = node;
if (needCopy) {
subQuery = node.deepCopy();
}
subQuery.useIndex(index);
if (index == null) {// 如果无主键进行全表扫描
subQuery.setFullTableScan(true);
} else {
subQuery.query((IFilter) null);// 清空where
}
Map<FilterType, IFilter> filters = splitByIndex(DNFNode, subQuery);
subQuery.setKeyFilter(filters.get(FilterType.IndexQueryKeyFilter));
subQuery.setIndexQueryValueFilter(filters.get(FilterType.IndexQueryValueFilter));
subQuery.setResultFilter(filters.get(FilterType.ResultFilter));
subQueries.add(subQuery);
}
} else {
node.useIndex(node.getTableMeta().getPrimaryIndex());// 默认选中主键
node.setResultFilter(node.getWhereFilter());
}
return subQueries;
}
示例8: splitByDNF
import com.taobao.tddl.optimizer.core.ast.query.TableNode; //导入方法依赖的package包/类
/**
* 根据where中的所有条件按照or进行分隔,生成多个query请求. (主要考虑部分存储引擎不支持or语法)
*/
public static List<QueryTreeNode> splitByDNF(TableNode node, Map<String, Object> extraCmd) throws QueryException {
if (node.getWhereFilter() == null) {
return new LinkedList<QueryTreeNode>();
}
if (!FilterUtils.isDNF(node.getWhereFilter())) {
throw new IllegalArgumentException("not dnf!!! fuck!!\n" + node.getWhereFilter());
}
List<QueryTreeNode> subQueries = new LinkedList<QueryTreeNode>();
List<List<IFilter>> DNFNodes = FilterUtils.toDNFNodesArray(node.getWhereFilter());
// 判断是否要处理OR转化为index merge,比如mysql可以push
// 比如hbase/bdb这一类,OR条件目前只能是主键索引,由执行器层面去解决
// 如果涉及多字段时就需要拆分为index merge,同时做uniq
boolean needCopy = (DNFNodes.size() > 1);
if (isOptimizeIndexMerge(extraCmd) || DNFNodes.size() == 1) {
for (List<IFilter> DNFNode : DNFNodes) {
List columns = Arrays.asList(FilterUtils.toColumnFiltersMap(DNFNode).keySet().toArray());
String tablename = node.getTableName();
IndexMeta index = IndexChooser.findBestIndex(node.getTableMeta(), columns, DNFNode, tablename, extraCmd);
if (index == null) {
index = node.getTableMeta().getPrimaryIndex();
}
// 如果找不到对应条件的主键,可能需要全表扫描
TableNode subQuery = node;
if (needCopy) {
subQuery = node.deepCopy();
}
subQuery.useIndex(index);
if (index == null) {// 如果无主键进行全表扫描
subQuery.setFullTableScan(true);
}
Map<FilterType, IFilter> filters = splitByIndex(DNFNode, subQuery);
subQuery.setKeyFilter(filters.get(FilterType.IndexQueryKeyFilter));
subQuery.setIndexQueryValueFilter(filters.get(FilterType.IndexQueryValueFilter));
subQuery.setResultFilter(filters.get(FilterType.ResultFilter));
subQueries.add(subQuery);
}
} else {
node.useIndex(node.getTableMeta().getPrimaryIndex());// 默认选中主键
node.setResultFilter(node.getWhereFilter());
}
return subQueries;
}