How can I generate a consistent entity graph (say from 10 tables) from a database fetch
-
07-03-2021 - |
题
Suppose I have many tables in a database that need to be joined together to get a single consistent view of the entire entity graph. Am I forced to do this as a single query? I don't care about locks, I just want to ensure the graph is consistent as of the time of the query execution.
My concern is one of performance of joining a large number of entities together in a single query. Is it possible to do this in multiple queries but still realize the same level of consistency as having performed these individual selects as a single query?
解决方案
Is it possible to do this in multiple queries but still realize the same level of consistency as having performed these individual selects as a single query?
It depends on the RDBMS.
In SQL Server you can use a transaction with SNAPSHOT transaction isolation level to get a consistent view of the database across multiple queries.
The isolation level Oracle calls SERIALIZABLE does the same thing.
My concern is one of performance of joining a large number of entities together in a single query
This is a valid concern because most RDBMS engines only return tabular results from queries. The strategies to generate a single tabular result for a complex object graph can lead to large resultsets and complex queries. This has always been a problem for ORMs.