Jump to content

[SOLVED] Using temporary; Using filesort -- odd issue


phpknight

Recommended Posts

I am trying to optimize every database query I run.  Here is an issue somebody might be able to help me with.  I have a query that returns 51 rows.  If I request LIM 0, 25 or even LIM 0, 51, my EXPLAIN statements come back great.  However, if I do the same query with LIM 0, 100, then it adds

 

Using where; Using temporary; Using filesort

 

Why would this be the case?  The application is simply allowing the uses to select how many items per page, and 100 is one of the default values.

 

I've tried using a straight join and switching the table order.  That helps get rid of some of them, but firesort remains.

Link to comment
Share on other sites

I did what you said.  Here is the result.  Let me know which variables look off to you.

 

max_length_for_sort_data 1024

max_sort_length 1024

myisam_max_sort_file_size 9223372036854775807

myisam_sort_buffer_size 67108864

sort_buffer_size 2097144

 

The sort is being done on a varchar (99) field or by date.

Link to comment
Share on other sites

Bigger sort_buffer_size should prevent using filesort. But remember that size of all memory variables should depends on RAM size available in your server for MySQL engine. If you increase one variable to speed up one feature it may slow down performance of other feature. You'll find more after googling eg. "optimizing mysql variables".

 

To speed up filesort (not to prevent) increase read_rnd_buffer_size variable or use faster hard disk or use two hard disks and use tmpdir variable to define two paths to temporary directories on these disks.

 

Finally you may create indexes on sorted columns.

 

Michal

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.