Answer the question
In order to leave comments, you need to log in
How to limit search scope in mysql?
There is a table, in it it is a lot of records. How can I limit the area in which the search occurs (SELECT * from post where status = 1)? For example, let's search only in the first 1 million records. It is important for me that mysql does not go through all 13 million records. And analyzing the requests, I see that this is happening. Let the records be stored, but the selection is only from the first million records. Example:
MariaDB [yii2advanced]> DESCRIBE select * from scan limit 1;
+------+-------------+-------+------+---------------+------+---------+------+----------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+----------+-------+
| 1 | SIMPLE | scan | ALL | NULL | NULL | NULL | NULL | 13460011 | |
+------+-------------+-------+------+---------------+------+---------+------+----------+-------+
MariaDB [yii2advanced]> DESCRIBE select * from scan where url like "%1%" limit 20;
+------+-------------+-------+------+---------------+------+---------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+----------+-------------+
| 1 | SIMPLE | scan | ALL | NULL | NULL | NULL | NULL | 13460011 | Using where |
+------+-------------+-------+------+---------------+------+---------+------+----------+-------------+
Answer the question
In order to leave comments, you need to log in
If the id is autoincrement and there are no spaces in the numbering, then you can where id < 1000001
Well, or find out what id you have in the millionth place.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question