use of org.voltdb.catalog.Statement in project voltdb by VoltDB.
the class VoltCompiler method getExplainPlans.
/**
* Get textual explain plan info for each plan from the
* catalog to be shoved into the catalog jarfile.
*/
HashMap<String, byte[]> getExplainPlans(Catalog catalog) {
HashMap<String, byte[]> retval = new HashMap<>();
Database db = getCatalogDatabase(m_catalog);
assert (db != null);
for (Procedure proc : db.getProcedures()) {
for (Statement stmt : proc.getStatements()) {
String s = "SQL: " + stmt.getSqltext() + "\n";
s += "COST: " + Integer.toString(stmt.getCost()) + "\n";
s += "PLAN:\n\n";
s += Encoder.hexDecodeToString(stmt.getExplainplan()) + "\n";
byte[] b = s.getBytes(Constants.UTF8ENCODING);
retval.put(proc.getTypeName() + "_" + stmt.getTypeName() + ".txt", b);
}
}
return retval;
}
use of org.voltdb.catalog.Statement in project voltdb by VoltDB.
the class MaterializedViewProcessor method compileFallbackQueriesAndUpdateCatalog.
// Compile the fallback query XMLs, add the plans into the catalog statement (ENG-8641).
private void compileFallbackQueriesAndUpdateCatalog(Database db, String query, List<VoltXMLElement> fallbackQueryXMLs, MaterializedViewInfo matviewinfo) throws VoltCompilerException {
DatabaseEstimates estimates = new DatabaseEstimates();
for (int i = 0; i < fallbackQueryXMLs.size(); ++i) {
String key = String.valueOf(i);
Statement fallbackQueryStmt = matviewinfo.getFallbackquerystmts().add(key);
VoltXMLElement fallbackQueryXML = fallbackQueryXMLs.get(i);
fallbackQueryStmt.setSqltext(query);
StatementCompiler.compileStatementAndUpdateCatalog(m_compiler, m_hsql, db, estimates, fallbackQueryStmt, fallbackQueryXML, fallbackQueryStmt.getSqltext(), // no user-supplied join order
null, DeterminismMode.FASTER, StatementPartitioning.forceSP());
}
}
use of org.voltdb.catalog.Statement in project voltdb by VoltDB.
the class VoltCompiler method summarizeSuccess.
public void summarizeSuccess(PrintStream outputStream, PrintStream feedbackStream, String jarOutputPath) {
if (outputStream != null) {
Database database = getCatalogDatabase();
outputStream.println("------------------------------------------");
outputStream.println("Successfully created " + jarOutputPath);
for (String ddl : m_ddlFilePaths.keySet()) {
outputStream.println("Includes schema: " + m_ddlFilePaths.get(ddl));
}
outputStream.println();
// Accumulate a summary of the summary for a briefer report
ArrayList<Procedure> nonDetProcs = new ArrayList<>();
ArrayList<Procedure> tableScans = new ArrayList<>();
int countSinglePartition = 0;
int countMultiPartition = 0;
int countDefaultProcs = 0;
for (Procedure p : database.getProcedures()) {
if (p.getSystemproc()) {
continue;
}
// Aggregate statistics about MP/SP/SEQ
if (!p.getDefaultproc()) {
if (p.getSinglepartition()) {
countSinglePartition++;
} else {
countMultiPartition++;
}
} else {
countDefaultProcs++;
}
if (p.getHasseqscans()) {
tableScans.add(p);
}
outputStream.printf("[%s][%s] %s\n", p.getSinglepartition() ? "SP" : "MP", p.getReadonly() ? "READ" : "WRITE", p.getTypeName());
for (Statement s : p.getStatements()) {
String seqScanTag = "";
if (s.getSeqscancount() > 0) {
seqScanTag = "[TABLE SCAN] ";
}
String determinismTag = "";
// output determinism warnings
if (p.getHasjava() && (!p.getReadonly())) {
if (s.getIscontentdeterministic() == false) {
determinismTag = "[NDC] ";
nonDetProcs.add(p);
} else if (s.getIsorderdeterministic() == false) {
determinismTag = "[NDO] ";
nonDetProcs.add(p);
}
}
String statementLine;
String sqlText = s.getSqltext();
sqlText = squeezeWhitespace(sqlText);
if (seqScanTag.length() + determinismTag.length() + sqlText.length() > 80) {
statementLine = " " + (seqScanTag + determinismTag + sqlText).substring(0, 80) + "...";
} else {
statementLine = " " + seqScanTag + determinismTag + sqlText;
}
outputStream.println(statementLine);
}
outputStream.println();
}
outputStream.println("------------------------------------------\n");
if (m_addedClasses.length > 0) {
if (m_addedClasses.length > 10) {
outputStream.printf("Added %d additional classes to the catalog jar.\n\n", m_addedClasses.length);
} else {
String logMsg = "Added the following additional classes to the catalog jar:\n";
for (String className : m_addedClasses) {
logMsg += " " + className + "\n";
}
outputStream.println(logMsg);
}
outputStream.println("------------------------------------------\n");
}
//
// post-compile summary and legend.
//
outputStream.printf("Catalog contains %d built-in CRUD procedures.\n" + "\tSimple insert, update, delete, upsert and select procedures are created\n" + "\tautomatically for convenience.\n\n", countDefaultProcs);
if (countSinglePartition > 0) {
outputStream.printf("[SP] Catalog contains %d single partition procedures.\n" + "\tSingle partition procedures run in parallel and scale\n" + "\tas partitions are added to a cluster.\n\n", countSinglePartition);
}
if (countMultiPartition > 0) {
outputStream.printf("[MP] Catalog contains %d multi-partition procedures.\n" + "\tMulti-partition procedures run globally at all partitions\n" + "\tand do not run in parallel with other procedures.\n\n", countMultiPartition);
}
if (!tableScans.isEmpty()) {
outputStream.printf("[TABLE SCAN] Catalog contains %d procedures that use a table scan:\n\n", tableScans.size());
for (Procedure p : tableScans) {
outputStream.println("\t\t" + p.getClassname());
}
outputStream.printf("\n\tTable scans do not use indexes and may become slower as tables grow.\n\n");
}
if (!nonDetProcs.isEmpty()) {
outputStream.println("[NDO][NDC] NON-DETERMINISTIC CONTENT OR ORDER WARNING:\n" + "\tThe procedures listed below contain non-deterministic queries.\n");
for (Procedure p : nonDetProcs) {
outputStream.println("\t\t" + p.getClassname());
}
outputStream.printf("\n" + "\tUsing the output of these queries as input to subsequent\n" + "\twrite queries can result in differences between replicated\n" + "\tpartitions at runtime, forcing VoltDB to shutdown the cluster.\n" + "\tReview the compiler messages above to identify the offending\n" + "\tSQL statements (marked as \"[NDO] or [NDC]\"). Add a unique\n" + "\tindex to the schema or an explicit ORDER BY clause to the\n" + "\tquery to make these queries deterministic.\n\n");
}
if (countSinglePartition == 0 && countMultiPartition > 0) {
outputStream.printf("ALL MULTI-PARTITION WARNING:\n" + "\tAll of the user procedures are multi-partition. This often\n" + "\tindicates that the application is not utilizing VoltDB partitioning\n" + "\tfor best performance. For information on VoltDB partitioning, see:\n" + "\thttp://voltdb.com/docs/UsingVoltDB/ChapAppDesign.php\n\n");
}
if (m_reportPath != null) {
outputStream.println("------------------------------------------\n");
outputStream.println(String.format("Full catalog report can be found at file://%s.\n", m_reportPath));
}
outputStream.println("------------------------------------------\n");
}
if (feedbackStream != null) {
for (Feedback fb : m_warnings) {
feedbackStream.println(fb.getLogString());
}
for (Feedback fb : m_infos) {
feedbackStream.println(fb.getLogString());
}
}
}
Aggregations