-
Notifications
You must be signed in to change notification settings - Fork 192
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
Replace transitive closure with recursive query #258
Comments
Original comment by Giovanni Pizzi (Bitbucket: pizzi, GitHub: giovannipizzi): Considering that the columns entry_edge_id, direct_edge_id and exit_edge_id are needed only for deleting one node (or to efficiently know what is the path that is traversed), we can remove them. We can get results analogous to the following query with the db_dbpath table:
using the following recursive query:
and similarly, to get the parent links instead of the child links:
|
Original comment by Giovanni Pizzi (Bitbucket: pizzi, GitHub: giovannipizzi): A few comments on efficiency:
|
Original comment by Giovanni Pizzi (Bitbucket: pizzi, GitHub: giovannipizzi): Actually, for point 2 above, using directly PostgreSQL arrays (not JSON arrays, directly int[]) makes things more usable, but not necessarily faster. Using the following query:
it takes, starting on the same node (that would return 14982 rows in my example) 4.1 seconds for this query with arrays, and 4.3 with strings. |
Original comment by Giovanni Pizzi (Bitbucket: pizzi, GitHub: giovannipizzi): Final comment for today: you can also inject a function once, and then use it multiple times, for typical queries, I don't know if its more efficient. An example (not optimized!):
and then use it as
|
What we discussed during the coding week is implemented and currently in develop. The QueryBuilder has an option to use the DbPath, and if not to use recursive queries. |
…ts_beta and Declarative DbPathBeta to behave as DbPath does, with queryable properties being descendant_id (instead of child_id), ancestor_id (parent_id) and depth. Possibility to add traversed path as an array, though this will only work in Postgresql, so commented out for now. To initialize the mapper correctly, I added imports in the __init__ of backends.sqlalchemy.model This might be also of greater convenience when importing! Added headers to all files in the querybuild module.
… the filters inside the recursive query [aiidateam#258]
…ts using recursive unions in SQL. It was made more efficient by not building the whole dbpath in memory, but the needed subset. Needs to be implemented now for ancestors, and documented.
…Builder switch between using the DbPath and not using it. Adapted the tests. The previous functionalities in dummy_model and in sqlalchemy.model.__init__ are now obsolete and were removed.
… the triggers, without making it yet compulsory to migrate. This related to replacing the DbPath table with recursive queries on the links, #258
…setting is with_dbpath=False. The whole option needs to be removed asap
…ango with a QueryBuilder query, so that the recursive query is used there
…ll for when working with the Django backend
…or Node.has_children, Node.has_parents, added import
…the transitive closure. In essence this is also the test for the recursive queries, so there is redundancy now, and we can remove some tests for the queries
The main work is done in branch tc_wo_dbpath. Tests that fail so far are backup_scripts, export_and_import, tcod_exporters (for the main reason as export_and_import). Holding me back is now the reliance on DbPath table in the import and export functionality. This probably deserves a new issue. |
…Path model and the corresponding relationshio fields
…ive to explicitly not follow return links.
…ble to simplify the code significantly, leading to a much cleaner API of the QB
This has been fixed in the linked issues, and anyway in 0.10.0 the transitive closure has been removed, so I close this issue |
Originally reported by: Giovanni Pizzi (Bitbucket: pizzi, GitHub: giovannipizzi)
The transitive closure, for big graphs, can become large. We should disable it, but provide equivalent functionality when needed (especially, but not only, for the QueryBuilder).
Since we are moving to the support of PostgreSQL only, we can use recursive queries that can get a similar table automatically.
The text was updated successfully, but these errors were encountered: