Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 880 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 880 Rev 890
1
/*
1
/*
2
  Mise à jour de réferentiels NULL ou vides pour les observations dotées d'un nom_sel_nn
2
  Mise à jour de réferentiels NULL ou vides pour les observations dotées d'un nom_sel_nn
3
  75427 observations trouvées au 2013/07/19
3
  75427 observations trouvées au 2013/07/19
4
 
4
 
5
  Les observations problématiques sont les suivantes:
5
  Les observations problématiques sont les suivantes:
6
  SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille
6
  SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille
7
  FROM `BASEEDIT`.`cel_obs`
7
  FROM `BASEEDIT`.`cel_obs`
8
  WHERE nom_referentiel IS NULL AND nom_sel != '' AND nom_sel IS NOT NULL AND nom_ret_nn IS NOT NULL;
8
  WHERE nom_referentiel IS NULL AND nom_sel != '' AND nom_sel IS NOT NULL AND nom_ret_nn IS NOT NULL;
9
 
9
 
10
  Or maj-cleanup-201307.sql reset les valeurs des observations ayant un nom_sel NULL ou '', de plus la préférence de sélection est
10
  Or maj-cleanup-201307.sql reset les valeurs des observations ayant un nom_sel NULL ou '', de plus la préférence de sélection est
11
  donné au nom_sel (incluant les synonymes) plutôt que nom_ret_nn.
11
  donné au nom_sel (incluant les synonymes) plutôt que nom_ret_nn.
12
 
12
 
13
  La requête est donc:
13
  La requête est donc:
14
  SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille
14
  SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille
15
  FROM `BASEEDIT`.`cel_obs` WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL;
15
  FROM `BASEEDIT`.`cel_obs` WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL;
16
  => 76486
16
  => 76486
17
*/
17
*/
18
 
18
 
19
 
19
 
20
DROP TEMPORARY TABLE IF EXISTS T_bis;
20
DROP TEMPORARY TABLE IF EXISTS T_bis;
21
DROP PROCEDURE IF EXISTS majreferentiel;
21
DROP PROCEDURE IF EXISTS majreferentiel;
22
 
22
 
23
CREATE TEMPORARY TABLE IF NOT EXISTS T_bis ( INDEX(`nom`(30))) AS \
23
CREATE TEMPORARY TABLE IF NOT EXISTS T_bis ( INDEX(`nom`(30))) AS \
24
           SELECT "bdtfx" AS valid_ref, CONCAT(b.nom_sci, ' ', b.auteur) AS nom, b.num_nom, b.num_taxonomique, b.famille FROM `BASESOURCE`.`TABLEBDTFX` b UNION ALL \
24
           SELECT "bdtfx" AS valid_ref, CONCAT(b.nom_sci, ' ', b.auteur) AS nom, b.num_nom, b.num_taxonomique, b.famille FROM `BASESOURCE`.`TABLEBDTFX` b UNION ALL \
25
           SELECT "bdtxa" AS valid_ref, CONCAT(a.nom_sci, ' ', a.auteur) AS nom, a.num_nom, a.num_tax, a.famille FROM `BASESOURCE`.`TABLEBDTXA` a;
25
           SELECT "bdtxa" AS valid_ref, CONCAT(a.nom_sci, ' ', a.auteur) AS nom, a.num_nom, a.num_tax, a.famille FROM `BASESOURCE`.`TABLEBDTXA` a UNION ALL \
-
 
26
           SELECT "isfan" AS valid_ref, CONCAT(i.nom_sci, ' ', i.auteur) AS nom, i.num_nom, i.num_taxonomique, i.famille FROM `BASESOURCE`.`TABLEISFAN` i;
26
 
27
 
27
/* Donc nous JOINons:
28
/* Donc nous JOINons:
28
-- INNER JOIN sur bdtfx: 69719
29
-- INNER JOIN sur bdtfx: 62633
-
 
30
SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, c.famille FROM `BASEEDIT`.`cel_obs` c INNER JOIN `BASESOURCE`.`TABLEBDTFX` b ON (b.num_nom = c.nom_sel_nn) WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL;
-
 
31
-- INNER JOIN sur bdtxa: 9469
-
 
32
SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, c.famille FROM `BASEEDIT`.`cel_obs` c INNER JOIN `BASESOURCE`.`TABLEISFAN` i ON (i.num_nom = c.nom_sel_nn) WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL;
-
 
33
-- INNER JOIN sur isfan: 1991
29
SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, c.famille FROM `BASEEDIT`.`cel_obs` c INNER JOIN `BASESOURCE`.`TABLEBDTFX` b ON (b.num_nom = c.nom_sel_nn) WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL;
34
SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, c.famille FROM `BASEEDIT`.`cel_obs` c INNER JOIN `BASESOURCE`.`TABLEISFAN` i ON (i.num_nom = c.nom_sel_nn) WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL;
30
-- INNER JOIN sur bdtxa: 79471 dont 9752 en dup (bdtxa + bdtfx), eg: 1005047
35
-- INNER JOIN sur les 3 référentiels (bdtxa + bdtfx + isfan): 74093
31
SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, c.famille FROM `BASEEDIT`.`cel_obs` c INNER JOIN T_bis b ON (b.num_nom = c.nom_sel_nn) WHERE nom_referentiel AND nom_sel_nn IS NOT NULL;
36
SELECT id_observation, valid_ref, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, c.famille FROM `BASEEDIT`.`cel_obs` c INNER JOIN T_bis b ON (b.num_nom = c.nom_sel_nn) WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL;
-
 
37
*/
32
*/
38
 
-
 
39
/* mais de nombreux noms sont exactement présents dans plusieurs référentiels,
33
 
40
   d'où GROUP BY id_observation HAVING count(id_observation) = 1,
34
/* d'où GROUP BY id_observation HAVING count(id_observation) = 1 */
41
   ce qui ne produit plus que 51359 matches (soit 22734 dups) */
35
/*
42
/*
36
SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, c.famille 
43
SELECT id_observation, nom_referentiel, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, c.famille 
37
FROM `BASEEDIT`.`cel_obs` c 
44
FROM `BASEEDIT`.`cel_obs` c 
38
INNER JOIN T_bis b 
45
INNER JOIN T_bis b 
39
ON (b.num_nom = c.nom_sel_nn) 
46
ON (b.num_nom = c.nom_sel_nn) 
40
WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL GROUP BY id_observation HAVING count(id_observation) = 1;
47
WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL GROUP BY id_observation HAVING count(id_observation) = 1;
41
-- 59967, tous bdtfx...
48
-- 51359, tous bdtfx...
42
*/
49
*/
43
 
50
 
44
 
51
 
45
delimiter |
52
delimiter |
46
 
53
 
47
CREATE PROCEDURE majreferentiel()
54
CREATE PROCEDURE majreferentiel()
48
BEGIN
55
BEGIN
49
DECLARE done INT DEFAULT 0;
56
DECLARE done INT DEFAULT 0;
50
DECLARE subst INT DEFAULT 0;
57
DECLARE subst INT DEFAULT 0;
51
DECLARE _id_observation bigint(20) DEFAULT 0;
58
DECLARE _id_observation bigint(20) DEFAULT 0;
52
DECLARE _valid_ref varchar(20) DEFAULT NULL;
59
DECLARE _valid_ref varchar(20) DEFAULT NULL;
53
DECLARE cur1 CURSOR FOR SELECT id_observation, valid_ref FROM `BASEEDIT`.`cel_obs` c INNER JOIN T_bis b ON (b.num_nom = c.nom_sel_nn)
60
DECLARE cur1 CURSOR FOR SELECT id_observation, valid_ref FROM `BASEEDIT`.`cel_obs` c INNER JOIN T_bis b ON (b.num_nom = c.nom_sel_nn)
54
                        WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL GROUP BY id_observation HAVING count(id_observation) = 1;
61
                        WHERE nom_referentiel IS NULL AND nom_sel_nn IS NOT NULL GROUP BY id_observation HAVING count(id_observation) = 1;
55
-- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
62
-- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
56
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
63
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
57
 
64
 
58
OPEN cur1;
65
OPEN cur1;
59
REPEAT
66
REPEAT
60
        FETCH cur1 INTO _id_observation, _valid_ref;
67
        FETCH cur1 INTO _id_observation, _valid_ref;
61
        UPDATE `BASEEDIT`.`cel_obs` c SET nom_referentiel = _valid_ref WHERE id_observation = _id_observation;
68
        UPDATE `BASEEDIT`.`cel_obs` c SET nom_referentiel = _valid_ref WHERE id_observation = _id_observation;
62
        SET subst = subst + 1;
69
        SET subst = subst + 1;
63
UNTIL done END REPEAT;
70
UNTIL done END REPEAT;
64
select subst AS 'nombre de mises à jour de référentiel effectuées';
71
select subst AS 'nombre de mises à jour de référentiel effectuées';
65
CLOSE cur1;
72
CLOSE cur1;
66
END
73
END
67
|
74
|
68
 
75
 
69
delimiter ;
76
delimiter ;