gpt4 book ai didi

sql-server - 优化sql server数据库

转载 作者:搜寻专家 更新时间:2023-10-30 19:40:45 25 4
gpt4 key购买 nike

我的数据库有一个非常大的表,其中包含超过 20 亿行和 3 列。Id(uniqueidentity), Type(int, between 0-10. 0 = most used. 10 = least used), Data(Binary data between 1-10MB)

我可以通过哪些方式优化此数据库? (主要是选择查询)

*注意:稍后我可能会在此表中添加更多列(例如:位置、日期...)

最佳答案

假设 id 列是聚集索引键,并假设 uniqueidentity 是指 uniqueidentifier:

  • 您需要uniqueidentifier 类型吗?为什么?
  • 您还考虑过哪些其他替代方案?
  • 您是否使用顺序 GUID 填充数据?

众所周知,GUID 是集群键的糟糕选择。参见 GUIDs as PRIMARY KEYs and/or the clustering key更详细的讨论:

But, a GUID that is not sequential - like one that has it's values generated in the client (using .NET) OR generated by the newid() function (in SQL Server) can be a horribly bad choice - primarily because of the fragmentation that it creates in the base table but also because of its size. It's unnecessarily wide (it's 4 times wider than an int-based identity - which can give you 2 billion (really, 4 billion) unique rows). And, if you need more than 2 billion you can always go with a bigint (8-byte int) and get 2^63-1 rows

另请阅读 Disk space is cheap...That's not the point!作为跟进。

除此之外,您需要做功课并发布此类问题所需的详细信息:精确 表和索引定义、流行的数据访问模式(按键、按范围、过滤器排序顺序) ,加入等等)。

到目前为止,您是否做过任何工作来发现问题?如果不是,从 Waits and Queues 开始,一种经过验证的识别性能瓶颈的方法。一旦您衡量并找到需要改进的地方,我们就可以建议如何改进。

关于sql-server - 优化sql server数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4393507/

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