0

我创建了一个带有在 localhost 上运行的查询的存储过程:

在 0,0065s (0,1426s) 内获取 21 行

在服务器上:

在 0,0037 秒 (15,9947 秒) 内提取了 21 行

我尝试了以下选项以在本地主机上获得与服务器相同的结果:

  • SQL_NO_CACHE
  • 重置缓存
  • 刷新缓存

但它并没有给我相同的结果,所以我想知道为什么在服务器上运行的查询要慢得多。

我已经运行了一个解释,但真的不知道我可以从中准备什么:

1, 'PRIMARY', '<derived2>', 'ALL', '', '', '', '', 16106, 100.00, 'Using temporary; Using filesort'
1, 'PRIMARY', 'A', 'ALL', 'PRIMARY', '', '', '', 5214, 100.00, 'Using where; Using join buffer'
2, 'DERIVED', 'T', 'ALL', 'PRIMARY', '', '', '', 76211, 100.00, 'Using wher

e'

这是我正在运行的查询:

SELECT
        `A`.`country_description`,
    SUM(`turnover_ytd`) AS `turnover_currentyear_ytd`,
    SUM(`turnover_ly`) AS `turnover_lastyear_ytd`,
    SUM(`turnover_sly`) AS `turnover_2ndlastyear_ytd`,
    SUM(`turnover_ytd`) AS `volume_currentyear_ytd`,
    SUM(`turnover_ly`) AS `volume_lastyear_ytd`,
    SUM(`turnover_sly`) AS `volume_2ndlastyear_ytd`,
    COALESCE(((SUM(`turnover_ytd`)-SUM(`turnover_ly`))/SUM(`turnover_ly`))*100, 0) AS `turnover_percentage_currentandlastyear_ytd`,
        COALESCE(((SUM(`volume_ytd`)-SUM(`volume_ly`))/SUM(`volume_ly`))*100, 0) AS `volume_percentage_currentandlastyear_ytd`,
        COALESCE(((SUM(`turnover_ly`)-SUM(`turnover_sly`))/SUM(`turnover_sly`))*100, 0) AS `turnover_percentage_lastand2ndlastyear_ytd`,
        COALESCE(((SUM(`volume_ly`)-SUM(`volume_sly`))/SUM(`volume_sly`))*100, 0) AS `volume_percentage_lastand2ndlastyear_ytd`


  FROM
        `agent` AS `A`
        INNER JOIN
        (
            SELECT
                `debtor_number`,
                IF(SUBSTR(`period`,1,4) = SUBSTR(201210,1,4), `turnover_ytd`, 0) AS `turnover_ytd`,
                IF(SUBSTR(`period`,1,4) = SUBSTR(201210-100,1,4), `turnover_ytd`, 0) AS `turnover_ly`,
        IF(SUBSTR(`period`,1,4) = SUBSTR(201210-200,1,4), `turnover_ytd`, 0) AS `turnover_sly`,
        IF(SUBSTR(`period`,1,4) = SUBSTR(201210,1,4), `volume_ytd`, 0) AS `volume_ytd`,
                IF(SUBSTR(`period`,1,4) = SUBSTR(201210-100,1,4), `volume_ytd`, 0) AS `volume_ly`,
        IF(SUBSTR(`period`,1,4) = SUBSTR(201210-200,1,4), `volume_ytd`, 0) AS `volume_sly`
            FROM
                `turnover_volume` AS `T`
            WHERE
        `company_number` = 01
      AND
        SUBSTR(`period`,5,2) <= SUBSTR(201210,5,2)
      AND
        SUBSTR(`period`,1,4) IN (SUBSTR(201210,1,4), SUBSTR(201210-100,1,4), SUBSTR(201210-200,1,4))
      AND
        `turnover_ytd` != 0
      AND
        `volume_ytd` != 0

    ) AS `T` ON (`T`.`debtor_number` = `A`.`debtor_number`)

    WHERE
    `A`.`agent_number` = 003
  GROUP BY
    `A`.`country_description`;

服务器规格如下:

主机是运行 ESX 的物理服务器,而 Web 服务器在 ESX 内以虚拟方式运行。

主机规格为:

品牌和类型:Altos R720 CPU:Xeon E5404 (2ghz) 存储:通过 Iscsi 通过存储连接。(Eternus DX80) 内存:6 GB

访客规格为: CPU:2x vCPU 内存:2 GB

操作系统是:红帽 4.1.2-44

除了这些规格之外,客人还可以无限制地访问主机。

我的本地 PC 规格是:

CPU:Intel Core 2 Quad CPU Q9300 @ 2.50GHz 内存:3 GB 操作系统:Windows 7 32 位

帮助将不胜感激。

4

2 回答 2

0

我发现了问题,与我的本地主机数据库相比,网络服务器上的排序规则类型有所不同。

在本地主机上我有:

latin1_swedish_ci

在服务器上是:

utf8_unicode_ci

表上的引擎也不同,服务器上的 InnoDB 与 MyIsam ......

通过检查不同排序规则类型之间的翻译,这会导致查询速度变慢。

于 2012-10-17T15:13:34.393 回答
0

与本地计算机相比,您是否考虑过服务器的硬件?

这是一个共享主机包吗?专用服务器?云?

于 2012-10-15T08:53:18.537 回答