Hello
I have a table, named logs, with 60.000.000 rows.
The table structure is:
id BIGINT, user_id INT, page_viewed VARCHAR(255), last_visit BIGINT
Id is primary key with autoincrement, user_id and last_visit are indexed.
The second table named users, containing ~100.000 rows, has the following structure:
id INT, user_name VARCHAR(255), banned BOOL, blocked INT
Id is primary key, banned and blocked are indexed.
I want to select from logs 200 rows ordered by last_visit ascending where user is not banned and blocked count smaller than 11.
I have made the following query:
Code:
select id, page_viewed from `logs`
where
(select banned from users where id=logs.user_id limit 1)=0
and
(select blocked from users where id=urls.user_id limit 1)<11
order by `last_visit` asc
limit 200
This query takes ~9secs to complete on CORE2DUO E7300 with 4GB DDR2 RAM and 4 DRIVES SATA2 in RAID STRIPPING.
Biggest table, logs has ~10GB with 7GB data and 3GB indexes.
Is there any way to improve execution time?
I'm struggling with this query in different modes but this is the fastest way until now.
Please help!
Thank you!