为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:DM8
【操作系统】:CentOS Linux release 7.8.2003 (Core)
【CPU】: Intel(R) Core(TM) i9-9880H CPU @ 2.30GH
【问题描述】*:这段sql查询从pg迁移过来,在dm需要20几秒请教一下如何优化,奇怪的是原来pg里面80ms就查询出来了
select
mscores0_."id" as id1_43_,
mscores0_."audit_date" as audit_da2_43_,
mscores0_."build_in" as build_in3_43_,
mscores0_."created_time" as created_4_43_,
mscores0_."deleted" as deleted5_43_,
mscores0_."update_version" as update_v6_43_,
mscores0_."updated_time" as updated_7_43_,
mscores0_."optlock" as optlock8_43_,
mscores0_."auditdate" as auditdat9_43_,
mscores0_."auditor" as auditor10_43_,
mscores0_."certid" as certid11_43_,
mscores0_."coursehours" as courseh12_43_,
mscores0_."create_timestamp" as create_13_43_,
mscores0_."createdate" as created14_43_,
mscores0_."creator" as creator15_43_,
mscores0_."external_score_id" as externa16_43_,
mscores0_."institution_id" as institu29_43_,
mscores0_."needcheck" as needche17_43_,
mscores0_."project_id" as project30_43_,
mscores0_."projectdate" as project18_43_,
mscores0_."reach_sign" as reach_s19_43_,
mscores0_."remark" as remark20_43_,
mscores0_."score" as score21_43_,
mscores0_."scoreins_id" as scorein31_43_,
mscores0_."source" as source22_43_,
mscores0_."status" as status23_43_,
mscores0_."student_id" as student32_43_,
mscores0_."studentid" as student24_43_,
mscores0_."stustatus_id" as stustat33_43_,
mscores0_."title_id" as title_i34_43_,
mscores0_."unique_key" as unique_25_43_,
mscores0_."verifier" as verifie26_43_,
mscores0_."verifydate" as verifyd27_43_,
mscores0_."year" as year28_43_
from
"m_scores" mscores0_
cross join "m_students" mstudents2_
cross join "m_projects" mprojects4_
where
mscores0_."student_id" = mstudents2_."id"
and mscores0_."project_id" = mprojects4_."id"
and mscores0_."year" = 2024
and (mscores0_."student_id" not in (select distinct
mstuqualif1_."student_id"
from
"m_stu_qualified_history" mstuqualif1_
where
mstuqualif1_."year" = 2024))
and mstudents2_."status_id" = 1
and mstudents2_."isdelete" = 0
and ((mprojects4_."projecttype_id" in (1, 18, 17, 4, 3, 2))
and (mscores0_."student_id" in (select
mstureachh5_."student_id"
from
"m_stu_reach_history" mstureachh5_
where
mstureachh5_."year" = 2024
and mstureachh5_."student_id" = mscores0_."student_id"
and mstureachh5_."secondclassscore" >= mstureachh5_."secondclassminscore"))
and (mscores0_."student_id" in (select
mscoresdet6_."student_id"
from
"m_scores_detail_history" mscoresdet6_
where
mscoresdet6_."year" = 2024
and mscoresdet6_."student_id" = mscores0_."student_id"
and (mscoresdet6_."secondscorecomplete" = 1
and mscoresdet6_."firstscore" >= mscoresdet6_."firstscorestd"
and mscoresdet6_."scorecomplete" = 1
or mscoresdet6_."otherscore" > 0.0)))
or mprojects4_."projecttype_id" in (16, 28, 25, 24, 23, 22, 21, 20)
or (mscores0_."title_id" in (4, 5, 6, 10, 11, 12, 16, 17, 18, 22, 23, 24, 28, 29, 30, 34, 35, 39, 40))
and (mprojects4_."projecttype_id" in (1, 18, 17, 4, 3, 2))
or (mscores0_."title_id" in (1, 2, 3, 7, 8, 9, 13, 14, 15, 19, 20, 21, 25, 26, 27, 31, 32, 33, 36, 37, 38))
and (mprojects4_."projecttype_id" in (1, 18, 17, 4, 3, 2))
or (mscores0_."title_id" in (4, 5, 6, 10, 11, 12, 16, 17, 18, 22, 23, 24, 28, 29, 30, 34, 35, 39, 40))
and (mprojects4_."projecttype_id" in (61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 38, 37, 36, 35, 27, 26, 19, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5))
or (mscores0_."title_id" in (1, 2, 3, 7, 8, 9, 13, 14, 15, 19, 20, 21, 25, 26, 27, 31, 32, 33, 36, 37, 38))
and (mprojects4_."projecttype_id" in (61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 38, 37, 36, 35, 27, 26, 19, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5)))
limit 20;
迁移过来之后,是否有收集统计信息。迁移过后需要收集统计信息。
你试下加hint /*+ OPTIMIZER_OR_NBEXP(2) */