I've a MySQL question
I've two tables (posts and authors) in a one to many relationship (since each post is written by an author and an author can write multiple posts).
So here are the tables:
id:BIGINT, author_id:BIGINT, body:TEXT
SELECT * FROM Posts WHERE author_id = 45 ORDER BY RAND() LIMIT 1;
Yes, you definitely should add the index.
CREATE INDEX Post_author_id ON Posts(author_id);
As further evidence, run
EXPLAIN SELECT * FROM Posts WHERE author_id = 45 ORDER BY RAND() LIMIT 1;