当前位置: 首页>>代码示例>>Java>>正文


Java TableNode.useIndex方法代码示例

本文整理汇总了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));
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:21,代码来源:JoinChooserTest.java

示例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));
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:21,代码来源:JoinChooserTest.java

示例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);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:14,代码来源:FilterSpliterTest.java

示例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());
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:9,代码来源:IndexChooserTest.java

示例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);
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:14,代码来源:FilterSpliterTest.java

示例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());
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:9,代码来源:IndexChooserTest.java

示例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;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:53,代码来源:FilterSpliter.java

示例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;
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:51,代码来源:FilterSpliter.java


注:本文中的com.taobao.tddl.optimizer.core.ast.query.TableNode.useIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。