English 中文(简体)
图表和指数
原标题:mysql AND index
  • 时间:2012-01-15 18:40:42
  •  标签:
  • mysql
  • sql

我的指数结构如下:

BTREE merchant_id
BTREE flag

BTREE test    (merchant_id, flag)

I do a SlectT query as a :

 SELECT badge_id, merchant_id, badge_title, badge_class
FROM badges WHERE merchant_id = 1 AND flag = 1

what index would be better? Does it matter if they are in a seperate index?

最佳回答

回答诸如“Which列”和“使用某种指数进行质问吗?”等问题,你可以使用EXPLAIN>/code>,。 见优良条款。 用<条码>EXPLAIN分析速成表,全面概述在优化查询和图表时使用<条码>EXPLAIN的情况。

一般来说,如果能够把几个栏中的一栏索引成指数,那么,有益的总则是将所有记录中“最独特”或“最有选择”一栏索引;也就是说,将各行各有最多不同数值的一栏索引。 我猜测,就你而言,merchant_id。 第1栏载有大多数独特的数值,因此可能应当加以指数化。 您可以核实,指数选择最好使用EXPLAIN

请注意,“指数是最有选择的一栏”的规则不一定适用于混合指数第一栏(也称为化合物或多栏)的选择。 这取决于您的询问。 例如,如果employee_id 是最具选择性的一栏,但你需要填写诸如SlectT* 等查询,这些询问来自WHERE旗=17,然后作为表badges的唯一索引,综合索引<代码>(employee_id,code),意味着查询结果将载于完整的表格扫描。

问题回答

在3个指数中,你没有真正需要一个单独的商家资格指数,因为商家佣可使用你的“测试”指数。

More details: http://dev.mysql.com/doc/refman/5.0/en/multiple-column-indexes.html





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

热门标签