我已創建了運行在本地主機查詢的存儲過程:MySQL的存儲過程需要更長的時間在服務器上除localhost
21排在0,0065s獲取(0,1426s)
而且在服務器上:
在0,0037s(15,9947s)獲取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的物理服務器,網絡服務器運行g虛擬爲ESX內的guest虛擬機。
主機規格是:
品牌和類型:託斯R720 CPU:至強E5404(2GHz的) 存儲:通過iSCSI經由存儲連接。 (DX80的Eternus) 內存:6種GB
旅客規格是: CPU:2倍的vCPU 內存:2 GB
OS是:紅帽4.1.2-44
除了這些規範,客人有無限制的訪問主機。
本地PC的規格是:
CPU:英特爾酷睿2四核Q9300 CPU @ 2.50GHz 內存:3 GB 操作系統:Windows 7 32位
幫助將非常感激。
它是一個Linux服務器,在我們的辦公室本地運行: Linux版本2.6.18-128.1.1.el5([email protected])(gcc版本4.1.2 20080704 (Red Hat 4.1.2-44))#1 SMP Mon Jan 26 13:59:00 EST 2009 With MySQL: mysql Ver 14.14 Distrib 5.1.50,for redhat-linux-gnu(i686)using readline 5.1 –
您是否可以使用Ram,CPU,OS更新您的問題,以及它是共享還是專用於本地和活動服務器? – LiamB
我已經用規格更新了我的問題,請您再看看這個問題嗎? –