[英]Which one is faster? Query 1 Entity and make roundtrip on other related entities? or just left join it with 1 roundtrip?
public class Item
{
public int Id { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public decimal Cost { get; set; }
public Department ItemDept { get; set; }
public Category ItemCat { get; set; }
public List<Supplier> Suppliers { get; set; }
public List<Barcode> Barcodes { get; set; }
public List<Discount> Discounts { get; set; }
}
Im using Dapper so my query is plain SQL talking to Sql Server 2008 我正在使用Dapper,因此我的查询是与SQL Server 2008对话的普通SQL
how do I improve performance on this? 我该如何提高性能? assuming the query is get Item by Id(Primary key) which one is faster or better? 假设查询是通过ID(主键)获取Item的,哪个更快或更佳? - with one query full of joins(left join, inner join..etc) (1 roundtrip only) or - query the item first then execute another query for related tables(many roundtrips) or do you guys have any recommendations? -使用一个充满连接的查询(左连接,内部连接等)(仅1个往返)或-首先查询该项目,然后对相关表执行另一个查询(许多往返),或者您有什么建议吗?
This is too long for a comment. 这个评论太长了。
The best way to answer a performance question is to try it out on your data on your systems. 回答性能问题的最佳方法是在系统上的数据上进行尝试。 You can then check what really works better. 然后,您可以检查真正有效的方法。
Informed speculation says that letting the database do the joins is the right thing to do. 明智的猜测是,让数据库进行联接是正确的做法。 Databases are designed for this operation and they should implement joins effectively. 数据库是为此操作而设计的,它们应该有效地实现联接。 Perhaps more importantly, there is overhead for each query that you run. 也许更重要的是,您运行的每个查询都有开销。 Overhead to compile the query. 开销来编译查询。 Latency is passing the query to the database. 延迟将查询传递给数据库。 Database overhead in processing the results and getting them back to the application. 处理结果并将其返回给应用程序的数据库开销。
That also suggests that doing more work in the database is a good thing. 这也表明在数据库中进行更多工作是一件好事。 But, you should check on your system. 但是,您应该检查系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.