Précédent   Forum des professionnels en informatique > Bases de données > MySQL
MySQL Forum d'entraide MySQL. Avant de poster -> FAQ MySQL, Tutoriels MySQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 30/11/2011, 16h37   #1
Candidat au titre de Membre du Club
 
Inscription : juillet 2007
Messages : 33
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 33
Points : 13
Points : 13
Par défaut résultat requete: ligne manquante

Bonjour,

Je travaille avec MySQL + phpMyAdmin avec une requete complexe (plusieurs sous-requetes, de jointures et beaucoup de conditions), et il semblerait qu'il puisse arriver que le résultat retourné par la requete soit incomplet, ce n'est pas systématique. on ne pense pas que le probleme vienne de la requete. donc on sait pas vraiment la cause du probleme

ma question: se pourrait-il que MySQL ignore ou saute certaines conditions dans certainsc cas si la requete est trop complexe?, quelqu'un a-t-il deja eu ce genre de problemes?

merci

Mehdi
perry_rhodan est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2011, 16h47   #2
Modérateur
 
Avatar de CinePhil
 
Homme Philippe Leménager
Ingénieur d'études en informatique
Inscription : août 2006
Messages : 11 029
Détails du profil
Informations personnelles :
Nom : Homme Philippe Leménager
Âge : 48
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Ingénieur d'études en informatique
Secteur : Enseignement

Informations forums :
Inscription : août 2006
Messages : 11 029
Points : 18 331
Points : 18 331
Envoyer un message via MSN à CinePhil
Non, la requête s'éxécutera toujours en entier, sauf éventuellement si elle est trop longue à exécuter et que tu arrêtes le processus.

On peut voir la requête et la description (SHOW CREATE TABLE) des tables impliquées ?
Ainsi qu'une explication de ce qu'est censée faire la requête et des cas que vous avez détectés qui posent problème.
__________________
Philippe Leménager. Ingénieur d'étude à l'École Nationale de Formation Agronomique.
Mon blog sur la conception des BDD, le langage SQL, le PHP avec Zend Framework...
« Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément ». (Nicolas Boileau)
À la maison comme au bureau, j'utilise Mandriva Linux ou Mageïa ! Soutenons l'industrie logicielle française !
Linuxiens, comptez-vous !
CinePhil est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2011, 17h27   #3
Candidat au titre de Membre du Club
 
Inscription : juillet 2007
Messages : 33
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 33
Points : 13
Points : 13
Citation:
Envoyé par CinePhil Voir le message
Non, la requête s'éxécutera toujours en entier, sauf éventuellement si elle est trop longue à exécuter et que tu arrêtes le processus.

On peut voir la requête et la description (SHOW CREATE TABLE) des tables impliquées ?
Ainsi qu'une explication de ce qu'est censée faire la requête et des cas que vous avez détectés qui posent problème.
merci, je vais aller cherche l'information.
perry_rhodan est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2011, 18h05   #4
Candidat au titre de Membre du Club
 
Inscription : juillet 2007
Messages : 33
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 33
Points : 13
Points : 13
Voila la requete et je poste la structure des tables apres

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
SELECT  
	exceptions.id, 
	exceptions.exception_field_value, 
	exceptions.priority, 
	exceptions.is_inclusif, 
	exceptions.exception_field_id, 
	exceptions_languages.short_description, 
	exceptions_languages.long_description,
	function_exceptions.FUNCTION 
 
FROM ( 
 
	SELECT  
		PosException.id, 
		PosException.exception_field_value, 
		PosException.priority, 
		PosException.is_inclusif, 
		PosException.exception_field_id,
 		PosException.function_exception_id,
 
		( SELECT COUNT(conditions.exception_field_id) 
		  FROM conditions
		  WHERE 
			PosException.id = conditions.exception_id 
			AND conditions.exception_field_id =9 
			AND conditions.status_id <> 10 
		) AS countCondition_9,  
 
		 ( SELECT COUNT(conditions.exception_field_id) 
		   FROM conditions 
			INNER JOIN condition_values 
				ON 
					conditions.id = condition_values.condition_id 
					AND condition_values.status_id <> 10 				   	
					AND condition_values.value IN (337,353,431,475,511,632,638,633,634,635,640,661,669,1880,1878,1883,1882) 
		   WHERE 
			PosException.id = conditions.exception_id 
			AND conditions.exception_field_id = 9 
			AND conditions.status_id <> 10 
		  GROUP BY conditions.exception_field_id
		) AS countConditionValue_9,
 
		 ( SELECT COUNT(conditions.exception_field_id) 
		   FROM conditions 
		   WHERE 
			PosException.id = conditions.exception_id 
			AND conditions.exception_field_id =46 
			AND conditions.status_id <> 10 
		 ) AS countCondition_46,
 
		 ( SELECT COUNT(conditions.exception_field_id) 
		   FROM conditions 
		   	INNER JOIN condition_values 
		  		ON 
					conditions.id = condition_values.condition_id 
					AND condition_values.status_id <> 10 
					AND condition_values.value IN (102,104,106,210,212,214,235,247,321,331,337,339,348,356,357,374,500,515,1224,1226)
		   WHERE 
			PosException.id = conditions.exception_id 
			AND conditions.exception_field_id = 46 
			AND conditions.status_id <> 10 
		 GROUP BY conditions.exception_field_id 
		) AS countConditionValue_46 	
	FROM exceptions AS PosException  
	WHERE 
		(
			(PosException.exception_type_id =5) 
			AND (PosException.status_id = 6) 
			AND (PosException.family_id = 7 ) 
			AND (((PosException.valid_to >= '2011-11-14 09:05:59') OR (PosException.valid_to IS NULL))) 
			AND (((PosException.valid_from <= '2011-11-14 09:05:59') OR (PosException.valid_from IS NULL))) 
			AND (((PosException.customer_parent_id =1 ) OR (PosException.customer_parent_id IS NULL)))
	      	) 
		AND (PosException.exception_field_id IN ( 71 )) 
		AND PosException.priority BETWEEN 0 AND 100
	) 
		AS exceptions 
		INNER JOIN 
			exceptions_languages 
			ON 
				exceptions_languages.exception_id = exceptions.id 
				AND exceptions_languages.language_id = 1 
		LEFT JOIN 
			function_exceptions 
			ON 
				exceptions.function_exception_id = function_exceptions.id 
		INNER JOIN 
			exception_details AS ed_8 
			ON 
				ed_8.exception_id = exceptions.id 
				AND ed_8.exception_field_id = 8        
				AND (ed_8.count = 0 OR FIND_IN_SET(63 ,ed_8.VALUES)) 
		INNER JOIN 
			exception_details AS ed_11 
			ON 
				ed_11.exception_id = exceptions.id 
				AND ed_11.exception_field_id = 11     
				AND (ed_11.count = 0 OR FIND_IN_SET(1 ,ed_11.VALUES)) 
		INNER JOIN 
			exception_details AS ed_44 
			ON 
				ed_44.exception_id = exceptions.id 
				AND ed_44.exception_field_id = 44    
				AND (ed_44.count = 0) 
		INNER JOIN 
			exception_details AS ed_45 
			ON 
				ed_45.exception_id = exceptions.id 
				AND ed_45.exception_field_id = 45    
				AND (
					ed_45.count = 0 
					OR FIND_IN_SET(78 ,ed_45.VALUES) 
					OR FIND_IN_SET(79 ,ed_45.VALUES) 
					OR FIND_IN_SET(81 ,ed_45.VALUES) 
					OR FIND_IN_SET(82 ,ed_45.VALUES)
				    ) 
WHERE 
	((exceptions.countCondition_9  = 0) OR (exceptions.countCondition_9 > 0 AND exceptions.countConditionValue_9 >= exceptions.countCondition_9))
	AND 
	((exceptions.countCondition_46  = 0) OR (exceptions.countCondition_46 > 0 AND exceptions.countConditionValue_46 >=exceptions.countCondition_46))
 
ORDER BY exceptions.priority
perry_rhodan est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2011, 18h08   #5
Candidat au titre de Membre du Club
 
Inscription : juillet 2007
Messages : 33
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 33
Points : 13
Points : 13
table exceptions
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
CREATE TABLE `exceptions` (
 `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
 `customer_parent_id` int(10) UNSIGNED DEFAULT NULL,
 `exception_field_id` int(10) UNSIGNED NOT NULL,
 `exception_type_id` int(10) UNSIGNED NOT NULL,
 `function_exception_id` int(10) UNSIGNED DEFAULT NULL,
 `exception_field_value` varchar(150) DEFAULT NULL,
 `created` datetime DEFAULT NULL,
 `created_by` int(10) UNSIGNED NOT NULL,
 `modified` datetime DEFAULT NULL,
 `modified_by` int(10) UNSIGNED NOT NULL,
 `priority` int(10) UNSIGNED NOT NULL,
 `is_inclusif` tinyint(1) NOT NULL,
 `status_id` int(10) UNSIGNED NOT NULL,
 `family_id` int(10) UNSIGNED DEFAULT NULL,
 `valid_from` datetime DEFAULT NULL,
 `valid_to` datetime DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `FK_exceptions_exception_types` (`exception_type_id`),
 KEY `FK_exceptions_exception_fields` (`exception_field_id`),
 KEY `FK_exceptions_function_exceptions` (`function_exception_id`),
 KEY `FK_exceptions_statuses` (`status_id`),
 KEY `FK_exceptions_customers` (`customer_parent_id`),
 KEY `FK_exceptions_families` (`family_id`),
 CONSTRAINT `exceptions_ibfk_1` FOREIGN KEY (`customer_parent_id`) REFERENCES `customers` (`id`) ON DELETE NO ACTION,
 CONSTRAINT `exceptions_ibfk_2` FOREIGN KEY (`family_id`) REFERENCES `families` (`id`),
 CONSTRAINT `FK_exceptions_exception_fields` FOREIGN KEY (`exception_field_id`) REFERENCES `exception_fields` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
 CONSTRAINT `FK_exceptions_exception_types` FOREIGN KEY (`exception_type_id`) REFERENCES `exception_types` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
 CONSTRAINT `FK_exceptions_function_exceptions` FOREIGN KEY (`function_exception_id`) REFERENCES `function_exceptions` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
 CONSTRAINT `FK_exceptions_statuses` FOREIGN KEY (`status_id`) REFERENCES `statuses` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=15711 DEFAULT CHARSET=utf8
table exception_languages
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CREATE TABLE `exceptions_languages` (
 `exception_id` int(10) UNSIGNED NOT NULL,
 `language_id` int(10) UNSIGNED NOT NULL,
 `created` datetime DEFAULT NULL,
 `created_by` int(10) UNSIGNED NOT NULL,
 `modified` datetime DEFAULT NULL,
 `modified_by` int(10) UNSIGNED NOT NULL,
 `short_description` varchar(150) NOT NULL,
 `long_description` varchar(250) NOT NULL DEFAULT '',
 PRIMARY KEY (`exception_id`,`language_id`),
 KEY `FK_exceptions_languages_languages` (`language_id`),
 KEY `FK_exceptions_languages_exceptions` (`exception_id`),
 CONSTRAINT `FK_exceptions_languages_exceptions` FOREIGN KEY (`exception_id`) REFERENCES `exceptions` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
 CONSTRAINT `FK_exceptions_languages_languages` FOREIGN KEY (`language_id`) REFERENCES `languages` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8
table function_exception
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
 
CREATE TABLE `function_exceptions` (
 `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
 `function` varchar(255) NOT NULL,
 `created` datetime DEFAULT NULL,
 `created_by` int(10) UNSIGNED NOT NULL,
 `modified` datetime DEFAULT NULL,
 `modified_by` int(10) UNSIGNED NOT NULL,
 `status_id` int(10) UNSIGNED NOT NULL,
 PRIMARY KEY (`id`),
 KEY `FK_function_exceptions_statuses` (`status_id`),
 CONSTRAINT `FK_function_exceptions_statuses` FOREIGN KEY (`status_id`) REFERENCES `statuses` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8
table conditions
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
CREATE TABLE `conditions` (
 `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
 `status_id` int(10) UNSIGNED NOT NULL,
 `exception_id` int(10) UNSIGNED NOT NULL,
 `exception_field_id` int(10) UNSIGNED NOT NULL,
 `created` datetime DEFAULT NULL,
 `created_by` int(10) UNSIGNED NOT NULL,
 `modified` datetime DEFAULT NULL,
 `modified_by` int(10) UNSIGNED NOT NULL,
 PRIMARY KEY (`id`),
 KEY `FK_conditions_exeption` (`exception_id`),
 KEY `FK_conditions_exception_fields` (`exception_field_id`),
 KEY `FK_conditions_statuses` (`status_id`),
 CONSTRAINT `FK_conditions_exception_fields` FOREIGN KEY (`exception_field_id`) REFERENCES `exception_fields` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
 CONSTRAINT `FK_conditions_exeption` FOREIGN KEY (`exception_id`) REFERENCES `exceptions` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
 CONSTRAINT `FK_conditions_statuses` FOREIGN KEY (`status_id`) REFERENCES `statuses` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=103531 DEFAULT CHARSET=utf8
table exception_detail
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
 
CREATE TABLE `exception_details` (
 `exception_id` int(10) UNSIGNED NOT NULL,
 `exception_field_id` int(10) UNSIGNED NOT NULL,
 `param_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
 `count` tinyint(4) DEFAULT NULL,
 `values` varchar(255) DEFAULT NULL,
 PRIMARY KEY (`exception_id`,`exception_field_id`,`param_id`),
 KEY `FK_ed_exceptions` (`exception_id`),
 KEY `FK_ed_exception_fields` (`exception_field_id`),
 CONSTRAINT `exception_details_ibfk_1` FOREIGN KEY (`exception_id`) REFERENCES `exceptions` (`id`) ON DELETE NO ACTION,
 CONSTRAINT `exception_details_ibfk_2` FOREIGN KEY (`exception_field_id`) REFERENCES `exception_fields` (`id`) ON DELETE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8
perry_rhodan est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2011, 22h31   #6
Modérateur
 
Avatar de CinePhil
 
Homme Philippe Leménager
Ingénieur d'études en informatique
Inscription : août 2006
Messages : 11 029
Détails du profil
Informations personnelles :
Nom : Homme Philippe Leménager
Âge : 48
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Ingénieur d'études en informatique
Secteur : Enseignement

Informations forums :
Inscription : août 2006
Messages : 11 029
Points : 18 331
Points : 18 331
Envoyer un message via MSN à CinePhil
Euh... elle est censée faire quoi cette requête monstrueuse ?
__________________
Philippe Leménager. Ingénieur d'étude à l'École Nationale de Formation Agronomique.
Mon blog sur la conception des BDD, le langage SQL, le PHP avec Zend Framework...
« Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément ». (Nicolas Boileau)
À la maison comme au bureau, j'utilise Mandriva Linux ou Mageïa ! Soutenons l'industrie logicielle française !
Linuxiens, comptez-vous !
CinePhil est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/12/2011, 14h17   #7
Candidat au titre de Membre du Club
 
Inscription : juillet 2007
Messages : 33
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 33
Points : 13
Points : 13
Citation:
Envoyé par CinePhil Voir le message
Euh... elle est censée faire quoi cette requête monstrueuse ?
c'Est pour faire des validations sur des caractéristiques de produits. assez complexe, c'est pourquoi je me demandais si ca pouvait affecter l'execution.
perry_rhodan est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/12/2011, 14h27   #8
Modérateur
 
Avatar de CinePhil
 
Homme Philippe Leménager
Ingénieur d'études en informatique
Inscription : août 2006
Messages : 11 029
Détails du profil
Informations personnelles :
Nom : Homme Philippe Leménager
Âge : 48
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Ingénieur d'études en informatique
Secteur : Enseignement

Informations forums :
Inscription : août 2006
Messages : 11 029
Points : 18 331
Points : 18 331
Envoyer un message via MSN à CinePhil
Et tu es sûr qu'elle est juste ?

J'ai commencé à la récrire hier soir en essayant de la simplifier mais elle est vraiment monstrueuse !
__________________
Philippe Leménager. Ingénieur d'étude à l'École Nationale de Formation Agronomique.
Mon blog sur la conception des BDD, le langage SQL, le PHP avec Zend Framework...
« Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément ». (Nicolas Boileau)
À la maison comme au bureau, j'utilise Mandriva Linux ou Mageïa ! Soutenons l'industrie logicielle française !
Linuxiens, comptez-vous !
CinePhil est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/12/2011, 14h39   #9
Candidat au titre de Membre du Club
 
Inscription : juillet 2007
Messages : 33
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 33
Points : 13
Points : 13
Citation:
Envoyé par CinePhil Voir le message
Et tu es sûr qu'elle est juste ?

J'ai commencé à la récrire hier soir en essayant de la simplifier mais elle est vraiment monstrueuse !
une autre requete est en cours de création pour valider celle-la, il y'a eu quelques ligne de différence jusqu'ici, mais tant qu'elle n'est pas finalisée, on ne peut pas avoir de données de comparaison fiable.
perry_rhodan est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/12/2011, 14h50   #10
Modérateur
 
Avatar de CinePhil
 
Homme Philippe Leménager
Ingénieur d'études en informatique
Inscription : août 2006
Messages : 11 029
Détails du profil
Informations personnelles :
Nom : Homme Philippe Leménager
Âge : 48
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Ingénieur d'études en informatique
Secteur : Enseignement

Informations forums :
Inscription : août 2006
Messages : 11 029
Points : 18 331
Points : 18 331
Envoyer un message via MSN à CinePhil
Pour vérifier que la requête est juste, coupe la en plusieurs morceaux et compare les résultats avec la grande. Regarde notamment combien te donnent les COUNT indépendamment par rapport au résultat donné dans la grande requête.
En plus, plusieurs petites requêtes seraient peut-être plus rapides qu'une seule énorme si le volume de données à traiter est gros.

Les requêtes correllées sont contre performantes. Les jointures, c'est mieux.
__________________
Philippe Leménager. Ingénieur d'étude à l'École Nationale de Formation Agronomique.
Mon blog sur la conception des BDD, le langage SQL, le PHP avec Zend Framework...
« Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément ». (Nicolas Boileau)
À la maison comme au bureau, j'utilise Mandriva Linux ou Mageïa ! Soutenons l'industrie logicielle française !
Linuxiens, comptez-vous !
CinePhil est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/12/2011, 17h26   #11
Candidat au titre de Membre du Club
 
Inscription : juillet 2007
Messages : 33
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 33
Points : 13
Points : 13
Citation:
Envoyé par CinePhil Voir le message
Pour vérifier que la requête est juste, coupe la en plusieurs morceaux et compare les résultats avec la grande. Regarde notamment combien te donnent les COUNT indépendamment par rapport au résultat donné dans la grande requête.
En plus, plusieurs petites requêtes seraient peut-être plus rapides qu'une seule énorme si le volume de données à traiter est gros.

Les requêtes correllées sont contre performantes. Les jointures, c'est mieux.
je vais aller voir du cote des count, je te reviens la-dessus
perry_rhodan est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 00h50.


 
 
 
 
Partenaires

Hébergement Web