import java.sql.*;


public final class HB4 {

	public static void main(String[] args) throws Exception {
		Class.forName("org.h2.Driver");
		Connection con = DriverManager.getConnection("jdbc:h2:/h2/bug/bug","sa","");
		try {
			buildTable(con);
			Statement stmt = con.createStatement();
			ResultSet rs = stmt.executeQuery(
				"explain select * from t where s=1 order by i"
			);
			rs.next();
			String plan = rs.getString("plan");
			System.out.println(plan);
			stmt.close();
		} finally {
			con.close();
		}
	}

	static void buildTable(Connection con) throws SQLException {
		Statement stmt = con.createStatement();
		stmt.executeUpdate(
			"drop table if exists t"
		);
		stmt.executeUpdate(
			"CREATE TABLE t"
			+" ("
			+"  s integer,"
			+"  i integer,"
			+")"
		);
		PreparedStatement insertStmt = con.prepareStatement(
			"insert into t values (?,?)"
		);
		for( int i=0; i<100000; i++ ) {
			insertStmt.setInt(1,0);
			insertStmt.setInt(2,i);
			insertStmt.executeUpdate();
			insertStmt.setInt(1,1);
			insertStmt.setInt(2,i);
			insertStmt.executeUpdate();
		}
		insertStmt.close();
		stmt.executeUpdate(
			"CREATE UNIQUE INDEX t_idx"
			+"  ON t (s,i)"
		);
		stmt.close();
	}

}
