我有一个类似于以下内容的MySql查询:
SELECT * FROM (
SELECT *
, ROW_NUMBER() over (PARTITION by SCHEMECODE order by SCHEMECODE ,NDATE DESC) as srno
FROM
(
SELECT NH.ADJNAVRS AS NAVRS ,SD.SCHEMECODE AS SCHEMECODE ,NH.NAVDATE as NDATE
,ROW_NUMBER() OVER (PARTITION BY SD.SCHEMECODE, YEAR(NH.NAVDATE), MONTH(NH.NAVDATE) ORDER BY NH.NAVDATE DESC) AS RANK1
FROM ACCORD.SCHEME_DETAILS SD
INNER JOIN ACCORD.NAVHIST NH ON SD.SCHEMECODE=NH.SCHEMECODE
INNER JOIN riasnature SCM ON SCM.ACLASSCODE=SD.CLASSCODE AND SCM.ASSET_CODE=3
left join Accord.SCHEME_DETAILS SD2 on SD2.SCHEMECODE=SD.PRIMARY_FD_CODE
WHERE Sd2.OPT_CODE=1 and Sd2.CLASSCODE=scm.AClasscode
-- GROUP BY SD.SCHEMECODE ,NH.ADJNAVRS ,NH.NAVDATE
) Z
WHERE RANK1 = 1
)C;
表ACCORD.NAVHIST包含近2000万个条目。
当我解释查询时:
我正在使用mysql 8.0和128 GB mysql专用服务器。该配置对于所有参数而言已足够。 我也尝试过desc索引,但这没用。
请告诉我有什么方法可以解决“在哪里使用;使用临时文件;使用文件排序”并提高此查询的性能?
有帮助吗?
非常感谢