I have a dictionary in my database which has over million records and this simple select
select * from Word where languageId = 'en' order by rand() limit 1
randomly selects one word.
The problem is that this request lasts 3-4 seconds which is very long because I have to repeat it many times.
Is there a way to achieve the same thing but much faster?
EDIT - table schema
wordId - integer, auto increment
languageId - varchar (FK), values like cs, en, de, ...
word - varchar, word itself
Data structure example
wordId languageId word
--------------------------
1 cs abatyše
...
100000 cs zip
100001 en aardvark
...
etc
SQL
CREATE TABLE Language (
languageId VARCHAR(20) NOT NULL ,
name VARCHAR(255) NULL ,
PRIMARY KEY(languageId));
CREATE TABLE Word (
wordId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
languageId VARCHAR(20) NOT NULL ,
word VARCHAR(255) NULL ,
PRIMARY KEY(wordId) ,
INDEX Word_FK_Language(languageId),
FOREIGN KEY(languageId)
REFERENCES Language(languageId)
ON DELETE NO ACTION
ON UPDATE NO ACTION);