Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

Consulta de 40,265 segundos

Estas en el tema de Consulta de 40,265 segundos en el foro de Mysql en Foros del Web. AMIGOS tengo una base de datos que almacena los datos de venta de 2 empresas al momento de querer sacar el calculo de rentabilidad se ...
  #1 (permalink)  
Antiguo 05/01/2011, 10:35
 
Fecha de Ingreso: enero-2009
Ubicación: talca
Mensajes: 23
Antigüedad: 15 años, 3 meses
Puntos: 0
Consulta de 40,265 segundos

AMIGOS tengo una base de datos que almacena los datos de venta de 2 empresas
al momento de querer sacar el calculo de rentabilidad se demora muchisimo en enviar los resultados y entiendo es por la complejidad de la base de datos.
Bueno ahora bien, en mi sistema que utilizo para hacer las consultas (EMS)
salen los resultados perfectamente, pero al momento de hacer la consulta en php
no me envia los resultados.

la consulta es la siguiente

Código SQL:
Ver original
  1. SELECT
  2.   persona.id_persona,
  3.   CONCAT(persona.nombrepersona, ' ', persona.apellidopersona) AS VENDEDOR,
  4.   ROUND(IFNULL((SUM(detalledocumento.cantidad * detalledocumento.vunitario) - SUM(detalledocumento1.cantidad * detalledocumento1.vunitario)),(SUM(detalledocumento.cantidad * detalledocumento.vunitario)))) AS FINAL,
  5.   ROUND(SUM( registroarticulos.costoarticulo*(detalledocumento.cantidad - IFNULL(detalledocumento1.cantidad,0))))AS COSTO,
  6.   ROUND(( IFNULL((SUM(detalledocumento.cantidad * detalledocumento.vunitario) - SUM(detalledocumento1.cantidad * detalledocumento1.vunitario)),(SUM(detalledocumento.cantidad * detalledocumento.vunitario)))-SUM( registroarticulos.costoarticulo*(detalledocumento.cantidad - IFNULL(detalledocumento1.cantidad,0))))) AS UTILIDAD,
  7.   ROUND((( IFNULL((SUM(detalledocumento.cantidad * detalledocumento.vunitario) - SUM(detalledocumento1.cantidad * detalledocumento1.vunitario)),(SUM(detalledocumento.cantidad * detalledocumento.vunitario)))-SUM( registroarticulos.costoarticulo*(detalledocumento.cantidad - IFNULL(detalledocumento1.cantidad,0))))/IFNULL((SUM(detalledocumento.cantidad * detalledocumento.vunitario) - SUM(detalledocumento1.cantidad * detalledocumento1.vunitario)),(SUM(detalledocumento.cantidad * detalledocumento.vunitario))))*100,1) AS PORCENTAJE
  8.  
  9. FROM
  10.   persona
  11.   INNER JOIN documento ON (persona.id_persona = documento.fkcreador)
  12.   INNER JOIN detalledocumento ON (documento.iddocumento = detalledocumento.fkiddoc)
  13.   LEFT OUTER JOIN documento documento1 ON (documento.iddocumento = documento1.numerodocobedece)
  14.   LEFT OUTER JOIN detalledocumento detalledocumento1 ON (documento1.iddocumento = detalledocumento1.fkiddoc)
  15.   AND (detalledocumento1.fkcodigoarticulo = detalledocumento.fkcodigoarticulo)
  16.   INNER JOIN registroarticulos ON (detalledocumento.fkcodigoarticulo = registroarticulos.fkcodigoarticulo)
  17. WHERE
  18.   documento.fkidvendedor = 126 AND
  19.   documento.fkidestadodoc = 113 AND
  20.   (documento.fkidtipodoc = 113 OR documento.fkidtipodoc=115 )AND
  21.   documento.fechaemisiondoc BETWEEN STR_TO_DATE(CONCAT('01-12-2010', ' 00:00:00'), '%d-%m-%Y %H:%i:%s') AND STR_TO_DATE(CONCAT('31-12-2010', ' 23:59:59'), '%d-%m-%Y %H:%i:%s') AND
  22.   registroarticulos.idregistroarticulo=(SELECT MAX(registroarticulos.idregistroarticulo)
  23.                                         FROM registroarticulos
  24.                                         WHERE registroarticulos.fkcodigoarticulo = detalledocumento.fkcodigoarticulo )
  25. GROUP BY
  26.   persona.id_persona,
  27.   CONCAT(persona.nombrepersona, ' ', persona.apellidopersona)

ahora bien si me resulta en el EMS (programa para hacer consultas)
por que no me resulta en php?
siendo este codigo el de php:
Código PHP:
Ver original
  1. <?php session_start();
  2. if(!$_SESSION['rut'])
  3. {
  4.     include('../includes/php/funciones.php');
  5.     salidasistema3();
  6. }
  7. include('../includes/php/coneccion.php');
  8.     header('Content-type: application/vnd.ms-excel');
  9.     header("Content-Disposition: attachment; filename=RUTA".$_GET['fecha'].".xls");
  10.     header("Pragma: no-cache");
  11.     header("Expires: 0");
  12. ?>
  13. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  14. <html xmlns="http://www.w3.org/1999/xhtml">
  15. <head>
  16. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  17. <title>cierre</title>
  18. </head>
  19. <body>
  20. <div id="contenedor_principal" align="center"  style="width:99%; height:99%; display:block; font-size:18px">
  21.  
  22.     <div style="height:10%; width:99%; font-size:18px;"></div>
  23.    
  24.    
  25.     <div style="height:89%; width:99%; font-size:18px;">
  26.  
  27. <?php
  28.    
  29. //  if(!empty($_GET['e_credito']) )
  30. //  {  
  31.         $link = conectar2();
  32.  
  33.         /* execute multi query */
  34.    
  35.  
  36.                         $fecha=$_GET['fecha'];
  37.                  
  38.                
  39.                         $xsql="SELECT
  40.  persona.id_persona,
  41.  CONCAT(persona.nombrepersona, ' ', persona.apellidopersona) AS VENDEDOR,
  42.  ROUND(IFNULL((SUM(detalledocumento.cantidad * detalledocumento.vunitario) - SUM(detalledocumento1.cantidad * detalledocumento1.vunitario)),(SUM(detalledocumento.cantidad * detalledocumento.vunitario)))) AS VENDIDO,
  43.  ROUND(SUM( registroarticulos.costoarticulo*(detalledocumento.cantidad - IFNULL(detalledocumento1.cantidad,0))))AS COSTO,
  44.  ROUND(( IFNULL((SUM(detalledocumento.cantidad * detalledocumento.vunitario) - SUM(detalledocumento1.cantidad * detalledocumento1.vunitario)),(SUM(detalledocumento.cantidad * detalledocumento.vunitario)))-SUM( registroarticulos.costoarticulo*(detalledocumento.cantidad - IFNULL(detalledocumento1.cantidad,0))))) AS UTILIDAD
  45. FROM
  46.  persona
  47.  INNER JOIN documento ON (persona.id_persona = documento.fkcreador)
  48.  INNER JOIN detalledocumento ON (documento.iddocumento = detalledocumento.fkiddoc)
  49.  LEFT OUTER JOIN documento documento1 ON (documento.iddocumento = documento1.numerodocobedece)
  50.  LEFT OUTER JOIN detalledocumento detalledocumento1 ON (documento1.iddocumento = detalledocumento1.fkiddoc)
  51.  AND (detalledocumento1.fkcodigoarticulo = detalledocumento.fkcodigoarticulo)
  52.  INNER JOIN registroarticulos ON (detalledocumento.fkcodigoarticulo = registroarticulos.fkcodigoarticulo)
  53. WHERE
  54.  documento.fkidvendedor = 126 AND
  55.  documento.fkidestadodoc = 113 AND
  56.  (documento.fkidtipodoc = 113 OR documento.fkidtipodoc=115 )AND
  57.  documento.fechaemisiondoc BETWEEN STR_TO_DATE(CONCAT('01-12-2010', ' 00:00:00'), '%d-%m-%Y %H:%i:%s') AND STR_TO_DATE(CONCAT('31-12-2010', ' 23:59:59'), '%d-%m-%Y %H:%i:%s') AND
  58.  registroarticulos.idregistroarticulo=(SELECT MAX(registroarticulos.idregistroarticulo)
  59.                                         FROM registroarticulos
  60.                                        WHERE registroarticulos.fkcodigoarticulo = detalledocumento.fkcodigoarticulo )
  61. GROUP BY
  62.  persona.id_persona,
  63.  CONCAT(persona.nombrepersona, ' ', persona.apellidopersona)";
  64.                        
  65.                
  66.         echo '<table width="500" height="34" border="1" cellpadding="1" cellspacing="1">
  67.  <tr>
  68.  
  69.    <td>ID</td>
  70.    <td>Vendedor</td>
  71.    <td>Vendido</td>
  72.    <td>Costo</td>
  73.    <td>Utilidad</td>
  74.    <td>Porcentaje</td>
  75.  
  76.  </tr>
  77.         ';
  78.        
  79.         if (mysqli_multi_query($link, $xsql))
  80.         {
  81.             do {
  82.                 /* store first result set */
  83.                
  84.                 if ($result = mysqli_store_result($link))
  85.                 {
  86.                     while ($row = mysqli_fetch_row($result))
  87.                     {
  88.                        
  89.                         //printf("%s\n", $row[0]);
  90.                         ?>
  91.                          <tr>
  92.                        
  93.                             <td style="font-size:18px; width:50px"><?php echo $row[1]; ?></td>
  94.                             <td style="font-size:10px;  width:50px"><?php echo htmlentities($row[2]); ?></td>
  95.                             <td style="font-size:18px;  width:50px"><?php echo $row[3]; ?></td>
  96.                             <td style="font-size:10px;  width:50px"><?php echo htmlentities($row[4]); ?></td>
  97.                              <td style="font-size:18px;"><?php echo $row[5]; ?></td>
  98.                               <td style="font-size:18px;"><?php echo $row[6]; ?></td>
  99.                                 <td style="font-size:18px;"></td>
  100.                            
  101.                            
  102.       </tr>
  103.                         <?php
  104.                         $cobrar=$cobrar+$row[4];
  105.                         $pagado=$pagado+$row[5];
  106.                         $saldo=$saldo+$row[6];
  107.                     }
  108.                     mysqli_free_result($result);
  109.                 }
  110.                 /* print divider */
  111.         //      if (mysqli_more_results($link))
  112.         //      {
  113.                     //printf("-----------------\n");
  114.         ///     }
  115.             } while (mysqli_next_result($link));
  116.         }      
  117.        
  118.         echo '</table><table width="500" height="34" border="0" cellpadding="0" cellspacing="0">
  119.  <tr>
  120.    <td></td>
  121.    <td></td>
  122.    <td></td>
  123.    <td></td>
  124.    <td></td>
  125.    <td></td>
  126.  
  127.  </tr>
  128.  
  129.  <tr>
  130.    <td></td>
  131.    <td></td>
  132.    <td></td>
  133.    <td></td>
  134.    <td></td>
  135.    <td></td>
  136.  
  137.  </tr>
  138.  <tr>
  139.  
  140.    <td></td>
  141.    <td></td>
  142.    <td style="border-top:thin; border-color:#000">Conforme Caja</td>
  143.    <td></td>
  144.    <td></td>
  145.     <td></td>
  146.  </tr>
  147.  </table>';      
  148.                  
  149.                  
  150.                  
  151.  
  152.      
  153.      
  154.      
  155.      
  156.      mysqli_close($link);
  157.                
  158.    
  159.    
  160.    
  161.    
  162.     ?>
  163.  
  164.  
  165. <table><tr><td style="border-top:thin; border-color:#000"></table>
  166.  
  167. </div></div>
  168.  
  169.  
  170.  
  171. </body>
  172. </html>
  #2 (permalink)  
Antiguo 05/01/2011, 11:55
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Cáceres
Mensajes: 3.735
Antigüedad: 16 años
Puntos: 300
Respuesta: Consulta de 40,265 segundos

Creo que es un asunto PHP, aunque podría ser que espacios en blanco tras las funciones estuvieran causando problema (revisa eso); es decir no CONCAT (, sino CONCAT(. Pero más bien parece un problema de tiempo. Una consulta tan prolongada en tiempo no es devuelta por el servidor, que seguro tiene un tiempo límite para responder, y este es inferior a esos 40 segundos. Pide ayuda en el foro PHP a ver si tienes suerte. De todas formas, probablemente esa consulta podría mejorarse para hacerla más rápida. Para ayudarte en eso deberíamos saber la estructura de las tablas y lo que quieres obtener, con algún ejemplo concreto.

Etiquetas: segundos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:07.