<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Le blog de SQLpro &#187; SQLpro</title>
	<atom:link href="https://blog.developpez.com/sqlpro/pauthor/SQLpro/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/sqlpro</link>
	<description>Le SQL pour SQL Server, PostGreSQL et tous les autres SGBDR</description>
	<lastBuildDate>Thu, 15 Oct 2020 12:59:17 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Modèle générique vs modèle spécifique</title>
		<link>https://blog.developpez.com/sqlpro/p13183/langage-sql-norme/modele-generique-vs-modele-specifique</link>
		<comments>https://blog.developpez.com/sqlpro/p13183/langage-sql-norme/modele-generique-vs-modele-specifique#comments</comments>
		<pubDate>Fri, 10 Aug 2018 08:04:43 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[bases de données]]></category>
		<category><![CDATA[Langage SQL (norme)]]></category>
		<category><![CDATA[Modélisation des donées]]></category>
		<category><![CDATA[comparaison]]></category>
		<category><![CDATA[enfant]]></category>
		<category><![CDATA[facilité]]></category>
		<category><![CDATA[famille]]></category>
		<category><![CDATA[générique]]></category>
		<category><![CDATA[héritage]]></category>
		<category><![CDATA[modélisation]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[qualité]]></category>
		<category><![CDATA[spécifique]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=842</guid>
		<description><![CDATA[Dans le cadre d&#8217;un héritage de données ayant de multiples enfants aux caractéristiques très diverses, est-il préférable de concevoir un modèle de données générique ou un modèle de données spécifique ? De nombreux jeunes développeurs pensent naïvement qu&#8217;un modèle générique est plus facile&#8230; Mais c&#8217;est souvent une erreur qu&#8217;il faudra payer au prix fort une [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Dans le cadre d&rsquo;un héritage de données ayant de multiples enfants aux caractéristiques très diverses, est-il préférable de concevoir un modèle de données générique ou un modèle de données spécifique ? De nombreux jeunes développeurs pensent naïvement qu&rsquo;un modèle générique est plus facile&#8230; Mais c&rsquo;est souvent une erreur qu&rsquo;il faudra payer au prix fort une fois l&rsquo;application fonctionnelle. Démonstration&#8230;<br />
<span id="more-842"></span><br />
Je suis partit initialement de ce post :</p>
<p><a href="https://www.developpez.net/forums/d1881400/bases-donnees/langage-sql/avis-l-architecture-base-donnees-choix-l-option/" rel="noopener" target="_blank">Avis sur l&rsquo;architecture de ma base de données (choix de l&rsquo;option)</a></p>
<p>La demande étant la suivante :</p>
<p><em>J&rsquo;ai 30 familles de critères. Chaque famille comporte un nombre variable de critères pour un total d&rsquo;environ 600 critères.<br />
Chaque critère appartient à une seule famille de sorte que les 600 sont à répartir dans les 30 familles.<br />
Ma question:<br />
&#8211; devrais-je créer <strong>une table par famille</strong> et insérer dans chaque table les critères qui lui appartiennent; (solution 1)<br />
ou alors:<br />
&#8211; créer <strong>une table contenant les 30 familles et une autre contenant les 600 critères</strong>. Ensuite, créer les relations qui lient chaque famille à ses critères et/ou inversement. (solution 2)</em></p>
<p>et ma réponse :</p>
<p><em>Pour qu&rsquo;une base réponde bien en terme de performances, on doit tout faire pour minimiser les IO.<br />
&#8211; Dans votre solution 1, les performances seront bonne si la plupart des requêtes portent sur plusieurs critères d&rsquo;une même famille<br />
&#8211; Dans votre solution 2, les performances seront bonne si la plupart des requêtes portent sur un seul critère.</em></p>
<p>Cependant un jeune internaute peu avisé, affirmait avec force que :</p>
<p><em>pour moi la solution 2 est la + simple à mettre en place.<br />
et le nombre d&rsquo;enregistrements ne justifie pas la solution 1..<br />
tout dépend de votre SGBD (pas précisé..), mais dans tous les cas, il suffit de mettre des ID numérique pour que les requêtes soient optimisées. Créez vos tables avec des id uniques (sous Oracle on peux utiliser les séquences) et vous aurez des traitements optimisées au mieux&#8230; mais bon, je vous rassure, sous Oracle, même avec des clefs en Varchar, pour 600 enregistrements, y a aucun pb..<br />
si je vois bien, vous aurez donc 3 tables avec les clef suivante :<br />
&#8211; FAMILLE (Pk : ID_FAMILLE)<br />
&#8211; FAMILLE_CRITERE (Pk : ID_FAMILLE, ID_CRITERE)<br />
&#8211; CRITERE (Pk : ID_CRITERE)<br />
Relations :<br />
¤ Famille &#8211;&gt; FAMILLE_CRITERES &lt;&#8212; CRITERE<br />
famille_critere ne contenant que le couple ID_FAMILLE, ID_CRITERE (on parle de table intermédiaire)  </em></p>
<p>Ce à quoi je répondais :</p>
<p><em>La solution 2 est correcte si vous ne requêtez JAMAIS plus d&rsquo;un critère à la fois. Elle est déjà moins performante à l’insertion/la mise à jour des données&#8230;<br />
La solution 2 est imbécile, complexe et peu performantes si vous avez plusieurs critères a rechercher&#8230;<br />
En sus, elle ne permet pas facilement de typer les informations, donc, vous aurez beaucoup de problématique de contrôle de qualité&#8230; et des performances catastrophiques</em></p>
<p><strong>DÉMONSTRATION</strong></p>
<p><strong>Partons d&rsquo;une table d&rsquo;animaux :</strong></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> T_ANIMAL_ANM<br />
<span style="color: #66cc66;">&#40;</span>ANM_ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span><br />
&nbsp;ANM_DATA &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8000</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> T_ANIMAL_ANM <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Mytilus Edulis'</span><span style="color: #66cc66;">&#41;</span></div></div>
<p><strong></strong><br />
<strong>█ █ █ 1ere solution : une seule table pour toute une même famille :</strong></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> T_MOLUSQUE_MSQ<br />
<span style="color: #66cc66;">&#40;</span>ANM_ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> T_ANIMAL_ANM <span style="color: #66cc66;">&#40;</span>ANM_ID<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp;MSQ_CARAPACE &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp;MSQ_SYMETRIE &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp;MSQ_COULEUR &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp;MSQ_DIAMETRE_MM &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FLOAT</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p><strong></strong><br />
<strong>█ █ █ 2e solution (pour toutes familles), des tables &laquo;&nbsp;génériques&nbsp;&raquo; :</strong></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> T_CARATERISTIQUE_CRT<br />
<span style="color: #66cc66;">&#40;</span>CRT_ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span><br />
&nbsp;CRT_LIBELLE &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">256</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> T_VALEUR_VLR<br />
<span style="color: #66cc66;">&#40;</span>ANM_ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> T_ANIMAL_ANM <span style="color: #66cc66;">&#40;</span>ANM_ID<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp;CRT_ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> T_CARATERISTIQUE_CRT<span style="color: #66cc66;">&#40;</span>CRT_ID<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp;VLR_VALEUR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">256</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp;<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>ANM_ID<span style="color: #66cc66;">,</span> CRT_ID<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Ajoutons les caractéristiques identiques à celle de la solution 1</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> T_CARATERISTIQUE_CRT <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">111</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Carapace'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> T_CARATERISTIQUE_CRT <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">222</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Symétrie'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> T_CARATERISTIQUE_CRT <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">333</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Couleur'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> T_CARATERISTIQUE_CRT <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">444</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Diamètre mm'</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p><strong></strong><br />
<strong>█ █ █ Voici maintenant les insertions :</strong></p>
<p><strong>Pour la solution 1 :</strong></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> T_MOLUSQUE_MSQ <span style="color: #66cc66;">&#40;</span>ANM_ID<span style="color: #66cc66;">,</span> MSQ_CARAPACE<span style="color: #66cc66;">,</span> MSQ_SYMETRIE<span style="color: #66cc66;">,</span> MSQ_COULEUR<span style="color: #66cc66;">,</span> MSQ_DIAMETRE_MM<span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'Creatine'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff0000;">'Mono'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Bleu'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'82.5'</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Notez que nous n&rsquo;avons fait qu&rsquo;<strong>une seule requête</strong> d&rsquo;insertion avec correspondance caractéristique / valeur et typage des données</p>
<p><strong>Pour la solution 2 :</strong></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> T_VALEUR_VLR <br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> CRT_ID<span style="color: #66cc66;">,</span> &nbsp; &nbsp;<span style="color: #ff0000;">'Creatine'</span> <span style="color: #993333; font-weight: bold;">FROM</span> T_CARATERISTIQUE_CRT <br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;CRT_LIBELLE <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Carapace'</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> T_VALEUR_VLR <br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> CRT_ID<span style="color: #66cc66;">,</span> &nbsp; &nbsp;<span style="color: #ff0000;">'Mono'</span> &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> T_CARATERISTIQUE_CRT <br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;CRT_LIBELLE <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Symétrie'</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> T_VALEUR_VLR <br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> CRT_ID<span style="color: #66cc66;">,</span> &nbsp; &nbsp;<span style="color: #ff0000;">'Bleu'</span> &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> T_CARATERISTIQUE_CRT <br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;CRT_LIBELLE <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Couleur'</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> T_VALEUR_VLR <br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> CRT_ID<span style="color: #66cc66;">,</span> &nbsp; &nbsp;<span style="color: #ff0000;">'82,5'</span> &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> T_CARATERISTIQUE_CRT <br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;CRT_LIBELLE <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Diamètre mm'</span>;</div></div>
<p>Pour stocker les mêmes informations, nous avons fait <strong>4 requêtes</strong> au lieu d&rsquo;une seule&#8230;.</p>
<p><strong>█ Comparons maintenant le coût des 2 solutions au niveau de l&rsquo;insertion :</strong></p>
<p><a href="http://blog.developpez.com/sqlpro/files/2018/08/Requetes-insertion-comparaison-couts.jpg"><img src="http://blog.developpez.com/sqlpro/files/2018/08/Requetes-insertion-comparaison-couts.jpg" alt="Comparaison des plans de requêtes pour l&#039;insertion" width="1190" height="897" class="alignnone size-full wp-image-857" /></a></p>
<p>Y&rsquo;a pas à tortiller 4 requêtes coutant deux fois plus cher qu&rsquo;une seule et unique requête cela est donc <strong>8 fois plus couteux</strong>&#8230;</p>
<p><strong>█ █ █ Voyons maintenant la facilité de requêtage :</strong></p>
<p>interrogation multicritères ET avec solution 1</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; T_ANIMAL_ANM <span style="color: #993333; font-weight: bold;">AS</span> A<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> T_MOLUSQUE_MSQ <span style="color: #993333; font-weight: bold;">AS</span> M<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> A<span style="color: #66cc66;">.</span>ANM_ID <span style="color: #66cc66;">=</span> M<span style="color: #66cc66;">.</span>ANM_ID<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;MSQ_CARAPACE <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Creatine'</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;MSQ_SYMETRIE <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Mono'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Double'</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;MSQ_COULEUR <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'Bleu%'</span> <span style="color: #808080; font-style: italic;">--&gt; peut être Bleue, Bleu-marine...</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;MSQ_DIAMETRE_MM <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #cc66cc;">75</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #cc66cc;">92</span>;</div></div>
<p>la requête fait <strong>8 lignes et 1 jointure</strong>. Elle en fera une de plus pour chaque critère supplémentaire avec juste quelques chose à rajouter à la clause WHERE&#8230;</p>
<p>interrogation multicritères ET avec solution 2</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; T_ANIMAL_ANM <span style="color: #993333; font-weight: bold;">AS</span> A<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> T_VALEUR_VLR <span style="color: #993333; font-weight: bold;">AS</span> V1 <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> A<span style="color: #66cc66;">.</span>ANM_ID <span style="color: #66cc66;">=</span> V1<span style="color: #66cc66;">.</span>ANM_ID<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> T_CARATERISTIQUE_CRT <span style="color: #993333; font-weight: bold;">AS</span> C1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> V1<span style="color: #66cc66;">.</span>CRT_ID <span style="color: #66cc66;">=</span> C1<span style="color: #66cc66;">.</span>CRT_ID<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> T_VALEUR_VLR <span style="color: #993333; font-weight: bold;">AS</span> V2 <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> A<span style="color: #66cc66;">.</span>ANM_ID <span style="color: #66cc66;">=</span> V2<span style="color: #66cc66;">.</span>ANM_ID<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> T_CARATERISTIQUE_CRT <span style="color: #993333; font-weight: bold;">AS</span> C2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> V2<span style="color: #66cc66;">.</span>CRT_ID <span style="color: #66cc66;">=</span> C2<span style="color: #66cc66;">.</span>CRT_ID<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> T_VALEUR_VLR <span style="color: #993333; font-weight: bold;">AS</span> V3 <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> A<span style="color: #66cc66;">.</span>ANM_ID <span style="color: #66cc66;">=</span> V3<span style="color: #66cc66;">.</span>ANM_ID<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> T_CARATERISTIQUE_CRT <span style="color: #993333; font-weight: bold;">AS</span> C3<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> V3<span style="color: #66cc66;">.</span>CRT_ID <span style="color: #66cc66;">=</span> C3<span style="color: #66cc66;">.</span>CRT_ID<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> T_VALEUR_VLR <span style="color: #993333; font-weight: bold;">AS</span> V4 <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> A<span style="color: #66cc66;">.</span>ANM_ID <span style="color: #66cc66;">=</span> V4<span style="color: #66cc66;">.</span>ANM_ID<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> T_CARATERISTIQUE_CRT <span style="color: #993333; font-weight: bold;">AS</span> C4<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> V4<span style="color: #66cc66;">.</span>CRT_ID <span style="color: #66cc66;">=</span> C4<span style="color: #66cc66;">.</span>CRT_ID<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;C1<span style="color: #66cc66;">.</span>CRT_LIBELLE <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Carapace'</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;V1<span style="color: #66cc66;">.</span>VLR_VALEUR <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Creatine'</span> <br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;C2<span style="color: #66cc66;">.</span>CRT_LIBELLE <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Symétrie'</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;V2<span style="color: #66cc66;">.</span>VLR_VALEUR <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Mono'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Double'</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;C3<span style="color: #66cc66;">.</span>CRT_LIBELLE <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Couleur'</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;V3<span style="color: #66cc66;">.</span>VLR_VALEUR <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'Bleu%'</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;C4<span style="color: #66cc66;">.</span>CRT_LIBELLE <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Diamètre mm'</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;V4<span style="color: #66cc66;">.</span>VLR_VALEUR <span style="color: #993333; font-weight: bold;">BETWEEN</span> <span style="color: #ff0000;">'75'</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #ff0000;">'92'</span></div></div>
<p>La requête fait <strong>26 lignes avec 8 jointures</strong>&#8230; Il faudra rajouter 6 lignes à chaque critère supplémentaire, dont 4 dans la clause FROM et 2 dans le WHERE, et encore, on ne sait pas dans la clause SELECT à quelle caractéristique se réfère chacune des valeurs&#8230; Il faudrait aussi customiser la clause SELECT&#8230;</p>
<p>Y&rsquo;a pas à tortiller la solution 1 est bien plus simple en matière d’écriture&#8230;</p>
<p><strong>█ Quelles sont les performances des requêtes de recherches des deux solutions ?</strong></p>
<p><a href="http://blog.developpez.com/sqlpro/files/2018/08/Requetes-selection-comparaison-couts.jpg"><img src="http://blog.developpez.com/sqlpro/files/2018/08/Requetes-selection-comparaison-couts.jpg" alt="Comparaison des plans de requêtes pour l&#039;extraction" width="2251" height="389" class="alignnone size-full wp-image-859" /></a></p>
<p><strong>Évidemment la première solution est 4,5 fois moins couteuse&#8230;</strong></p>
<p>Mais il y a pire&#8230; J&rsquo;ai du mettre des chiffres en chaine de caractères pour le diamètre (AND  V4.VLR_VALEUR BETWEEN &rsquo;75&rsquo; AND &rsquo;92&rsquo;). Si je tente de les typer en entier ou réel (AND  V4.VLR_VALEUR BETWEEN 75 AND 92), cela provoque une erreur d&rsquo;exécution (SQL Server) :<br />
<em>Msg*245, Niveau*16, État*1, Ligne*75<br />
Échec de la conversion de la valeur varchar &lsquo;Creatine&rsquo; en type de données int.</em><br />
Logique car pour effectuer une comparaison avec une valeur numérique, il faut convertir la colonne en numérique, mais comme il y a autres chose que de purs nombres (chaines de caractères) cela se passe mal.<br />
Bref certaines requêtes seront impossible à faire !</p>
<p>Plus catastrophique encore&#8230; mettre des index ne servira quasiment à rien ! En effet un index sur une chaine de caractères n’ordonne pas les valeurs de la même façon que s&rsquo;il s&rsquo;agissait de nombre&#8230;</p>
<p>En sus rien n&rsquo;interdira à quelqu’un de saisir 8,2 au lieu de 8.2 (une virgule au lieu d&rsquo;une point) comme diamètre, dans ce modèle inepte, alors qu&rsquo;avec le bon modèle les types sont respectés&#8230;. Si tel était le cas, la valeur ne pourra pas être retrouvée !!! Il existe bien évidemment une solution pour contourner, un tout petit peu, ce modèle pourri, pour le typage. Il consiste à rajouter autant de tables de valeurs que de type&#8230; Mais il n&rsquo;est pas possible de rajouter des contraintes spécifique à chaque type (par exemple vérifier qu&rsquo;une pourcentage est bien entre 0 et 100 &#8211; notion de domaine SQL), ni, bien entendu, de rajouter des contraintes multicritères (une valeur dépendant d&rsquo;une autre) comme c&rsquo;est le cas par exemple de la chronologie des temporels de type &laquo;&nbsp;début&nbsp;&raquo; et &laquo;&nbsp;fin&nbsp;&raquo;.<br />
Et dans tous les cas, les requêtes seront encore plus complexes à élaborer et les performances encore plus lamentables&#8230;</p>
<p><strong>En guise de conclusion</strong></p>
<p>Nous vous avons démontré les performances lamentable et la complexité horrifiante d&rsquo;un tel modèle&#8230;.</p>
<li>Complexité d&rsquo;insertion des données</li>
<li>Mauvaise performances à l&rsquo;insertion des données</li>
<li>Complexité d&rsquo;écriture des recherches</li>
<li>Mauvaise performances pour la recherches de données</li>
<li>Impossibilité de typer finement (notion de domaine)</li>
<li>Impossibilité de placer des contraintes multicritères</li>
<li>Difficultés pour l&rsquo;indexation</li>
<p><strong></strong><br />
<strong></strong></p>
<p>Mais comment se fait-il que des internautes osent affirmer de pareilles stupidités ?</p>
<p>Il est amusant de voir que certains développeur incultes affirment n&rsquo;importe quoi, par ignorance, ou par bêtise, ne prenant même pas la peine de tester ce qu&rsquo;ils disent&#8230; Ensuite ces mêmes développeurs, sans aucune expérience, iront vous raconter que les SGBDR c&rsquo;est pas performant&#8230; Ils vous vendrons alors du NoSQL, ce qui, dans beaucoup de cas, sera pire encore !</p>
<p>Comme disent les américains : &laquo;&nbsp;garbage in, garbage out&nbsp;&raquo; qui peut se traduire si tu fais de la merde en entrée, tu auras de la merde en sortie ! Autrement dit, si le modèle de données est inepte, la qualité des données sera pourrie et les performances lamentables&#8230;</p>
<p><strong>Décortiquons d&rsquo;ailleurs les affirmations de l&rsquo;internate que nous avons cité :</strong><br />
&laquo;&nbsp;<em>tout dépend de votre SGBD (pas précisé..), mais dans tous les cas, il suffit de mettre des ID numérique pour que les requêtes soient optimisées. Créez vos tables avec des id uniques (sous Oracle on peux utiliser les séquences) et vous aurez des traitements optimisées au mieux&#8230; mais bon, je vous rassure, sous Oracle, même avec des clefs en Varchar, pour 600 enregistrements, y a aucun pb..</em>&nbsp;&raquo;</p>
<p><strong>Première affirmation stupide</strong> : &laquo;&nbsp;<em>tout dépend de votre SGBD (pas précisé..)</em>&nbsp;&raquo;<br />
Comme nous sommes dans un forum sur les SGBDR, sachez cher monsieur, que tout les SGBDR fonctionnent de la même façon. Certains allant plus vite que d&rsquo;autre (une Ferrari va généralement plus vite qu&rsquo;une Peugeot), certains avec plus de qualité que d&rsquo;autres (une Rolls-Royce est généralement de meilleure qualité qu&rsquo;une Dacia).</p>
<p><strong>Seconde affirmation stupide</strong> : &laquo;&nbsp;<em>il suffit de mettre des ID numérique pour que les requêtes soient optimisées</em>&nbsp;&raquo;<br />
Si c&rsquo;était le cas alors, pas besoin d&rsquo;index ni de contraintes&#8230; On se demande donc pourquoi les éditeurs de SGBDR font de tels effort en R&amp;D pour trouver de nouvelles formes d&rsquo;index toujours plus performant&#8230;  Et la plupart des informaticiens ignorent que les contraintes permettent de mieux optimiser les plans de requête&#8230; Hélas ceci est très rarement enseigné par les professeurs des universités et encore moins ceux des écoles d&rsquo;ingénieurs&#8230; (je le sais pertinemment puisque j&rsquo;en étais un&#8230;).</p>
<p><strong>Troisième affirmation stupide</strong> : &laquo;&nbsp;<em>mais bon, je vous rassure, sous Oracle, même avec des clefs en Varchar</em>&nbsp;&raquo;<br />
Et bien, non, plus une clef est longue en nombre d&rsquo;octets, plus ses performances décroissent. Pour avoir la même longueur qu&rsquo;un entier auto incrémenté il faudrait se limiter à 4 caractères&#8230; En sus certaines phénomènes apparaissent avec des clefs non numériques et en particulier pour des clefs littérales :
<li>distribution peu aléatoire (parce que concentrées sur les 26 lettres et 10 chiffres parmi les 256 caractères disponibles) induisant des statistiques d&rsquo;optimisation mal réparties (histogrammes erratiques)</li>
<li>extra-overhead lié à la gestion de la collation (sensibilité ou non à la casse, aux accents&#8230;)</li>
<li>façon de stocker physiquement les VARCHAR induisant des octets suplementaires et de la fragmentaion en cas d&rsquo;UPDATE</li>
<p><strong></strong><br />
<strong></strong></p>
<p><strong>Quatrième affirmation stupide</strong> : &laquo;&nbsp;<em>sous Oracle, même avec des clefs en Varchar, pour 600 enregistrements, y a aucun pb..</em>&nbsp;&raquo;<br />
Nous avons déjà dit précédemment que les clef littérales (VARCHAR) étaient une plaie&#8230; Mais ce qui ne va pas dans cette phrase est le terme &laquo;&nbsp;<strong>enregistrement</strong>&laquo;&nbsp;&#8230; Cet internaute sait-il au moins que les SGBDR ne travaillent pas avec des &laquo;&nbsp;enregistrement&nbsp;&raquo; propre aux bases de données de type &laquo;&nbsp;fichier&nbsp;&raquo; comme c&rsquo;était las cas dans les années 50 à 70 ? Les SGBDR structurent les lignes des tables dans des pages qui sont modifiées en mémoire et non pas directement sur le disque (notion physique d&rsquo;enregistrement). Les pages étant physiquement écrites de temps à autres quand il y en a suffisamment à écrire par un processus asynchrone travaillant en tâche de fond.</p>
<p>Bref voici q&rsquo;un internaute ne connaissant ni la modélisation des données ni les technologies des SGDB, vient donner des conseils stupides hélas parfois repris dans certaines applications&#8230;.</p>
<p><strong></strong><br />
<strong></strong></p>
<p><strong>CQFD</strong></p>
<p><strong></strong><br />
<strong></strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Cosmos DB, la base NoSQL à tout faire !</title>
		<link>https://blog.developpez.com/sqlpro/p13182/bases-de-donnees/cosmos-db-la-base-nosql-a-tout-faire</link>
		<comments>https://blog.developpez.com/sqlpro/p13182/bases-de-donnees/cosmos-db-la-base-nosql-a-tout-faire#comments</comments>
		<pubDate>Mon, 06 Aug 2018 16:19:14 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[bases de données]]></category>
		<category><![CDATA[Amazon DynamoDB]]></category>
		<category><![CDATA[Cassandra]]></category>
		<category><![CDATA[Cosmos DB]]></category>
		<category><![CDATA[CouchDB]]></category>
		<category><![CDATA[Document Stores]]></category>
		<category><![CDATA[Google Big Table]]></category>
		<category><![CDATA[Google Cloud]]></category>
		<category><![CDATA[Graph Database]]></category>
		<category><![CDATA[HBase]]></category>
		<category><![CDATA[Key-Value]]></category>
		<category><![CDATA[MarkLogic]]></category>
		<category><![CDATA[Memcached]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[Neo4J]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Oracle Berkely DB]]></category>
		<category><![CDATA[OrientDB]]></category>
		<category><![CDATA[Redis]]></category>
		<category><![CDATA[Wide Column]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=830</guid>
		<description><![CDATA[Vous en rêviez ? Cosmos DB l&#8217;a fait ! Une seul base de données, permettant à la fois et dans un même espace de stockage de combiner les différentes technologies des bases de données NoSQL&#8230; &#171;&#160;Wide Column&#160;&#187;, &#171;&#160;Graph Database&#160;&#187;, &#171;&#160;Key-Value&#160;&#187; et &#171;&#160;Document Stores&#160;&#187;, toutes ces technologies sont disponible dans une seule et même base de [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Vous en rêviez ? Cosmos DB l&rsquo;a fait ! Une seul base de données, permettant à la fois et dans un même espace de stockage de combiner les différentes technologies des bases de données NoSQL&#8230; &laquo;&nbsp;Wide Column&nbsp;&raquo;, &laquo;&nbsp;Graph Database&nbsp;&raquo;, &laquo;&nbsp;Key-Value&nbsp;&raquo; et &laquo;&nbsp;Document Stores&nbsp;&raquo;, toutes ces technologies sont disponible dans une seule et même base de données de nom Cosmos DB&#8230;<br />
<span id="more-830"></span><br />
Là ou certaines clients doivent jongler avec plusieurs SGBD pour satisfaire différentes facettes fonctionnelles, Cosmos DB fait la synthèses des plus importantes technologies utilisées de manière combinées dans un seul et même produit.</p>
<p>Je me suis amusé à comparer, via le célèbre site db-engines.com qui publie des résultats de collecte de données statistiques d&rsquo;utilisation, les différents graphes de popularité des produits concurrents de Cosmos DB et n&rsquo;ai retenu que les SGBD qui lui était encore supérieur&#8230; Force est de constater la progression fulgurante de Cosmos DB qui, en quelques mois à dépassé OrientDB, Oracle Berkely DB, CouchDB, Google Cloud, MarkLogic, Google Big Table&#8230;<br />
Et Cosmos DB talonne Cassandra, HBase, Neo4J, MongoDB, Memcached, Amazon DynamoDB et Redis.</p>
<p><strong>1 &#8211; Graphe de popularité Key-value stores</strong></p>
<p><a href="http://blog.developpez.com/sqlpro/files/2018/08/MS-Azure-Cosmos-DB-Key-Value-Stores-ranking-2018-08.jpg"><img src="http://blog.developpez.com/sqlpro/files/2018/08/MS-Azure-Cosmos-DB-Key-Value-Stores-ranking-2018-08.jpg" alt="MS Azure Cosmos DB Key-Value Stores ranking 2018-08" width="985" height="531" class="alignnone size-full wp-image-831" /></a></p>
<p>Cosmos DB progresse de 29 fois en 4 ans alors que Redis (leader) n&rsquo;a fais que 4,6 sur la même période !</p>
<p><strong>2 &#8211; Graphe de popularité Wide Columns stores</strong></p>
<p><a href="http://blog.developpez.com/sqlpro/files/2018/08/MS-Azure-Cosmos-DB-Wide-Column-Stores-ranking-2018-08.jpg"><img src="http://blog.developpez.com/sqlpro/files/2018/08/MS-Azure-Cosmos-DB-Wide-Column-Stores-ranking-2018-08.jpg" alt="MS Azure Cosmos DB Wide Column Stores ranking 2018-08" width="969" height="516" class="alignnone size-full wp-image-835" /></a></p>
<p>Cosmos DB progresse de 29 fois en 4 ans alors que Cassandra (leader) n&rsquo;a fais que 1,4 sur la même période !</p>
<p><strong>3 &#8211; Graphe de popularité Graph DBMS</strong></p>
<p><a href="http://blog.developpez.com/sqlpro/files/2018/08/MS-Azure-Cosmos-DB-Graph-DBMS-ranking-2018-08.jpg"><img src="http://blog.developpez.com/sqlpro/files/2018/08/MS-Azure-Cosmos-DB-Graph-DBMS-ranking-2018-08.jpg" alt="MS Azure Cosmos DB Graph DBMS ranking 2018-08" width="980" height="526" class="alignnone size-full wp-image-836" /></a></p>
<p>Cosmos DB progresse de 29 fois en 4 ans alors que Neo4j (leader) n&rsquo;a fais que 1,7 sur la même période !</p>
<p><strong>4 &#8211; Graphe de popularité Document Stores</strong></p>
<p><a href="http://blog.developpez.com/sqlpro/files/2018/08/MS-Azure-Cosmos-DB-Document-Stores-ranking-2018-08.jpg"><img src="http://blog.developpez.com/sqlpro/files/2018/08/MS-Azure-Cosmos-DB-Document-Stores-ranking-2018-08.jpg" alt="MS Azure Cosmos DB Document Stores ranking 2018-08" width="980" height="526" class="alignnone size-full wp-image-837" /></a></p>
<p>Cosmos DB progresse de 29 fois en 4 ans alors que MongoDB (leader) n&rsquo;a fais que 1,46 sur la même période !</p>
<p>Allez, je fais un pari&#8230; Avant 2 ans, Cosmos DB sera au pire, la seconde base en popularité dans chacune de ces 4 catégories avec comme unique &laquo;&nbsp;sparring partner&nbsp;&raquo; :</p>
<li>Redis pour la partie Key-Value</li>
<li>MongoDB pour la partie Document Stores</li>
<li>Neo4J pour la partie &laquo;&nbsp;graph database&nbsp;&raquo; (et là je pense que Cosmos DB va le doubler)</li>
<li>Cassandra pour la partie &laquo;&nbsp;Wide Column&nbsp;&raquo;</li>
<p>Je parie aussi pour la disparition, à plus ou moins long terme, de produits comme OrientDB, CouchDB et MarkLogic&#8230; </p>
<p>Donc rendez vous début août 2020&#8230;</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Une peste nommée NOLOCK&#8230; et comment l&#8217;éviter</title>
		<link>https://blog.developpez.com/sqlpro/p13181/langage-sql-norme/une-peste-nommee-nolock-et-comment-leviter</link>
		<comments>https://blog.developpez.com/sqlpro/p13181/langage-sql-norme/une-peste-nommee-nolock-et-comment-leviter#comments</comments>
		<pubDate>Sun, 08 Jul 2018 14:55:07 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[Langage SQL (norme)]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[ISOLATION]]></category>
		<category><![CDATA[NOLOCK]]></category>
		<category><![CDATA[SNAPSHOT]]></category>
		<category><![CDATA[transaction]]></category>
		<category><![CDATA[verrou]]></category>
		<category><![CDATA[verrouilage]]></category>
		<category><![CDATA[verrous]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=818</guid>
		<description><![CDATA[L&#8217;utilisation du tag de table NOLOCK, hélas largement prisé par de nombreux développeurs, est, la plupart du temps, une absurdité conduisant à des résultats potentiellement faux. Est-il possible de faire autrement pour minimiser les blocages induit par les verrouillages dans SQL Server ? Réponse OUI ! À la suite de cette remarque : &#171;&#160;&#8230;je passe [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>L&rsquo;utilisation du tag de table NOLOCK, hélas largement prisé par de nombreux développeurs, est, la plupart du temps, une absurdité conduisant à des résultats potentiellement faux. Est-il possible de faire autrement pour minimiser les blocages induit par les verrouillages dans SQL Server ? Réponse OUI !<br />
<span id="more-818"></span><br />
À la suite de cette remarque :<br />
<em>&laquo;&nbsp;&#8230;je passe aussi sur le NOLOCK qui est une véritable connerie en production et donne des valeurs fausses !&nbsp;&raquo;</em><br />
Publiée ici :<br />
<a href="https://www.developpez.net/forums/d1870299/bases-donnees/ms-sql-server/developpement/utilisation-excessive-structure-conditionnelle-choix-multiples/#post10343427" rel="noopener" target="_blank"></a><br />
Mon interlocuteur me répondais :<br />
<em>&laquo;&nbsp;Merci pour cette précision. Comme vous abordez le sujet du NOLOCK effectivement j&rsquo;ai constaté certaines fois en production on avait des valeurs totalement erronées, mais je n&rsquo;arrivais pas à me l&rsquo;expliquer. J&rsquo;ai maintenant une piste et je vais creuser du côté du NOLOCK que nous utilisons beaucoup en production sur une base de données CRM 2013. Aussi par quoi pouvons nous remplacer le NOLOCK ??&nbsp;&raquo;</em></p>
<p>Je lui donnais donc l&rsquo;explication suivante&#8230;<br />
<strong><br />
Le &laquo;&nbsp;NOLOCK&nbsp;&raquo; peut parfaitement se remplacer par le niveau d&rsquo;isolation SNAPSHOT</strong> par exemple&#8230;</p>
<p>NOLOCK ne signifie pas &laquo;&nbsp;<em>je ne pose pas de verrou</em>&laquo;&nbsp;, mais plus précisément : &laquo;&nbsp;<em>j&rsquo;ignore qu&rsquo;il y a des verrous et je lit ce que je peut</em>&nbsp;&raquo; (ceci est plus connu dans la littérature professionnelle sous le nom de <em><strong>lecture dans le chaos</strong></em>&#8230;). Vous pouvez donc lire plusieurs fois les mêmes données ou encore ne pas lire certaines.</p>
<p><strong>Quid du mode SNAPSHOT ?</strong></p>
<p>SNAPSHOT fait du verrouillage optimiste pour les lectures. Par défaut SQL Server fait du verrouillage pessimiste, c&rsquo;est à dire que les lectures posent des verrous qui permettent d&rsquo;autres lectures concurrentes (verrous partagés, mode &laquo;&nbsp;SHARE&nbsp;&raquo;), mais empêchent les écritures des autres utilisateurs. Conceptuellement, le verrouillage optimiste (donc via le mode d’isolation SNAPSHOT) fait une copie (si besoin) des données avant de permettre leurs lectures. Comme vous travaillez sur une copie, les utilisateurs concurrent peuvent modifier les vraies ligne sans que cela vous concerne. Bien entendu il peut toujours y avoir des conflits, mais cela réduit considérablement le nombre de verrous bloquants tout en gardant l&rsquo;intégrité et la consistante de la base, ce qui n&rsquo;est pas du tout le cas du NOLOCK.</p>
<p><strong>Alors, à quoi sert le NOLOCK ? </strong></p>
<p>Cela peut servir pour certains cas ou l&rsquo;on désire des résultats dont on se fout de l&rsquo;intégrité ou de la précision. Souvent dans le domaine de la statistique.<br />
par exemple si vous voulez savoir combien les français ont d&rsquo;enfant par foyer et scrutez donc, pour ce faire, une table de 60 millions de lignes (population française), je ne suis pas sûr que dans un camembert représentant la chose, on fasse la distinction des quelques pixels de l&rsquo;imprécision de la 6e décimale du résultat liées à quelques mauvaises lectures de lignes !<br />
On utilise d&rsquo;ailleurs très souvent le NOLOCK pour des tâches d&rsquo;administration systèmes dans SQL Server afin d&rsquo;éviter tout blocage au risque de perdre quelques lignes, ce qui n&rsquo;a pas toujours une importance capitale lorsque l&rsquo;on veut remonter quelques informations concernant les 20% de requêtes les moins performantes !</p>
<p><strong>Mais alors, le SNAPSHOT fait la même chose en mieux ? </strong></p>
<p>Oui et non&#8230; Certes il permet de garantir l&rsquo;intégrité, la consistance, etc&#8230; mais son mécanisme est plus lourd (un peu moins rapide) et consomme des ressources pour générer les copies (SNAPSHOT). Rassurez-vous il est assez malin pour ne faire ces copies qui s&rsquo;il a besoin de les faire&#8230; En d&rsquo;autres termes si aucun utilisateur concurrent veut faire des modif sur le jeu de lignes que vous manipulez en mode SNAPSHOT, aucune copie ne sera générée. Mais si, lorsque vous avez démarré une lecture en mode SNAPSHOT, un utilisateur concurrent veut modifier des lignes, et bien la copie sera réalisée au cours de votre lecture sans que vous vous en aperceviez&#8230; En quelque sorte le système fonctionne à l&rsquo;envers&#8230; Bien évidemment il faut un espace de stockage pour ces copies et c&rsquo;est la base tempdb qui s&rsquo;y colle. Il faut donc, la dimensionner correctement&#8230;<br />
Tiens, à nouveau un travail de DBA !</p>
<p><strong>Des conflits ! Quels conflits ?</strong></p>
<p>J&rsquo;ai précédemment parlé de conflits possible avec l&rsquo;utilisation du mode SNAPSHOT. En effet, si vous voulez modifier des données lors d&rsquo;une transaction en mode d’isolation SNAPSHOT, c&rsquo;est possible, mais ces modifications seront faites sur la copie, et non sur la base originale, et seront reportées sur la base originale au moment du COMMIT. Deux hypothèses se font alors jour :<br />
■ soit aucune ligne visée par vos modifications faites en mode SNAPSHOT n&rsquo;a été modifié dans une autre session directement sur la base, alors la mise à jour est appliquée.<br />
Ou alors :<br />
■ s&rsquo;il existe au moins une ligne qui a été modifiée par une autre session entre temps sur la base originale, alors vos modifications ne pourront être appliquées aux données originales et vont êtres abandonnées.<br />
Dans ce dernier cas vous obtiendrez une message d&rsquo;erreur (3960) assez abscons, qui indique :<br />
<em>&laquo;&nbsp;La transaction d&rsquo;isolement d&rsquo;instantané a été abandonnée en raison d&rsquo;un conflit de mise à jour. &#8230;&nbsp;&raquo;</em></p>
<p>Notez qu&rsquo;il existe un autre tag plus intéressant que le NOLOCK&#8230;. Le <strong>READPAST</strong> !&#8230;  Qui fait presque la même chose, mais ignore tout ce qui est verrouillé !</p>
<p><strong>Les modes d&rsquo;isolation selon la norme SQL</strong></p>
<p>Sachez que le mode d’isolation SNAPSHOT ne fait pas partie de la norme SQL qui n&rsquo;autorise que les modes d&rsquo;isolation suivants :<br />
0 &#8211; READ UNCOMMITTED : lecture des données invalides (non &laquo;&nbsp;committées&nbsp;&raquo;)<br />
1 &#8211; READ COMMITTED : lecture de données valides (ce qui n&rsquo;empêche pas certaines anomalies transactionnelles comme la lecture non répétable, ou l&rsquo;apparition de lignes fantômes)<br />
2 &#8211; REPEATABLE READ : lecture répétable de données (ce qui n&rsquo;empêche pas certaines anomalies transactionnelles comme l&rsquo;apparition de lignes fantômes)<br />
3 &#8211; SERIALIZABLE : lecture en mode série (aucun accès concurrent aux tables lors des mises à jour, ce qui empêche toute anomalies)<br />
Évidemment plus on monte le niveau d’isolation, plus le verrouillage est important et moins les accès concurrents peuvent travailler.<br />
La norme SQL considère que les manipulation des données doivent porter sur des valeurs &laquo;&nbsp;vivantes&nbsp;&raquo;. Hors, en utilisant le mode SNAPSHOT et son versionnement des lignes, ont est appelé à lire potentiellement des valeurs antérieurs des données, ce n&rsquo;est donc pas une lecture de l&rsquo;état actuel des valeurs dans la base&#8230;</p>
<p>Pour informations, des SGBRD comme Oracle, ou PostGreSQL fonctionnent nativement en mode d&rsquo;isolation SNAPSHOT, autrement dit utilisent systématiquement le verrouillage optimiste et ne savent pas faire autres choses (verrouillage pessimiste en particulier) voir ne savent même pas utiliser certains autres niveau d&rsquo;isolation. Par exemple PostGreSQL ne permet pas de faires des transaction en mode READ UNCOMMITTED et Oracle ne permettent pas d&rsquo;utiliser le niveau d&rsquo;isolation REPEATABLE READ&#8230;</p>
<p><strong>Activer le mode s&rsquo;isolation SNAPSHOT</strong></p>
<p>Pour permettre ce mode d&rsquo;isolation, vous devez d&rsquo;abord autoriser la base à utiliser le mode SNAPSHOT. Ce paramétrage est à deux niveaux :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ALTER DATABASE { CURRENT | nom_base } SET ALLOW_SNAPSHOT_ISOLATION ON;</div></div>
<p>permet d&rsquo;utiliser à tout moment le mode d’isolation SNAPSHOT qui doit être introduit préalablement par la commande SET TRANSACTION ISOLATION SNAPSHOT ou par un tag de table (SNAPSHOT)<br />
&#8230; et :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ALTER DATABASE { CURRENT | nom_base } SET READ_COMMITTED_SNAPSHOT ON;</div></div>
<p>qui place d&rsquo;office toutes les lectures en mode SNAPSHOT (comme le fait Oracle ou PostGreSQL);<br />
<strong>ATTENTION</strong> : pour assurer le versionnement des lignes, SQL Server rajoute à toutes les lignes de toutes les tables une information de version qui est codé sur 14 octets. Ceci peut prendre du temps à mettre en œuvre, en particulier sur de grosses bases.<br />
<strong></p>
<p>Appendice :</strong></p>
<p>Pour une démonstration des effets du NOLOCK : <a href="http://mssqlserver.fr/les-dangers-du-nolock/" rel="noopener" target="_blank">http://mssqlserver.fr/les-dangers-du-nolock/</a></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comparer deux requêtes aux résultats identiques</title>
		<link>https://blog.developpez.com/sqlpro/p13180/langage-sql-norme/comparer-deux-requetes-aux-resultats-identiques</link>
		<comments>https://blog.developpez.com/sqlpro/p13180/langage-sql-norme/comparer-deux-requetes-aux-resultats-identiques#comments</comments>
		<pubDate>Mon, 28 May 2018 07:25:44 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[Langage SQL (norme)]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=814</guid>
		<description><![CDATA[Comment savoir si deux requêtes donnent le même résultat ? Il suffit d&#8217;une simple équation ensembliste pour ce faire. Sachant que la requête 1 donne comme résultat l&#8217;ensemble A et que la requête 2 donne comme résultat l&#8217;ensemble B, prouver que ces deux requêtes donnent le même résultat, nécessite d&#8217;appliquer l&#8217;équation : A &#8211; B [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Comment savoir si deux requêtes donnent le même résultat ?</p>
<p>Il suffit d&rsquo;une simple équation ensembliste pour ce faire. Sachant que la requête 1 donne comme résultat l&rsquo;ensemble A et que la requête 2 donne comme résultat l&rsquo;ensemble B, prouver que ces deux requêtes donnent le même résultat, nécessite d&rsquo;appliquer l&rsquo;équation :</p>
<p><strong>A &#8211; B U B &#8211; A = Ø</strong><br />
<span id="more-814"></span></p>
<p>Autrement dit que l&rsquo;union de la soustraction des éléments de B à l&rsquo;ensemble A et de la soustraction des éléments de A à l&rsquo;ensemble B ne donne aucun résultat (ensemble vide).</p>
<p>Ceci s&rsquo;exprime en SQL de la sorte :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">WITH<br />
TA AS (SELECT ....), -- requête 1<br />
TB AS (SELECT ....) &nbsp;-- requête 2<br />
SELECT * FROM TA<br />
EXCEPT<br />
SELECT * FROM TB<br />
UNION ALL<br />
SELECT * FROM TB<br />
EXCEPT<br />
SELECT * FROM TA;</div></div>
<p>Ne donne aucun résultat&#8230; CQFD</p>
<p>PS : pour oracle utilisez MINUS au lieu de EXCEPT&#8230;.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server 2017 comparatif performances Linux vs Windows</title>
		<link>https://blog.developpez.com/sqlpro/p13177/langage-sql-norme/sql-server-2017-comparatif-performances-linux-vs-windows</link>
		<comments>https://blog.developpez.com/sqlpro/p13177/langage-sql-norme/sql-server-2017-comparatif-performances-linux-vs-windows#comments</comments>
		<pubDate>Tue, 27 Mar 2018 09:38:20 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[Langage SQL (norme)]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=810</guid>
		<description><![CDATA[Le but de cet article est de comparer les performances de Microsoft SQL Server 2017 sous Linux par rapport à Windows. Il a été élaboré sur des machines physiques strictement identiques pour ôter tout biais lié a l’utilisation de machines virtuelles. Vous trouverez les détails de cet article dans le fichier pdf suivant : sqlpro.developpez.com/article/sql_server_2017_linux_vs_windows/Benchmark_SQL_Server_2017_Linux_vs_Windows.pdf [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Le but de cet article est de comparer les performances de Microsoft SQL Server 2017 sous Linux par rapport à Windows. Il a été élaboré sur des machines physiques strictement identiques pour ôter tout biais lié a l’utilisation de machines virtuelles.<br />
<span id="more-810"></span></p>
<p>Vous trouverez les détails de cet article dans le fichier pdf suivant :<br />
<a href="http://sqlpro.developpez.com/article/sql_server_2017_linux_vs_windows/Benchmark_SQL_Server_2017_Linux_vs_Windows.pdf" title="Comparatif des performances SQL Server 2017 Linux vs Windows">sqlpro.developpez.com/article/sql_server_2017_linux_vs_windows/Benchmark_SQL_Server_2017_Linux_vs_Windows.pdf</a></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extraire le code des requêtes d&#8217;un verrou mortel traqué par un graphe &#171;&#160;deadlock&#160;&#187; du profiler</title>
		<link>https://blog.developpez.com/sqlpro/p13176/ms-sql-server/extraire-le-code-des-requetes-dun-verrou-mortel-traque-par-un-graphe-deadlock-du-profiler</link>
		<comments>https://blog.developpez.com/sqlpro/p13176/ms-sql-server/extraire-le-code-des-requetes-dun-verrou-mortel-traque-par-un-graphe-deadlock-du-profiler#comments</comments>
		<pubDate>Thu, 22 Feb 2018 18:26:45 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[capture]]></category>
		<category><![CDATA[deadlock]]></category>
		<category><![CDATA[détection]]></category>
		<category><![CDATA[étreinte fatale]]></category>
		<category><![CDATA[interblocage]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[profiler]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[trace]]></category>
		<category><![CDATA[verrou mortel]]></category>
		<category><![CDATA[victime]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=794</guid>
		<description><![CDATA[L&#8217;outil profiler de SQL Server permet de partir à la chasse au verrous mortel et peut récupérer le graphe du verrouillage des éléments concurrents et notamment les données technique de la victime. Mais ce graphe est en fait un document XML contenant toutes les informations sur les processus en jeu, la victime et les survivants. [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>L&rsquo;outil profiler de SQL Server permet de partir à la chasse au verrous mortel et peut récupérer le graphe du verrouillage des éléments concurrents et notamment les données technique de la victime. Mais ce graphe est en fait un document XML contenant toutes les informations sur les processus en jeu, la victime et les survivants. Il est alors intéressant d&rsquo;en extraire les requêtes fautives afin de corriger son code ou d&rsquo;indexer les tables, quelques un des moyens de se débarrasser des interblocages&#8230;<br />
<span id="more-794"></span><br />
Pour détecter les verrous mortels, il suffit de demander au profiler de tracer les événements de type &laquo;&nbsp;deadlock&nbsp;&raquo; de la catégorie &laquo;&nbsp;locks&nbsp;&raquo;, à savoir :</p>
<ul>
<li>Deadlock graph</li>
<li>Lock: Deadlock</li>
<li>Lock Deadlock Chain</li>
</ul>
<div id="attachment_797" style="width: 853px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2018/02/Profiler-Deadlock.jpg"><img src="http://blog.developpez.com/sqlpro/files/2018/02/Profiler-Deadlock.jpg" alt="Événements à cocher pour auditer les verrous mortels de SQL Server" width="843" height="540" class="size-full wp-image-797" /></a><p class="wp-caption-text">Événements à cocher pour auditer les verrous mortels de SQL Server</p></div>
<p>Une foi enregistrés, les données du profiler peuvent être vues par le client graphique sous cette forme :<br />
<div id="attachment_798" style="width: 1930px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2018/02/Profiler-SQL-Server-et-Deadlock.png"><img src="http://blog.developpez.com/sqlpro/files/2018/02/Profiler-SQL-Server-et-Deadlock.png" alt="Lecture des informations de verrous mortels dans le client graphique du profiler de SQL Server" width="1920" height="1040" class="size-full wp-image-798" /></a><p class="wp-caption-text">Lecture des informations de verrous mortels dans le client graphique du profiler de SQL Server</p></div></p>
<p>Néanmoins, il faut passer à l&rsquo;aide de sa souris sur chacune des bulles représentant les processus pour obtenir le texte des requêtes en jeu. Les rectangles visualisant les verrous, les pattes formant le graphe, qui lorsqu&rsquo;il présente un cycle contient un interblocage.</p>
<p>Dès lors, on peut récupérer les fichiers générés sous forme SQL via la fonction table sys.fn_trace_gettable dont le premier argument est le chemin de stockage des fichiers de trace du profiler et le second le numéro du fichier concerné. On peut aussi tous les obtenir en mettant le mot clef DEFAULT.<br />
L&rsquo;événement de graphe de verrouillage étant de classe 148, il suffit ensuite de filtrer sur ces lignes.<br />
Exemple :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT *<br />
FROM &nbsp; sys.fn_trace_gettable('C:\SQL_TRACE\20180219_14H30_DEADLOCK_.trc', default)</div></div>
<p>La colonne TextData de cette table virtuelle contient alors le XML donnant toutes les informations sur le verrou mortel. En voici un exemple :<br />
<div id="attachment_799" style="width: 780px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2018/02/Deadlock-XML-SQL-Server.jpg"><img src="http://blog.developpez.com/sqlpro/files/2018/02/Deadlock-XML-SQL-Server.jpg" alt="Document XML montrant toutes les informations d&#039;un verrou mortel survenu dans SQL Server" width="770" height="702" class="size-full wp-image-799" /></a><p class="wp-caption-text">Document XML montrant toutes les informations d&rsquo;un verrou mortel survenu dans SQL Server</p></div></p>
<p>Avec une requête mêlant du SQL et du XML via XQuery et XPath, il est possible d&rsquo;extraire ce qui nous intéresse, à savoir, le texte des requêtes en jeu ainsi qu&rsquo;une indication disant quelle est la victime et les survivants. Et comme il n&rsquo;y a pas qu&rsquo;un seul interblocage en général, alors on les identifie par un numéro. la requête au final ressemble à cela :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">WITH</span> <br />
TX <span style="color: #993333; font-weight: bold;">AS</span> <br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> StartTime<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>TextData <span style="color: #993333; font-weight: bold;">AS</span> xml<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TextData <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>fn_trace_gettable<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'C:<span style="color: #000099; font-weight: bold;">\!</span> FB<span style="color: #000099; font-weight: bold;">\R</span>henus<span style="color: #000099; font-weight: bold;">\2</span>018-02-19<span style="color: #000099; font-weight: bold;">\2</span>0180219_14H30_DEADLOCK_.trc'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;EventClass <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">148</span> <br />
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
TVM <span style="color: #993333; font-weight: bold;">AS</span> <br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> StartTime<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;v<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">VALUE</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'(./inputbuf)[1]'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'nvarchar(max)'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> Query<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;i<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">VALUE</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'(./deadlock/@victim)[1]'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'varchar(32)'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> ProcessVictim<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;v<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">VALUE</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'(./@id)[1]'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'varchar(32)'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> ProcessID<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp;TX<br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">CROSS</span> APPLY TextData<span style="color: #66cc66;">.</span>nodes<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/deadlock-list'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> X<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">CROSS</span> APPLY TextData<span style="color: #66cc66;">.</span>nodes<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/deadlock-list/deadlock/process-list/process'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> V<span style="color: #66cc66;">&#40;</span>v<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
TVV <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> DENSE_RANK<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> StartTime<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> ID<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;StartTime<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;Query<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CASE</span> <span style="color: #993333; font-weight: bold;">WHEN</span> ProcessVictim <span style="color: #66cc66;">=</span> ProcessID <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'Victim!'</span> <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #ff0000;">'Alive'</span> <span style="color: #993333; font-weight: bold;">END</span> <span style="color: #993333; font-weight: bold;">AS</span> FinalState<br />
<span style="color: #993333; font-weight: bold;">FROM</span> TVM<br />
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
TQV <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> ID<span style="color: #66cc66;">,</span> Query<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; TVV <br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;FinalState <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Victim!'</span><br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> TVV<span style="color: #66cc66;">.</span>ID<span style="color: #66cc66;">,</span> TVV<span style="color: #66cc66;">.</span>StartTime<span style="color: #66cc66;">,</span> TVV<span style="color: #66cc66;">.</span>Query<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CASE</span> <span style="color: #993333; font-weight: bold;">WHEN</span> TQV<span style="color: #66cc66;">.</span>ID <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'Victim!'</span> <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #ff0000;">'Alive'</span> <span style="color: #993333; font-weight: bold;">END</span> <span style="color: #993333; font-weight: bold;">AS</span> FinalState <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; TVV <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">OUTER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> TQV<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">ON</span> TVV<span style="color: #66cc66;">.</span>ID <span style="color: #66cc66;">=</span> TQV<span style="color: #66cc66;">.</span>ID <span style="color: #993333; font-weight: bold;">AND</span> TVV<span style="color: #66cc66;">.</span>Query <span style="color: #66cc66;">=</span> TQV<span style="color: #66cc66;">.</span>Query<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #cc66cc;">1</span>;</div></div>
<p>Au final une telle requête permet de présenter les informations suivantes :<br />
<div id="attachment_807" style="width: 588px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2018/02/Resultat-requête-deadlock1.jpg"><img src="http://blog.developpez.com/sqlpro/files/2018/02/Resultat-requête-deadlock1.jpg" alt="Visualisation des requêtes en jeu dans un verrou mortel" width="578" height="383" class="size-full wp-image-807" /></a><p class="wp-caption-text">Visualisation des requêtes en jeu dans un verrou mortel</p></div><br />
Notez au passage le colonne &laquo;&nbsp;FinalState&nbsp;&raquo; indiquant quelle requête a été victime et celles ayant survécus.</p>
<p><a href="http://sqlpro.developpez.com/_fichierSQL/DEADLOCK-SQL.txt" title="Fichier du code" target="_blank">Le code ! Le code ! Le code ! Le code ! Le code ! Le code ! Le code ! Le code ! Le code ! Le code ! </a></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Estimation des IO (ES) en lecture et écriture table par table d&#8217;une base SQL</title>
		<link>https://blog.developpez.com/sqlpro/p13175/ms-sql-server/estimation-des-io-es-en-lecture-et-ecriture-table-par-table-dune-base-sql</link>
		<comments>https://blog.developpez.com/sqlpro/p13175/ms-sql-server/estimation-des-io-es-en-lecture-et-ecriture-table-par-table-dune-base-sql#comments</comments>
		<pubDate>Wed, 21 Feb 2018 18:07:18 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[accès]]></category>
		<category><![CDATA[écriture]]></category>
		<category><![CDATA[ES]]></category>
		<category><![CDATA[IO]]></category>
		<category><![CDATA[lecture]]></category>
		<category><![CDATA[métrique]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[Statistiques]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=791</guid>
		<description><![CDATA[Les deux requêtes que je vous présente permettent d&#8217;estimer le nombres de pages lues et écrites table par table tenant compte de tous les index des tables. Attention : il ne s&#8217;agit pas d&#8217;une mesure exacte. Une telle mesure est impossible mais bien d&#8217;une estimation pour connaître les tables les plus écrites et celles les [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Les deux requêtes que je vous présente permettent d&rsquo;estimer le nombres de pages lues et écrites table par table tenant compte de tous les index des tables. Attention : il ne s&rsquo;agit pas d&rsquo;une mesure exacte. Une telle mesure est impossible mais bien d&rsquo;une estimation pour connaître les tables les plus écrites et celles les plus lues de manières relatives les unes aux autres.<br />
<span id="more-791"></span><br />
Elle se base sur le nombre d&rsquo;opération unitaire d&rsquo;accès effectué sur chaque table et index. En gros, il y a trois types d&rsquo;accès :<br />
1) un accès par balayage de la table ou de l&rsquo;index (scan) appelé &laquo;&nbsp;analyse&nbsp;&raquo; dans les plans de requête en français;<br />
2) un accès pour recherche dichotomique dans l&rsquo;index (seek) appelé &laquo;&nbsp;recherche&nbsp;&raquo; dans les plans de requête en français;<br />
3) un accès multi recherche dans l&rsquo;index (lookup) appelé &laquo;&nbsp;recherche de clés&nbsp;&raquo; dans les plans de requête en français;</p>
<p>Nous avons compter qu&rsquo;un SCAN balayait toutes les pages de l&rsquo;index ou de la table, ce qui est faux dans certains cas particulier (par exemple recherche TOP n)<br />
Nous avons compter qu&rsquo;un SEEK parcourait un nombre de page équivalent à la profondeur de l&rsquo;arbre ce qui n&rsquo;est pas vrai pour les recherches de type &laquo;&nbsp;range&nbsp;&raquo; (par exemple lors d&rsquo;un BETWEEN)<br />
Nous avons compter qu&rsquo;un LOOKUP était l&rsquo;équivalent de 10 seeks. Mais cela peut être plus ou moins et dans certains cas, ce n&rsquo;est même pas réellement l&rsquo;équivalent d&rsquo;un seek.</p>
<p>Ces approximations nous permettent quand même une bonne évaluation de la surface d&rsquo;attaque des données des tables en production, dans un but comparatif, voir les tables les plus accédées en lecture ou en écriture.</p>
<p><strong>La requête pour les lectures :</strong></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">WITH</span> <br />
idx_details <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> ius<span style="color: #66cc66;">.</span>object_id<span style="color: #66cc66;">,</span> ius<span style="color: #66cc66;">.</span>index_id<span style="color: #66cc66;">,</span> user_seeks<span style="color: #66cc66;">,</span> user_lookups<span style="color: #66cc66;">,</span> user_scans<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>INDEXPROPERTY<span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">.</span>object_id<span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'IndexDepth '</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> index_depth<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>used_page_count<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> pages<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>dm_db_partition_stats <span style="color: #993333; font-weight: bold;">AS</span> s<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;s<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> ius<span style="color: #66cc66;">.</span>object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AND</span> &nbsp;s<span style="color: #66cc66;">.</span>index_id &nbsp;<span style="color: #66cc66;">=</span> ius<span style="color: #66cc66;">.</span>index_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> page_count<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>dm_db_index_usage_stats <span style="color: #993333; font-weight: bold;">AS</span> ius<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>indexes <span style="color: #993333; font-weight: bold;">AS</span> i<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> &nbsp;ius<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> i<span style="color: #66cc66;">.</span>object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AND</span> ius<span style="color: #66cc66;">.</span>index_id &nbsp;<span style="color: #66cc66;">=</span> i<span style="color: #66cc66;">.</span>index_id<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;database_id <span style="color: #66cc66;">=</span> DB_ID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">AND</span> &nbsp; &nbsp;ius<span style="color: #66cc66;">.</span>index_id &nbsp;<span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">OR</span> user_lookups <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">OR</span> user_scans <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> &nbsp;<br />
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
TOPT <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> s<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> TABLE_SCHEMA<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_seeks <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">*</span> user_lookups <span style="color: #66cc66;">*</span> index_depth<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_scans <span style="color: #66cc66;">*</span> page_count<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> IO_READS_ESTIMATE<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;">100.0</span> <span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_seeks <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">*</span> user_lookups <span style="color: #66cc66;">*</span> index_depth<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_scans <span style="color: #66cc66;">*</span> page_count<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NULLIF</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_seeks <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">*</span> user_lookups <span style="color: #66cc66;">*</span> index_depth<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_scans <span style="color: #66cc66;">*</span> page_count<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #993333; font-weight: bold;">AS</span> PERCENT_READS_ESTIMATE<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; idx_details <span style="color: #993333; font-weight: bold;">AS</span> id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>objects <span style="color: #993333; font-weight: bold;">AS</span> o<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> id<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> o<span style="color: #66cc66;">.</span>object_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>schemas <span style="color: #993333; font-weight: bold;">AS</span> s <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> s<span style="color: #66cc66;">.</span>schema_id <span style="color: #66cc66;">=</span> o<span style="color: #66cc66;">.</span>schema_id<br />
<span style="color: #993333; font-weight: bold;">GROUP</span> &nbsp;<span style="color: #993333; font-weight: bold;">BY</span> s<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name<br />
<span style="color: #993333; font-weight: bold;">HAVING</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_seeks <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">*</span> user_lookups <span style="color: #66cc66;">*</span> index_depth<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_scans <span style="color: #66cc66;">*</span> page_count<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> TABLE_SCHEMA<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">,</span> IO_READS_ESTIMATE<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>PERCENT_READS_ESTIMATE <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">DECIMAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> PERCENT_READS_ESTIMATE<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>PERCENT_READS_ESTIMATE<span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> PERCENT_READS_ESTIMATE <span style="color: #993333; font-weight: bold;">DESC</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">DECIMAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> CUMUL_PERCENT<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> sqlserver_start_time <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>dm_os_sys_info<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> datetime2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> SINCE<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; TOPT<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> &nbsp;<span style="color: #993333; font-weight: bold;">BY</span> IO_READS_ESTIMATE <span style="color: #993333; font-weight: bold;">DESC</span>;</div></div>
<p><strong>La requête pour les écritures :</strong></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">WITH</span> <br />
idx_details <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> ius<span style="color: #66cc66;">.</span>object_id<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_updates <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> user_updates<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>dm_db_index_usage_stats <span style="color: #993333; font-weight: bold;">AS</span> ius<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>indexes <span style="color: #993333; font-weight: bold;">AS</span> i<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> ius<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> i<span style="color: #66cc66;">.</span>object_id <span style="color: #993333; font-weight: bold;">AND</span> ius<span style="color: #66cc66;">.</span>index_id <span style="color: #66cc66;">=</span> i<span style="color: #66cc66;">.</span>index_id<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;database_id <span style="color: #66cc66;">=</span> DB_ID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">AND</span> &nbsp; &nbsp;ius<span style="color: #66cc66;">.</span>index_id &nbsp;<span style="color: #cc66cc;">0</span> <br />
<span style="color: #993333; font-weight: bold;">GROUP</span> &nbsp;<span style="color: #993333; font-weight: bold;">BY</span> ius<span style="color: #66cc66;">.</span>object_id<br />
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
TOPT <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> s<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> TABLE_SCHEMA<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;user_updates <span style="color: #993333; font-weight: bold;">AS</span> IO_WRITES_ESTIMATE<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #cc66cc;">100.0</span> <span style="color: #66cc66;">*</span> user_updates <span style="color: #66cc66;">/</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>user_updates<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> PERCENT_WRITES_ESTIMATE<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; idx_details <span style="color: #993333; font-weight: bold;">AS</span> id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>objects <span style="color: #993333; font-weight: bold;">AS</span> o<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> id<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> o<span style="color: #66cc66;">.</span>object_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>schemas <span style="color: #993333; font-weight: bold;">AS</span> s <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> s<span style="color: #66cc66;">.</span>schema_id <span style="color: #66cc66;">=</span> o<span style="color: #66cc66;">.</span>schema_id<br />
<span style="color: #993333; font-weight: bold;">GROUP</span> &nbsp;<span style="color: #993333; font-weight: bold;">BY</span> s<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> user_updates<br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> TABLE_SCHEMA<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">,</span> IO_WRITES_ESTIMATE<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>PERCENT_WRITES_ESTIMATE <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">DECIMAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> PERCENT_WRITES_ESTIMATE<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>PERCENT_WRITES_ESTIMATE<span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> PERCENT_WRITES_ESTIMATE <span style="color: #993333; font-weight: bold;">DESC</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">DECIMAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> CUMUL_PERCENT<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> sqlserver_start_time <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>dm_os_sys_info<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> datetime2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> SINCE<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; TOPT<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> &nbsp;<span style="color: #993333; font-weight: bold;">BY</span> PERCENT_WRITES_ESTIMATE <span style="color: #993333; font-weight: bold;">DESC</span>;</div></div>
<p><em>Un exemple de résultat pour la lecture :</em></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">TABLE_SCHEMA &nbsp; TABLE_NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IO_READS_ESTIMATE &nbsp; &nbsp;PERCENT_READS_ESTIMATE &nbsp;CUMUL_PERCENT &nbsp; SINCE<br />
-------------- --------------------------- -------------------- ----------------------- --------------- ---------------------------<br />
S_GEO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;COMMUNE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 748792 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 55.59 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 55.59 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2018-01-16 16:17:28<br />
S_RTE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TRONCON_ROUTE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 520044 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 38.61 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 94.19 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2018-01-16 16:17:28<br />
S_ADR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CODE_INSEE_CODE_POSTAL &nbsp; &nbsp; &nbsp;42147 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3.13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;97.32 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2018-01-16 16:17:28<br />
S_GEO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DEPARTEMENT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 36057 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.68 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;100.00 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2018-01-16 16:17:28</div></div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Métrique de volumétrie du stockage par table, index et partition</title>
		<link>https://blog.developpez.com/sqlpro/p13171/ms-sql-server/metrique-de-volumetrie-du-stockage-par-table-index-et-partition</link>
		<comments>https://blog.developpez.com/sqlpro/p13171/ms-sql-server/metrique-de-volumetrie-du-stockage-par-table-index-et-partition#comments</comments>
		<pubDate>Wed, 07 Feb 2018 09:19:04 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[métrique]]></category>
		<category><![CDATA[partition]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[stockage]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=789</guid>
		<description><![CDATA[Voici une petite requête complémentaire pour mesurer les volumes stockées par partition, index et tables d&#8217;une base : SELECT s.name AS TABLE_SCHEMA, o.name AS TABLE_NAME, i.name AS INDEX_NAME, &#160; &#160; &#160; &#160;fs.name AS FILEGROUP_NAME, f.name AS FILE_NAME, f.physical_name, p.partition_number, &#160; &#160; &#160; &#160;p.ROWS, p.data_compression_desc, au.total_pages * 8 AS SIZE_TOTAL_KO, &#160; &#160; &#160; &#160;SUM&#40;au.total_pages * 8&#41; [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Voici une petite requête complémentaire pour mesurer les volumes stockées par partition, index et tables d&rsquo;une base :<br />
<span id="more-789"></span></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> s<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> TABLE_SCHEMA<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">,</span> i<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> INDEX_NAME<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;fs<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> FILEGROUP_NAME<span style="color: #66cc66;">,</span> f<span style="color: #66cc66;">.</span>name <span style="color: #993333; font-weight: bold;">AS</span> FILE_NAME<span style="color: #66cc66;">,</span> f<span style="color: #66cc66;">.</span>physical_name<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>partition_number<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;p<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">ROWS</span><span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>data_compression_desc<span style="color: #66cc66;">,</span> au<span style="color: #66cc66;">.</span>total_pages <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">8</span> <span style="color: #993333; font-weight: bold;">AS</span> SIZE_TOTAL_KO<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>au<span style="color: #66cc66;">.</span>total_pages <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span>PARTITION <span style="color: #993333; font-weight: bold;">BY</span> i<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> s<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> SIZE_TOTAL_INDEX_KO<span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>au<span style="color: #66cc66;">.</span>total_pages <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span>PARTITION <span style="color: #993333; font-weight: bold;">BY</span> s<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> o<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> SIZE_TOTAL_TABLE_KO<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; sys<span style="color: #66cc66;">.</span>partitions <span style="color: #993333; font-weight: bold;">AS</span> p<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>allocation_units <span style="color: #993333; font-weight: bold;">AS</span> au<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> p<span style="color: #66cc66;">.</span>hobt_id <span style="color: #66cc66;">=</span> au<span style="color: #66cc66;">.</span>container_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>filegroups <span style="color: #993333; font-weight: bold;">AS</span> fs<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> au<span style="color: #66cc66;">.</span>data_space_id <span style="color: #66cc66;">=</span> fs<span style="color: #66cc66;">.</span>data_space_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>database_files <span style="color: #993333; font-weight: bold;">AS</span> f<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> fs<span style="color: #66cc66;">.</span>data_space_id <span style="color: #66cc66;">=</span> f<span style="color: #66cc66;">.</span>file_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>objects <span style="color: #993333; font-weight: bold;">AS</span> o<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> p<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> o<span style="color: #66cc66;">.</span>object_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>schemas <span style="color: #993333; font-weight: bold;">AS</span> s <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> o<span style="color: #66cc66;">.</span>schema_id <span style="color: #66cc66;">=</span> s<span style="color: #66cc66;">.</span>schema_id<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>indexes <span style="color: #993333; font-weight: bold;">AS</span> i<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> p<span style="color: #66cc66;">.</span>object_id <span style="color: #66cc66;">=</span> i<span style="color: #66cc66;">.</span>object_id <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>index_id <span style="color: #66cc66;">=</span> i<span style="color: #66cc66;">.</span>index_id;</div></div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vérification de la dernière sauvegarde d&#8217;une base</title>
		<link>https://blog.developpez.com/sqlpro/p13170/ms-sql-server/verification-de-la-derniere-sauvegarde-dune-base</link>
		<comments>https://blog.developpez.com/sqlpro/p13170/ms-sql-server/verification-de-la-derniere-sauvegarde-dune-base#comments</comments>
		<pubDate>Thu, 01 Feb 2018 10:51:55 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[verification]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=787</guid>
		<description><![CDATA[Parmi les opérations importantes à systématiser, la vérification de consistance d&#8217;une sauvegarde est une opération à ne pas négliger. Mais compte tendu qu&#8217;une sauvegarde peut être multi-famille (donc répartie sur plusieurs fichiers), multi-support (donc redondées dans plusieurs destinations) ou intégré dans un &#171;&#160;device&#160;&#187; (donc noyée au milieu de plusieurs sauvegarde dans un fichier), la complexité [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Parmi les opérations importantes à systématiser, la vérification de consistance d&rsquo;une sauvegarde est une opération à ne pas négliger. Mais compte tendu qu&rsquo;une sauvegarde peut être multi-famille (donc répartie sur plusieurs fichiers), multi-support (donc redondées dans plusieurs destinations) ou intégré dans un &laquo;&nbsp;device&nbsp;&raquo; (donc noyée au milieu de plusieurs sauvegarde dans un fichier), la complexité augmente d&rsquo;autant. Voici donc une petite procédure pour ce faire&#8230;<br />
<span id="more-787"></span></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURE</span> P_VERIFY_LAST_BACKUP @DB sysname<br />
<span style="color: #993333; font-weight: bold;">AS</span><br />
<br />
<span style="color: #993333; font-weight: bold;">SET</span> NOCOUNT <span style="color: #993333; font-weight: bold;">ON</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @<span style="color: #993333; font-weight: bold;">SQL</span> NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">''</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">WITH</span> <br />
T0 <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> TOP <span style="color: #cc66cc;">1</span> media_set_id<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">POSITION</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; msdb<span style="color: #66cc66;">.</span>dbo<span style="color: #66cc66;">.</span>backupset<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;database_name <span style="color: #66cc66;">=</span> @DB<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> &nbsp;<span style="color: #993333; font-weight: bold;">BY</span> backup_start_date <span style="color: #993333; font-weight: bold;">DESC</span><br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'RESTORE VERIFYONLY FROM DISK = '</span><span style="color: #ff0000;">''</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">+</span> physical_device_name <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">''</span><span style="color: #ff0000;">' WITH FILE = '</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">POSITION</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">';'</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; msdb<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>dbo<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>backupmediafamily<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> mf<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">JOIN</span> T0 <span style="color: #993333; font-weight: bold;">ON</span> mf<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>media_set_id<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> T0<span style="color: #66cc66;">.</span>media_set_id;<br />
<br />
PRINT @<span style="color: #993333; font-weight: bold;">SQL</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">EXEC</span> <span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">GO</span></div></div>
<p>Exemple d&rsquo;utilisation :</p>
<p>EXEC P_VERIFY_LAST_BACKUP &lsquo;master';</p>
<p><a href="http://sqlpro.developpez.com/_fichierSQL/SET_STATISTIS_IO_AGGREGATE.txt" title="Fichier du code" target="_blank">Le code !</a></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
<div id="attachment_590" style="width: 548px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg"><img src="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg" alt="Développez et administrez pour la performance avec SQL Server 2014" width="538" height="652" class="size-full wp-image-590" /></a><p class="wp-caption-text">Développez et administrez pour la performance avec SQL Server 2014</p></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Agrégation des statistiques d&#8217;IO d&#8217;une requête</title>
		<link>https://blog.developpez.com/sqlpro/p13157/ms-sql-server/agregation-des-statistiques-dio-dune-requete</link>
		<comments>https://blog.developpez.com/sqlpro/p13157/ms-sql-server/agregation-des-statistiques-dio-dune-requete#comments</comments>
		<pubDate>Thu, 28 Dec 2017 18:55:58 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[ES]]></category>
		<category><![CDATA[IO]]></category>
		<category><![CDATA[performance requête]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[STATISTICS IO]]></category>
		<category><![CDATA[statistiques entrées sorties]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=778</guid>
		<description><![CDATA[Si le paramétrage SET STATISTICS IO ON de Microsoft SQL Server permet de savoir, table par table les statistiques d&#8217;entrées/sorties (IO pour Input/Output) des requêtes, il n&#8217;est pas toujours facile de s&#8217;y repérer lorsque la requête est complexe et fait appel à de multiples tables. Voici une procédure qui en effectue la synthèse. Rappelons que [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Si le paramétrage <strong>SET STATISTICS IO ON</strong> de Microsoft SQL Server permet de savoir, table par table les statistiques d&rsquo;entrées/sorties (IO pour Input/Output) des requêtes, il n&rsquo;est pas toujours facile de s&rsquo;y repérer lorsque la requête est complexe et fait appel à de multiples tables. Voici une procédure qui en effectue la synthèse.<br />
<span id="more-778"></span><br />
Rappelons que les statistiques IO sont le nombre de pages lues par le moteur SQL pour exécuter une requête. Le paramètre de session STATISTICS IO peut être mis à ON ou OFF. Par défaut il est à OFF. Mis sur ON, il permet, dans SQL Server Management Studio (SSMS), de voir le nombre de pages accédées pour une requête ou un lot de requête. C&rsquo;est une série de message d&rsquo;une ligne commençant par &laquo;&nbsp;Table&#8230;&nbsp;&raquo; qui suit immédiatement le message indiquant le nombre de lignes affectées par la requête.<br />
<div id="attachment_780" style="width: 530px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO.jpg"><img src="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO.jpg" alt="SQL Server onglet message STATISTICS IO" width="520" height="310" class="size-full wp-image-780" /></a><p class="wp-caption-text">SQL Server onglet message STATISTICS IO</p></div> </p>
<p>Néanmoins il est assez difficile de lire tout cela et d&rsquo;en déduire une tendance globale.<br />
Ne serait-ce pas plus intéressante de les présenter de cette manière :<br />
<div id="attachment_781" style="width: 989px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO_GLOBAL.jpg"><img src="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO_GLOBAL.jpg" alt="SQL Server STATISTICS IO aggregate" width="979" height="329" class="size-full wp-image-781" /></a><p class="wp-caption-text">Statistiques IO SQL Server avec totaux et agrégation</p></div></p>
<p>La petite procédure que voici permet justement d&rsquo;effectuer cette tâche. Il suffit de lui passer le texte complet des message d&rsquo;IO et elle vous retournera tout cela, formaté, totalisé et agrégé !</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">USE</span> msdb;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">CREATE</span> SCHEMA S_DBA;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURE</span> S_DBA<span style="color: #66cc66;">.</span>P_SPLIT_STATS_IO @<span style="color: #993333; font-weight: bold;">DATA</span> NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #993333; font-weight: bold;">SET</span> NOCOUNT <span style="color: #993333; font-weight: bold;">ON</span>;<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @LINE NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">SQL</span> NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">''</span>;<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @L <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#40;</span>LINE NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">800</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @T <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">TABLE_NAME</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sysname<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SCAN_COUNT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGICAL_READS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PHYSICAL_READS &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; READ_AHEAD_READS &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOB_LOGICAL_READS &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOB_PHYSICAL_READS &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOB_READ_AHEAD_READS &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
WHILE CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">LEFT</span><span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">,</span> CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @L <span style="color: #993333; font-weight: bold;">SELECT</span> @LINE;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @<span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">RIGHT</span><span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">,</span> LEN<span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @L <span style="color: #993333; font-weight: bold;">SELECT</span> @<span style="color: #993333; font-weight: bold;">DATA</span>;<br />
<span style="color: #993333; font-weight: bold;">DELETE</span> @L <span style="color: #993333; font-weight: bold;">WHERE</span> LINE <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">''</span> <span style="color: #993333; font-weight: bold;">OR</span> LINE <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">LIKE</span> N<span style="color: #ff0000;">'%Table %'</span> <span style="color: #993333; font-weight: bold;">COLLATE</span> French_BIN;<br />
<br />
<span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @L <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;LINE <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%Nombre d'</span><span style="color: #ff0000;">'analyses%'</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #808080; font-style: italic;">--&gt; français</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Table '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">','</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' lectures logiques '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' lectures physiques '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' lectures anticipées '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'de données d'</span><span style="color: #ff0000;">'objets volumineux '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @L <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;LINE <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%Scan count%'</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #808080; font-style: italic;">--&gt; anglais</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Table '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'. Scan count '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">','</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' logical reads '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' physical reads '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' read-ahead reads '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'lob'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'SELECT '</span> <span style="color: #66cc66;">+</span> LINE <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' UNION ALL '</span> <span style="color: #993333; font-weight: bold;">FROM</span> @L;<br />
<span style="color: #993333; font-weight: bold;">SET</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">LEFT</span><span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">,</span> LEN<span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @T<br />
<span style="color: #993333; font-weight: bold;">EXEC</span> <span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">WITH</span> <br />
T <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @T<br />
<span style="color: #993333; font-weight: bold;">UNION</span> <span style="color: #993333; font-weight: bold;">ALL</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'°°° TOTAL °°°'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>SCAN_COUNT<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOGICAL_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>PHYSICAL_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>READ_AHEAD_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOB_LOGICAL_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOB_PHYSICAL_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOB_READ_AHEAD_READS<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @T<br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <br />
<span style="color: #993333; font-weight: bold;">FROM</span> T<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #993333; font-weight: bold;">CASE</span> <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'°°° TOTAL °°°'</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">END</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LOGICAL_READS <span style="color: #993333; font-weight: bold;">DESC</span>; &nbsp;<br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>SCAN_COUNT<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TOTAL_SCANS<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOGICAL_READS <span style="color: #66cc66;">+</span> LOB_LOGICAL_READS<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TOTAL_LOGICAL_READS<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>PHYSICAL_READS <span style="color: #66cc66;">+</span> READ_AHEAD_READS <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LOB_PHYSICAL_READS <span style="color: #66cc66;">+</span> LOB_READ_AHEAD_READS<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TOTAL_PHYSICAL_READS<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @T;<br />
<br />
<span style="color: #993333; font-weight: bold;">GO</span></div></div>
<p><strong>Exemple d&rsquo;utilisation :</strong></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">EXECUTE</span> msdb<span style="color: #66cc66;">.</span>S_DBA<span style="color: #66cc66;">.</span>P_SPLIT_STATS_IO <span style="color: #ff0000;">'Table '</span><span style="color: #ff0000;">'PARAM_EAC'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 13, lectures logiques 26, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'Worktable'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 0, lectures logiques 0, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'VAL_PARAM_EAC'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 1, lectures logiques 59, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'ESP'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 31, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'TL_EXP_COOP'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 178, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'UC'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 5633, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'TL_PP_UC'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 1254, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'PG'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 85289, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'Worktable'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 0, lectures logiques 0, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'PG'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 1, lectures logiques 437, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'PP'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 7271, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'EXP'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 1996, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'VAR'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 866, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.'</span></div></div>
<p>Le résultat :<br />
<div id="attachment_782" style="width: 986px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO_GLOBAL-results.jpg"><img src="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO_GLOBAL-results.jpg" alt="Les statistiques d&#039;IO d&#039;une requête, sus forme tabulaire, totalisés et agrégés" width="976" height="337" class="size-full wp-image-782" /></a><p class="wp-caption-text">Les statistiques d&rsquo;IO d&rsquo;une requête, sous forme tabulaire, totalisés et agrégés</p></div></p>
<p><strong>QUELQUES EXPLICATIONS SUR LES MÉTRIQUES</strong></p>
<li><strong>analyses</strong> (scan count) : nombre de fois ou l&rsquo;exécuteur de requête a du pénétrer dans un index de la table ou dans la table (en cas de parallélisme, autant de fois que de threads&#8230;)</li>
<li><strong>lectures logiques</strong> (logical reads) : nombre de pages lues en RAM</li>
<li><strong>lectures physiques</strong> (physical reads) : nombre de pages lues depuis le disque (avec transfert en RAM) en mode aléatoire.</li>
<li><strong>lectures anticipées</strong> (read-ahead physical read) : nombre de pages lues depuis le disque (avec transfert en RAM) en mode continu.</li>
<li>&#8230;<strong>d&rsquo;objets volumineux</strong> (lob &#8230;) : nombre de pages &#8230; pour les &laquo;&nbsp;Large OBjects&nbsp;&raquo;.
</li>
<p><strong>NOTA </strong>: cet outil fonctionne que votre serveur soit en anglais ou français.</p>
<p><strong>LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE</strong><br />
<a href="http://sqlpro.developpez.com/_fichierSQL/SET_STATISTIS_IO_AGGREGATE.txt" title="Fichier du code" target="_blank">Le code !</a></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
<div id="attachment_590" style="width: 548px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg"><img src="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg" alt="Développez et administrez pour la performance avec SQL Server 2014" width="538" height="652" class="size-full wp-image-590" /></a><p class="wp-caption-text">Développez et administrez pour la performance avec SQL Server 2014</p></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
