I am new in database sql. I know that indexes make query faster. But I want to learn the ways of making query slowing down without dropping or creating objects.
create index ind1 on students_2(surname);
select * from students s1, students_2 s2
where s1.name1=substr(s2.surname,1,5) and s1.dep=s2.dep and
s1.dep in ('Econ','Law')
You can embed a sleep into any expression.
select *
from students s1
join students_2 s2
on s1.name1=substr(s2.surname,1,5) and s1.dep=s2.dep
where s1.dep in ('Econ','Law')
and sleep(0.1)=0;
This will add a 0.1 second sleep every time a row is examined. The sleep() function normally returns 0.
PS: Please use proper JOIN
syntax instead of obsolete "comma" joins.
One solution, and probably the easiest one, would be to use an index hint to ignore the indexes you have, like this:
select *
from
students s1
ignore index ind1
Alternatively, you can try to slown down the query (more) by makeing it more complex. The query below is modified a bit, especially the part that checks for the name. Instead of just matching by name, it matches two parts of the name. Because of the second condition, any index on s1.name1
cannot be efficiently used, and MySQL has to do a lot of string manipulation:
select *
from
students s1, students_2 s2
where
substr(s1.name1, 1, 1) = substr(s2.surname, 1, 1) and
substr(s1.name1, 2) = substr(s2.surname, 2, 5) and
s1.dep = s2.dep and
s1.dep in ('Econ','Law')
Just like with adding indexes, forcefully not using indexes will also have varying results. Query results might still be cached, and even without indexes, a query can be pretty fast.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.