michaellperry / jinaga

Universal web back-end, offering an application-agnostic API, real-time collaboration, and conflict resolution.
http://jinaga.com
MIT License
35 stars 3 forks source link

Optimize load request by replacing recursive query with transitive closure table #28

Open michaellperry opened 5 years ago

michaellperry commented 5 years ago

Create a table having fact type, fact hash, ancestor type, ancestor hash. Define a unique index on the Cartesian product of all four columns. This table contains a record for every predecessor, and computes the transitive closure over predecessors.

To migrate, run the recursive query currently used in the load request.

Upon save, execute a self-join to insert all ancestors of all predecessors. Ignore duplicate inserts.

Replace the recursive query in load with a join to this table. Measure performance difference between the two mechanisms, and accept the optimization only if it produces a statistically significant improvement.