For some reason the ASTStaticJoinOptimizer / StaticOptimizer code does not consider Values clauses as part of the ancestry, which leads to a bad join ordering. Here is an example:
values (?a, ?b)
?a ?p ?b . # cardinality 100k, but bound by values
?p <x> <y> . #cardinality 10k
The query above will reorder the (?p <x> <y>) above (?a ?p ?b) because it thinks the cardinality is lower, even though (?a ?p ?b) will run as-bound by the values clause. The results in an unnecessary cross-product and large # of intermediate solutions.