Sql *在EXISTS查询中,通常略快于SELECT 1/SELECT NULL/etc。但是是的,使用EXISTS通常比join快,但并不总是,它是在每个场景中尝试的一种武器…“我从不使用join或unions”当然,您确实使用join。来自订户s、bio b
Sql *在EXISTS查询中,通常略快于SELECT 1/SELECT NULL/etc。但是是的,使用EXISTS通常比join快,但并不总是,它是在每个场景中尝试的一种武器…“我从不使用join或unions”当然,您确实使用join。来自订户s、bio b,sql,optimization,join,Sql,Optimization,Join,*在EXISTS查询中,通常略快于SELECT 1/SELECT NULL/etc。但是是的,使用EXISTS通常比join快,但并不总是,它是在每个场景中尝试的一种武器…“我从不使用join或unions”当然,您确实使用join。来自订户s、bio b、shirtsizes sh,其中s.season_id=185181和shirtsize.bio_id=bio.bio_id和b.user_id=s.user_id是一组连接。它使用的是过时的连接样式,但它仍然是一个连接。我想写“我避免使用连
*在EXISTS查询中,通常略快于SELECT 1/SELECT NULL/etc。但是是的,使用EXISTS通常比join快,但并不总是,它是在每个场景中尝试的一种武器…“我从不使用join或unions”当然,您确实使用join。来自订户s、bio b、shirtsizes sh,其中s.season_id=185181和shirtsize.bio_id=bio.bio_id和b.user_id=s.user_id是一组连接。它使用的是过时的连接样式,但它仍然是一个连接。我想写“我避免使用连接语法,我从不使用联合”会更正确。没有理由在子查询中使用DISTINCT。我想这就是我相信贡献的模块具有正确索引的原因。谢谢
| season_id | user_id |
| bio_id | user_id |
| bio_id | 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);
| 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 |
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)
SELECT s.user_id
FROM subscribers s
LEFT JOIN bio b ON b.user_id = s.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);
(SELECT s.user_id FROM subscribers s WHERE s.season_id = 185181)
UNION
(SELECT b.user_id, b.bio_id FROM bio b WHERE bio.bio_id IS NULL)
UNION
(SELECT shirtsizes.bio_id FROM shirtsizes WHERE shirtsizes.size is NULL)
SELECT *
FROM subscribers s, bio b, shirtsizes sh
WHERE s.season_id = 185181
AND shirtsize.bio_id = bio.bio_id
AND b.user_id = s.user_id
AND (bio.bio_id IS NULL
OR
shirtsize.size IS NULL);
SELECT s.user_id
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);
select *
from subscribers
where s.season_id = 185181
and not exists (select *
from bio join shirtsizes on bio.bio_id = shirtsizes.bio_id
where bio.user_id = subscribers.user_id)
SELECT *
FROM Subscribers
WHERE season_id = 185181
AND user_id NOT IN
(SELECT DISTINCT s.user_id
FROM subscribers s
JOIN bios b ON s.user_id = b.user_id
JOIN shirtsizes z ON b.bio_id = z.bio_id
WHERE s.season_id = 185181
)
select * from subscribers where user_id not in (
select user_id from bio where bio_id not in (
select bio_id from shirt_sizes
)
) and season_id=185181
select uid
from bio
inner join shirtsizes
on shirtsizes.bio_id = bio.bio_id
select *
from subscribers s
left outer join (select uid
from bio
inner join shirtsizes
on shirtsizes.bio_id = bio.bio_id) x
on x.uid = s.uid
where s.season_id = 185181
and x.uid is null
SELECT *
FROM (
SELECT ogu.nid, ogu.is_active, ogu.uid,
(
SELECT 1
FROM bio b, term_node tn
WHERE b.uid = ogu.uid
AND tn.nid = b.nid
LIMIT 1
) AS ex
FROM og_uid ogu
WHERE ogu.nid = 185033
AND ogu.is_admin = 0
) ogu1
WHERE ex IS NULL