本文整理匯總了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;
}