I have 2 table: words with word examples. There is appx 70k words with ~1 million examples. Im trying to add admin with search and paginated results but running into queries taking 6-7 seconds to produce results.
Am I doing something wrong?
Here's the schema:
```
CREATE TABLE IF NOT EXISTS words (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
word VARCHAR(191) DEFAULT NULL,
fl VARCHAR(191) DEFAULT NULL,
UNIQUE KEY (word, fl),
FULLTEXT (word)
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS examples (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
fk_words_id BIGINT UNSIGNED,
src VARCHAR(50) DEFAULT NULL,
example VARCHAR(400) DEFAULT NULL,
cite_author VARCHAR(400) DEFAULT NULL,
cite_publication VARCHAR(400) DEFAULT NULL,
cite_title VARCHAR(400) DEFAULT NULL,
FULLTEXT (example,cite_author,cite_publication),
PRIMARY KEY (id),
FOREIGN KEY (fk_words_id) REFERENCES words (id) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;
```
My queries for paginated results look like this:
SELECT DISTINCT
a.id,
a.word,
a.fl,
a.updated
FROM words AS a
LEFT JOIN examples AS b
ON a.id = b.fk_words_id
WHERE (a.word = :search_string OR MATCH(b.example,b.cite_author,b.cite_publication) AGAINST(+'some word' IN BOOLEAN MODE))
ORDER BY id asc
LIMIT 0,20;
Is there a way I improve performance here?