sql - Why does oracle optimiser treat join by JOIN and WHERE differently? -
i have query on used query optimiser:
select res.studentid, res.examid, r.percentcorrect, max(attempt) attempt tbl res join (select studentid, examid, max(percentcorrect) percentcorrect tbl group studentid, examid) r on r.studentid = res.studentid , r.examid = res.examid , r.percentcorrect = res.percentcorrect group res.studentid, res.examid, r.percentcorrect order res.examid
what surprised me optimiser returned following on 40% faster:
select /*+ no_cpu_costing */ res.studentid, res.examid, r.percentcorrect, max(attempt) attempt tbl res, (select studentid, examid, max(percentcorrect) percentcorrect tbl group studentid, examid) r r.studentid = res.studentid , r.examid = res.examid , r.percentcorrect = res.percentcorrect group res.studentid, res.examid, r.percentcorrect order res.examid
here execution plans both:
how possible? thought optimiser treats join clause in optimised query...
from here:
in general should find cost of table scan increase when enable cpu costing (also known "system statistics"). means improved run time due changes in execution path have started favour execution plans. there few articles system statistics on blog might give more background, , couple of links there other relevant articles: http://jonathanlewis.wordpress.com/category/oracle/statistics/system-stats/
in other words, statistics might stale, since have "turned them off" query, avoid using inefficient path: hence (temporary?) improvement.
Comments
Post a Comment