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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.