Пример #1
0
  /**
   * Test case for ALTER [IGNORE] TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2 syntax
   *
   * @throws SQLException
   */
  public void testExchangePartition() throws Exception {
    if (versionMeetsMinimum(5, 6, 6)) {
      createTable(
          "testExchangePartition1",
          "(id int(11) NOT NULL AUTO_INCREMENT, year year(2) DEFAULT NULL,"
              + " modified timestamp NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB ROW_FORMAT=COMPACT PARTITION BY HASH (id) PARTITIONS 2");
      createTable("testExchangePartition2", "LIKE testExchangePartition1");

      this.stmt.executeUpdate("ALTER TABLE testExchangePartition2 REMOVE PARTITIONING");
      if (versionMeetsMinimum(5, 7, 4)) {
        this.stmt.executeUpdate(
            "ALTER TABLE testExchangePartition1 EXCHANGE PARTITION p1 WITH TABLE testExchangePartition2");
      } else {
        this.stmt.executeUpdate(
            "ALTER IGNORE TABLE testExchangePartition1 EXCHANGE PARTITION p1 WITH TABLE testExchangePartition2");
      }

      if (versionMeetsMinimum(5, 7, 4)) {
        this.pstmt =
            this.conn.prepareStatement(
                "ALTER TABLE testExchangePartition1 EXCHANGE PARTITION p1 WITH TABLE testExchangePartition2");
      } else {
        this.pstmt =
            this.conn.prepareStatement(
                "ALTER IGNORE TABLE testExchangePartition1 "
                    + "EXCHANGE PARTITION p1 WITH TABLE testExchangePartition2");
      }
      assertEquals(
          Util.isJdbc4()
              ? Class.forName("com.mysql.jdbc.JDBC4PreparedStatement")
              : com.mysql.jdbc.PreparedStatement.class,
          this.pstmt.getClass());
      this.pstmt.executeUpdate();

      Connection testConn = null;
      try {
        testConn = getConnectionWithProps("useServerPrepStmts=true,emulateUnsupportedPstmts=false");
        if (versionMeetsMinimum(5, 7, 4)) {
          this.pstmt =
              testConn.prepareStatement(
                  "ALTER TABLE testExchangePartition1 EXCHANGE PARTITION p1 WITH TABLE testExchangePartition2");
        } else {
          this.pstmt =
              testConn.prepareStatement(
                  "ALTER IGNORE TABLE testExchangePartition1 "
                      + "EXCHANGE PARTITION p1 WITH TABLE testExchangePartition2");
        }
        assertEquals(
            Util.isJdbc4()
                ? Class.forName("com.mysql.jdbc.JDBC4ServerPreparedStatement")
                : com.mysql.jdbc.ServerPreparedStatement.class,
            this.pstmt.getClass());
        this.pstmt.executeUpdate();
      } finally {
        if (testConn != null) {
          testConn.close();
        }
      }
    }
  }
 static {
   BASELINE_TIMES.put("ResultSet.getInt()", new Double(0.00661));
   BASELINE_TIMES.put("ResultSet.getDouble()", new Double(0.00671));
   BASELINE_TIMES.put("ResultSet.getTime()", new Double(0.02033));
   BASELINE_TIMES.put("ResultSet.getTimestamp()", new Double(0.02363));
   BASELINE_TIMES.put("ResultSet.getDate()", new Double(0.02223));
   BASELINE_TIMES.put("ResultSet.getString()", new Double(0.00982));
   BASELINE_TIMES.put("ResultSet.getObject() on a string", new Double(0.00861));
   BASELINE_TIMES.put("Connection.prepareStatement()", new Double(0.18547));
   BASELINE_TIMES.put("single selects", new Double(46));
   BASELINE_TIMES.put("5 standalone queries", new Double(146));
   BASELINE_TIMES.put("total time all queries", new Double(190));
   if (com.mysql.jdbc.Util.isJdbc4()) {
     BASELINE_TIMES.put("PreparedStatement.setInt()", new Double(0.0014));
     BASELINE_TIMES.put("PreparedStatement.setTime()", new Double(0.0107));
     BASELINE_TIMES.put("PreparedStatement.setTimestamp()", new Double(0.0182));
     BASELINE_TIMES.put("PreparedStatement.setDate()", new Double(0.0819));
     BASELINE_TIMES.put("PreparedStatement.setString()", new Double(0.0081));
     BASELINE_TIMES.put("PreparedStatement.setObject() on a string", new Double(0.00793));
     BASELINE_TIMES.put("PreparedStatement.setDouble()", new Double(0.0246));
   } else {
     BASELINE_TIMES.put("PreparedStatement.setInt()", new Double(0.0011));
     BASELINE_TIMES.put("PreparedStatement.setTime()", new Double(0.0642));
     BASELINE_TIMES.put("PreparedStatement.setTimestamp()", new Double(0.03184));
     BASELINE_TIMES.put("PreparedStatement.setDate()", new Double(0.12248));
     BASELINE_TIMES.put("PreparedStatement.setString()", new Double(0.01512));
     BASELINE_TIMES.put("PreparedStatement.setObject() on a string", new Double(0.01923));
     BASELINE_TIMES.put("PreparedStatement.setDouble()", new Double(0.00671));
   }
 }