gpt4 book ai didi

mysql - 优化 select SQL - MySQL

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

请帮我解决这个问题

表结构

ID(主键)文本

要查找文本我应该写什么?

select Text from table where ID=1  

select Text from table where ID=1 limit 1

另一个表结构

父表
PID(p k) ID

子表
ID(p.k)PID(f.k)

我应该写什么才能快速删除?

delete from ChildTable where ID=1;

delete from ChildTable where ID=1 and pid=1;  [i know the PID]

最佳答案

前两个语句是等效的。它不应返回超过一行,因此添加限制 1 是多余的。

对于删除来说,这应该不重要。 Mysql 应该首先通过 ID 查找,因为它是最有效的索引。应该只返回一行,因此 PID 列是多余的,最坏的情况下实际上可能会混淆 mysql 使用效率较低的查询计划。

关于mysql - 优化 select SQL - MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5739221/

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