Bonjour,
Merci, pour ce dernier jour de l'année, j'ai appris quelque chose.
La requête utilisée dans la procédure PROC_ORPHELIN était celle-ci:SELECT CLE_FICHE,
NOM,
PRENOM,
DATE_NAISSANCE,
DATE_DECES,
SEXE
FROM INDIVIDU
WHERE KLE_DOSSIER = :IDOSSIER and
CLE_PERE IS NULL and
CLE_MERE IS NULL And
CLE_FICHE not in (select cle_pere from individu) and
CLE_FICHE not in (select cle_mere from individu) and
CLE_FICHE not in (select union_mari from T_UNION) and
CLE_FICHE not in (select union_femme from T_UNION) and
CLE_FICHE not in (select assoc_kle_associe from T_ASSOCIATIONS)
ORDER BY NOM, PRENOM
où :IDOSSIER est à remplacer par le n° du dossier.
Elle fonctionne sous Firebird 1.5, mais plus sous FB2.0.
La raison, c'est que FB2.0 n'accepte pas que dans" Y in(X1,X2,...,Xi,...,Xn)", l'un des termes Xi soit null. Il faudrait donc écrireSELECT CLE_FICHE,
NOM,
PRENOM,
DATE_NAISSANCE,
DATE_DECES,
SEXE
FROM INDIVIDU
WHERE KLE_DOSSIER = :IDOSSIER
and CLE_PERE IS NULL
and CLE_MERE IS NULL
and CLE_FICHE not in (select cle_pere from individu where cle_pere is not null)
and CLE_FICHE not in (select cle_mere from individu where cle_mere is not null)
and CLE_FICHE not in (select union_mari from T_UNION where union_mari is not null)
and CLE_FICHE not in (select union_femme from T_UNION where union_femme is not null)
and CLE_FICHE not in (select assoc_kle_associe from T_ASSOCIATIONS where assoc_kle_associe is not null)
ORDER BY NOM, PRENOM
et là çà marche.
Comme cette requête met plus de 5s à s'exécuter, je préfère mettre cette autre forme dans PROC_ORPHELINSELECT i.CLE_FICHE,
i.NOM,
i.PRENOM,
i.DATE_NAISSANCE,
i.DATE_DECES,
i.SEXE
FROM INDIVIDU i
WHERE i.KLE_DOSSIER = :IDOSSIER
and i.CLE_PERE IS NULL
and i.CLE_MERE IS NULL
and not exists (select * from individu where cle_pere=i.cle_fiche
or cle_mere=i.cle_fiche)
and not exists (select * from T_UNION where union_mari=i.cle_fiche
or union_femme=i.cle_fiche)
and not exists (select * from T_ASSOCIATIONS
where assoc_kle_associe=i.cle_fiche)
ORDER BY i.NOM, i.PRENOM
qui met 10 fois moins de temps pour obtenir le même résultat.
J'espère seulement qu'il n'y a pas d'autres cas comme celui-là dans le code...
A+ et bonnes fêtes.
André