I want to insert 700 million rows to a table which is defined in a following way.
CREATE TABLE KeywordIndex (id INT PRIMARY KEY AUTO_INCREMENT, keyValue VARCHAR(45) NOT NULL, postings LONGTEXT NOT NULL); To insert data in the table I first check if the keyValue exists I update the value of postings by concatenating new value to old value. Otherwise, insert data as a new row of the table. Also, if the size of postings is bigger than its definition I consider a new row to write extension of postings of the keyValue. In my implementation, inserting 70,294 entry took 12 hours!!!!
( I am not a database expert, so the code I've written could be based on wrong foundations. Please help me to understand my mistakes :) )
I read this page but I could not find a solution for my problem.
I add code that I wrote to do this process.
public void writeTermIndex( HashMap<String, ArrayList<TermPosting>> finalInvertedLists) { try { for (String key : finalInvertedLists.keySet()) { int exist=ExistTerm("KeywordIndex",key); ArrayList<TermPosting> currentTermPostings=finalInvertedLists.get(key); if (exist>0) { String postings=null; String query = "select postings from KeywordIndex where keyValue=?"; PreparedStatement preparedStmt = conn.prepareStatement(query); preparedStmt.setString (1, key); ResultSet rs=preparedStmt.executeQuery(); if(rs.next()) postings=rs.getString("postings"); postings=postings+convertTermPostingsToString(currentTermPostings); if(getByteSize(postings)>65530) insertUpdatePostingList("KeywordIndex",key,postings); else{ updatePosting("KeywordIndex",key,postings); rs.close(); preparedStmt.close(); } } else { String postings=convertTermPostingsToString(currentTermPostings); if(getByteSize(postings)>65530) insertPostingList("KeywordIndex",key,postings); else insetToHashmap("KeywordIndex",key,postings); } } } catch(Exception e){ e.printStackTrace(); } }