If you're using SQL Server 2005 and set on using uniqueidentifiers (guids), and do NOT need them to be of a random nature, check out the sequential uniqueidentifier type.
Lastly, if you're talking about clustered indexes, you're talking about the sort of the physical data. If you have a string as your clustered index, that could get ugly.
SELECT
buyers.buyer_id, /* no need to index */
country.name /* no need to index */
FROM buyers LEFT JOIN country
ON buyers.country_id=country.country_id /* consider indexing */
WHERE
first_name='Tariq' /* consider indexing */
AND
last_name='Iqbal' /* consider indexing */
According to the above queries first_name, last_name columns can be indexed as they are located in the WHERE clause. Also an additional field, country_id from country table, can be considered for indexing because it is in a JOIN clause. So indexing can be considered on every field in the WHERE clause or a JOIN clause.
下面的列表还提供了一些在为表创建索引时应始终牢记的提示:
Only index those columns that are required in WHERE and ORDER BY clauses. Indexing columns in abundance will result in some disadvantages.
尝试利用 MySQL 的“索引前缀”或“多列索引”特性。如果创建 INDEX (first _ name,last _ name)等索引,则不要创建 INDEX (first _ name)。但是,不建议在所有搜索案例中使用“索引前缀”或“多列索引”。
对考虑索引的列使用 NOTNULL 属性,这样就永远不会存储 NULL 值。
Use the --log-long-format option to log queries that aren’t using indexes. In this way, you can examine this log file and adjust your queries accordingly.
EXPLAIN 语句可以帮助您了解 MySQL 将如何执行查询。它显示了如何以及以什么顺序连接表。这对于确定如何编写优化的查询以及是否需要对列进行索引非常有用。
最新消息(2015年2月23日) :
任何索引(好/坏)都会增加插入和更新时间。
Depending on your indexes (number of indexes and type), result is searched. If your search time is gonna increase because of index then that's bad index.