查詢多列索引(x,y,z)的列(x,z) - Query on columns (x, z) for a multi-column index (x, y, z) -开发者知识库

查詢多列索引(x,y,z)的列(x,z) - Query on columns (x, z) for a multi-column index (x, y, z) -开发者知识库,第1张

I have a table that looks like:

我有一張表看起來像:

CREATE TABLE t (
  x some_type_1,
  y some_type_2,
  z some_type_3,
  PRIMARY KEY (x, y, z)
);

Now I want to execute this query efficiently:

現在我想有效地執行此查詢:

SELECT * FROM t WHERE x = ? AND z = ?;

Is the (primary-key) index (x, y, z) enough in this case, or should I create a separate index (x, z)?

在這種情況下,(主鍵)索引(x,y,z)是否足夠,或者我應該創建一個單獨的索引(x,z)?

2 个解决方案

#1


1  

That existing index on primary key should be enough in this case since with PRIMARY KEY (x, y, z) what you essentially have is a Covering Index. See What is a Covered Index?

在這種情況下,主鍵上的現有索引應該足夠了,因為使用PRIMARY KEY(x,y,z)你基本上擁有的是覆蓋索引。請參閱什么是涵蓋指數?

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复