I have the following SQL:
SELECT group_id FROM products WHERE category = 12345 GROUP BY group_id LIMIT 0, 10
or:
SELECT DISTINCT group_id FROM products WHERE category = 12345 LIMIT 0, 10
LIMIT is used for pagination. I want to know how I can avoid MySQL to search all rows until it finds 10 different group_id that I want. For example, if I did:
SELECT DISTINCT group_id FROM products WHERE category = 12345 LIMIT 200, 10
It scans the first 200 lines with category = 12345, how will it start collecting 10 different group_objects?
UPDATE: What if I created an index (group_id, category)?
source
share