The Little Guy Posted November 20, 2011 Share Posted November 20, 2011 I am trying to add a primary key on a temporary table, but it isn't working. Here are the following queries: create temporary table rt_results (document_id int, weight int, primary key(document_id)); insert into rt_results values(1, 123); explain select dom.domain_id, domain, url, title, content from rt_results rt left join documents doc on (rt.document_id = doc.document_id) left join urls u on(doc.document_id = u.document_id) left join domains dom on(doc.domain_id = dom.domain_id) order by rt.weight desc; And here is the explain result: +----+-------------+-------+--------+---------------+-------------+---------+------------------------+------+----------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+--------+---------------+-------------+---------+------------------------+------+----------------+ | 1 | SIMPLE | rt | ALL | NULL | NULL | NULL | NULL | 1 | Using filesort | | 1 | SIMPLE | doc | eq_ref | PRIMARY | PRIMARY | 4 | search.rt.document_id | 1 | | | 1 | SIMPLE | u | ref | document_id | document_id | 4 | search.doc.document_id | 1 | | | 1 | SIMPLE | dom | eq_ref | PRIMARY | PRIMARY | 4 | search.doc.domain_id | 1 | | +----+-------------+-------+--------+---------------+-------------+---------+------------------------+------+----------------+ 4 rows in set (0.00 sec) Why does it say "NULL" for the key? I added a primary key to rt.document_id so shouldn't it use it? It seem logical that it would to me. Thanks! Link to comment https://forums.phpfreaks.com/topic/251491-primary-key-on-temporary-table/ Share on other sites More sharing options...
fenway Posted November 20, 2011 Share Posted November 20, 2011 It says "NULL" because you have no where clause -- so it has to read all the rows from one of the tables. Link to comment https://forums.phpfreaks.com/topic/251491-primary-key-on-temporary-table/#findComment-1289822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.