Search in sources :

Example 1 with PlanNodeTree

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

the class TestMultipleOuterJoinPlans method testFullIndexJoinExpressions.

public void testFullIndexJoinExpressions() {
    AbstractPlanNode pn;
    AbstractPlanNode n;
    // Simple FULL NLIJ
    pn = compile("select * FROM  " + "R3 FULL JOIN R1 ON R3.A = R1.A WHERE R3.C IS NULL");
    n = pn.getChild(0).getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOPINDEX, JoinType.FULL, null, null, ExpressionType.OPERATOR_IS_NULL, PlanNodeType.SEQSCAN, PlanNodeType.INDEXSCAN);
    String json = (new PlanNodeTree(pn)).toJSONString();
    // Same Join as above but using FULL OUTER JOIN syntax
    pn = compile("select * FROM  " + "R3 FULL OUTER JOIN R1 ON R3.A = R1.A WHERE R3.C IS NULL");
    String json1 = (new PlanNodeTree(pn)).toJSONString();
    assertEquals(json, json1);
    // FULL NLJ. R3.A is an index column but R3.A > 0 expression is used as a PREDICATE only
    pn = compile("select * FROM  " + "R1 FULL JOIN R3 ON R3.C = R1.A AND R3.A > 0");
    n = pn.getChild(0).getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOP, JoinType.FULL, null, ExpressionType.CONJUNCTION_AND, null, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN, "R1", "R3");
    // FULL NLIJ, inner join R3.A > 0 is added as a post-predicate to the inline Index scan
    pn = compile("select * FROM R1 FULL JOIN R3 ON R3.A = R1.A AND R3.A > 55");
    n = pn.getChild(0).getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOPINDEX, JoinType.FULL, null, null, null, PlanNodeType.SEQSCAN, PlanNodeType.INDEXSCAN, "R1", "R3");
    verifyIndexScanNode(n.getInlinePlanNode(PlanNodeType.INDEXSCAN), IndexLookupType.EQ, ExpressionType.COMPARE_GREATERTHAN);
    // FULL NLIJ, inner join L.A > 0 is added as a pre-predicate to the NLIJ
    pn = compile("select * FROM R3 L FULL JOIN R3 R ON L.A = R.A AND L.A > 55");
    n = pn.getChild(0).getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOPINDEX, JoinType.FULL, ExpressionType.COMPARE_GREATERTHAN, null, null, PlanNodeType.SEQSCAN, PlanNodeType.INDEXSCAN, "L", "R");
    verifyIndexScanNode(n.getInlinePlanNode(PlanNodeType.INDEXSCAN), IndexLookupType.EQ, null);
    // FULL NLIJ, inner-outer join R3.c = R1.c is a post-predicate for the inline Index scan
    pn = compile("select * FROM R1 FULL JOIN R3 ON R3.A = R1.A AND R3.C = R1.C");
    n = pn.getChild(0).getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOPINDEX, JoinType.FULL, null, null, null, PlanNodeType.SEQSCAN, PlanNodeType.INDEXSCAN, "R1", "R3");
    verifyIndexScanNode(n.getInlinePlanNode(PlanNodeType.INDEXSCAN), IndexLookupType.EQ, ExpressionType.COMPARE_EQUAL);
    // FULL NLIJ, outer join (R1, R2) expression R1.A > 0 is a pre-predicate
    pn = compile("select * FROM R1 JOIN R2 ON R1.A = R2.C FULL JOIN R3 ON R3.A = R2.C  AND R1.A > 0");
    n = pn.getChild(0).getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOPINDEX, JoinType.FULL, ExpressionType.COMPARE_GREATERTHAN, null, null, PlanNodeType.NESTLOOP, PlanNodeType.INDEXSCAN, null, "R3");
    verifyIndexScanNode(n.getInlinePlanNode(PlanNodeType.INDEXSCAN), IndexLookupType.EQ, null);
    n = n.getChild(0);
    verifyJoinNode(n, PlanNodeType.NESTLOOP, JoinType.INNER, null, ExpressionType.COMPARE_EQUAL, null, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) PlanNodeTree(org.voltdb.plannodes.PlanNodeTree)

Example 2 with PlanNodeTree

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

the class plannerTester method loadPlanFromFile.

public static AbstractPlanNode loadPlanFromFile(String path, ArrayList<String> getsql) {
    BufferedReader reader;
    try {
        reader = new BufferedReader(new FileReader(path));
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
        String message = "ERROR: Plan file " + path + " doesn't exist.\n" + "Use -s (the Compile/Save option) or 'ant plannertestrefresh'" + " ' to generate plans to the baseline directory.\n";
        System.err.print(message);
        try {
            m_reportWriter.write(message);
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        return null;
    }
    try {
        String json = "";
        try {
            String line = reader.readLine();
            getsql.add(line);
            while ((line = reader.readLine()) != null) {
                json += line;
            }
        } catch (IOException e2) {
            e2.printStackTrace();
            return null;
        }
        try {
            PlanNodeTree pnt = new PlanNodeTree();
            JSONObject jobj = new JSONObject(json);
            Database db = s_singleton.getDatabase();
            pnt.loadFromJSONPlan(jobj, db);
            return pnt.getRootPlanNode();
        } catch (JSONException e3) {
            e3.printStackTrace();
            System.out.println("Failed on input from file: " + path + " with JSON text: \n'" + json + "'");
            return null;
        }
    } finally {
        try {
            reader.close();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
    }
}
Also used : JSONObject(org.json_voltpatches.JSONObject) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Database(org.voltdb.catalog.Database) JSONException(org.json_voltpatches.JSONException) FileReader(java.io.FileReader) IOException(java.io.IOException) PlanNodeTree(org.voltdb.plannodes.PlanNodeTree)

Example 3 with PlanNodeTree

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

the class testLoadPlanNodeFromJSON method testLoadQueryPlanTree.

public void testLoadQueryPlanTree(String sql) throws JSONException {
    AbstractPlanNode pn = compile(sql);
    PlanNodeTree pnt = new PlanNodeTree(pn);
    String str = pnt.toJSONString();
    JSONObject jsonPlan = new JSONObject(str);
    PlanNodeTree pnt1 = new PlanNodeTree();
    pnt1.loadFromJSONPlan(jsonPlan, getDatabase());
    String str1 = pnt1.toJSONString();
    assertTrue(str.equals(str1));
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) JSONObject(org.json_voltpatches.JSONObject) PlanNodeTree(org.voltdb.plannodes.PlanNodeTree)

Example 4 with PlanNodeTree

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

the class plannerTester method writePlanToFile.

public static void writePlanToFile(AbstractPlanNode pn, String pathToDir, String fileName, String sql) {
    assert (pn != null);
    PlanNodeTree pnt = new PlanNodeTree(pn);
    String prettyJson = pnt.toJSONString();
    if (!new File(pathToDir).exists()) {
        new File(pathToDir).mkdirs();
    }
    try {
        BufferedWriter writer = new BufferedWriter(new FileWriter(pathToDir + fileName));
        writer.write(sql);
        writer.write("\n");
        writer.write(prettyJson);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) PlanNodeTree(org.voltdb.plannodes.PlanNodeTree) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 5 with PlanNodeTree

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

the class TestPlansSubQueries method checkSubquerySimplification.

private void checkSubquerySimplification(String sql, String equivalentSql, List<String[]> ignoreList) {
    AbstractPlanNode pn = compile(sql);
    PlanNodeTree pnt = new PlanNodeTree(pn);
    String jsonSql = pnt.toJSONString();
    //* enable to debug */ System.out.println(jsonSql);
    AbstractPlanNode equivalentPne = compile(equivalentSql);
    PlanNodeTree equivalentPnt = new PlanNodeTree(equivalentPne);
    String equivalentJsonSql = equivalentPnt.toJSONString();
    //* enable to debug */ System.out.println(equivalentJsonSql);
    if (ignoreList != null) {
        for (String[] ignorePair : ignoreList) {
            jsonSql = jsonSql.replaceAll(ignorePair[0], ignorePair[1]);
        }
    }
    assertEquals(jsonSql, equivalentJsonSql);
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) PlanNodeTree(org.voltdb.plannodes.PlanNodeTree)

Aggregations

PlanNodeTree (org.voltdb.plannodes.PlanNodeTree)7 JSONObject (org.json_voltpatches.JSONObject)4 JSONException (org.json_voltpatches.JSONException)3 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)3 IOException (java.io.IOException)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 Database (org.voltdb.catalog.Database)1 SendPlanNode (org.voltdb.plannodes.SendPlanNode)1