gpt4 book ai didi

database - 在我的情况下,哪种索引方法更好?

转载 作者:行者123 更新时间:2023-11-29 13:54:19 25 4
gpt4 key购买 nike

在一个表中我有 4 列:

(a(int),b(int),c(var-char),d(var-char))

我有两个查询如下:

select *from table where a=1 and b=2 and c="abc";

select *from table where a=1 and b=2 and d="zyz";

现在索引方法:

  • 在 (a,b,c) 上建立索引
  • 在 (a,b,d) 上建立索引

  • 索引(a,b)
  • 索引(c)
  • 索引(d)

哪种方法更好?

最佳答案

最好是尝试一下。除非您知道您计划使用的数据是什么,否则不可能说哪些索引更好。最好的方法是创建表,插入一些样本数据,然后使用 EXPLAINEXPLAIN ANALYZE 进行一些典型的查询。

一个例子是

EXPLAIN select *from table where a=1 and b=2 and c="abc";

EXPLAIN select *from table where a=1 and b=2 and d="zyz";

EXPLAIN ANALYZE 选择 *from table where a=1 and b=2 and c="abc";

EXPLAIN ANALYZE select *from table where a=1 and b=2 and d="zyz";

另见http://www.postgresql.org/docs/9.5/static/sql-explain.html

关于database - 在我的情况下,哪种索引方法更好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35147202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com