Re: MySQL performance question

From: Date: Mon, 05 Aug 2002 11:14:16 +0000
Subject: Re: MySQL performance question
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-20991@lists.php.net to get a copy of this message
Hi, the 2 queries runs at exact speed. They differ only in that mysql has to return 1 row. So mysql generates the result as in the first query and returns only one row. You may get better performance for the second query because less data is transported over TCP/IP or unix domain sockets. If the result set is extremely big in the first query the second will be fast but because the transport of the result set of it will be faster. AFAIK, LIMIT clause is like HAVING clause but having is on some column and because mysql does not have default column as I heard there is in postgres LIMIT is used. This query will work in Postrgresq but mysql queries with LIMIT x,y will also run but will give unexpected results because in Postgres LIMIT how, offset (in mysql LIMIT offset, how). Andrey > > -----Original Message----- > > From: Lars Olsson [mailto:lasso@lassoweb.nu] > > Sent: Sunday, August 04, 2002 4:28 PM > > To: php-general@lists.php.net > > Subject: [PHP] MySQL performance question > > > > Hi all! > > > > Sorry for being slightly off topic, but this list seems to have it's > > fair share of MySQL gurus... :-) Anyway, here's my question: > > > > Suppose I create a table (called table1) which has a field with only > > unique values (called id). Now suppose this table has some rows and > that > > I want to select ONE of them. I usually do this: > > > > "SELECT * FROM table1 WHERE id=somevalue" > > > > Since id is a unique value this can only return (at most) 1 row. Now > > let's try this: > > > > "SELECT * FROM table1 WHERE id=somevalue LIMIT 1" > > > > This query will produce exactly the same result as the first query. > But > > which one (if any) of the two queries are the most efficient? Is it > > > > a) The first one, since it's a less complicated SQL query (less time > to > > parse) > > b) The second one, since it will restrict MySQL from searching further > > whenever a row is found > > > > Any opinions? > > > > /lasso (lasso@lassoweb.nu) > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.db (#20991) next »