-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using json_agg to avoid cartesian explosions like Hasura and Postgraphile #2434
Comments
Duplicate of #1691 |
Note that #1691 is about using PG (non-JSON) arrays to load one-to-many relationships in a single query without the "cartesian explosion" problem. This is different from using JSON-based techniques in that that the array would contain a PG record/composite type, representing a (dependent) row in PG. Using JSON, you get back JSON documents which you must then deserialize; but JSON documents lose most of the type information, encoding everything as text. In other words, we'd have to be able to decode e.g. a timestamp from text. In addition, since JSON uses text encoding, it is less efficient than the binary encoding you get with record/composite types. Note that lots of preliminary work has been done:
The main remaining task here would be to do the actual shape in the PG EF provider, which is likely a bit complicated and would also probably require changes on the EF side. I hope to be able to tackle this in 8.0. |
Closing as the plan for now is to go with non-JSON PG arrays, for the above reasons. I'd be happy to continue the conversation though. |
Hasura and Postgraphile use PG in a way that:
This is discussed in the following HN article:
https://news.ycombinator.com/item?id=27550151
The current best solution with EF to avoid cartesian explosion results in multiple calls to the db, incurring latency, and causes possible data synchronization issues due to that latency. This is asSplitQuery().
Would it be possible (hypothetically) for EF + npgsql to query data from PG in a way that compiles a complex query involving multiple tables into a single query using the same techniques as Hasura? (row_to_json, json_agg etc)
This would bring (possibly significant) performance improvements, and remove the data sync issue as only a single query needs sending to the db, regardless of how much related data is required.
Thanks
The text was updated successfully, but these errors were encountered: