| 156 | | SELECT COUNT(*) FROM table WHERE status = 'something' |
|---|
| 157 | | |
|---|
| 158 | | PostgreSQL, MySQL, and most other database implementations will take advantage of available indexes against the restricted field(s) to limit how many records must be counted, which can greatly accelerate such queries. PostgreSQL will still need to read the resulting rows to verify that they exist; other database systems many only need to reference the index in this situation. |
|---|
| 159 | | |
|---|
| 160 | | One popular approach for applications that need a row count but can tolerate it not including transactions that are in the middle of being committed is to use a trigger-based mechanism to count the rows in the table. In PostgreSQL, another alternative when only an approximate count is needed is to use the reltuples field from the pg_class catalog table. |
|---|
| 161 | | Join Complexity |
|---|
| 162 | | PostgreSQL uses cost-based query optimization methods in order to get good performance for many different types of joins. Query costs are assessed based on planner statistics collected when tables are analyzed combined with adjustable planner costs, and advanced features such as the Genetic Query Optimizer allow optimizing even very complicated joins efficiently. |
|---|
| 163 | | |
|---|
| 164 | | MySQL doesn't have this level of sophistication in its planner, and the tunables for Controlling Query Optimizer Performance are crude. Developers instead do things like explicitly provide index hints to make sure joins are executed correctly. To make this task easier, MySQL provides a Query Profiler that is easier to work with than typical EXPLAIN data. Regardless of hinting, subselect optimization is a known weak spot in MySQL. There is also a fairly serious subquery null handling bug in MySQL 5.0 (which at this time appears to be still present in 5.1). |
|---|
| 165 | | |
|---|
| 166 | | Finding order in execution provides several comparisons of how the two databases handle queries differently. Because of its more robust automatic optimization, PostgreSQL usually does a better job of handling complicated joins than MySQL--but only if the planner is properly configured (setting the effective_cache_size tunable too small is one common mistake) and statistics about the tables are kept up to date (typically via auto-vacuum). The fact that you must give the PostgreSQL optimizer correct information to work with, and can't explicitly control which join it uses, is a somewhat controversial design decision. The core PostgreSQL developers feel that it's more important to focus on improving the optimizer so it works correctly in all cases instead of just allowing queries to hint at a plan as a workaround for problems. |
|---|
| 167 | | |
|---|
| 168 | | There are some add-on tools some find useful for exploring the PostgreSQL planner. pgAdmin includes an explain plan viewer (sample). Another option is Visual Explain, originally a RedHat component that has been kept current and improved by Enterprise DB. It comes bundled with the EnterpriseDB Advanced Server package and can be built to run against other PostgreSQL installations using the source code to their Developer Studio package. |
|---|
| 169 | | Credits and Feedback |
|---|
| 170 | | |
|---|
| 171 | | This document was written by Greg Smith with substantial contributions by Christopher Browne, Lukas Kahwe Smith, and other members of the PostgreSQL Advocacy mailing list. Some of the references linked to by this document point to articles also written by these authors. |
|---|
| 172 | | |
|---|
| 173 | | Corrections, suggestions, flames, and similar feedback should be addressed to Greg, an independent consultant whose only affiliation with The PostgreSQL Global Development Group consists of submitting patches to improve the upcoming 8.3 release. He feels that PostgreSQL stands on its own merits and comparisons with MySQL should be as factual as possible, and feedback will be treated accordingly. |
|---|
| | 156 | // SELECT COUNT(*) FROM table WHERE status = 'something' |
|---|
| | 157 | SELECT COUNT(*) FROM table WHERE status = 'quelque chose' |
|---|
| | 158 | |
|---|
| | 159 | //PostgreSQL, MySQL, and most other database implementations will take advantage of available indexes against |
|---|
| | 160 | //the restricted field(s) to limit how many records must be counted, which can greatly accelerate such queries. |
|---|
| | 161 | //PostgreSQL will still need to read the resulting rows to verify that they exist; other database systems |
|---|
| | 162 | //many only need to reference the index in this situation. |
|---|
| | 163 | PostgreSQL, MySQL, et beaucoup d'autres implémentations de base de données tireront profil de la disponibilités des |
|---|
| | 164 | indexes pour le champs restreint afin de limiter le nombre d'enregistrement devant être comptés, ce qui accelère |
|---|
| | 165 | grandement de telles requêtes. |
|---|
| | 166 | |
|---|
| | 167 | //One popular approach for applications that need a row count but can tolerate it not including transactions that are |
|---|
| | 168 | //in the middle of being committed is to use a trigger-based mechanism to count the rows in the table. In PostgreSQL, |
|---|
| | 169 | //another alternative when only an approximate count is needed is to use the reltuples field from the pg_class catalog table. |
|---|
| | 170 | Une approche apprécié pour les applications qui ont besoin de compter les lignes mais ... |
|---|
| | 171 | |
|---|
| | 172 | //Join Complexity |
|---|
| | 173 | Jointure complèxe |
|---|
| | 174 | |
|---|
| | 175 | //PostgreSQL uses cost-based query optimization methods in order to get good performance for many different types of |
|---|
| | 176 | //joins. Query costs are assessed based on planner statistics collected when tables are analyzed combined |
|---|
| | 177 | //with adjustable planner costs, and advanced features such as the Genetic Query Optimizer allow optimizing |
|---|
| | 178 | //even very complicated joins efficiently. |
|---|
| | 179 | PostgreSQL utilise une méthode économique d'optimisation des requêtes afin d'obtenir de bonne performances pour les |
|---|
| | 180 | différents types de jointures. |
|---|
| | 181 | Les requêtes coûteuses sont évalués et basé sur des statistiques du planificateur recueillies quand les tables |
|---|
| | 182 | sont analysées et combiner avec l'ajustements des coûts du planificateur, et les fonctionnalités avancées tel que le |
|---|
| | 183 | "Genetix Query Optimizer" permettant l'optimisation efficace de jointûres très compliqués. |
|---|
| | 184 | |
|---|
| | 185 | //MySQL doesn't have this level of sophistication in its planner, and the tunables for Controlling Query Optimizer |
|---|
| | 186 | //Performance are crude. Developers instead do things like explicitly provide index hints to make sure joins |
|---|
| | 187 | //are executed correctly. To make this task easier, MySQL provides a Query Profiler that is easier to work with than |
|---|
| | 188 | //typical EXPLAIN data. Regardless of hinting, subselect optimization is a known weak spot in MySQL. |
|---|
| | 189 | //There is also a fairly serious subquery null handling bug in MySQL 5.0 |
|---|
| | 190 | //(which at this time appears to be still present in 5.1). |
|---|
| | 191 | |
|---|
| | 192 | |
|---|
| | 193 | |
|---|
| | 194 | //Finding order in execution provides several comparisons of how the two databases handle queries differently. |
|---|
| | 195 | //Because of its more robust automatic optimization, PostgreSQL usually does a better job of handling complicated |
|---|
| | 196 | //joins than MySQL--but only if the planner is properly configured (setting the effective_cache_size tunable too small |
|---|
| | 197 | //is one common mistake) and statistics about the tables are kept up to date (typically via auto-vacuum). |
|---|
| | 198 | //The fact that you must give the PostgreSQL optimizer correct information to work with, and can't explicitly control |
|---|
| | 199 | //which join it uses, is a somewhat controversial design decision. The core PostgreSQL developers feel that it's more |
|---|
| | 200 | //important to focus on improving the optimizer so it works correctly in all cases instead of just allowing queries |
|---|
| | 201 | //to hint at a plan as a workaround for problems. |
|---|
| | 202 | |
|---|
| | 203 | |
|---|
| | 204 | |
|---|
| | 205 | // There are some add-on tools some find useful for exploring the PostgreSQL planner. pgAdmin includes an explain plan |
|---|
| | 206 | // viewer (sample). Another option is Visual Explain, originally a RedHat component that has been kept current and |
|---|
| | 207 | // improved by Enterprise DB. It comes bundled with the EnterpriseDB Advanced Server package and can be built to run |
|---|
| | 208 | // against other PostgreSQL installations using the source code to their Developer Studio package. |
|---|
| | 209 | Il y'a quelque outils complémentaires pour explorer le planificateur de PostgreSQL. pgAdmin inclus une visionneuse |
|---|
| | 210 | de plan d'exécution. Une autre option est "Visual Explain", à l'origine un composant de RedHat qui est maintenant |
|---|
| | 211 | maintenu par Enterprise DB. Il est inclus dans l'offre EnterpriseDB Advanced Server et peut être compiler avec une |
|---|
| | 212 | installation de PostgreSQL en utilisant le code source du paquet "Developer Studio". |
|---|
| | 213 | |
|---|
| | 214 | |
|---|
| | 215 | //Credits and Feedback |
|---|
| | 216 | Remerciements et Remarques |
|---|
| | 217 | |
|---|
| | 218 | // This document was written by Greg Smith with substantial contributions by Christopher Browne, Lukas Kahwe Smith, |
|---|
| | 219 | // and other members of the PostgreSQL Advocacy mailing list. Some of the references linked to by this document |
|---|
| | 220 | // point to articles also written by these authors. |
|---|
| | 221 | Ce document à été écrit par Greg Smith incluant de pertinante contribution de Christopher Browne, Lukas Kahwe Smith, |
|---|
| | 222 | et beaucoup d'autres membres de la liste de diffusion Advocacy. Quelques unes de ces références citées dans ce document |
|---|
| | 223 | proviennent d'articles qui ont été écrit par ces mêmes auteur. |
|---|
| | 224 | |
|---|
| | 225 | // Corrections, suggestions, flames, and similar feedback should be addressed to Greg, an independent consultant |
|---|
| | 226 | // whose only affiliation with The PostgreSQL Global Development Group consists of submitting patches to improve |
|---|
| | 227 | // the upcoming 8.3 release. He feels that PostgreSQL stands on its own merits and comparisons with MySQL should be |
|---|
| | 228 | // as factual as possible, and feedback will be treated accordingly. |
|---|
| | 229 | Corrections, suggestions, coup de gueule, et autres remarques peuvent être adresser à Greg, un consultant indépendant |
|---|
| | 230 | dont le seul lien avec l'équipe de développement mondial consiste à soumettre des patchs pour améliorer la future |
|---|
| | 231 | version 8.3 |
|---|