powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / MySQL [игнор отключен] [закрыт для гостей] / Разница в запросах. Один зависает, а другой нет.
2 сообщений из 2, страница 1 из 1
Разница в запросах. Один зависает, а другой нет.
    #38405338
Vladimit04
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Привет. Вот нужно было селектануть из базы, написал запрос:
Код: php
1.
2.
3.
4.
5.
6.
7.
8.
9.
select a.id,a.item from table1 a, table2 b where a.item not in (b.entry);

explain
+----+-------------+-------+-------+---------------+---------+---------+------+--------+---------------------------------------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows   | Extra                                       |
+----+-------------+-------+-------+---------------+---------+---------+------+--------+---------------------------------------------+
|  1 | SIMPLE      | b     | index | NULL          | PRIMARY | 4       | NULL |  23916 | Using index                                 |
|  1 | SIMPLE      | a     | index | NULL          | PRIMARY | 6       | NULL | 265195 | Using where; Using index; Using join buffer |
+----+-------------+-------+-------+---------------+---------+---------+------+--------+---------------------------------------------+


- выполняю, а он зависает.

Написал по-другому запрос:
Код: php
1.
2.
3.
4.
5.
6.
7.
8.
9.
select id,item from table1 where item not in (select entry from table2);

explain
+----+--------------------+------------------------+-----------------+---------------+---------+---------+------+--------+--------------------------+
| id | select_type        | table                  | type            | possible_keys | key     | key_len | ref  | rows   | Extra                    |
+----+--------------------+------------------------+-----------------+---------------+---------+---------+------+--------+--------------------------+
|  1 | PRIMARY            | table1                 | index           | NULL          | PRIMARY | 6       | NULL | 265195 | Using where; Using index |
|  2 | DEPENDENT SUBQUERY | table2                 | unique_subquery | PRIMARY       | PRIMARY | 4       | func |      1 | Using index; Using where |
+----+--------------------+------------------------+-----------------+---------------+---------+---------+------+--------+--------------------------+


- выполнился быстро.

Почему первый запрос зависает?
...
Рейтинг: 0 / 0
Разница в запросах. Один зависает, а другой нет.
    #38405359
Shahriyar.R
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Vladimit04,

First of all check using join buffer clause:

Using join buffer

Tables from earlier joins are read in portions into the join buffer, and then their rows are used from the buffer to perform the join with the current table.


Here is great article for this:

http://s.petrunia.net/blog/?p=18


Second one the examined row count:
From 1st query it will examine 23916+265195 rows, but 2nd query will examine 265195+1.
Using Join Buffer indicates that 23916 rows(table b) firstly are reading to join buffer then for each of them MySQL performs join with "table a"...surely it must take long time than exact match and join (2nd query)...

Also you can read about "unique_subquery" clause..it is kind of great optimization for IN subqueries:

jointype_unique_subquery

unique_subquery is just an index lookup function that replaces the subquery completely for better efficiency.
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / MySQL [игнор отключен] [закрыт для гостей] / Разница в запросах. Один зависает, а другой нет.
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]