In current project we need to find cheapest paths in almost fully connected graph which can contain lots of edges per vertex pair.
We developed a plugin containing functions
- for special traversal this graph to lower reoccurences of similar paths while
TRAVERSE
execution. We will refer it assearch()
- for special effective extraction of desired information from results of such traverses. We will refer it as
extract()
- for extracting best
N
records according to target parameter without costlyORDER BY
. We will refer it asbest()
But resulted query still has unsatisfactory performance on full data.
So we decided to modify search()
function so it could watch best edges first and prune paths leading to definitely undesired result by using current state of best()
function.
Overall solution is effectively a flexible implementation of Branch and Bound method
Resulting query (omitting extract()
step) should look like
SELECT best(path, <limit>) FROM (
TRAVERSE search(<params>) FROM #<starting_point>
WHILE <conditions on intermediate vertixes>
) WHERE <conditions on result elements>
This form is very desired so we could adapt conditions under WHILE
and WHERE
for our current task. The path
field is generated by search()
containing all information for best()
to proceed.
The trouble is that best()
function is executed strictly after search()
function, so search()
can not prune non-optimal branches according to results already evaluated by best()
.
So the Question is:
Is there a way to pipeline results from TRAVERSE
step to SELECT
step in the way that older paths were TRAVERSE
d with search()
after earlier paths handled by SELECT
with best()
?