Optimisation

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Optimisation

par kidpigeyre » 25 janv. 2006, 15:57

Cela venait du fait que dans la boucle il effectuait une selection sur une grosse table en select * et sans index donc j'ai juste sélectionné les champs nécessaire et créé les index

par Invité » 25 janv. 2006, 15:31

Problème résolu

par Hubert Roksor » 25 janv. 2006, 15:08

Je n'ai pas lu ta requête en détail, mais avant toute chose lance "OPTIMIZE TABLE t_requests, t_product_date_comparator, t_client_ranking". Puis fais un EXPLAIN et ta requête et poste le résultat ici. Et n'oublie pas les balises

Code : Tout sélectionner

! ;)

par kidpigeyre » 25 janv. 2006, 13:11

Code : Tout sélectionner

$sql = "SELECT SQL_BIG_RESULT DISTINCT t_product_date_comparator.ref, searched, found, parsed, rank_client_totprice, rank_client_totprice_virtual, ectype_client_first, ectype_client_first_virtual, libelle, ref_c, brand, category, prec "; ///$sql = "SELECT t_product_date_comparator.ref, searched, found, parsed, libelle, ref_c, brand, category, prec "; ///$sql = "SELECT libelle, ref_c, brand, category "; $sql .= "FROM t_requests "; $sql .= ", t_product_date_comparator "; // $sql .= 'LEFT JOIN t_client_ranking ON '; $sql .= "t_client_ranking.id_client = t_requests.id_client "; $sql .= "AND t_client_ranking.datebatch = t_requests.date "; $sql .= 'AND t_client_ranking.id_product = t_requests.ref '; $sql .= 'AND t_client_ranking.id_comparator = t_product_date_comparator.id_comparator '; // $sql .= "WHERE "; $sql .= "t_requests.date = t_product_date_comparator.date "; ...

Code : Tout sélectionner

// echo '$showfirstid= '.$showfirstid; $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; $sqlres = mysql_query($sql) or die('Erreur SQL (affiche_results2)!<br>'.$sql.'<br>'.mysql_error()); $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); echo "temps de requete : ".number_format($totaltime,4,',','')."<br>"; while($row = mysql_fetch_array($sqlres, MYSQL_ASSOC)) { $id_product = $row['ref']; // recuperation des données relatives $separator = '__'; $str = get_rang_client($date_batch, $id_product, get_id_comparator($le_comparateur), $webshops); $relative_data = explode($separator, $str); // $rank_me = $str; $rank_me = $relative_data[0]; $tot_price_me = $relative_data[1]; $tot_price_first = $relative_data[2]; // calcul de l'ecart if ($tot_price_me != 0){ $ectypep0 = (($tot_price_first - $tot_price_me)/$tot_price_me)*100; } else{ $ectypep0 = 'NC'; } // determination du style d'affichage des résultats en fonction de l'état // ainsi que de l'activation ou non du lien vers le zoom $class_state = ""; $zoom_active = 0; if ( ( $row['searched'] == 0 ) ){ $class_state = "notsearched"; $zoom_active = 0; } elseif ( ( $row['found'] == 1 ) && ( $row['parsed'] == 1 ) ){ $class_state = ""; $zoom_active = 1; } elseif ( ( $row['found'] == 1 ) && ( $row['parsed'] == 0 ) && ($_SESSION["superadmin"]==1) ){ $class_state = "notparsed"; $zoom_active = 0; } elseif( ( $row['found'] == 0 ) && ($_SESSION["superadmin"]==1) ){ $class_state = "notfound"; $zoom_active = 0; } // pour un utilisateur lambda, toutes les erreurs sont de la meme couleur else{ $class_state = "notfound"; $zoom_active = 0; } /////////////Tests pour affichage Reel/theorique $rank_display = ''; $ecart_display = ''; $virtually_ranked = 0; $rank_client_totprice_display = 'NC'; if( ($row['rank_client_totprice'] != 0) ){ $rank_client_totprice_display = $row['rank_client_totprice']; if ($rank_display == ''){ $rank_display = $rank_client_totprice_display; } } else{ $rank_client_totprice_display = 'Abs.'; } $rank_client_totprice_virtual_display = 'NC'; if( ($row['rank_client_totprice_virtual'] != 0) && !($row['parsed'] == 0) && !($row['found'] == 0) ){ $rank_client_totprice_virtual_display = $row['rank_client_totprice_virtual']; if ($rank_display == ''){ $rank_display = $rank_client_totprice_virtual_display; $virtually_ranked = 1; } } else{ $rank_client_totprice_virtual_display = 'abs'; } if ($rank_display == ''){ $rank_display = 'NC'; } $ectype_client_first_display = 'NC'; if( ($row['ectype_client_first'] != 0) ){ $ectype_client_first_display = number_format($row['ectype_client_first'],2); $ectype_client_first_display .= '%'; if ($ecart_display == ''){ $ecart_display = $ectype_client_first_display; } } elseif ($row['rank_client_totprice'] == 1){ $ectype_client_first_display = '0%'; if ($ecart_display == ''){ $ecart_display = $ectype_client_first_display; } } else{ $ectype_client_first_display = 'Abs.'; } $ectype_client_first_virtual_display = 'NC'; if( ($row['ectype_client_first_virtual'] != 0) ){ $ectype_client_first_virtual_display = number_format($row['ectype_client_first_virtual'],2); $ectype_client_first_virtual_display .= '%'; if ($ecart_display == ''){ $ecart_display = $ectype_client_first_virtual_display; } } else{ $ectype_client_first_virtual_display = ''; } if ($ecart_display == ''){ $ecart_display = 'NC'; } ?> <tr <? if ( ($showId == $row['ref']) && ($showfirstid == -1) ){ $_SESSION['showId'] = -1; ?>class="clic"<? } elseif ( ($showId == $row['ref']) && ($showfirstid != 1) ){ ?>class="clic"<? } else if ( ($showfirstid == 1) && ($zoom_active == 1) && ($showf == 0) ) { ?> <? $showf = 1; $_SESSION['showId'] = $row['ref']; ?> class="clic" <? } ?> > <? // affichage du numero de résultat ?> <td><? echo $cpt; ?></td> <? // affichage du lien vers l'inclusion du zoom dans la page ?> <? if ($zoom_active == 1){ ?> <td > <a title=" <? if ($row['libelle'] != $row['ref_c']){ echo $row['ref_c']." - "; } echo $row['libelle']; ?>" href="<? echo $_SERVER['PHP_SELF'].'?page='.$pagephp.' &debut='.$debut.'&showId='.$row['ref']; ?>#details" > <? echo tronquer_chaine(htmlentities($row['ref_c']), 15); ?></a> </td> <? } ?> <? if ($zoom_active == 0){ ?> <td class="<? echo $class_state; ?>"> <abbr title=" <? if ($row['libelle'] != $row['ref_c']){ echo $row['ref_c']." - "; } echo $row['libelle']; ?>"> <? echo tronquer_chaine(htmlentities($row['ref_c']), 4); ?> </abbr> </td> <? } ?> <? // affichage du lien vers l'affichage du zoom // dans une nouvelle page ?> <? /*?> <? if ($zoom_active == 1){ ?> <td><a target="_blank" href="display_one.php?ref= <? echo $row['ref']; ?> &bdate=<? echo lockdate2($date_batch); ?>"> <img src="/images/about.png" alt="En savoir +" width="14" height="14" border="0"></a></td> <? } ?> <? if ($zoom_active == 0){ ?> <td class="<? echo $class_state; ?>">&nbsp;</td> <? } ?> <? */?> <? // affichage de la marque ?> <? if ( ($mode != 'mesres') ) { ?> <td class="<? echo $class_state; ?> capitalize"> <? echo htmlentities($row['brand']); ?></td> <? } ?> <? // affichage du libelle ?> <? /*?> <td class="<? echo $class_state; ?>"> <? echo htmlentities($row['libelle']); ?></td> <? */?> <? // affichage de la catégorie ?> <? if ( ($mode != 'mesres') ) { ?> <td class="<? echo $class_state; ?>"> <? echo htmlentities($row['category']); ?></td> <? } ?> <? // affichage du rang a posteriori ?> <? /*?> <td><? echo $rank_me;?>&deg;</td> <? */?> <? // affichage de l'écart en pourcentage à posteriori?> <? /*?> <td><? echo round($ectypep0,2); ?>%</td> <? */?> <? // affichage de la pertinence (ou précision) ?> <td> <? // si la ref a été trouvée & parsée if ( ($zoom_active == 1) ){ if( $row['prec'] != '' ){ // echo money_format('%.2n', htmlentities($row['prec'])); //echo number_format( // htmlentities($row['prec']), 2, '.', '' ); } // FIN if( $row['prec'] != '' ){ ?> <? // si la pretinence est forte ou // si le client est pas absent if( ($row['prec'] >= 80) || ($row['rank_client_totprice'] == '') ) { ?> <img src="../images/3stars.png" width="40" height="13" alt="Pertinence>=80"> <? } // FIN if( ($row['prec'] >= 80) ){ else if( ($row['prec'] >= 50 and $row['prec'] < 80) ){ ?> <img src="../images/2stars.png" width="40" height="13" alt="Pertinence>=50"> <? } // FIN if( ($row['prec'] >= 50 and $row['prec'] < 80) ){ else if( ($row['prec'] < 50) ){ ?> <img src="../images/1stars.png" width="40" height="13" alt="Pertinence<50"> <? } // FIN if( ($row['prec'] < 50) ){ } // FIN if ( ($row['rank_client_totprice'] != '') // && ($zoom_active == 1) ){ ?> </td> <? if ( ($mode == 'mesres') ) { ?> <? // affichage du rang ?> <td class="flechette"> <div <? if ($virtually_ranked==1) { ?> class="data_theorique" <? } ?>> <abbr title="<? echo " Rang reel: ".$rank_client_totprice_display." - Rang theorique: ".$rank_client_totprice_virtual_display; ?>"> <? echo $rank_display; ?> </abbr></div> </td> <? } ?> <? if ( ($mode == 'mesres') ) { ?> <? // affichage de l'ecart en % ?> <td class="flechette"> <div <? if ($virtually_ranked==1) { ?> class="data_theorique" <? } ?>> <abbr title="<? echo " Ecart reel: ".$ectype_client_first_display." - Ecart theorique: ".$ectype_client_first_virtual_display; ?>"> <? echo $ecart_display; ?> </abbr></div></td> <? } ?> <? // affichage de l'écart en pourcentage ?> <? /*?> <td><? if( ($row['totprice_client'] != 0) ){ $ectypep_dur = (($row['totprice_first'] - $row['totprice_client'])/$row['totprice_client'])*100; echo money_format('%.2n', $ectypep_dur); ?>%<? } ?></td> <? */?> </tr> <? echo "\n"; // incrementation du compteur afin de numerotation des lignes resultat $cpt++; } // fin while($row = mysql_fetch_array($sqlres)) //fin du tableau ?> </tbody> </table> <? $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); echo "temps d'affichage : ".number_format($totaltime,4,',','')."<br>";

par DarkBlue » 25 janv. 2006, 12:51

hello ,

donne nous un bout de code svp , c est peut etre un probleme de boucle ... ?

Optimisation

par kidpigeyre » 25 janv. 2006, 12:44

Bonjour dans un site web jutilise une grande requete avec jointure gauche etc

L'affichage est très long sur la page (de l'ordre de la dizaine de secondes). Pour quelle raison?

Quand j'execute la requete sur EMS mysql manager il me srt les résultats en 0,5s


Les résultats de la ruête sont afichés sur le site par un mysql_fetch_array($sql,MYSQL_ASSOC)

Avez vous une idée?