sql server - MSSQL Query optimization : remove functions from query and optimizing -
vm table
- id
- teacher1_id
- teacher2_id
teacher table
- id
teacherclass table
teacherid
classid
class table
- id
uni table
id
name
classid
i want fetch vm.id, teacher1.id,teacher1_uni.id,teacher2.id,teacher2_uni.id
current query:
select vm.id, vm.teacher1_id, getuni(vm.teacher1_id), vm.teacher2_id, getunit(vm.teacher2_id) vm
getuni(@teacherid):
select u.id uni join class c on uni.classid = c.id join teacherclass tc on tc.classid = c.id tc.teacherid = @teacherid
the above query slow , return data after 21 seconds. kindly me speed up. suppose function calling making query slow. how optimize query?
Comments
Post a Comment