I observe there are two ways to achieve an objective on multiple tables. A column in the resultset will be updated and speed may be a requirement. The resultset is obtained either by:
Case 1:
select ert.*
from eval_rep_track ert
inner join
(
select erp.evaluation_fk, erp.report_type, LTRIM(erp.assign_group_id, '/site/') course_name
from eval_report_dup@prod erp
inner join eval_report er
on er.id = erp.id
where erp.status='queue'
and er.status='done'
) cat
on ert.eval_id || '.' || ert.report_type || '.' || ert.course_name = cat.evaluation_fk || '.' || cat.report_type || '.' || cat.course_name;
OR
Case 2:
select ert.*
from eval_rep_track ert
inner join
(
select erp.evaluation_fk, erp.report_type, LTRIM(erp.assign_group_id, '/site/') course_name
from eval_report_dup@prod erp
inner join eval_report er
on er.id = erp.id
where erp.status='queue'
and er.status='done'
) cat
on ert.eval_id = cat.evaluation_fk
and ert.report_type = cat.report_type
and ert.course_name = cat.course_name;
with both giving the same result, with only the join condition varying. Which will run/exec faster?
eval_id is NUMBER
, report_type and course_name are VARCHAR2
.
From the developer used, case 1 has the following stats: [SELECT - 3077 row(s), 0.048 secs] Result set fetched ... 1 statement(s) executed, 3077 row(s) affected, exec/fetch time: 0.048/0.236 sec [1 successful, 0 warnings, 0 errors]
while case 2: [SELECT - 3077 row(s), 0.019 secs] Result set fetched ... 1 statement(s) executed, 3077 row(s) affected, exec/fetch time: 0.019/0.194 sec [1 successful, 0 warnings, 0 errors]
The results suggest case 2 is faster. Will this be universal across any platform (ide, developer) and database? Is this dependent on the data-type or is concatenation always expensive? I don't actually need the result of the concatenation. Thanks.