use of org.h2.command.dml.Explain in project ignite by apache.
the class GridSqlUpdate method getSQL.
/**
* {@inheritDoc}
*/
@Override
public String getSQL() {
StatementBuilder buff = new StatementBuilder(explain() ? "EXPLAIN " : "");
buff.append("UPDATE ").append(target.getSQL()).append("\nSET\n");
for (GridSqlColumn c : cols) {
GridSqlElement e = set.get(c.columnName());
buff.appendExceptFirst(",\n ");
buff.append(c.columnName()).append(" = ").append(e != null ? e.getSQL() : "DEFAULT");
}
if (where != null)
buff.append("\nWHERE ").append(StringUtils.unEnclose(where.getSQL()));
if (limit != null)
buff.append("\nLIMIT ").append(StringUtils.unEnclose(limit.getSQL()));
return buff.toString();
}
use of org.h2.command.dml.Explain in project h2database by h2database.
the class Parser method parsePrepared.
private Prepared parsePrepared() {
int start = lastParseIndex;
Prepared c = null;
String token = currentToken;
if (token.length() == 0) {
c = new NoOperation(session);
} else {
char first = token.charAt(0);
switch(first) {
case '?':
// read the ? as a parameter
readTerm();
// this is an 'out' parameter - set a dummy value
parameters.get(0).setValue(ValueNull.INSTANCE);
read("=");
read("CALL");
c = parseCall();
break;
case '(':
c = parseSelect();
break;
case 'a':
case 'A':
if (readIf("ALTER")) {
c = parseAlter();
} else if (readIf("ANALYZE")) {
c = parseAnalyze();
}
break;
case 'b':
case 'B':
if (readIf("BACKUP")) {
c = parseBackup();
} else if (readIf("BEGIN")) {
c = parseBegin();
}
break;
case 'c':
case 'C':
if (readIf("COMMIT")) {
c = parseCommit();
} else if (readIf("CREATE")) {
c = parseCreate();
} else if (readIf("CALL")) {
c = parseCall();
} else if (readIf("CHECKPOINT")) {
c = parseCheckpoint();
} else if (readIf("COMMENT")) {
c = parseComment();
}
break;
case 'd':
case 'D':
if (readIf("DELETE")) {
c = parseDelete();
} else if (readIf("DROP")) {
c = parseDrop();
} else if (readIf("DECLARE")) {
// support for DECLARE GLOBAL TEMPORARY TABLE...
c = parseCreate();
} else if (readIf("DEALLOCATE")) {
c = parseDeallocate();
}
break;
case 'e':
case 'E':
if (readIf("EXPLAIN")) {
c = parseExplain();
} else if (readIf("EXECUTE")) {
c = parseExecute();
}
break;
case 'f':
case 'F':
if (isToken("FROM")) {
c = parseSelect();
}
break;
case 'g':
case 'G':
if (readIf("GRANT")) {
c = parseGrantRevoke(CommandInterface.GRANT);
}
break;
case 'h':
case 'H':
if (readIf("HELP")) {
c = parseHelp();
}
break;
case 'i':
case 'I':
if (readIf("INSERT")) {
c = parseInsert();
}
break;
case 'm':
case 'M':
if (readIf("MERGE")) {
c = parseMerge();
}
break;
case 'p':
case 'P':
if (readIf("PREPARE")) {
c = parsePrepare();
}
break;
case 'r':
case 'R':
if (readIf("ROLLBACK")) {
c = parseRollback();
} else if (readIf("REVOKE")) {
c = parseGrantRevoke(CommandInterface.REVOKE);
} else if (readIf("RUNSCRIPT")) {
c = parseRunScript();
} else if (readIf("RELEASE")) {
c = parseReleaseSavepoint();
} else if (readIf("REPLACE")) {
c = parseReplace();
}
break;
case 's':
case 'S':
if (isToken("SELECT")) {
c = parseSelect();
} else if (readIf("SET")) {
c = parseSet();
} else if (readIf("SAVEPOINT")) {
c = parseSavepoint();
} else if (readIf("SCRIPT")) {
c = parseScript();
} else if (readIf("SHUTDOWN")) {
c = parseShutdown();
} else if (readIf("SHOW")) {
c = parseShow();
}
break;
case 't':
case 'T':
if (readIf("TRUNCATE")) {
c = parseTruncate();
}
break;
case 'u':
case 'U':
if (readIf("UPDATE")) {
c = parseUpdate();
} else if (readIf("USE")) {
c = parseUse();
}
break;
case 'v':
case 'V':
if (readIf("VALUES")) {
c = parseValues();
}
break;
case 'w':
case 'W':
if (readIf("WITH")) {
c = parseWithStatementOrQuery();
}
break;
case ';':
c = new NoOperation(session);
break;
default:
throw getSyntaxError();
}
if (indexedParameterList != null) {
for (int i = 0, size = indexedParameterList.size(); i < size; i++) {
if (indexedParameterList.get(i) == null) {
indexedParameterList.set(i, new Parameter(i));
}
}
parameters = indexedParameterList;
}
if (readIf("{")) {
do {
int index = (int) readLong() - 1;
if (index < 0 || index >= parameters.size()) {
throw getSyntaxError();
}
Parameter p = parameters.get(index);
if (p == null) {
throw getSyntaxError();
}
read(":");
Expression expr = readExpression();
expr = expr.optimize(session);
p.setValue(expr.getValue(session));
} while (readIf(","));
read("}");
for (Parameter p : parameters) {
p.checkSet();
}
parameters.clear();
}
}
if (c == null) {
throw getSyntaxError();
}
setSQL(c, null, start);
return c;
}
use of org.h2.command.dml.Explain in project h2database by h2database.
the class TestSpatial method testExplainSpatialIndexWithPk.
private void testExplainSpatialIndexWithPk() throws SQLException {
deleteDb("spatial");
try (Connection conn = getConnection(URL)) {
Statement stat = conn.createStatement();
stat.execute("drop table if exists pt_cloud;");
stat.execute("CREATE TABLE PT_CLOUD(id serial, the_geom geometry) AS " + "SELECT null, CONCAT('POINT(',A.X,' ',B.X,')')::geometry the_geom " + "from system_range(0,120) A,system_range(0,10) B;");
stat.execute("create spatial index on pt_cloud(the_geom);");
try (ResultSet rs = stat.executeQuery("explain select * from PT_CLOUD " + "where the_geom && 'POINT(1 1)'")) {
assertTrue(rs.next());
assertFalse("H2 should use spatial index got this explain:\n" + rs.getString(1), rs.getString(1).contains("tableScan"));
}
}
deleteDb("spatial");
}
use of org.h2.command.dml.Explain in project h2database by h2database.
the class TestSpatial method testSpatialIndexWithOrder.
private void testSpatialIndexWithOrder() throws SQLException {
deleteDb("spatial");
try (Connection conn = getConnection(URL)) {
Statement stat = conn.createStatement();
stat.execute("DROP TABLE IF EXISTS BUILDINGS;" + "CREATE TABLE BUILDINGS (PK serial, THE_GEOM geometry);" + "insert into buildings(the_geom) SELECT 'POINT(1 1)" + "'::geometry from SYSTEM_RANGE(1,10000);\n" + "CREATE SPATIAL INDEX ON PUBLIC.BUILDINGS(THE_GEOM);\n");
try (ResultSet rs = stat.executeQuery("EXPLAIN SELECT * FROM " + "BUILDINGS ORDER BY PK LIMIT 51;")) {
assertTrue(rs.next());
assertTrue(rs.getString(1).contains("PRIMARY_KEY"));
}
}
deleteDb("spatial");
}
use of org.h2.command.dml.Explain in project h2database by h2database.
the class TestSpatial method testScanIndexOnNonSpatialQuery.
private void testScanIndexOnNonSpatialQuery() throws SQLException {
deleteDb("spatial");
try (Connection conn = getConnection(URL)) {
Statement stat = conn.createStatement();
stat.execute("drop table if exists test");
stat.execute("create table test(id serial primary key, " + "value double, the_geom geometry)");
stat.execute("create spatial index spatial on test(the_geom)");
ResultSet rs = stat.executeQuery("explain select * from test where _ROWID_ = 5");
assertTrue(rs.next());
assertFalse(rs.getString(1).contains("/* PUBLIC.SPATIAL: _ROWID_ = " + "5 */"));
}
deleteDb("spatial");
}
Aggregations