English 中文(简体)
我sql query not using indexes for association all (Rows_sent: 115 Rows_Reviewd:1008)
原标题:mysql query not using indexes for union all (Rows_sent: 115 Rows_examined: 1008)

我试图简单地把12张桌子全部合并。 所有表格加在一起,有115行。 然而,如果我处理下面的提问,那么我会利用解释以及在我的餐桌上作一个入场。 用于记录-频率-非使用-指数的标识:

Rows_sent: 115  Rows_examined: 1008

我稍感想一下的是,当我所必须做的一切只是一起加入(福利、工会)时,我的sql正在研究1008个牢房。 任何背心或指点都将受到高度赞赏。

这里要问:

(SELECT id, var_lng_1, 0 as tbl_col FROM tbl1 )

UNION ALL 

(SELECT id, var_lng_1, 1 as tbl_col FROM tbl2 )

UNION ALL 

(SELECT id, var_lng_1, 2 as tbl_col FROM tbl3 )

UNION ALL 

(SELECT id, var_lng_1, 3 as tbl_col FROM tbl4 )

UNION ALL 

(SELECT id, var_lng_1, 4 as tbl_col FROM tbl5 )

UNION ALL 

(SELECT id, var_lng_1, 5 as tbl_col FROM tbl6 )

UNION ALL 

(SELECT id, var_lng_1, 6 as tbl_col FROM tbl7 )

UNION ALL 

(SELECT id, var_lng_1, 7 as tbl_col FROM tbl8 )

UNION ALL 

(SELECT id, var_lng_1, 8 as tbl_col FROM tbl9 )

UNION ALL 

(SELECT id, var_lng_1, 9 as tbl_col FROM tbl10 )

UNION ALL 

(SELECT id, var_lng_1, 10 as tbl_col FROM tbl11 )

UNION ALL 

(SELECT id, var_lng_1, 11 as tbl_col FROM tbl12 );

赞赏任何投入

PS: (如果情况会有所改变),所有补贴都是初级、中级、直线(3)、汽车-水泥一栏。 我也尝试了同样的询问(即从......选择补贴,但没有区别):

全面解释产出:

[id] => 1  
[select_type] => PRIMARY  
[table] => tbl1  
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] => 7  
[Extra] =>   

[id] => 2  
[select_type] => UNION  
[table] => tbl2  
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] => 18  
[Extra] =>   

[id] => 3  
[select_type] => UNION  
[table] => tbl3  
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] => 8  
[Extra] =>   

[id] => 4  
[select_type] => UNION  
[table] => tbl4  
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] => 10  
[Extra] =>   

[id] => 5  
[select_type] => UNION  
[table] => tbl5  
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] => 11  
[Extra] =>   

[id] => 6  
[select_type] => UNION  
[table] => tbl6  
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] => 14  
[Extra] =>   

[id] => 7  
[select_type] => UNION  
[table] => tbl7  
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] => 10  
[Extra] =>   

[id] => 8  
[select_type] => UNION  
[table] => tbl8  
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] => 6  
[Extra] =>   

[id] => 9  
[select_type] => UNION  
[table] => tbl9  
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] => 3  
[Extra] =>   

[id] => 10  
[select_type] => UNION  
[table] => tbl10  
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] => 2  
[Extra] =>   

[id] => 11  
[select_type] => UNION  
[table] => tbl11  
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] => 6  
[Extra] =>   

[id] => 12  
[select_type] => UNION  
[table] => tbl12  
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] => 20  
[Extra] =>   


[id] =>   
[select_type] => UNION RESULT  
[table] => <union1,2,3,4,5,6,7,8,9,10,11,12>   
[type] => ALL  
[possible_keys] =>   
[key] =>   
[key_len] =>   
[ref] =>   
[rows] =>   
[Extra] => 
问题回答

页: 1 WHERE 条款使您重新回到所有各行,并使用<代码> UNION ALL(而不是UNION)阻止对不同组别中的重复进行核对。 本文要求每个表格有一个完整的表格扫描,以便得出正确的结果。 页: 1 载于条款。 没有任何问题可能得益于指数。 仅仅使用指数就无助于。





相关问题
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 ...

热门标签