Utilisation de table temporaire
Bonjour,
Je suis sur Oracle 10g.
J'ai une requête qui peut prendre en entré un très grand nombre d'identifiants (plus de 1 000). Pour contourner le problème, j'utilise une table temporaire : j'insère les identifiants, puis je fais une jointure sur cette table pour ne sélectionner que les enregistrements que je souhaite. La table est ensuite vidée.
Cela fonctionne bien, sauf qu'après un certain temps, le temps d'exécution de la requête se augmente considérablement (multiplié par 2 ou 3), mais je ne trouve pas la raison.
Si je supprime puis recrée la table temporaire, tout redevient normal.
Ma table temporaire est définie ainsi :
Code:
1 2 3 4 5 6 7 8 9
|
create global temporary table TABLETMP
(
TMP_ID NUMBER(10) not null,
TMP_IDSELECTION NUMBER(10) not null
)
on commit delete rows;
alter table TABLETMP
add constraint PK_TABLETMP primary key (TMP_ID, TMP_IDSELECTION); |
TMP_ID est un identifiant unique par session
TMP_IDSELECTION contient la valeur que je veux selectionner
A l'utilisation, cela donne :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
Insert into TABLETMP (TMP_ID, TMP_IDSELECTION)
Values(1, 1);
Insert into TABLETMP (TMP_ID, TMP_IDSELECTION)
Values(1, 2);
With TABLE1 As (Select 1 MonId, 'Label1' MonLabel From Dual Union All
Select 1 MonId, 'Label1' MonLabel From Dual Union All
Select 2 MonId, 'Label2' MonLabel From Dual Union All
Select 3 MonId, 'Label3' MonLabel From Dual Union All
Select 4 MonId, 'Label4' MonLabel From Dual)
Select T1.*
From TABLE1 T1
Join TABLETMP TMP On TMP.TMP_IDSELECTION T1.MONID
Where TMP.TMP_ID = 1;
MonId MonLabel
---------------
1 Label1
2 Label2 |
Si je simule ma table temporaire avec un WITH, j'obtiens les performances normal.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
With TABLETMP As (Select 1 TMP_IDSELECTION From Dual Union All
Select 2 TMP_IDSELECTION From Dual)
TABLE1 As (Select 1 MonId, 'Label1' MonLabel From Dual Union All
Select 1 MonId, 'Label1' MonLabel From Dual Union All
Select 2 MonId, 'Label2' MonLabel From Dual Union All
Select 3 MonId, 'Label3' MonLabel From Dual Union All
Select 4 MonId, 'Label4' MonLabel From Dual)
Select T1.*
From TABLE1 T1
Join TABLETMP TMP On TMP.TMP_IDSELECTION T1.MONID;
MonId MonLabel
---------------
1 Label1
2 Label2 |
Quelqu'un a t il une explication sur la dégradation des performances si j'utilise la table temporaire ?