Crosswords1 min ago
Database question
1 Answers
wot is query optimisation? could you may explain how it works and a few examples.
thanks
Answers
Best Answer
No best answer has yet been selected by keys. Once a best answer has been selected, it will be shown here.
For more on marking an answer as the "Best Answer", please visit our FAQ.It's basically looking at your SQL query and making changes so it runs faster.
Most RDBMS will optimize the query anyway so it's not always an easy task. It's too difficult to give examples because it depends very much on how the database has been set up. But as a way of a rather contrived example.....
lets say you had the following SQL query
select * from emps where lower(ename) = 'smith';
There could be an index on ename which will not be used because the column has been converted using the lower function, it might be faster to remove the lower, but you would need to make sure your application converts any entries into the ename column into lower case.
Other options might be to use EXISTS rather than IN or vica versa, but again it depends very much on the database setup
Most RDBMS will optimize the query anyway so it's not always an easy task. It's too difficult to give examples because it depends very much on how the database has been set up. But as a way of a rather contrived example.....
lets say you had the following SQL query
select * from emps where lower(ename) = 'smith';
There could be an index on ename which will not be used because the column has been converted using the lower function, it might be faster to remove the lower, but you would need to make sure your application converts any entries into the ename column into lower case.
Other options might be to use EXISTS rather than IN or vica versa, but again it depends very much on the database setup