I have created a table with some dummy data. The table (ARTICLES) consists of id, author_id, title, description and the table (AUTHOR) consists of author_id, name, article_list.
As per application flow first I would take out the list of authors, this will give me author name and article list and id. When the user navigates inside author I can get the list of all articles in two way.
First
SELECT * FROM articles WHERE author_id = 100;
and secondly, if I keep all list of all articles in form of a list inside my author table then I can use
SELECT *
FROM articles
WHERE id IN (100, 1100, 2100, 3100, 4100, 5100, 6100,
7100, 8100, 9100, 10100, 11100, 12100, 13100,
14100, 15100, 16100, 17100, 18100, 19100, 20100,
21100, 22100, 23100, 24100, 25100, 26100, 27100,
28100, 29100, 30100, 31100, 32100, 33100, 34100);
The first query took 0.0329 sec while the second query took 0.0017 sec.
I am not able to understand how is it possible that the first query is taking more time than the second query.
All I know the second query will execute like
SELECT *
FROM articles
WHERE id = 100
OR id = 1100
OR id = 2100... and so on