English 中文(简体)
加入指数
原标题:Using index on join

利用EXPLAIN处理以下询问:

SELECT cha.cid AS cid,
       cha.data AS dl
FROM cha, c_users
WHERE uid = 808
AND cha.cid = c_users.cid;
  1. it does a full scan on cha table
  2. uses the multi column index(cid,uid) from c_users.

为什么不使用<代码>cha的主要指数,而是用完整的表格扫描。 是否有更好的办法选择询问/表。

Edit: cha.cid is my primary key. Added after the comment below.

最佳回答

在普通的生物贸易统计和(酸的、ui的)指数中,如果你不具体指明酸液,只搜寻ui,则需要扫描。 关于(人工、酸)(通知命令)的指数将可帮助。

我的SQL认为,如果某种指数/加入很可能需要一定比例的指数使用,则完全扫描可能更快速(连续读)。 页: 1 FORCE INDEX,如果使用钥匙而使用扫描器,实际上会更快(在测试之前,检测器上可辨的电池)。

问题回答

编制一栏的索引。

当你询问执行情况时,EXPLAIN和CREATE TABLE声明的输出使帮助者更容易一些。 请下次补充。

http://en.wikipedia.org/wiki/Index_(数据库)#Covering_Index”rel=“nofollow noreferer” 对于这一询问,它必须进入任何数据页,以检索它所需要的一些数据。 根据表格统计,优化机构决定,综合组织首次扫描索引,然后跳跃到数据页,比仅仅扫描表更糟。

......

SELECT cha.cid AS cid,
       cha.data AS dl
    FROM cha INNER JOIN c_users ON cha.cid = c_users.cid
    WHERE uid = 808;

是否更具属性?

(考虑到knittl的评论)。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签