G’day!
I have one million different words which I’d like to query for in a table with 15 million rows. The result of synonyms together with the word is getting processed after each query.
table looks like this:
synonym word --------------------- ancient old anile old centenarian old darkened old distant far remote far calm gentle quite gentle
This is how it is done in Java currently:
.... PreparedStatement stmt; ResultSet wordList; ResultSet syns; ... stmt = conn.prepareStatement('select distinct word from table'); wordList = stmt.executeQuery(); while (wordList.next()) { stmt = conn.prepareStatement('select synonym from table where word=?'); stmt.setString(1, wordList.getString(1)); syns = stmt.executeQuery(); process(syns, wordList.getString(1)); } ...
This is incredible slow. What’s the fastest way to do stuff like this?
Cheers, Chris
Two ideas:
a) How about making it one query:
b) Or, if you
processmethod needs to deal with them as a set of synonyms of one word, why not sort them bywordand startprocessanew each timewordis different? That query would be: