gpt4 book ai didi

sql - 使用哪个索引

转载 作者:行者123 更新时间:2023-11-29 14:33:58 24 4
gpt4 key购买 nike

我有两个经常使用的查询,所以索引是我真正应该使用的东西,在查看所有索引之后我仍然无法决定哪个更适合以下查询:

select distinct F.nif, F.nome
from fornecedor F, produto P
where F.nif = P.forn_primario
and P.categoria = 'Frutos'

select ean, count(nif)
from produto P, fornece_sec F
where P.ean = F.ean
group by P.ean

由于第一个查询是多列的,我认为它应该是一个 B 树,但在文档中他们又没有提到来自不同表的列。

最佳答案

你这样做的方式是,当你不确定时,你会在潜在的候选人身上测试它(希望在你的开发环境中)。所以你用 b-tree 创建它然后运行 ​​

explain analyse select ...

然后用你的结果做一个矩阵

b-tree(select whatever)     hash (select whatever)
time 0.0001 ms time 9999 ms
plan ... plan ...

这就是您将如何准确地知道您需要的那个,因为我们不知道您的表的大小、列的选择性以及许多其他内容

可能是 btree 在你的连接和谓词上 :)

关于sql - 使用哪个索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47758655/

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