Welcome, Guest. Please login or register.

Author Topic: MySQL and LIMIT for speed  (Read 2401 times)

oxo

  • Guest
MySQL and LIMIT for speed
« on: January 23, 2010, 01:31:10 PM »
Does anyone know if an SQL query is speeded up when there is known to be only one row for a column even when the column is UNIQUE.
ie
SELECT * FROM devices WHERE name='OpenWrt' LIMIT 1;
contra
SELECT * FROM devices WHERE name='OpenWrt';
(name is UNIQUE)

MySQL could be intelligent enough to think that if a column is UNIQUE, it doesn't need to search for more rows and just return the first row.
On the other hand, it may not be ...

Edit:
... and on the third hand, MySQL is soon Oracle.
Maybe I shouldn't presume MySQL and say from first principles that a LIMIT 1 will allways return on first match regardless of the SQL engine used.
(Gotta do a POC on using another SQL engine: it's a long time since this was "allowed", but no one did it. DBD::CSV - DBI driver for CSV files could be a "nice" easy proof giving txt for those who need it, and if it works there it'll work anywhere and postreq was once asked for ...).


MySQL fork: AskMonty
Google: Oracle and MySQL: good or bad ...
« Last Edit: January 23, 2010, 02:36:24 PM by oxo »