简体   繁体   中英

mysql slow speed simple query

I have a very simple sql query which is just a select * from "table name" I have not indexed my table or anything else special.

The problem is that when I execute it through phpmyadmin , the query takes about 0.003 seconds but when I execute it through a browser in my web site it takes about 3 minutes!

There are 20K rows in the table and 19 fields. Can anyone help me?

include "config.php"; //Connect to Database

$query= mysql_query("SELECT * FROM table_name");
$num_rsl=mysql_num_rows($query);
echo '<table border="1">';
    for($i=0; $i <$num_rsl; $i++)
{
echo '<tr>';
$row=mysql_fetch_assoc($query);

    echo '<td>'.$row['id'].'</td>';
    echo '<td>'.$row['idLeistung'].'</td>';
    echo '<td>'.$row['dtEAN'].'</td>';
    echo '<td>'.$row['dtReifenBreite'].'</td>';
    echo '<td>'.$row['dtReifenQuerschnitt'].'</td>';
    echo '<td>'.$row['dtReifenBauart'].'</td>';
    echo '<td>'.$row['dtReifentragfahigkeit'].'</td>';
    echo '<td>'.$row['dtReifenGeschwindigkeitsindex'].'</td>';
    echo '<td>'.$row['dtReifenTTTL'].'</td>';
    echo '<td>'.$row['dtReifenProfil'].'</td>';
    echo '<td>'.$row['dtHersteller'].'</td>';
    echo '<td>'.$row['dtbestand'].'</td>';
    echo '<td>'.$row['FZG'].'</td>';
    echo '<td>'.$row['dtEinsatzZweck'].'</td>';
    echo '<td>'.$row['dtArtikelNr'].'</td>';
    echo '<td>'.$row['dtBeschreibung'].'</td>';
    echo '<td>'.$row['dtArtikelNrA2'].'</td>';
    echo '<td>'.$row['dtFremdVKPreis'].'</td>'; 
    echo '</tr>';
}
echo '</table>';

Usually, phpmyadmin modifies queries you issue through it to MySQL to limit the number of rows in the result set. Your

SELECT * FROM table_name 

most likely gets changed by phpmyadmin to

SELECT * FROM table_name LIMIT 0, 30

Pulling thirty rows certainly takes less time than pulling all the rows.

@scones mentioned this in the comments: pulling 20K rows from a table, turning them into a big old HTML table, and sending them over the wire to your browser takes a lot of elapsed time. But that elapsed time is probably mostly determined by the performance of your web server (where PHP runs) and the wire between server and browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM