查询执行时间mysql:workbench vs php

时间:2013-11-07 13:49:54

标签: php mysql sql mysql-workbench

我有一个查询,在2秒内在Workbench中执行。当我在PHP文件中执行它大约需要40秒。有什么想法吗?

thnks。 查询:

SELECT
        sum((1 - (Data.Data1.`Ggdata` / 100)) * (Data.Data1.`Datagg`)) As 'EUH'
    FROM
        Data.Data1
    INNER JOIN
        (Data.trans_UN, Data.input_Ex, Data.trans_M, Data.trans_Pa) ON (Data.trans_Une.Une_ID = Data.input_Data1.Une_ID
        AND Data.trans_Une.GN = Data.input_Ex.GN
        AND Data.input_Ex.EQ = Data.trans_M.EQ
        AND Data.input_Ex.GL = Data.trans_M.GL
        AND Data.input_Ex.MN = Data.trans_P.GP)
    WHERE
        Data.tGModel = 'Model1'
    GROUP BY Data.Data1.`Year` , Data.Data1.`Month`

PHP代码:

    $time_mysql_data = -microtime(true);    
    $sth1 = mysql_query("
    SELECT
        sum((1 - (Data.Data1.`Ggdata` / 100)) * (Data.Data1.`Datagg`)) As 'EUH'
    FROM
        Data.Data1
    INNER JOIN
        (Data.trans_UN, Data.input_Ex, Data.trans_M, Data.trans_Pa) ON (Data.trans_Une.Une_ID = Data.input_Data1.Une_ID
        AND Data.trans_Une.GN = Data.input_Ex.GN
        AND Data.input_Ex.EQ = Data.trans_M.EQ
        AND Data.input_Ex.GL = Data.trans_M.GL
        AND Data.input_Ex.MN = Data.trans_P.GP)
    WHERE
        Data.tGModel = 'Model1'
    GROUP BY Data.Data1.`Year` , Data.Data1.`Month`");
    $time_mysql_data += microtime(true);

    $time_php_data = -microtime(true);
    $rows1 = array();
    $rows1['name'] = 'EUH';
    while($r = mysql_fetch_array($sth1)) {
        $rows1['data'][] = $r['EUH'];
    };
    $time_php_data += microtime(true);

我知道我应该使用mysqli或PDO,而我正在这样做。此代码尚未续订:)

Thnks

0 个答案:

没有答案