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:

execution plans

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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -