}
private void fillUpBigTable(String filler,
Random randomgen) throws SQLException {
StopWatch sw = new StopWatch();
int i;
PreparedStatement ps =
cConnection.prepareStatement("INSERT INTO zip VALUES(?)");
for (i = 0; i <= smallrows; i++) {
ps.setInt(1, i);
ps.execute();
}
ps.close();
sStatement.execute("SET DATABASE REFERENTIAL INTEGRITY "
+ this.refIntegrity);
ps = cConnection.prepareStatement(
"INSERT INTO test (firstname,lastname,zip,filler) VALUES (?,?,?,?)");
ps.setString(1, "Julia");
ps.setString(2, "Clancy");
for (i = 0; i < bigrows; i++) {
ps.setInt(3, nextIntRandom(randomgen, smallrows));
{
// small rows
long nextrandom = randomgen.nextLong();
int randomlength = (int) nextrandom & 0x7f;
if (randomlength > filler.length()) {
randomlength = filler.length();
}
String varfiller = filler.substring(0, randomlength);
ps.setString(4, nextrandom + varfiller);
}
/*
{
// big rows
long nextrandom = randomgen.nextLong();
int randomlength = (int) nextrandom & 0x7ff;
if (randomlength > filler.length() * 20) {
randomlength = filler.length() * 20;
}
StringBuffer sb = new StringBuffer(0xff);
for (int j = 0; j < 20; j++) {
sb.append(filler);
}
String varfiller = sb.substring(0, randomlength);
ps.setString(4, nextrandom + varfiller);
}
*/
ps.execute();
if (reportProgress && (i + 1) % 10000 == 0) {
System.out.println("insert " + (i + 1) + " : "
+ sw.elapsedTime());
}
// delete and add 4000 rows to introduce fragmentation
if (deleteWhileInsert && i != 0
&& i % deleteWhileInsertInterval == 0) {
sStatement.execute("CALL IDENTITY();");
ResultSet rs = sStatement.getResultSet();
rs.next();
int lastId = rs.getInt(1);
sStatement.execute(
"SELECT * INTO TEMP tempt FROM test WHERE id > "
+ (lastId - 4000));
sStatement.execute("DELETE FROM test WHERE id > "
+ (lastId - 4000));
sStatement.execute("INSERT INTO test SELECT * FROM tempt");
sStatement.execute("DROP TABLE tempt");
}
}
ps.close();
// sStatement.execute("INSERT INTO test SELECT * FROM temptest;");
// sStatement.execute("DROP TABLE temptest;");
// sStatement.execute(ddl7);
long time = sw.elapsedTime();
long rate = ((long) i * 1000) / (time + 1);
storeResult("insert", i, time, rate);
System.out.println("insert time for " + i + " rows -- " + time
+ " ms -- " + rate + " tps");