English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

im using a PHP-MySQL application and when i need to query about 1500 records with some JOINS to other tables and GROUPED BY statements, the query takes about an hour to load. I need to know some techniques on MySQL to make the query faster. (such as are VIEWS available in MySQL?)

2006-09-18 17:03:29 · 5 answers · asked by patweak 1 in Computers & Internet Programming & Design

5 answers

With only 1500 records taking an hour it is likely that you are missing indices. Start by using EXPLAIN to find out how MySQL is processing the query. When looking at the EXPLAIN results, check for places where the query is doing a full table scan. Those are the areas where you are most likely to be missing an index.

Simple EXPLAIN example:
explain
select t.name, min(t.test_date)
from sometable t
group by t.name

2006-09-21 00:20:06 · answer #1 · answered by Jeff Alexander 2 · 0 0

Instead of a single highly complex query, why not break the query into a series of 2 or 3 queries each of which produces an intermediate table that is used in the subsequent query?

2006-09-18 17:15:39 · answer #2 · answered by glenbarrington 7 · 0 0

Try to break the query into simple units, step by step, the more important to the less important. Eliminate all the unimportant parts. And make a chain of easy simple queries.
That's gonna help you to review the code and maintain it.

2006-09-18 17:32:35 · answer #3 · answered by Anonymous · 0 0

Make sure that your your group by is on an indexed column!

You can also speed up the SQL by getting the PHP to do some of the processing.

2006-09-18 22:18:35 · answer #4 · answered by AnalProgrammer 7 · 0 0

better keys! no views.

that was easy!

2006-09-18 17:09:49 · answer #5 · answered by jake cigar™ is retired 7 · 0 0

fedest.com, questions and answers