Jump to content

Primary Key On Temporary Table


The Little Guy

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.