Package org.voltdb.plannodes

Examples of org.voltdb.plannodes.PlanNodeList


            column.setSize(planColumn.width());
            index++;
        }

        CompiledPlan.Fragment fragment = plan.fragments.get(0);
        PlanNodeList nodeList = new PlanNodeList(fragment.planGraph);

        //Store the list of parameters types and indexes in the plan node list.
        List<Pair<Integer, VoltType>> parameters = nodeList.getParameters();
        for (ParameterInfo param : plan.parameters) {
            Pair<Integer, VoltType> parameter = new Pair<Integer, VoltType>(param.index, param.type);
            parameters.add(parameter);
        }

        // Now update our catalog information
        // HACK: We're using the node_tree's hashCode() as it's name. It would be really
        //     nice if the Catalog code give us an guid without needing a name first...

        String json = null;
        try {
            JSONObject jobj = new JSONObject(nodeList.toJSONString());
            json = jobj.toString(4);
        } catch (JSONException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
            System.exit(-1);
        }

        //
        // We then stick a serialized version of PlanNodeTree into a PlanFragment
        //
        try {
            PrintStream plansJSONOut = BuildDirectoryUtils.getDebugOutputPrintStream(
                    "statement-plans", name + "_json.txt");
            plansJSONOut.print(json);
            plansJSONOut.close();

            PrintStream plansDOTOut = BuildDirectoryUtils.getDebugOutputPrintStream(
                     "statement-plans", name + ".dot");
            plansDOTOut.print(nodeList.toDOTString("name"));
            plansDOTOut.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return nodeList.getRootPlanNode();
    }
View Full Code Here


        }

        try {
            String jsonString = Encoder.hexDecodeToString(fullPlan);
            JSONObject jsonObject = new JSONObject(jsonString);
            PlanNodeList list = (PlanNodeList) PlanNodeTree.fromJSONObject(jsonObject, catalog_db);
            ret = list.getRootPlanNode();
            // } else {
            // //
            // // FIXME: If it's an INSERT query, then we have to use the plan
            // fragments instead of
            // // the full query plan tree because the full plan is missing the
View Full Code Here

        if (ret == null) {
            if (debug.val)
                LOG.warn("No cached object for " + catalog_frag.fullName());
            Database catalog_db = CatalogUtil.getDatabase(catalog_frag);
            String jsonString = Encoder.hexDecodeToString(catalog_frag.getPlannodetree());
            PlanNodeList list = null;
            try {
                JSONObject jsonObject = new JSONObject(jsonString);
                list = (PlanNodeList) PlanNodeTree.fromJSONObject(jsonObject, catalog_db);
            } catch (JSONException ex) {
                String msg = String.format("Invalid PlanNodeTree for %s [plantreeLength=%d, jsonLength=%d]",
                                           catalog_frag.fullName(),
                                           catalog_frag.getPlannodetree().length(),
                                           jsonString.length());
                throw new RuntimeException(msg, ex);
            }
            ret = list.getRootPlanNode();
            PlanNodeUtil.CACHE_DESERIALIZE_FRAGMENT.put(id, ret);
        }
        return (ret);
    }
View Full Code Here

        // HACK: For now just return the PlanNodeList from the first fragment
        System.err.println("CATALOG_STMT: " + CatalogUtil.debug(catalog_stmt.getFragments()));
        assert (catalog_stmt.getFragments().get(0) != null);
        String serialized = catalog_stmt.getFragments().get(0).getPlannodetree();
        String jsonString = Encoder.hexDecodeToString(serialized);
        PlanNodeList list = null; // FIXME
                                  // (PlanNodeList)PlanNodeTree.fromJSONObject(new
                                  // JSONObject(jsonString), catalog_db);
        return (list.getRootPlanNode());
    }
View Full Code Here

        AbstractPlanNode clone = (AbstractPlanNode)root.clone();
        assertNotNull(clone);
//        assertEquals(root, clone);
        assertFalse(root == clone);
       
        List<AbstractPlanNode> list0 = new PlanNodeList(root).getExecutionList();
        List<AbstractPlanNode> list1 = new PlanNodeList(clone).getExecutionList();
        assertEquals(list0.size(), list1.size());
       
        for (int i = 0, cnt = list0.size(); i < cnt; i++) {
            AbstractPlanNode node0 = list0.get(i);
            assertNotNull(node0);
View Full Code Here

            //////////////////////

            // print out the run-at-every-partition fragment
            for (int i = 0; i < plan.fragments.size(); i++) {
                Fragment frag = plan.fragments.get(i);
                PlanNodeList planList = new PlanNodeList(frag.planGraph);
                String serializedPlan = planList.toJSONString();
                String encodedPlan = serializedPlan; //Encoder.compressAndBase64Encode(serializedPlan);
                if (frag.multiPartition) {
                    log("PLAN-ALL GENERATED");
                    System.out.println("PLAN-ALL: " + encodedPlan);
                }
View Full Code Here

        Procedure catalog_proc = catalogStmt.getParent();
        boolean isMapReduce = catalog_proc.getMapreduce();

        CompiledPlan plan = null;
        CompiledPlan last_plan = null;
        PlanNodeList node_list = null;
       
        QueryPlanner planner = new QueryPlanner(catalog.getClusters().get("cluster"), db, hsql, estimates, true, false);

        Throwable first_exception = null;
        for (boolean _singleSited : new boolean[]{ true, false }) {
            if (_singleSited == false && isMapReduce) continue;
           
            QueryType stmt_type = QueryType.get(catalogStmt.getQuerytype());
            String msg = "Creating " + stmt_type.name() + " query plan for " + catalogStmt.fullName() + ": singleSited=" + _singleSited;
            if (trace.val) LOG.trace(msg);
            compiler.addInfo(msg);

            catalogStmt.setSinglepartition(_singleSited);
            String name = catalogStmt.getParent().getName() + "-" + catalogStmt.getName();
   
            TrivialCostModel costModel = new TrivialCostModel();
            try {
                plan = planner.compilePlan(costModel, catalogStmt.getSqltext(),
                        catalogStmt.getName(), catalogStmt.getParent().getName(),
                        catalogStmt.getSinglepartition(), null);
            } catch (Throwable e) {
                LOG.error("Failed to plan for stmt: " + catalogStmt.fullName(), e);
                if (first_exception == null) {
                    if (debug.val) LOG.warn("Ignoring first error for " + catalogStmt.getName() + " :: " + e.getMessage());
                    first_exception = e;
                    continue;
                }
                e.printStackTrace();
                throw compiler.new VoltCompilerException("Failed to plan for stmt: " + catalogStmt.fullName());
            }

            if (plan == null) {
                msg = "Failed to plan for stmt: " + catalogStmt.fullName();
                String plannerMsg = planner.getErrorMessage();

                if (plannerMsg == null) plannerMsg = "PlannerMessage was empty!";
               
                // HACK: Ignore if they were trying to do a single-sited INSERT/UPDATE/DELETE
                //       on a replicated table
                if (plannerMsg.contains("replicated table") && _singleSited) {
                    if (debug.val)
                        LOG.warn(String.format("Ignoring error for %s: %s", catalogStmt.fullName(), plannerMsg));
                    continue;
                // HACK: If we get an unknown error message on an multi-sited INSERT/UPDATE/DELETE, assume
                //       that it's because we are trying to insert on a non-replicated table
                } else if (!_singleSited && stmt_type == QueryType.INSERT && plannerMsg.contains("Error unknown")) {
                    if (debug.val)
                        LOG.warn(String.format("Ignoring multi-sited %s %s on non-replicated table: %s",
                                               stmt_type.name(), catalogStmt.fullName(), plannerMsg));
                    continue;
                } else if (planner.getError() != null) {
                    if (debug.val) LOG.error(msg);
                    throw compiler.new VoltCompilerException(msg, planner.getError());
                // Otherwise, report the error
                } else {
                    if (plannerMsg != null)
                        msg += " with error: \"" + plannerMsg + "\"";
                    if (debug.val) LOG.error(msg);
                    throw compiler.new VoltCompilerException(msg);
                }
            }
            if (trace.val)
                LOG.trace(String.format("%s Analyzing %s query plan",
                                        catalogStmt.fullName(), (_singleSited == false ? "DTXN" : "SP")))

            // serialize full where clause to the catalog
            // for the benefit of the designer
            if (plan.fullWhereClause != null) {
                String json = "ERROR";
                try {
                    // serialize to pretty printed json
                    String jsonCompact = plan.fullWhereClause.toJSONString();
                    // pretty printing seems to cause issues
                    //JSONObject jobj = new JSONObject(jsonCompact);
                    //json = jobj.toString(4);
                    json = jsonCompact;
                } catch (Exception e) {
                    // hopefully someone will notice
                    e.printStackTrace();
                }
                String hexString = Encoder.hexEncode(json);
                catalogStmt.setExptree(hexString);
            }

            // serialize full plan to the catalog
            // for the benefit of the designer
            if (plan.fullWinnerPlan != null) {
                String json = plan.fullplan_json;
                String hexString = Encoder.hexEncode(json);
                if (_singleSited) {
                    catalogStmt.setFullplan(hexString);
                } else {
                    catalogStmt.setMs_fullplan(hexString);
                }
            }
   
            //Store the list of parameters types and indexes in the plan node list.
   
            /*List<Pair<Integer, VoltType>> parameters = node_list.getParameters();
            for (ParameterInfo param : plan.parameters) {
                Pair<Integer, VoltType> parameter = new Pair<Integer, VoltType>(param.index, param.type);
                parameters.add(parameter);
            }*/
   
            int i = 0;
            Collections.sort(plan.fragments);
            if (trace.val)
                LOG.trace(catalogStmt.fullName() + " Plan Fragments: " + plan.fragments);
            for (CompiledPlan.Fragment fragment : plan.fragments) {
                node_list = new PlanNodeList(fragment.planGraph);
               
                boolean readonly = fragmentReadOnly(fragment.planGraph);
                boolean fastAggregate = false; // FIXME
                boolean fastCombine = false; // FIXME
               
                // Now update our catalog information
                int id = getNextFragmentId(db, readonly, fastAggregate, fastCombine);
                String planFragmentName = Integer.toString(id);
                PlanFragment planFragment = null;
                   
                if (_singleSited) {
                    planFragment = catalogStmt.getFragments().add(planFragmentName);
                    catalogStmt.setHas_singlesited(true);
                    if (trace.val)
                        LOG.trace(String.format("%s SP PLAN FRAGMENT: %s", catalogStmt.fullName(), planFragment));
                } else {
                    planFragment = catalogStmt.getMs_fragments().add(planFragmentName);
                    catalogStmt.setHas_multisited(true);
                    if (trace.val)
                        LOG.trace(String.format("%s DTXN PLAN FRAGMENT: %s", catalogStmt.fullName(), planFragment));
                }
   
                // mark a fragment as non-transactional if it never touches a persistent table
                planFragment.setNontransactional(!fragmentReferencesPersistentTable(fragment.planGraph));
                planFragment.setReadonly(readonly);
                planFragment.setHasdependencies(fragment.hasDependencies);
                planFragment.setMultipartition(fragment.multiPartition);
                planFragment.setId(id);

                String json = null;
                try {
                    JSONObject jobj = new JSONObject(node_list.toJSONString());
                    json = jobj.toString(4);
                } catch (JSONException e2) {
                    throw new RuntimeException(e2);
                }
   
View Full Code Here

                    boolean result = planGraph.computeEstimatesRecursively(stats, m_cluster, m_db, m_estimates, paramHints);
                    assert(result);

                    // GENERATE JSON DEBUGGING OUTPUT BEFORE WE CLEAN UP THE PlanColumns
                    // convert a tree into an execution list
                    PlanNodeList nodeList = new PlanNodeList(planGraph);

                    // get the json serialized version of the plan
                    String json = "";
//                    try {
//                        String crunchJson = nodeList.toJSONString();
                        //System.out.println(crunchJson);
                        //System.out.flush();
                        /* FIXME
                        JSONObject jobj = new JSONObject(crunchJson);
                        json = jobj.toString(4);
                    } catch (JSONException e2) {
                        // Any plan that can't be serialized to JSON to
                        // write to debugging output is also going to fail
                        // to get written to the catalog, to sysprocs, etc.
                        // Just bail.
                        m_recentErrorMsg = "Plan for sql: '" + sql +
                                           "' can't be serialized to JSON";
                        return null;
                    }
                    */

                    // compute the cost based on the resources using the current cost model
                    double cost = costModel.getPlanCost(stats);

                    // find the minimum cost plan
                    if (cost < minCost) {
                        minCost = cost;
                        // free the PlanColumns held by the previous best plan
                        if (bestPlan != null) {
                            bestPlan.freePlan(m_context, plan.getColumnGuids());
                        }
                        bestPlan = plan;
                    } else {
                        plan.freePlan(m_context, bestPlan.getColumnGuids());
                    }

                    // output a description of the parsed stmt
                    String filename = String.valueOf(i++);
                    if (bestPlan == plan) winnerName = filename;
                    json = "COST: " + String.valueOf(cost) + "\n" + json;
                    planOutputs.put(filename, json);

                    // create a graph friendly version
                    dotPlanOutputs.put(filename, nodeList.toDOTString("name"));
                }
            }
            tpce_limit = null;
        }

        // make sure we got a winner
        if (bestPlan == null) {
            m_recentErrorMsg = "Unable to plan for statement. Error unknown.";
            return null;
        }

        // Validate that everything is there
        Set<Integer> bestPlan_columns = bestPlan.getColumnGuids();
        for (Integer column_guid : bestPlan_columns) {
            if (m_context.hasColumn(column_guid) == false) {
                m_recentErrorMsg = "Missing column guid " + column_guid;
                return (null);
            }
        } // FOR
        if (debug.val) LOG.debug(String.format("All columns are there for %s.%s: %s", procName, stmtName, bestPlan_columns));

        // reset all the plan node ids for a given plan
        bestPlan.resetPlanNodeIds();

        if (!m_quietPlanner)
        {
            // print all the plans to disk for debugging
            for (Entry<String, String> output : planOutputs.entrySet()) {
                String filename = output.getKey();
                if (winnerName.equals(filename)) {
                    filename = "WINNER " + filename;
                }
                PrintStream candidatePlanOut =
                    BuildDirectoryUtils.getDebugOutputPrintStream("statement-all-plans/" + procName + "_" + stmtName,
                                                                  filename + ".txt");

                candidatePlanOut.println(output.getValue());
                candidatePlanOut.close();
            }

            for (Entry<String, String> output : dotPlanOutputs.entrySet()) {
                String filename = output.getKey();
                if (winnerName.equals(filename)) {
                    filename = "WINNER " + filename;
                }
                PrintStream candidatePlanOut =
                    BuildDirectoryUtils.getDebugOutputPrintStream("statement-all-plans/" + procName + "_" + stmtName,
                                                                  filename + ".dot");

                candidatePlanOut.println(output.getValue());
                candidatePlanOut.close();
            }

            // output the plan statistics to disk for debugging
            PrintStream plansOut =
                BuildDirectoryUtils.getDebugOutputPrintStream("statement-stats", procName + "_" + stmtName + ".txt");
            plansOut.println(stats.toString());
            plansOut.close();
        }

        // PAVLO: Get the full plan json
        AbstractPlanNode root = bestPlan.fragments.get(0).planGraph;
//        String orig_debug = PlanNodeUtil.debug(root);
        assert(root != null);
        String json = null;
        try {
            JSONObject jobj = new JSONObject(new PlanNodeList(root).toJSONString());
            json = jobj.toString();
        } catch (JSONException e2) {
            throw new RuntimeException(String.format("Failed to serialize JSON query plan for %s.%s", procName, stmtName), e2);
        }
        assert(json != null);
View Full Code Here

            catalogParam.setIsarray(pve.getParamIsVector());
            catalogParam.setIndex(i);
        }

        List<PlanNodeList> nodeLists = new ArrayList<PlanNodeList>();
        nodeLists.add(new PlanNodeList(plan.rootPlanGraph));
        if (plan.subPlanGraph != null) {
            nodeLists.add(new PlanNodeList(plan.subPlanGraph));
        }

        //Store the list of parameters types and indexes in the plan node list.
        List<Pair<Integer, VoltType>> parameters = nodeLists.get(0).getParameters();
        for (int i = 0; i < plan.parameters.length; ++i) {
View Full Code Here

     */
    private String outputPlanFullDebug(CompiledPlan plan, AbstractPlanNode planGraph, String filename) {
        // GENERATE JSON DEBUGGING OUTPUT BEFORE WE CLEAN UP THE
        // PlanColumns
        // convert a tree into an execution list
        PlanNodeList nodeList = new PlanNodeList(planGraph);

        // get the json serialized version of the plan
        String json = null;

        try {
            String crunchJson = nodeList.toJSONString();
            //System.out.println(crunchJson);
            //System.out.flush();
            JSONObject jobj = new JSONObject(crunchJson);
            json = jobj.toString(4);
        } catch (JSONException e2) {
            // Any plan that can't be serialized to JSON to
            // write to debugging output is also going to fail
            // to get written to the catalog, to sysprocs, etc.
            // Just bail.
            String errorMsg = "Plan for sql: '" + plan.sql +
                               "' can't be serialized to JSON";
            // This case used to exit the planner
            // -- a strange behavior for something that only gets called when full debug output is enabled.
            // For now, just skip the output and go on to the next plan.
            return errorMsg;
        }

        // output a description of the parsed stmt
        json = "PLAN:\n" + json;
        json = "COST: " + String.valueOf(plan.cost) + "\n" + json;
        assert (plan.sql != null);
        json = "SQL: " + plan.sql + "\n" + json;

        // write json to disk
        BuildDirectoryUtils.writeFile("statement-all-plans/" + m_procName + "_" + m_stmtName,
                                      filename + "-json.txt",
                                      json,
                                      true);

        // create a graph friendly version
        BuildDirectoryUtils.writeFile("statement-all-plans/" + m_procName + "_" + m_stmtName,
                                      filename + ".dot",
                                      nodeList.toDOTString("name"),
                                      true);
        return null;
    }
View Full Code Here

TOP

Related Classes of org.voltdb.plannodes.PlanNodeList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.