That query is slow (about 1.5 seconds). It should simply return a list of posts
SELECT SQL_NO_CACHE p.id FROM 1_posts p LEFT JOIN 1_topics t ON (p.cid = t.cid AND p.container = t.id) WHERE t.cid = 1010699;
EXPLAIN gives:
+----+-------------+-------+------+-----------------------+-----------+---------+---------------+------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+-----------------------+-----------+---------+---------------+------+--------------------------+ | 1 | SIMPLE | t | ref | PRIMARY,cid | cid | 4 | const | 216 | Using where; Using index | | 1 | SIMPLE | p | ref | PRIMARY,cid,container | container | 4 | forumdb.t.id | 49 | Using where | +----+-------------+-------+------+-----------------------+-----------+---------+---------------+------+--------------------------+
Note that SQL_NO_CACHE is there for testing purposes only.
Partial structure of tables:
1_posts:
mysql> explain 1_posts; +----------------+----------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+----------------------+------+-----+---------+----------------+ | cid | int(20) unsigned | NO | PRI | 0 | | | id | int(20) unsigned | NO | PRI | NULL | auto_increment | | container | int(20) unsigned | NO | MUL | 0 | |
mysql> explain 1_topics; +-----------------+----------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+----------------------+------+-----+---------+----------------+ | cid | int(10) unsigned | NO | PRI | 0 | | | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | container | int(20) | NO | MUL | 0 | |
Table posts has many millions of entries, topics about a 500k.
cid and id, on both tables are primary combo keys. cid means Community ID. These tables host many different forums.
Thank you for any help you could give with speeding this stuff up.
Using temporary; Using filesort
. – Vatevt.cid = 1010699
is an edge case that has a lot more rows than the average (which explain shows). – Vatev