Bonjour,

j'ai des jointures qui reviennent souvent, et un lenteur excessive depuis la mise en place de ses jointures (mais on ne choisi pas les fichiers qu'on reçoit...)

Les 2 jointures en question sont les suivantes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
from
	#tw_BSI_ToProcess tpr
		inner join #tw_duplicatedBSI dup
		on tpr.EMP_EAFBIRTHYEAR = dup.EMP_EAFBIRTHYEAR
			and tpr.EMP_LASTNAME = dup.EMP_LASTNAME
			and tpr.EMP_FIRSTNAME = dup.EMP_FIRSTNAME
			and tpr.EMP_COMMENT = dup.EMP_COMMENT
			and tpr.EMP_CUSTOMERCODE = dup.EMP_CUSTOMERCODE
			and tpr.CUS_CODECLIENT = dup.CUS_CODECLIENT
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from
	#tw_BSI_ToProcess tpr
		inner join EMP_EMPLOYEE empParent
		on (tpr.CUS_IDPARENT = empParent.CUS_IDPARENT 
			and tpr.emp_customercode = empParent.emp_customercode)
 
			inner join EMP_EMPLOYEE empChild
			on (empChild.EMP_IDPARENT = empParent.emp_id
				and YEAR(empChild.EMP_BIRTHDATE)%100 = tpr.EMP_EAFBIRTHYEAR
				and empChild.EMP_LASTNAME = tpr.EMP_LASTNAME
				and empChild.EMP_FIRSTNAME = tpr.EMP_FIRSTNAME
				and empChild.EMP_COMMENT = 'customer code : ' + tpr.EMP_CUSTOMERCODE
				and empChild.EMP_CUSTOMERCODE = '')
			inner join CUS_CUSTOMER cusChild	
			on (empChild.CUS_IDPARENT = cusChild.CUS_ID
				and cusChild.CUS_CODECLIENT = tpr.CUS_CODECLIENT	)
La 2ème jointure est utilisée 4 fois, la 1ère 1 seul fois, dans la requête d'import (donc respectivement 800 et 200fois pour une fichier de 200 000lignes, puisqu'on traite des lots de 1000lignes... D'où mon besoin d'optimisation)

Je ne peux pas toucher aux tables EMP_EMPLOYEE et CUS_CUSTOMER. Par contre, les tables tpr et dup peuvent surement bénéficier d'index. Vaut-il mieux créer un index pour chaque colonne ? Un index avec tous les colonnes ? Un mix de l'ensemble ?
N'ayant pas d'expérience en ce domaine, je fais appel à la votre. Merci d'avance !