Rendimiento de MySQL

MyPHP Application sends a SELECT statement to MySQL with HTTPClient.

It takes about 20 seconds or more. I thought MySQL can’t get result immediately because MySQL Administrator shows stat for sending data or copying to tmp table while I'd been waiting for result.

But when I send same SELECT statement from another application like phpMyAdmin or jmater it takes 2 seconds or less.10 times faster!!

Dose anyone know why MySQL perform so difference?

preguntado el 28 de agosto de 12 a las 09:08

Show us the query, and it'd also help if you could show the output of 'EXPLAIN <QUERY>' in your mysql console. -

What is the query, table schema and how many rows are there in the table? -

algo misterio query (and or code) is slow, how do you think we can help you ? -

Very sorry. This PHP Application has sent another tow SELECT statements.That’s why MySQL shows different performance.Vote delete to remove this post. -

2 Respuestas

Like @symcbean already said, php's mysql driver caches query results. This is also why you can do another mysql_query() mientras que en un while($row=mysql_fetch_array()) lazo.

The reason MySql Administrator or phpMyAdmin shows result so fast is they append a LIMIT 10 to your query behind your back.

If you want to get your query results fast, i can offer some tips. They involve selecting only what you need and when you need:

  • Select only the columns you need, don't throw select * everywhere. This might bite you later when you want another column but forget to add it to select statement, so do this when needed (like tables with 100 columns or a million rows).
  • Don't throw a 20 by 1000 table in front of your user. She cant find what she's looking for in a giant table anyway. Offer sorting and filtering. As a bonus, find out what she generally looks for and offer a way to show that records with a single click.
  • With very big tables, select only primary keys of the records you need. Than retrieve additional details in the while() loop. This might look like illogical 'cause you make more queries but when you deal with queries involving around ~10 tables, hundreds of concurrent users, locks and query caches; things don't always make sense at first :)

These are some tips i learned from my boss and my own experince. As always, YMMV.

Respondido 28 ago 12, 11:08

Dose anyone know why MySQL perform so difference?

Because MySQL caches query results, and the operating system caches disk I/O (ver este enlace for a description of the process in Linux)

Respondido 28 ago 12, 10:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.