From: Reindl Harald Date: October 24 2011 4:32pm Subject: Re: large temp files created by mysql List-Archive: http://lists.mysql.com/mysql/226170 Message-Id: <4EA59329.6000603@thelounge.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigA0453DF956DEC39FF580302F" --------------enigA0453DF956DEC39FF580302F Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Am 24.10.2011 18:02, schrieb mos: > At 10:34 AM 10/24/2011, you wrote: >> select id from table order by rand() limit 1; >> is doing as example a dumb temporary table with the full size >=20 > Because it has to sort the entire table, then it returns the one row. T= his of course is extremely inefficient. :) > You need to choose a random row by using an auto-inc field. Something l= ike: >=20 > select id from table where id>=3Dmyrandomnum limit 1 but this is TOTALLY braindead if "id" is a primary-KEY with auto-incremen= t --------------enigA0453DF956DEC39FF580302F 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/ iEYEARECAAYFAk6lkykACgkQhmBjz394AnkkdACeO7B06dOWlPaCW6rO0CqRilyj W5cAoJMpBvtK26ProRs33AxzDFGaLnSc =yHEh -----END PGP SIGNATURE----- --------------enigA0453DF956DEC39FF580302F--