两列上的唯一索引是否意味着每个列都有索引? [英] Does a unique-index on two columns imply an index on each of them?

查看:291
本文介绍了两列上的唯一索引是否意味着每个列都有索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的架构中有一个表,它对两列有唯一约束:

I have a table in my schema that has a unique constraint on two columns:

UNIQUE(Column1, Column2)

SQlite文档告诉我这个在这些列上创建唯一索引。我的问题是,是否在其中一列上显式创建了索引,比如 Column1 ,多余?

The SQlite documentation tells me that this creates a unique index on these columns. My question is, does that make an explicitly created index on one of the columns, say Column1, redundant?

推荐答案

对你的例子是肯定的,对你的问题没有。

Yes to your example, no to your question.

2列的复合索引会使首先一个冗余。但是,第二个列上的索引可能仍然有用。

A compound index on 2 columns would make the additional index on the first one redundant. However, the index on the second column might still be useful.

但是如果每个列本身都是唯一的,那么你可能不需要复合索引。你可能想看一下。

But if each of the columns is by itself unique, it's possible you don't need a compound index. You might want to look into that.

索引太多并不总是一个明显的问题。但浪费资源,尤其是出于多余目的,总是很糟糕。

Having too many indexes is not always an obvious problem. But wasting resources, especially for redundant purposes, is always bad.

这篇关于两列上的唯一索引是否意味着每个列都有索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆