且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

主机时在网站上查询性能

更新时间:2022-06-27 02:41:26

我认为性能不会降低很多,但你可以检查比较表名静态和给出表名,列名的实际时间和列值并检查时间差异是否太小然后它不是问题,但是当你有更多数量的表时,你可能会遇到问题,因为数据库中表格的搜索索引将花费更多时间。



我的建议是为每个表使用单独的存储过程,这是***的编程方式。不要考虑某些条件下的代码可重用性,因为有些情况下你不能使用代码,因为所有的代码部分看起来都是一样的。



希望你理解我的意思说。



谢谢

Ganesh
I think the performance will not degrade much, but you can check comparing the actual time taken when the table name is static and when you have given a table name, column name and column value and check if the time diff is too small then it is not an issue, but u might land in a problem when u have more number of tables, as the search index for the tables in the database will take more time.

My suggestion is to use a separate stored proc for each table and that is the best way of programming. Dont think about code reusability in certain conditions as there are situations where you cannot use the code as all of the code part seems same.

Hope u understand what I mean to say.

Thanks
Ganesh


一些建议。



0) The Evil ThatSelect * [ ^ ]

如果你的表有100多列,但你想只显示一堆列(比如10),不要使用 SELECT * 。请记住,如果您的表有百万行,那么您选择(百万行* 90列)单元格是不必要的。



1)不要使用像调用表这样的查询,列动态。同意解决方案1 ​​,肯定会降低性能。在这里查看这篇文章,肯定是给你的。

动态SQL的诅咒与祝福 [ ^ ]



2)使用***实践。优化您的数据库。

在SQL Server中优化数据访问的十大步骤:第一部分(使用索引) [ ^ ]

在SQL Server中优化数据访问的十大步骤:第二部分(重新考虑TSQL和应用***做法) [ ^ ]

在SQL Server中优化数据访问的十大步骤:第三部分(应用高级索引和非规范化) [ ^ ]

优化SQL Server中数据访问的十大步骤:第四部分(诊断数据库性能问题) [ ^ ]

在SQL Server中优化数据访问的十大步骤:第五部分(优化数据库文件并应用分区) [ ^ ]



3)为每个 SELECT创建单独的存储过程



SQL Server DO和DONT [ ^ ]
Couple of suggestions.

0) The Evil That is "Select *"[^]
If your table has 100+ columns but you want to display only bunch of columns(say 10), don't use SELECT *. Remember if your table has million rows then you're selecting (million rows * 90 columns) cells which is unnecessary.

1) Don't use queries like calling table, columns dynamically. Agree with Solution 1, surely it'll degrade the performance. Here check this article, surely it's for you now.
The Curse and Blessings of Dynamic SQL[^]

2) Use best practices. Optimize your database.
Top 10 steps to optimize data access in SQL Server: Part I (use indexing)[^]
Top 10 steps to optimize data access in SQL Server: Part II (Re-factor TSQL and apply best practices)[^]
Top 10 steps to optimize data access in SQL Server: Part III (Apply advanced indexing and denormalization)[^]
Top 10 steps to optimize data access in SQL Server: Part IV (Diagnose database performance problems)[^]
Top 10 steps to optimize data access in SQL Server: Part V (Optimize database files and apply partitioning)[^]

3) Create separate stored procedure for each SELECT.

SQL Server DO's and DONT's[^]