Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
postgres: poor performance on simple recursive queries #765
Postgres driver performs badly on certain simple recursive queries. Herein are two Gizmo queries (a trivial select by-type and a recursive walk over the tree) over n=8258 nodes.
Toy dataset (n-quads, 2mb compress) used in this example: knols.nq.zip
//// postgres: cayley -d postgres -a "..." http //// bolt: cayley -d bolt -a knols.db http //// memstore: cayley -d memstore http -i knols.nq // // postgres: 5ms // bolt: 14ms // memstore: 4ms g.V() .Has("<rdf:type>", "<tas:Critique>") .Count() // 8258 // postgres: 4.2s (849x) sic! // bolt: 204ms (14x) // memstore: 60ms (15x) var child_critique = g.M() .Out("<tas:text>") .Out("<tas:critique>") g.V() .Has("<rdf:type>", "<tas:Knol>") .FollowRecursive(child_critique) .Count() // 8258
dennwc [12:45 AM]
I've also tested cockroach, and got the following result:
In the case (a) cockroach is 2x faster than postgres, but later it fails to load (b) completely. I suspect that cockroach driver's implementation is probably based off postgres driver, and could be lagging behind.
As mentioned in Slack discussion, this is due to a bug in query optimizer - it won't let SQL to run a full optimization pass for recursive queries.
Fixing the issue allows recursive queries to be optimized, but a set of output SQL queries turns out to be slower then the scan from Cayley side.
So this will require more work to implement properly - need to add a few more optimizers to SQL.