概要:左の結合は私が望むものですが、それらは非常に遅いですか?
Iは、1)加入者、BIOS、およびshirtsizes 3つのテーブルを持っていると私はバイオのない加入者を見つける必要があるかのテーブルが
加入者ようなレイアウトされて
shirtsizes
| season_id | user_id |
バイオ
| bio_id | user_id |
なしバイオた場合(、シャツは
| bio_id | shirtsize |
のサイズと私はバイオやshirtsizeを持っていないすべてのユーザーを見つける必要があります。特定のシーズンの関係を介してshirtsizeしないでください)。
私はもともとのようなクエリを書いた:
SELECT *
FROM subscribers s
LEFT JOIN bio b ON b.user_id = subscribers.user_id
LEFT JOIN shirtsizes ON shirtsize.bio_id = bio.bio_id
WHERE s.season_id = 185181 AND (bio.bio_id IS NULL OR shirtsize.size IS NULL);
今完了するまでに10秒を取っています。
私は、それが合理的にプリフォームされるように、クエリ(または場合によっては問題)をどのように再構築できるか疑問に思っています。ここで
は、mysqlは説明している:(OGUの加入者を=、B =バイオ、TN = shirtshize)
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+-------------+--------+-------------+
| 1 | SIMPLE | ogu | ref | PRIMARY | PRIMARY | 4 | const | 133 | Using where |
| 1 | SIMPLE | b | index | NULL | PRIMARY | 8 | NULL | 187644 | Using index |
| 1 | SIMPLE | tn | ref | nid | nid | 4 | waka2.b.nid | 1 | Using where |
上記かなりサニタイズされ、ここでrealz情報です:
mysql> DESCRIBE subscribers
+-----------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+-------+
| subscribers | int(11) | NO | PRI | | |
| uid | int(11) | NO | PRI | | |
mysql> DESCRIBE bio;
+-------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| bio_id | int(10) unsigned | NO | PRI | 0 | |
| uid | int(10) unsigned | NO | PRI | 0 | |
mysql> DESCRIBE shirtsize;
+-------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| bio_id | int(10) unsigned | NO | PRI | 0 | |
| shirtsize | int(10) unsigned | NO | PRI | 0 | |
と実際のクエリは次のようになります。
SELECT ogu.nid, ogu.is_active, ogu.uid, b.nid AS bio_node, tn.nid AS size
FROM og_uid ogu
LEFT JOIN bio b ON b.uid = ogu.uid
LEFT JOIN term_node tn ON tn.nid = b.nid
WHERE ogu.nid = 185033 AND ogu.is_admin = 0
AND (b.nid IS NULL OR tn.tid IS NULL)
nidはseason_idまたはbio_id(型付き)です。 term_nodeはshirtsizeになります
これらのテーブルにはインデックスがありますか? –
@jskulksi:各テーブルに「SHOW CREATE TABLE」の出力を含めることができますか? –