Exemple #1
0
  /**
   * NAME=1的选择性显然比SCHOOL>1好,所以选择二级索引NAME
   *
   * @throws QueryException
   */
  @Test
  public void testChooseIndex列出现的顺序不影响索引选择() throws QueryException {
    TableNode table1 = new TableNode("TABLE1");
    QueryTreeNode qn1 = table1.query("SCHOOL>1&&NAME=1");
    qn1.build();

    IndexMeta index =
        IndexChooser.findBestIndex(
            table1.getTableMeta(),
            table1.getColumnsRefered(),
            toDNFFilter(table1.getWhereFilter()),
            table1.getTableName(),
            extraCmd);

    Assert.assertNotNull(index);
    Assert.assertEquals(index.getName(), "TABLE1._NAME");

    TableNode table2 = new TableNode("TABLE1");
    QueryTreeNode qn2 = table2.query("NAME=1&&SCHOOL>1");
    qn2.build();

    index =
        IndexChooser.findBestIndex(
            table2.getTableMeta(),
            table2.getColumnsRefered(),
            toDNFFilter(table2.getWhereFilter()),
            table2.getTableName(),
            extraCmd);

    Assert.assertNotNull(index);
    Assert.assertEquals(index.getName(), "TABLE1._NAME");
  }
Exemple #2
0
  /** 虽然C1,C2上存在组合索引,但是由于范围查询的选择度不如等值查询 因此还是选择了单索引NAME=1 */
  @Test
  public void testChooseIndex单索引选择度好于组合索引() throws QueryException {
    TableNode table = new TableNode("TABLE9");
    QueryTreeNode qn = table.query("C1>10&&C2>3&&NAME=1");
    qn.build();

    IndexMeta index =
        IndexChooser.findBestIndex(
            table.getTableMeta(),
            table.getColumnsRefered(),
            toDNFFilter(table.getWhereFilter()),
            table.getTableName(),
            extraCmd);

    Assert.assertNotNull(index);
    Assert.assertEquals(index.getName(), "TABLE9._NAME");
  }
Exemple #3
0
  @Test
  public void testChooseIndex() throws QueryException {
    TableNode table = new TableNode("TABLE1");
    QueryTreeNode qn = table.query("ID=1");
    qn.build();

    IndexMeta index =
        IndexChooser.findBestIndex(
            table.getTableMeta(),
            emptyColumns,
            toDNFFilter(table.getWhereFilter()),
            table.getTableName(),
            extraCmd);

    Assert.assertNotNull(index);
    Assert.assertEquals(index.getName(), "TABLE1");
  }
Exemple #4
0
  /** C6,C7同时存在组合索引和倒排索引 同时有倒排和组合索引,并且选择度一样,优先选择组合 */
  @Test
  public void testChooseIndex选择度相同优先选组合() throws QueryException {
    TableNode table = new TableNode("TABLE9");
    QueryTreeNode qn = table.query("C6=10&&C7=3");
    qn.build();

    IndexMeta index =
        IndexChooser.findBestIndex(
            table.getTableMeta(),
            table.getColumnsRefered(),
            toDNFFilter(table.getWhereFilter()),
            table.getTableName(),
            extraCmd);

    Assert.assertNotNull(index);
    Assert.assertEquals(index.getName(), "TABLE9._C6_C7");
  }