From: Reindl Harald Date: October 26 2011 9:15am Subject: Re: large temp files created by mysql List-Archive: http://lists.mysql.com/mysql/226185 Message-Id: <4EA7CFBD.90802@thelounge.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig7646E30FEA0210EC44D5FC31" --------------enig7646E30FEA0210EC44D5FC31 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Am 26.10.2011 05:14, schrieb mos: >> > It is not "braindead". You told MySQL to sort by rand() which is a n= on-indexed column. >> > It needs to assign a value to each row of the result set (all ids of= the table) and sort >> > it to get the lowest random number. This is very inefficient for lar= ge tables. >> >> but there is mo need to do this with the whole table >> if the only requested field is the primary key >=20 > Sure but if the table has 100 million rows and you want 1 random id, th= at means sorting 100 million id's from the > index to disk. This is still grossly inefficient. It may work fine on t= ables with a couple thousand rows, but not > for million row tables. That's why the two methods I suggested don't us= e sorting. this is not the topic the topic is "order by rand()" works braindead all other things are workarounds and it still matters on small tables with only 512KB if mysqld makes on each query a 512KB temp-file or not - have fun under concurrent load even with small tables! only the auto-ids are tiny data and nothing more is requested here as result and no reason to copy the whole table with all fields around --------------enig7646E30FEA0210EC44D5FC31 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk6nz74ACgkQhmBjz394Ann3zACeLYg8dAtozg0jHQjrCzP3NFvS wlgAn3X8rd23owo37ujWrY6Hfgt+/q05 =Vh/A -----END PGP SIGNATURE----- --------------enig7646E30FEA0210EC44D5FC31--