Search in sources :

Example 51 with IndexScanPlanNode

use of org.voltdb.plannodes.IndexScanPlanNode in project voltdb by VoltDB.

the class TestMultipleOuterJoinPlans method testMultitableDistributedJoin.

public void testMultitableDistributedJoin() {
    List<AbstractPlanNode> lpn;
    AbstractPlanNode n;
    // One distributed table
    lpn = compileToFragments("select *  FROM R3,R1 LEFT JOIN P2 ON R3.A = P2.A WHERE R3.A=R1.A ");
    assertTrue(lpn.size() == 2);
    n = lpn.get(0).getChild(0).getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOP, JoinType.LEFT, null, ExpressionType.COMPARE_EQUAL, null, PlanNodeType.NESTLOOPINDEX, PlanNodeType.RECEIVE);
    // R3.A and P2.A have an index. P2,R1 is NLIJ/inlined IndexScan because it's an inner join even P2 is distributed
    lpn = compileToFragments("select *  FROM P2,R1 LEFT JOIN R3 ON R3.A = P2.A WHERE P2.A=R1.A ");
    assertTrue(lpn.size() == 2);
    n = lpn.get(0).getChild(0).getChild(0);
    assertTrue(n instanceof ReceivePlanNode);
    n = lpn.get(1).getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOPINDEX, JoinType.LEFT, null, null, null, PlanNodeType.NESTLOOPINDEX, PlanNodeType.INDEXSCAN);
    // R3.A has an index. R3,P2 is NLJ because it's an outer join and P2 is distributed
    lpn = compileToFragments("select *  FROM R3,R1 LEFT JOIN P2 ON R3.A = P2.A WHERE R3.A=R1.A ");
    assertTrue(lpn.size() == 2);
    // to debug */ System.out.println("DEBUG 0.0: " + lpn.get(0).toExplainPlanString());
    // to debug */ System.out.println("DEBUG 0.1: " + lpn.get(1).toExplainPlanString());
    n = lpn.get(0).getChild(0).getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOP, JoinType.LEFT, null, ExpressionType.COMPARE_EQUAL, null, PlanNodeType.NESTLOOPINDEX, PlanNodeType.RECEIVE);
    n = n.getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOPINDEX, JoinType.INNER, null, null, null, PlanNodeType.SEQSCAN, PlanNodeType.INDEXSCAN);
    n = lpn.get(1).getChild(0);
    // For determinism reason
    assertTrue(n instanceof IndexScanPlanNode);
    // R3.A has an index. P2,R1 is NLJ because P2 is distributed and it's an outer join
    lpn = compileToFragments("select *  FROM R1 LEFT JOIN P2 ON R1.A = P2.A, R3 WHERE R1.A=R3.A ");
    assertTrue(lpn.size() == 2);
    // to debug */ System.out.println("DEBUG 1.0: " + lpn.get(0).toExplainPlanString());
    // to debug */ System.out.println("DEBUG 1.1: " + lpn.get(1).toExplainPlanString());
    n = lpn.get(0).getChild(0).getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOPINDEX, JoinType.INNER, null, null, null, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN);
    n = n.getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOP, JoinType.LEFT, null, ExpressionType.COMPARE_EQUAL, null, PlanNodeType.SEQSCAN, PlanNodeType.RECEIVE);
    n = lpn.get(1).getChild(0);
    // For determinism reason
    assertTrue(n instanceof IndexScanPlanNode);
    // Two distributed table
    lpn = compileToFragments("select *  FROM R3,P1 LEFT JOIN P2 ON R3.A = P2.A WHERE R3.A=P1.A ");
    assertTrue(lpn.size() == 2);
    n = lpn.get(0).getChild(0).getChild(0);
    assertTrue(n instanceof ReceivePlanNode);
    n = lpn.get(1).getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOPINDEX, JoinType.LEFT, null, null, null, PlanNodeType.NESTLOOPINDEX, PlanNodeType.INDEXSCAN);
    n = n.getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOPINDEX, JoinType.INNER, null, null, null, PlanNodeType.SEQSCAN, PlanNodeType.INDEXSCAN);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) IndexScanPlanNode(org.voltdb.plannodes.IndexScanPlanNode) ReceivePlanNode(org.voltdb.plannodes.ReceivePlanNode)

Example 52 with IndexScanPlanNode

use of org.voltdb.plannodes.IndexScanPlanNode in project voltdb by VoltDB.

the class TestIndexReverseScan method checkForwardScan.

private void checkForwardScan(String indexName, IndexLookupType lookupType, int searchKeys, int endKeys, int predicates, SortDirectionType sortType, boolean needOrderby) {
    AbstractPlanNode pn = compile(sql);
    System.out.println(pn.toExplainPlanString());
    assertTrue(pn instanceof SendPlanNode);
    pn = pn.getChild(0);
    if (needOrderby) {
        assertTrue(pn instanceof ProjectionPlanNode);
        pn = pn.getChild(0);
        assertTrue(pn instanceof OrderByPlanNode);
        pn = pn.getChild(0);
    }
    assertTrue(pn instanceof IndexScanPlanNode);
    IndexScanPlanNode ispn = (IndexScanPlanNode) pn;
    assertTrue(ispn.getTargetIndexName().contains(indexName));
    assertEquals(lookupType, ispn.getLookupType());
    assertEquals(searchKeys, ispn.getSearchKeyExpressions().size());
    assertEquals(endKeys, ExpressionUtil.uncombinePredicate(ispn.getEndExpression()).size());
    assertEquals(predicates, ExpressionUtil.uncombinePredicate(ispn.getPredicate()).size());
    assertEquals(0, ExpressionUtil.uncombinePredicate(ispn.getInitialExpression()).size());
    assertEquals(sortType, ispn.getSortDirection());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) SendPlanNode(org.voltdb.plannodes.SendPlanNode) IndexScanPlanNode(org.voltdb.plannodes.IndexScanPlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 53 with IndexScanPlanNode

use of org.voltdb.plannodes.IndexScanPlanNode in project voltdb by VoltDB.

the class TestIndexReverseScan method checkReverseScan.

private void checkReverseScan(String indexName, IndexLookupType lookupType, int searchKeys, int endKeys, int predicates, int initials, boolean artificial, SortDirectionType sortType, boolean needOrderby) {
    AbstractPlanNode pn = compile(sql);
    System.out.println(pn.toExplainPlanString());
    assertTrue(pn instanceof SendPlanNode);
    pn = pn.getChild(0);
    if (needOrderby) {
        assertTrue(pn instanceof ProjectionPlanNode);
        pn = pn.getChild(0);
        assertTrue(pn instanceof OrderByPlanNode);
        pn = pn.getChild(0);
    }
    assertTrue(pn instanceof IndexScanPlanNode);
    IndexScanPlanNode ispn = (IndexScanPlanNode) pn;
    assertTrue(ispn.getTargetIndexName().contains(indexName));
    assertEquals(lookupType, ispn.getLookupType());
    assertEquals(searchKeys, ispn.getSearchKeyExpressions().size());
    assertEquals(endKeys, ExpressionUtil.uncombinePredicate(ispn.getEndExpression()).size());
    assertEquals(predicates, ExpressionUtil.uncombinePredicate(ispn.getPredicate()).size());
    assertEquals(initials, ExpressionUtil.uncombinePredicate(ispn.getInitialExpression()).size());
    // Test artificial post predicate
    if (predicates == 1 && artificial) {
        assertTrue(ispn.getPredicate().getExpressionType() == ExpressionType.OPERATOR_NOT);
        assertTrue(ispn.getPredicate().getLeft().getExpressionType() == ExpressionType.OPERATOR_IS_NULL);
    } else if (predicates > 1) {
        assertTrue(ispn.getPredicate().getExpressionType() == ExpressionType.CONJUNCTION_AND);
    }
    // SortDirection can be INVALID because we use LookupType to determine
    // index scan direction instead in EE.
    assertEquals(sortType, ispn.getSortDirection());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) SendPlanNode(org.voltdb.plannodes.SendPlanNode) IndexScanPlanNode(org.voltdb.plannodes.IndexScanPlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 54 with IndexScanPlanNode

use of org.voltdb.plannodes.IndexScanPlanNode in project voltdb by VoltDB.

the class TestIndexSelection method testEng4792PlanWithCompoundEQLTEOrderedByPK.

// This tests recognition of a prefix parameter and upper bound to prefer an index that would
// use a greater number of key components even though another index would give the desired ordering.
public void testEng4792PlanWithCompoundEQLTEOrderedByPK() throws JSONException {
    AbstractPlanNode pn = compile("select id from a where deleted=? and updated_date <= ? order by id limit ?;");
    // System.out.println("DEBUG: " + pn.toExplainPlanString());
    pn = pn.getChild(0);
    // ENG-5066: now Limit is pushed under Projection
    assertTrue(pn instanceof ProjectionPlanNode);
    pn = pn.getChild(0);
    // inline limit with order by
    assertTrue(pn instanceof OrderByPlanNode);
    assertNotNull(pn.getInlinePlanNode(PlanNodeType.LIMIT));
    pn = pn.getChild(0);
    assertTrue(pn instanceof IndexScanPlanNode);
    IndexScanPlanNode ispn = (IndexScanPlanNode) pn;
    assertEquals("DELETED_SINCE_IDX", ispn.getTargetIndexName());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) OrderByPlanNode(org.voltdb.plannodes.OrderByPlanNode) IndexScanPlanNode(org.voltdb.plannodes.IndexScanPlanNode) ProjectionPlanNode(org.voltdb.plannodes.ProjectionPlanNode)

Example 55 with IndexScanPlanNode

use of org.voltdb.plannodes.IndexScanPlanNode in project voltdb by VoltDB.

the class TestIndexSelection method testEng2541Plan.

// This tests recognition of prefix parameters and constants to prefer an index that
// would use a greater number of key components AND would give the desired ordering.
public void testEng2541Plan() throws JSONException {
    AbstractPlanNode pn = compile("select * from l where lname=? and b=0 order by id asc limit ?;");
    pn = pn.getChild(0);
    // System.out.println("DEBUG: " + pn.toExplainPlanString());
    assertTrue(pn instanceof IndexScanPlanNode);
    IndexScanPlanNode ispn = (IndexScanPlanNode) pn;
    assertEquals("IDX_B", ispn.getTargetIndexName());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) IndexScanPlanNode(org.voltdb.plannodes.IndexScanPlanNode)

Aggregations

IndexScanPlanNode (org.voltdb.plannodes.IndexScanPlanNode)60 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)48 AbstractExpression (org.voltdb.expressions.AbstractExpression)22 NestLoopIndexPlanNode (org.voltdb.plannodes.NestLoopIndexPlanNode)15 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)14 NestLoopPlanNode (org.voltdb.plannodes.NestLoopPlanNode)11 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)8 AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)7 OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)6 ArrayList (java.util.ArrayList)5 Index (org.voltdb.catalog.Index)5 ReceivePlanNode (org.voltdb.plannodes.ReceivePlanNode)5 AbstractReceivePlanNode (org.voltdb.plannodes.AbstractReceivePlanNode)4 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)4 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)4 SendPlanNode (org.voltdb.plannodes.SendPlanNode)4 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)3 IndexCountPlanNode (org.voltdb.plannodes.IndexCountPlanNode)3 StmtTableScan (org.voltdb.planner.parseinfo.StmtTableScan)2 AbstractJoinPlanNode (org.voltdb.plannodes.AbstractJoinPlanNode)2