0

1.5Gb 前後の非常に大きなテキスト ファイルがあります。ファイルを 1 行ずつ解析し、その行を Derby データベースに挿入する必要があります。パフォーマンスやファイルの解析方法などに関する多くのフォーラムを読みました。私の問題は、すべてのプロセスをベンチマークし、1 ミリ秒の行を読み取って解析するのにかかることです。挿入しようとしているのは存在しない場合、それを更新する必要があります。プロセスのこの部分には約 9 ミリ秒かかります。

ファイルに約1,000万行が含まれていることを考えると、合計で10ミリ秒です。

クエリに使用PreparedStatementしています。

コードのクエリ部分を高速化する方法はありますか?

4

2 に答える 2

2

Autocommit をオフにしましたか?

dbConnection.setAutoCommit(false);

次のように、1 つずつではなくバッチ挿入を使用します。

    Connection dbConnection = null;
    PreparedStatement preparedStatement = null;

    String insertTableSQL = "INSERT INTO DBUSER"
            + "(USER_ID, USERNAME, CREATED_BY, CREATED_DATE) VALUES"
            + "(?,?,?,?)";

    try {
        dbConnection = getDBConnection();
        preparedStatement = dbConnection.prepareStatement(insertTableSQL);

        dbConnection.setAutoCommit(false);

        preparedStatement.setInt(1, 101);
        preparedStatement.setString(2, "mkyong101");
        preparedStatement.setString(3, "system");
        preparedStatement.setTimestamp(4, getCurrentTimeStamp());
        preparedStatement.addBatch();

        preparedStatement.setInt(1, 102);
        preparedStatement.setString(2, "mkyong102");
        preparedStatement.setString(3, "system");
        preparedStatement.setTimestamp(4, getCurrentTimeStamp());
        preparedStatement.addBatch();

        preparedStatement.setInt(1, 103);
        preparedStatement.setString(2, "mkyong103");
        preparedStatement.setString(3, "system");
        preparedStatement.setTimestamp(4, getCurrentTimeStamp());
        preparedStatement.addBatch();

        preparedStatement.executeBatch();

        dbConnection.commit();

        System.out.println("Record is inserted into DBUSER table!");

    } catch (SQLException e) {

        System.out.println(e.getMessage());
        dbConnection.rollback();

    } finally {

        if (preparedStatement != null) {
            preparedStatement.close();
        }

        if (dbConnection != null) {
            dbConnection.close();
        }

    }

以下をご覧ください: https://builds.apache.org/job/Derby-docs/lastSuccessfulBuild/artifact/trunk/out/tuning/tuningderby.pdf

于 2015-01-30T14:00:55.417 に答える