Search in sources :

Example 46 with AbstractPlanNode

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

the class PlannerTestCase method assertLeftChain.

/**
     * Assert that a plan's left-most branch is made up of plan nodes of
     * expected classes.
     * @param expectedClasses a list of expected AbstractPlanNode classes
     * @param actualPlan the top of a plan node tree expected to have instances
     *                   of the expected classes along its left-most branch
     *                   listed from top to bottom.
     */
protected static void assertLeftChain(AbstractPlanNode start, PlanNodeType... nodeTypes) {
    AbstractPlanNode pn = start;
    for (PlanNodeType type : nodeTypes) {
        assertFalse("Child node(s) are missing from the actual plan chain.", pn == null);
        if (!type.equals(pn.getPlanNodeType())) {
            fail("Expecting plan node of type " + type + ", " + "instead found " + pn.getPlanNodeType() + ".");
        }
        pn = (pn.getChildCount() > 0) ? pn.getChild(0) : null;
    }
    assertTrue("Actual plan chain was longer than expected", pn == null);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) PlanNodeType(org.voltdb.types.PlanNodeType)

Example 47 with AbstractPlanNode

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

the class PlannerTestCase method assertTopDownTree.

/**
     * Assert that a plan node tree contains the expected types of plan nodes
     * in the order listed, assuming a top-down left-to-right depth-first
     * traversal through the child vector. A null plan node type in the list
     * will match any plan node or subtree at the corresponding position.
     **/
protected static void assertTopDownTree(AbstractPlanNode start, PlanNodeType... nodeTypes) {
    Stack<AbstractPlanNode> stack = new Stack<>();
    stack.push(start);
    for (PlanNodeType type : nodeTypes) {
        // Process each node before its children or later siblings.
        AbstractPlanNode parent;
        try {
            parent = stack.pop();
        } catch (EmptyStackException ese) {
            fail("No node was found in the tree to match node type " + type);
            // This dead code hushes warnings.
            return;
        }
        int childCount = parent.getChildCount();
        if (type == null) {
            // A null type wildcard matches any child TREE or NODE.
            System.out.println("DEBUG: Suggestion -- expect " + parent.getPlanNodeType() + " with " + childCount + " direct children.");
            continue;
        }
        assertEquals(type, parent.getPlanNodeType());
        // Iterate from the last child to the first.
        while (childCount > 0) {
            // Push each child to be processed before its parent's
            // or its own later (already pushed) siblings.
            stack.push(parent.getChild(--childCount));
        }
    }
    assertTrue("Extra plan node(s) (" + stack.size() + ") were found in the tree with no node type to match", stack.isEmpty());
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) PlanNodeType(org.voltdb.types.PlanNodeType) EmptyStackException(java.util.EmptyStackException) Stack(java.util.Stack)

Example 48 with AbstractPlanNode

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

the class TestIndexSelection method testSkipNullPartialIndex.

public void testSkipNullPartialIndex() {
    AbstractPlanNode pn;
    //CREATE INDEX partial_idx_7 ON c (g) where g is not null;
    // skipNull predicate is redundant and eliminated
    pn = compile("select count(*) from c where g > 0;");
    checkCountUsesIndex(pn, "PARTIAL_IDX_7");
    checkIndexSkipNullPredicateIsNull(pn, false);
    //CREATE INDEX partial_idx_7 ON c (g) where g is not null;
    // skipNull predicate is redundant and eliminated
    pn = compile("select e from c where g > 0;");
    checkScanUsesIndex(pn, "PARTIAL_IDX_7");
    checkIndexSkipNullPredicateIsNull(pn, false);
    //CREATE INDEX partial_idx_6 ON c (g) where g < 0;
    // skipNull predicate is redundant and eliminated
    pn = compile("select count(*) from c where g < 0;");
    checkCountUsesIndex(pn, "PARTIAL_IDX_6");
    checkIndexSkipNullPredicateIsNull(pn, false);
    //CREATE INDEX partial_idx_6 ON c (g) where g < 0;
    // skipNull predicate is redundant and eliminated
    pn = compile("select g from c where g < 0;");
    checkScanUsesIndex(pn, "PARTIAL_IDX_6");
    checkIndexSkipNullPredicateIsNull(pn, false);
    // CREATE UNIQUE INDEX z_full_idx_a ON c (a);
    // skipNull is required - full index
    pn = compile("select count(*) from c where a > 0;");
    checkCountUsesIndex(pn, "Z_FULL_IDX_A");
    checkIndexSkipNullPredicateIsNull(pn, true);
    // CREATE UNIQUE INDEX z_full_idx_a ON c (a);
    // skipNull is required - full index
    pn = compile("select e from c where a > 0;");
    checkScanUsesIndex(pn, "Z_FULL_IDX_A");
    checkIndexSkipNullPredicateIsNull(pn, true);
    // CREATE INDEX partial_idx_3 ON c (b) where d > 0;
    // skipNull is required - index predicate is not NULL-rejecting for column B
    pn = compile("select count(*) from c where b > 0 and d > 0;");
    checkCountUsesIndex(pn, "PARTIAL_IDX_3");
    checkIndexSkipNullPredicateIsNull(pn, true);
    // CREATE INDEX partial_idx_3 ON c (b) where d > 0;
    // skipNull is required - index predicate is not NULL-rejecting for column B
    pn = compile("select b from c where b > 0 and d > 0;");
    checkScanUsesIndex(pn, "PARTIAL_IDX_3");
    checkIndexSkipNullPredicateIsNull(pn, true);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode)

Example 49 with AbstractPlanNode

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

the class TestIndexSelection method testCaseWhenIndex.

public void testCaseWhenIndex() {
    AbstractPlanNode pn;
    pn = compile("select * from l where CASE WHEN a > b THEN a ELSE b END > 8;");
    pn = pn.getChild(0);
    //*enable to debug*/System.out.println(pn.toExplainPlanString());
    assertTrue(pn.toExplainPlanString().contains("CASEWHEN_IDX1"));
    pn = compile("select * from l WHERE CASE WHEN a < 10 THEN a*5 ELSE a + 5 END > 2");
    pn = pn.getChild(0);
    //*enable to debug*/System.out.println(pn.toExplainPlanString());
    assertTrue(pn.toExplainPlanString().contains("CASEWHEN_IDX2"));
    // Negative case
    pn = compile("select * from l WHERE CASE WHEN a < 10 THEN a*2 ELSE a + 5 END > 2");
    pn = pn.getChild(0);
    /*enable to debug*/
    System.out.println(pn.toExplainPlanString());
    assertTrue(pn.toExplainPlanString().contains("using its primary key index (for deterministic order only)"));
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode)

Example 50 with AbstractPlanNode

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

the class TestIndexSelection method testPartialIndexArbitraryPredicate.

public void testPartialIndexArbitraryPredicate() {
    AbstractPlanNode pn;
    // CREATE INDEX partial_idx_or_expr ON c (f) where e > 0 or d < 5;
    pn = compile("select * from c where f > 0 and (e > 0 or d < 5);");
    checkScanUsesIndex(pn, "PARTIAL_IDX_OR_EXPR");
    checkIndexPredicateIsNull(pn);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode)

Aggregations

AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)259 AbstractExpression (org.voltdb.expressions.AbstractExpression)55 IndexScanPlanNode (org.voltdb.plannodes.IndexScanPlanNode)48 ProjectionPlanNode (org.voltdb.plannodes.ProjectionPlanNode)48 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)46 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)44 AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)37 NestLoopPlanNode (org.voltdb.plannodes.NestLoopPlanNode)37 HashAggregatePlanNode (org.voltdb.plannodes.HashAggregatePlanNode)29 OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)29 ReceivePlanNode (org.voltdb.plannodes.ReceivePlanNode)27 SendPlanNode (org.voltdb.plannodes.SendPlanNode)27 MergeReceivePlanNode (org.voltdb.plannodes.MergeReceivePlanNode)20 AbstractReceivePlanNode (org.voltdb.plannodes.AbstractReceivePlanNode)16 NestLoopIndexPlanNode (org.voltdb.plannodes.NestLoopIndexPlanNode)16 SchemaColumn (org.voltdb.plannodes.SchemaColumn)15 NodeSchema (org.voltdb.plannodes.NodeSchema)14 UnionPlanNode (org.voltdb.plannodes.UnionPlanNode)14 LimitPlanNode (org.voltdb.plannodes.LimitPlanNode)12 PlanNodeType (org.voltdb.types.PlanNodeType)12