SQL语句在laravel中执行需要26秒,在phpmyadmin上需要.0075秒

我有一个涉及6个表的sql语句,在laravel中需要26秒才能执行它,但是在phpmyadmin中,相同的sql语句大约需要0.0075至.0089秒。

这是我在laravel中的代码:

use DB;    
$partidas = DB::select("SELECT A.Patente, A.Pedimento, A.SeccionAduanera, A.Fraccion, A.SecuenciaFraccion, A.ValorComercial, A.PrecioUnitario, A.CantidadUMComercial, A.UnidadMedidaComercial, A.CantidadUMTarifa, A.UnidadMedidaTarifa, A.MetodoValorizacion, A.PaisOrigenDestino, A.PaisCompradorVendedor,  
                                                B.ClavePermiso, B.NumeroPermiso, 
                                                C.ClaveCaso, C.IdentificadorCaso, C.ComplementoCaso, 
                                                D.ClaveContribucion, D.FormaPago, D.ImportePago, 
                                                E.TasaContribucion, E.TipoTasa, 
                                                F.Observaciones
                                        FROM `551` A
                                        INNER JOIN `553` B ON B.Fraccion = A.Fraccion
                                                AND (A.SecuenciaFraccion = B.SecuenciaFraccion)
                                                AND (A.auditoria_id = 4 AND B.auditoria_id = 4)
                                                AND (A.Patente = '3452' AND B.Patente = '3452')
                                                AND (A.Pedimento = '0000180' AND B.Pedimento = '0000180') 
                                                AND (A.SeccionAduanera = '430' AND B.SeccionAduanera = '430')
                                        INNER JOIN `554` C ON C.Fraccion = A.Fraccion 
                                                AND (A.SecuenciaFraccion = C.SecuenciaFraccion)
                                                AND (A.auditoria_id = 4 AND C.auditoria_id = 4)
                                                AND (A.Patente = '3452' AND C.Patente = '3452')
                                                AND (A.Pedimento = '0000180' AND C.Pedimento = '0000180') 
                                                AND (A.SeccionAduanera = '430' AND C.SeccionAduanera = '430')
                                        INNER JOIN `557` D ON D.Fraccion = A.Fraccion 
                                                AND (A.SecuenciaFraccion = D.SecuenciaFraccion)
                                                AND (A.auditoria_id = 4 AND D.auditoria_id = 4)
                                                AND (A.Patente = '3452' AND D.Patente = '3452')
                                                AND (A.Pedimento = '0000180' AND D.Pedimento = '0000180') 
                                                AND (A.SeccionAduanera = '430' AND D.SeccionAduanera = '430')
                                        INNER JOIN `556` E ON E.Fraccion = A.Fraccion 
                                                AND (A.SecuenciaFraccion = E.SecuenciaFraccion)
                                                AND (A.auditoria_id = 4 AND E.auditoria_id = 4)
                                                AND (A.Patente = '3452' AND E.Patente = '3452')
                                                AND (A.Pedimento = '0000180' AND E.Pedimento = '0000180') 
                                                AND (A.SeccionAduanera = '430' AND E.SeccionAduanera = '430')
                                        INNER JOIN `558` F ON F.Fraccion = A.Fraccion 
                                                AND (A.SecuenciaFraccion = F.SecuenciaFraccion)
                                                AND (A.auditoria_id = 4 AND F.auditoria_id = 4)
                                                AND (A.Patente = '3452' AND F.Patente = '3452')
                                                AND (A.Pedimento = '0000180' AND F.Pedimento = '0000180') 
                                                AND (A.SeccionAduanera = '430' AND F.SeccionAduanera = '430')
                                        ");
                dd($partidas);

我需要知道我是否可以雄辩地或以其他方式发表声明,以在laravel中获得更好的性能。

谢谢!

PD:英语不是我的母语,所以请您原谅任何错误!

评论
  • Oo傻吖頭
    Oo傻吖頭 回复

    试试这个,也许有时间像在您的phpmyadmin中

    <?php
    
    use DB;
    
    $pdo = DB::connection()->getPdo();
    
    $SQL = "SELECT A.Patente, A.Pedimento, A.SeccionAduanera, A.Fraccion, A.SecuenciaFraccion, A.ValorComercial, A.PrecioUnitario, A.CantidadUMComercial, A.UnidadMedidaComercial, A.CantidadUMTarifa, A.UnidadMedidaTarifa, A.MetodoValorizacion, A.PaisOrigenDestino, A.PaisCompradorVendedor,  
            B.ClavePermiso, B.NumeroPermiso, 
            C.ClaveCaso, C.IdentificadorCaso, C.ComplementoCaso, 
            D.ClaveContribucion, D.FormaPago, D.ImportePago, 
            E.TasaContribucion, E.TipoTasa, 
            F.Observaciones
        FROM `551` A
        INNER JOIN `553` B ON B.Fraccion = A.Fraccion
            AND (A.SecuenciaFraccion = B.SecuenciaFraccion)
            AND (A.auditoria_id = 4 AND B.auditoria_id = 4)
            AND (A.Patente = '3452' AND B.Patente = '3452')
            AND (A.Pedimento = '0000180' AND B.Pedimento = '0000180') 
            AND (A.SeccionAduanera = '430' AND B.SeccionAduanera = '430')
        INNER JOIN `554` C ON C.Fraccion = A.Fraccion 
            AND (A.SecuenciaFraccion = C.SecuenciaFraccion)
            AND (A.auditoria_id = 4 AND C.auditoria_id = 4)
            AND (A.Patente = '3452' AND C.Patente = '3452')
            AND (A.Pedimento = '0000180' AND C.Pedimento = '0000180') 
            AND (A.SeccionAduanera = '430' AND C.SeccionAduanera = '430')
        INNER JOIN `557` D ON D.Fraccion = A.Fraccion 
            AND (A.SecuenciaFraccion = D.SecuenciaFraccion)
            AND (A.auditoria_id = 4 AND D.auditoria_id = 4)
            AND (A.Patente = '3452' AND D.Patente = '3452')
            AND (A.Pedimento = '0000180' AND D.Pedimento = '0000180') 
            AND (A.SeccionAduanera = '430' AND D.SeccionAduanera = '430')
        INNER JOIN `556` E ON E.Fraccion = A.Fraccion 
            AND (A.SecuenciaFraccion = E.SecuenciaFraccion)
            AND (A.auditoria_id = 4 AND E.auditoria_id = 4)
            AND (A.Patente = '3452' AND E.Patente = '3452')
            AND (A.Pedimento = '0000180' AND E.Pedimento = '0000180') 
            AND (A.SeccionAduanera = '430' AND E.SeccionAduanera = '430')
        INNER JOIN `558` F ON F.Fraccion = A.Fraccion 
            AND (A.SecuenciaFraccion = F.SecuenciaFraccion)
            AND (A.auditoria_id = 4 AND F.auditoria_id = 4)
            AND (A.Patente = '3452' AND F.Patente = '3452')
            AND (A.Pedimento = '0000180' AND F.Pedimento = '0000180') 
            AND (A.SeccionAduanera = '430' AND F.SeccionAduanera = '430')
    ";
    
    $stmt = $pdo->prepare($SQL);
    $stmt->execute();
    
    var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));