use of org.voltdb.plannodes.AbstractPlanNode in project voltdb by VoltDB.
the class TestIndexCoveringPlans method testCover3ColumnsInOrderWithLessThanAndOrderBy.
public void testCover3ColumnsInOrderWithLessThanAndOrderBy() {
AbstractPlanNode pn = compile("select a, b from t where a = ? and c = ? and b < ? order by b;");
pn = pn.getChild(0);
if (pn != null) {
System.out.println(pn.toJSONString());
}
assertTrue(pn instanceof IndexScanPlanNode);
IndexScanPlanNode ispn = (IndexScanPlanNode) pn;
assertEquals("COVER3_TREE", ispn.getTargetIndexName());
assertEquals(IndexLookupType.GTE, ispn.getLookupType());
assertEquals(2, ispn.getSearchKeyExpressions().size());
}
use of org.voltdb.plannodes.AbstractPlanNode in project voltdb by VoltDB.
the class TestIndexSelection method testGeoIndex.
public void testGeoIndex() {
AbstractPlanNode pn;
IndexScanPlanNode indexScan;
String jsonicIdxScan;
pn = compile("select polys.point " + "from polypoints polys " + "where contains(polys.poly, ?);");
pn = pn.getChild(0);
/* enable to debug */
System.out.println("DEBUG: " + pn.toExplainPlanString());
assertTrue(pn instanceof IndexScanPlanNode);
indexScan = (IndexScanPlanNode) pn;
assertEquals(IndexLookupType.GEO_CONTAINS, indexScan.getLookupType());
jsonicIdxScan = indexScan.toJSONString();
/* enable to debug */
System.out.println("DEBUG: " + jsonicIdxScan);
assertEquals("POLYPOINTSPOLY", indexScan.getTargetIndexName());
// Expecting one index search key expression
// that is a parameter (31) of type GEOGRAPHY_POINT (26).
assertEquals(1, indexScan.getSearchKeyExpressions().size());
assertTrue(jsonicIdxScan.contains("\"SEARCHKEY_EXPRESSIONS\":[{\"TYPE\":31,\"VALUE_TYPE\":26"));
pn = compile("select polys.poly, points.point " + "from polypoints polys, polypoints points " + "where contains(polys.poly, points.point);");
pn = pn.getChild(0);
pn = pn.getChild(0);
/* enable to debug */
System.out.println("DEBUG: " + pn.toExplainPlanString());
assertTrue(pn instanceof NestLoopIndexPlanNode);
indexScan = ((NestLoopIndexPlanNode) pn).getInlineIndexScan();
assertEquals(IndexLookupType.GEO_CONTAINS, indexScan.getLookupType());
jsonicIdxScan = indexScan.toJSONString();
assertEquals("POLYPOINTSPOLY", indexScan.getTargetIndexName());
// Expecting one index search key expression
// that is a TVE (32) of type GEOGRAPHY_POINT (26).
assertEquals(1, indexScan.getSearchKeyExpressions().size());
assertTrue(jsonicIdxScan.contains("\"SEARCHKEY_EXPRESSIONS\":[{\"TYPE\":32,\"VALUE_TYPE\":26"));
pn = pn.getChild(0);
// A non-geography index scan over a unique key for the
// outer scan of "points" gets injected strictly for determinism.
assertTrue(pn instanceof IndexScanPlanNode);
indexScan = (IndexScanPlanNode) pn;
assertEquals(IndexLookupType.GTE, indexScan.getLookupType());
pn = compile("select polys.point " + "from polypoints polys " + "where contains(polys.poly, ?);");
pn = pn.getChild(0);
//* enable to debug */ System.out.println("DEBUG: " + pn.toExplainPlanString());
assertTrue(pn instanceof IndexScanPlanNode);
indexScan = (IndexScanPlanNode) pn;
assertEquals(IndexLookupType.GEO_CONTAINS, indexScan.getLookupType());
jsonicIdxScan = indexScan.toJSONString();
//* enable to debug */ System.out.println("DEBUG: " + jsonicIdxScan);
assertEquals("POLYPOINTSPOLY", indexScan.getTargetIndexName());
// Expecting one index search key expression
// that is a parameter (31) of type GEOGRAPHY_POINT (26).
assertEquals(1, indexScan.getSearchKeyExpressions().size());
assertTrue(jsonicIdxScan.contains("\"SEARCHKEY_EXPRESSIONS\":[{\"TYPE\":31,\"VALUE_TYPE\":26"));
}
use of org.voltdb.plannodes.AbstractPlanNode in project voltdb by VoltDB.
the class TestPlansGroupBy method testComplexGroupBy.
public void testComplexGroupBy() {
List<AbstractPlanNode> pns;
pns = compileToFragments("SELECT A1, ABS(A1), ABS(A1)+1, sum(B1) FROM P1 GROUP BY A1, ABS(A1)");
checkHasComplexAgg(pns);
// Check it can compile
pns = compileToFragments("SELECT ABS(A1), sum(B1) FROM P1 GROUP BY ABS(A1)");
AbstractPlanNode p = pns.get(0).getChild(0);
assertTrue(p instanceof AggregatePlanNode);
p = pns.get(1).getChild(0);
// inline aggregate
assertTrue(p instanceof AbstractScanPlanNode);
assertNotNull(p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
pns = compileToFragments("SELECT A1+PKEY, avg(B1) as tag FROM P1 GROUP BY A1+PKEY ORDER BY ABS(tag), A1+PKEY");
checkHasComplexAgg(pns);
}
use of org.voltdb.plannodes.AbstractPlanNode in project voltdb by VoltDB.
the class TestPlansGroupBy method testGroupByOnly.
public void testGroupByOnly() {
List<AbstractPlanNode> pns;
System.out.println("Starting testGroupByOnly");
/**
* Serial Aggregate cases
*/
// Replicated Table
// only GROUP BY cols in SELECT clause
pns = compileToFragments("SELECT F_D1 FROM RF GROUP BY F_D1");
checkGroupByOnlyPlan(pns, false, S_AGG, true);
// SELECT cols in GROUP BY and other aggregate cols
pns = compileToFragments("SELECT F_D1, COUNT(*) FROM RF GROUP BY F_D1");
checkGroupByOnlyPlan(pns, false, S_AGG, true);
// aggregate cols are part of keys of used index
pns = compileToFragments("SELECT F_VAL1, SUM(F_VAL2) FROM RF GROUP BY F_VAL1");
checkGroupByOnlyPlan(pns, false, S_AGG, true);
// expr index, full indexed case
pns = compileToFragments("SELECT F_D1 + F_D2, COUNT(*) FROM RF GROUP BY F_D1 + F_D2");
checkGroupByOnlyPlan(pns, false, S_AGG, true);
// function index, prefix indexed case
pns = compileToFragments("SELECT ABS(F_D1), COUNT(*) FROM RF GROUP BY ABS(F_D1)");
checkGroupByOnlyPlan(pns, false, S_AGG, true);
// order of GROUP BY cols is different of them in index definition
// index on (ABS(F_D1), F_D2 - F_D3), GROUP BY on (F_D2 - F_D3, ABS(F_D1))
pns = compileToFragments("SELECT F_D2 - F_D3, ABS(F_D1), COUNT(*) FROM RF GROUP BY F_D2 - F_D3, ABS(F_D1)");
checkGroupByOnlyPlan(pns, false, S_AGG, true);
pns = compileToFragments("SELECT F_VAL1, F_VAL2, COUNT(*) FROM RF GROUP BY F_VAL2, F_VAL1");
//* enable to debug */ System.out.println(pns, "DEBUG: " + pns.get(0).toExplainPlanString());
checkGroupByOnlyPlan(pns, false, S_AGG, true);
// Partitioned Table
pns = compileToFragments("SELECT F_D1 FROM F GROUP BY F_D1");
// index scan for group by only, no need using hash aggregate
checkGroupByOnlyPlan(pns, true, S_AGG, true);
pns = compileToFragments("SELECT F_D1, COUNT(*) FROM F GROUP BY F_D1");
checkGroupByOnlyPlan(pns, true, S_AGG, true);
pns = compileToFragments("SELECT F_VAL1, SUM(F_VAL2) FROM F GROUP BY F_VAL1");
checkGroupByOnlyPlan(pns, true, S_AGG, true);
pns = compileToFragments("SELECT F_D1 + F_D2, COUNT(*) FROM F GROUP BY F_D1 + F_D2");
checkGroupByOnlyPlan(pns, true, S_AGG, true);
pns = compileToFragments("SELECT ABS(F_D1), COUNT(*) FROM F GROUP BY ABS(F_D1)");
checkGroupByOnlyPlan(pns, true, S_AGG, true);
pns = compileToFragments("SELECT F_D2 - F_D3, ABS(F_D1), COUNT(*) FROM F GROUP BY F_D2 - F_D3, ABS(F_D1)");
checkGroupByOnlyPlan(pns, true, S_AGG, true);
/**
* Hash Aggregate cases
*/
// unoptimized case (only use second col of the index), but will be replaced in
// SeqScanToIndexScan optimization for deterministic reason
// use EXPR_RF_TREE1 not EXPR_RF_TREE2
pns = compileToFragments("SELECT F_D2 - F_D3, COUNT(*) FROM RF GROUP BY F_D2 - F_D3");
checkGroupByOnlyPlan(pns, false, H_AGG, true);
// unoptimized case: index is not scannable
pns = compileToFragments("SELECT F_VAL3, COUNT(*) FROM RF GROUP BY F_VAL3");
checkGroupByOnlyPlan(pns, false, H_AGG, true);
// unoptimized case: F_D2 is not prefix indexable
pns = compileToFragments("SELECT F_D2, COUNT(*) FROM RF GROUP BY F_D2");
checkGroupByOnlyPlan(pns, false, H_AGG, true);
// unoptimized case (only uses second col of the index), will not be replaced in
// SeqScanToIndexScan for determinism because of non-deterministic receive.
// Use primary key index
pns = compileToFragments("SELECT F_D2 - F_D3, COUNT(*) FROM F GROUP BY F_D2 - F_D3");
checkGroupByOnlyPlan(pns, true, H_AGG, true);
// unoptimized case (only uses second col of the index), will be replaced in
// SeqScanToIndexScan for determinism.
// use EXPR_F_TREE1 not EXPR_F_TREE2
pns = compileToFragments("SELECT F_D2 - F_D3, COUNT(*) FROM RF GROUP BY F_D2 - F_D3");
//* enable to debug */ System.out.println(pns, pns.get(0).toExplainPlanString());
checkGroupByOnlyPlan(pns, false, H_AGG, true);
/**
* Partial Aggregate cases
*/
// unoptimized case: no prefix index found for (F_D1, F_D2)
pns = compileToFragments("SELECT F_D1, F_D2, COUNT(*) FROM RF GROUP BY F_D1, F_D2");
checkGroupByOnlyPlan(pns, false, P_AGG, true);
pns = compileToFragments("SELECT ABS(F_D1), F_D3, COUNT(*) FROM RF GROUP BY ABS(F_D1), F_D3");
checkGroupByOnlyPlan(pns, false, P_AGG, true);
// partition table
pns = compileToFragments("SELECT F_D1, F_D2, COUNT(*) FROM F GROUP BY F_D1, F_D2");
checkGroupByOnlyPlan(pns, true, P_AGG, true);
pns = compileToFragments("SELECT ABS(F_D1), F_D3, COUNT(*) FROM F GROUP BY ABS(F_D1), F_D3");
checkGroupByOnlyPlan(pns, true, P_AGG, true);
/**
* Regression case
*/
// ENG-9990 Repeating GROUP BY partition key in SELECT corrupts output schema.
//* enable to debug */ boolean was = AbstractPlanNode.enableVerboseExplainForDebugging();
pns = compileToFragments("SELECT G_PKEY, COUNT(*) C, G_PKEY FROM G GROUP BY G_PKEY");
//* enable to debug */ System.out.println(pns.get(0).toExplainPlanString());
//* enable to debug */ System.out.println(pns.get(1).toExplainPlanString());
//* enable to debug */ AbstractPlanNode.restoreVerboseExplainForDebugging(was);
AbstractPlanNode pn = pns.get(0);
pn = pn.getChild(0);
NodeSchema os = pn.getOutputSchema();
// The problem was a mismatch between the output schema
// of the coordinator's send node and its feeding receive node
// that had incorrectly rearranged its columns.
SchemaColumn middleCol = os.getColumns().get(1);
System.out.println(middleCol.toString());
assertTrue(middleCol.getColumnAlias().equals("C"));
}
use of org.voltdb.plannodes.AbstractPlanNode in project voltdb by VoltDB.
the class TestPlansGroupBy method testGroupByA1.
public void testGroupByA1() {
AbstractPlanNode p;
AggregatePlanNode aggNode;
List<AbstractPlanNode> pns;
pns = compileToFragments("SELECT A1 from T1 group by A1");
p = pns.get(0).getChild(0);
assertTrue(p instanceof AggregatePlanNode);
assertTrue(p.getChild(0) instanceof ReceivePlanNode);
p = pns.get(1).getChild(0);
assertTrue(p instanceof AbstractScanPlanNode);
// No index, inline hash aggregate
assertNotNull(p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
// Having
pns = compileToFragments("SELECT A1, count(*) from T1 group by A1 Having count(*) > 3");
p = pns.get(0).getChild(0);
assertTrue(p instanceof AggregatePlanNode);
aggNode = (AggregatePlanNode) p;
assertNotNull(aggNode.getPostPredicate());
assertTrue(p.getChild(0) instanceof ReceivePlanNode);
p = pns.get(1).getChild(0);
assertTrue(p instanceof AbstractScanPlanNode);
// No index, inline hash aggregate
assertNotNull(p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
aggNode = (AggregatePlanNode) p.getInlinePlanNode(PlanNodeType.HASHAGGREGATE);
assertNull(aggNode.getPostPredicate());
}
Aggregations