gpt4 book ai didi

mysql - 使用多个查询或 vs 联合多个查询,哪个会更快?

转载 作者:行者123 更新时间:2023-11-29 03:46:27 24 4
gpt4 key购买 nike

顾名思义,使用multiple or 的查询会更快,还是使用union joined 的多个查询 会更快?为了简单起见,我只连接了两个表,但连接中可以有更多表。

例如,

    select isbn, booktitle from book as b left join publisher as p
on b.publisherid = p.publisherid
where
booktitle like '%mysql%' or
isbn like '%mysql%' or
publishername like '%mysql%'

对比

      select isbn, booktitle from book as b left join publisher as p
on b.publisherid = p.publisherid
where
booktitle like '%mysql%'
union
select isbn, booktitle from book as b left join publisher as p
on b.publisherid = p.publisherid
where
isbn like '%mysql%'
union
select isbn, booktitle from book as b left join publisher as p
on b.publisherid = p.publisherid
where
publishername like '%mysql%'

最佳答案

我看不出你的工会会更快。您必须扫描并加入 3 次,与第一次一样,您只扫描一次,并且对于每个加入的记录,您都可以应用条件。

关于mysql - 使用多个查询或 vs 联合多个查询,哪个会更快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4164588/

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