Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare two mysql sql performance?

Tags:

mysql

select * from goods where (name like '%%' or brand '%%' or alias like '%%') and category_id = 1 order by id limit 20

select * from goods where category_id = 1 order by id limit 20;

Mysql version 5.6.16-log, Does above two sql has same performance?

Business background, user could search goods by keyword or category or both, if user does not input keyword then keyword parameter default is empty string. I want to use the same sql, but worry performance. If keyword is empty should has a special query sql?

like image 569
zhuguowei Avatar asked Sep 24 '26 16:09

zhuguowei


1 Answers

You could measure it using a profile; here the manual: http://dev.mysql.com/doc/refman/5.0/en/show-profiles.html

Start the profiler with

SET profiling = 1;

Then execute your Query. With

SHOW PROFILES;

you see a list of queries the profiler has statistics for. And finally you choose which query to examine with

SHOW PROFILE FOR QUERY 1;

or whatever number your query has.

What you get is a list where exactly how much time was spent during the query. Then you can decide which one was more perfomant

like image 125
pguetschow Avatar answered Sep 27 '26 05:09

pguetschow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!