<tfoot id='cuO4W'></tfoot>
      <bdo id='cuO4W'></bdo><ul id='cuO4W'></ul>

  • <small id='cuO4W'></small><noframes id='cuO4W'>

      1. <i id='cuO4W'><tr id='cuO4W'><dt id='cuO4W'><q id='cuO4W'><span id='cuO4W'><b id='cuO4W'><form id='cuO4W'><ins id='cuO4W'></ins><ul id='cuO4W'></ul><sub id='cuO4W'></sub></form><legend id='cuO4W'></legend><bdo id='cuO4W'><pre id='cuO4W'><center id='cuO4W'></center></pre></bdo></b><th id='cuO4W'></th></span></q></dt></tr></i><div id='cuO4W'><tfoot id='cuO4W'></tfoot><dl id='cuO4W'><fieldset id='cuO4W'></fieldset></dl></div>
        <legend id='cuO4W'><style id='cuO4W'><dir id='cuO4W'><q id='cuO4W'></q></dir></style></legend>

        有人可以推荐一个关于 MySQL 索引的好教程,特别是在连接期间在 order by 子句中使用时?

        时间:2023-10-09
              <bdo id='MK7SR'></bdo><ul id='MK7SR'></ul>
                <tbody id='MK7SR'></tbody>
            • <small id='MK7SR'></small><noframes id='MK7SR'>

              <i id='MK7SR'><tr id='MK7SR'><dt id='MK7SR'><q id='MK7SR'><span id='MK7SR'><b id='MK7SR'><form id='MK7SR'><ins id='MK7SR'></ins><ul id='MK7SR'></ul><sub id='MK7SR'></sub></form><legend id='MK7SR'></legend><bdo id='MK7SR'><pre id='MK7SR'><center id='MK7SR'></center></pre></bdo></b><th id='MK7SR'></th></span></q></dt></tr></i><div id='MK7SR'><tfoot id='MK7SR'></tfoot><dl id='MK7SR'><fieldset id='MK7SR'></fieldset></dl></div>

              1. <legend id='MK7SR'><style id='MK7SR'><dir id='MK7SR'><q id='MK7SR'></q></dir></style></legend>

                <tfoot id='MK7SR'></tfoot>
                  本文介绍了有人可以推荐一个关于 MySQL 索引的好教程,特别是在连接期间在 order by 子句中使用时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我可以尝试发布并解释我正在尝试运行的确切查询,但我会遵循古老的格言,给一个人一条鱼,他会吃一天,教一个人鱼,他会吃一辈子."SQL 优化似乎非常特定于查询,即使您可以为我解决这个特定的查询,我将来也将不得不编写更多查询,而且我想了解索引的工作原理总的来说.

                  I could try to post and explain the exact query I'm trying to run, but I'm going by the old adage of, "give a man a fish and he'll eat for a day, teach a man to fish and he'll eat for the rest of his life." SQL optimization seems to be very query-specific, and even if you could solve this one particular query for me, I'm going to have to write many more queries in the future, and I'd like to be educated on how indexes work in general.

                  不过,这里是我当前问题的简要说明.我有一个连接三个表并在 0.2 秒内运行的查询.惊人的.我添加了一个order by"子句,它在 4 分 30 秒内运行.糟透了.我对一张表进行了非规范化处理,这样就少了一个连接,到处添加索引,现在查询在…… 20 分钟内运行.我勒个去?最后,我根本不使用连接,而是使用带有where id in (...) order by"的子查询,现在它在 1.5 秒内运行.还算体面.以上帝的名义发生了什么?我觉得如果我真的了解索引的作用,我就能写出一些非常好的 SQL.

                  Still, here's a quick description of my current problem. I have a query that joins three tables and runs in 0.2 seconds flat. Awesome. I add an "order by" clause and it runs in 4 minutes and 30 seconds. Sucky. I denormalize one table so there is one fewer join, add indexes everywhere, and now the query runs in... 20 minutes. What the hell? Finally, I don't use a join at all, but rather a subquery with "where id in (...) order by" and now it runs in 1.5 seconds. Pretty decent. What in God's name is going on? I feel like if I actually understood what indexes were doing I could write some really good SQL.

                  有人知道一些好的教程吗?谢谢!

                  Anybody know some good tutorials? Thanks!

                  推荐答案

                  不是一个很吸引人的答案,但我找到了官方文档来提供很好的背景:

                  Not a very riveting answer, but I've found the official docs to give good background:

                  http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html

                  您可以尝试一些事情(假设您已经使用 EXPLAIN 分析了优化器路径):

                  A few things you could try (assuming you've already analysed the optimizer path with EXPLAIN):

                  • 尝试使用 USE INDEX 运行查询(<你的索引名称在这里>) 看看你的索引使用实际上会提供您期望的性能.
                  • 确保列的顺序在任何综合指数中都反映了您期望使用该索引的方式(对不起,如果这有点含糊,但是MySql 索引使用可能有点古怪有时).
                  • Try running the query with USE INDEX (<your index name here>) to see if your index usage would actually provide the performance you expect.
                  • Make sure the order of your columns in any composite index reflects the way you expect that index to be used (sorry if that's a bit vague, but MySql index usage can be a bit quirky at times).

                  这篇关于有人可以推荐一个关于 MySQL 索引的好教程,特别是在连接期间在 order by 子句中使用时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:这个(规范化的)数据库结构是否允许我按照我的意图按标签进行搜索? 下一篇:MySQL FULL JOIN 不工作,但 RIGHT 和 LEFT 连接工作

                  相关文章

                  <small id='JHGyE'></small><noframes id='JHGyE'>

                  <tfoot id='JHGyE'></tfoot>
                  1. <legend id='JHGyE'><style id='JHGyE'><dir id='JHGyE'><q id='JHGyE'></q></dir></style></legend>
                      <bdo id='JHGyE'></bdo><ul id='JHGyE'></ul>
                  2. <i id='JHGyE'><tr id='JHGyE'><dt id='JHGyE'><q id='JHGyE'><span id='JHGyE'><b id='JHGyE'><form id='JHGyE'><ins id='JHGyE'></ins><ul id='JHGyE'></ul><sub id='JHGyE'></sub></form><legend id='JHGyE'></legend><bdo id='JHGyE'><pre id='JHGyE'><center id='JHGyE'></center></pre></bdo></b><th id='JHGyE'></th></span></q></dt></tr></i><div id='JHGyE'><tfoot id='JHGyE'></tfoot><dl id='JHGyE'><fieldset id='JHGyE'></fieldset></dl></div>