1
学习MySQL(innodb)我试图用3个表编写一个twitter应用程序:users2,follow2和tweets2。MySQL优化 - 遍历WHERE foo IN子选择的整个表?
做一个解释如下显示可能被触摸的tweets2中的所有行。这是否准确?如果你打算做一个WHERE用户名IN(select),我会假定给定的用户名是索引的。MySQL将检索子选择子句并直接转到tweets2中有这些用户名的行。
explain select username, timestamp, tweet
from tweets2
where username in
(select followee from follow2 where follower='user1')
order by timestamp desc;
继承人的SQLAlchemy的代码创建表:
users = Table('users2', metadata,
Column('username', String(16), index=True),
Column('email', String(256)),
)
follow = Table('follow2', metadata,
Column('follower', String(16), index=True),
Column('followee', String(16), index=True),
)
tweets = Table('tweets2', metadata,
Column('id', Integer, primary_key=True),
Column('username', String(16), index=True),
Column('timestamp', BigInteger),
Column('tweet', String(200)),
)