|
|
|
How to avoid Using join buffer (Block Nested Loop)?
|
|||
|---|---|---|---|
|
#18+
dear experts, i have an interesting issue that i cant resolve at moment. Using: MySQL 5.6.12 + default my.cnf parameters Centos 6.4 Tables: Код: sql 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. First query is : Код: sql 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. Explain plan looks good: Код: sql 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. But when i add another clause to where: Код: sql 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. i takes approximately 25-29 seconds. Thinking that this query is a part of big one it will take much more time to execute. So i decided to break down into simple queries and then combine all optimization techniques together and need here your helps. Explain plan became worse than ever: Код: sql 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. So is there any tips to avoid Using join buffer (Block Nested Loop) especially for my purpose? Need any help,suggest. thanks. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.07.2013, 00:02:33 |
|
||
|
How to avoid Using join buffer (Block Nested Loop)?
|
|||
|---|---|---|---|
|
#18+
Тут плох не сам "Using join buffer" (он лишь следствие), а невозможность использования индекса для соединения таблиц. Методика, в общем-то, стандартная - "развалить" запрос на два с заменой OR на UNION/UNION ALL. Примерно так: Код: sql 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. Правда, из-за изначальной странности логики исходного запроса тут образуется странное место в виде декартового произведения во второй части запроса. Тут уж нужно по предметной области смотреть, насколько это правильно. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.07.2013, 00:31:21 |
|
||
|
How to avoid Using join buffer (Block Nested Loop)?
|
|||
|---|---|---|---|
|
#18+
Wow ;) Works greatly. Thanks. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.07.2013, 00:55:48 |
|
||
|
How to avoid Using join buffer (Block Nested Loop)?
|
|||
|---|---|---|---|
|
#18+
Кстати, этот метод описан в доке: http://dev.mysql.com/doc/refman/5.5/en/how-to-avoid-table-scan.html Minimize the OR keywords in your WHERE clauses. If there is no index that helps to locate the values on both sides of the OR, any row could potentially be part of the result set, so all rows must be tested, and that requires a full table scan. If you have one index that helps to optimize one side of an OR query, and a different index that helps to optimize the other side, use a UNION operator to run separate fast queries and merge the results afterward. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.07.2013, 01:26:11 |
|
||
|
|

start [/forum/topic.php?fid=47&fpage=217&tid=1836391]: |
0ms |
get settings: |
9ms |
get forum list: |
13ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
45ms |
get topic data: |
10ms |
get forum data: |
2ms |
get page messages: |
35ms |
get tp. blocked users: |
1ms |
| others: | 238ms |
| total: | 359ms |

| 0 / 0 |
