| 1 5 package org.h2.test.cases; 6 7 import java.sql.*; 8 import java.util.Random ; 9 10 import org.h2.tools.DeleteDbFiles; 11 import org.h2.util.MemoryUtils; 12 13 public class TestRebuildIndex { 14 public static void main (String [] args) throws Exception { 15 boolean init = false; 16 if(init) { 17 DeleteDbFiles.execute(".", "test", false); 18 } 19 Class.forName("org.h2.Driver"); 20 Connection conn = DriverManager.getConnection("jdbc:h2:test;cache_type=lzf", "sa", "sa"); 21 Statement stat = conn.createStatement(); 22 if(init) { 23 stat.executeUpdate("DROP TABLE IF EXISTS TEST"); 24 stat.executeUpdate("CREATE TABLE TEST(ID INT PRIMARY KEY, DATA INT)"); 25 PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?)"); 26 int max = 1000000; 27 Random random = new Random (10); 28 for(int i=0; i<max; i++) { 29 prep.setInt(1, i); 30 prep.setInt(2, random.nextInt()); 32 prep.execute(); 33 } 34 } else { 35 long time = System.currentTimeMillis(); 36 stat.execute("CREATE INDEX IDXDATA ON TEST(DATA)"); 37 time = System.currentTimeMillis() - time; 38 System.out.println("time: " + time); 39 System.out.println("mem: " + MemoryUtils.getMemoryUsed()); 42 } 43 conn.close(); 44 } 45 } 46 | Popular Tags |