使用 LINQ 加快查询速度

发布于 2024-08-24 10:19:04 字数 657 浏览 3 评论 0原文

我正在将大约 350 行(带有一些数据收集)从 MS SQL Server 传输到 iSeries 进行处理。我感觉这个过程太慢了,大约一分钟左右。我正在 LINQ2SQL 中完成所有 MS SQL 的工作。以下是我目前正在做的基础知识:

  1. 收集所有车辆主数据以一次处理一个。
  2. SUM() 车辆的燃油使用量
  3. SUM() 车辆的油使用量
  4. SUM() 车辆使用的零件
  5. SUM() 车辆的人工
  6. SUM() 车辆的外部维修
  7. SUM() 车辆的事故成本

我意识到这是很多查询,但其中大部分来自 MS SQL Server 中的不同表。所有这些都至少需要一个连接。我正在考虑将“石油和零件”加入到一个查询中,将“外部维修和事故成本”加入到一个查询中,因为这两个查询都存储在同一个表中,看看这是否会提高性能。

您还有其他建议吗?

请注意,这是供应商提供的产品,我宁愿不创建数据库中尚未存在的任何存储过程或视图(基本上没有)。

更新:我有另一篇文章寻找替代方案以提高速度。

I am transferring about 350 rows (with some data collection) from a MS SQL Server to the iSeries for processing. I feel the process is too slow which is about a minute or so. I am doing all of the MS SQL stuff in LINQ2SQL. Here is the basics of what I am doing currently:

  1. Collect all of the vehicle master data to process one-at-a-time.
  2. SUM() Fuel usage by vehicle
  3. SUM() Oil usage by vehicle
  4. SUM() Parts used by vehicle
  5. SUM() Labor by vehicle
  6. SUM() Outside Repairs by vehicle
  7. SUM() Accident Costs by vehicle

I realize this is a lot of queries, but most of these are from different tables in the MS SQL Server. All of these require at lease one join. I am thinking of joining Oil and Parts in to one query and Outside Repairs and Accident Costs into one query since both of those are stored in the same tables and see if that improves performance any.

Do you have any other suggestions?

Note that this is a vendor delivered product and I would prefer to not create any stored procedures or views (which is basically none) that aren't already in the database.

Update: I had another post looking at alternatives to improving speed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝戈者 2024-08-31 10:19:04

您也许可以将这些查询启动到单独的线程中并等待它们返回?然后,所有计算将在大约相同的时间内完成,比方说,我猜,现在所需时间的一半。

在我看来,对每个表的结果进行分组是一个好主意,因为您已经在处理这些数据。

将每个表的查询分组并将它们启动到不同的线程中肯定会提高性能。这完全取决于这是否最适合您的情况。

You could perhaps launch these queries into separated threads and wait for them to return? Then, all of your calculations would get done in about the same time as for, let's say, half the time it requires now, I guess.

Grouping your results per table is in my point of view a good idea as you're already processing these datum.

Grouping your queries per table and launching them into different threads would for sure gain in performance. It all depends on if this is optimal for your situation.

懒的傷心 2024-08-31 10:19:04

看来数据库设计得很糟糕。无论 LINQ 在后台生成什么,它都是非常低效的代码。我并不是说 LINQ 不好,只是它对这个数据库不好。我转换为快速组合的 .X​​SD 设置,处理时间从 1.25 分钟缩短到 15 秒。一旦我进行了适当的重新设计,我只能猜测我会再节省几秒钟。改天我会在更好的数据库上再次尝试 LINQ。

It appears like the database was poorly designed. Whatever LINQ was generating in the background it was highly inefficient code. I am not saying the LINQ is bad, it just was bad for this database. I converted to a quickly thrown together .XSD setup and the processing time went from 1.25 minutes to 15 seconds. Once I do a proper redesign, I can only guess I'll shave a few more seconds off of that. I'll try LINQ again some other day on a better database.

懷念過去 2024-08-31 10:19:04

如果性能很重要(一分钟是个问题?),您可能会考虑使用汇总表。然后您只需查询报告的汇总表即可。可以使用触发器或每晚批量提取到汇总表来构建汇总表。

If performance is important (one minute is a problem?) you might consider using a summary table. Then you just have to query the summary table for your report. The summary table could be built with triggers or with a nightly batch extraction to the summary table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文