Search in sources :

Example 41 with Plan

use of org.h2.table.Plan in project h2database by h2database.

the class TestTableEngines method checkPlan.

private void checkPlan(Statement stat, String sql) throws SQLException {
    ResultSet rs = stat.executeQuery("EXPLAIN " + sql);
    assertTrue(rs.next());
    String plan = rs.getString(1);
    assertEquals(normalize(sql), normalize(plan));
}
Also used : ResultSet(java.sql.ResultSet) ValueString(org.h2.value.ValueString)

Example 42 with Plan

use of org.h2.table.Plan in project h2database by h2database.

the class TestTableEngines method testSubQueryInfo.

private void testSubQueryInfo() throws SQLException {
    deleteDb("testSubQueryInfo");
    Connection conn = getConnection("testSubQueryInfo");
    Statement stat = conn.createStatement();
    stat.execute("create table SUB_QUERY_TEST(id int primary key, name varchar) ENGINE \"" + TreeSetIndexTableEngine.class.getName() + "\"");
    // test sub-queries
    stat.executeQuery("select * from " + "(select t2.id from " + "(select t3.id from sub_query_test t3 where t3.name = '') t4, " + "sub_query_test t2 " + "where t2.id = t4.id) t5").next();
    // test view 1
    stat.execute("create view t4 as (select t3.id from sub_query_test t3 where t3.name = '')");
    stat.executeQuery("select * from " + "(select t2.id from t4, sub_query_test t2 where t2.id = t4.id) t5").next();
    // test view 2
    stat.execute("create view t5 as " + "(select t2.id from t4, sub_query_test t2 where t2.id = t4.id)");
    stat.executeQuery("select * from t5").next();
    // test select expressions
    stat.execute("create table EXPR_TEST(id int) ENGINE \"" + TreeSetIndexTableEngine.class.getName() + "\"");
    stat.executeQuery("select * from (select (select id from EXPR_TEST x limit 1) a " + "from dual where 1 = (select id from EXPR_TEST y limit 1)) z").next();
    // test select expressions 2
    stat.execute("create table EXPR_TEST2(id int) ENGINE \"" + TreeSetIndexTableEngine.class.getName() + "\"");
    stat.executeQuery("select * from (select (select 1 from " + "(select (select 2 from EXPR_TEST) from EXPR_TEST2) ZZ) from dual)").next();
    // test select expression plan
    stat.execute("create table test_plan(id int primary key, name varchar)");
    stat.execute("create index MY_NAME_INDEX on test_plan(name)");
    checkPlan(stat, "select * from (select (select id from test_plan " + "where name = 'z') from dual)", "MY_NAME_INDEX");
    conn.close();
    deleteDb("testSubQueryInfo");
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcConnection(org.h2.jdbc.JdbcConnection)

Aggregations

PreparedStatement (java.sql.PreparedStatement)15 ResultSet (java.sql.ResultSet)14 Connection (java.sql.Connection)13 Statement (java.sql.Statement)13 SimpleResultSet (org.h2.tools.SimpleResultSet)9 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)7 Column (org.h2.table.Column)7 StatementBuilder (org.h2.util.StatementBuilder)6 ValueString (org.h2.value.ValueString)6 ArrayList (java.util.ArrayList)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteException (org.apache.ignite.IgniteException)4 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)4 Prepared (org.h2.command.Prepared)4 Expression (org.h2.expression.Expression)4 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 GridQueryCacheObjectsIterator (org.apache.ignite.internal.processors.query.GridQueryCacheObjectsIterator)3 UpdatePlan (org.apache.ignite.internal.processors.query.h2.dml.UpdatePlan)3 GridSqlColumn (org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn)3