Duplicate variables in a basic graph pattern are currently managed in StatementStoreDuplicateResolution. This is an excessively complex operation, trying to manage numerous corner cases, and yet it is completely unnecessary.
Instead, successive instances of the same variable should be renamed, and the constraint should be conjoined with itself with the repeated variables rotated around.
e.g. for 2 variables:
{?x ?x ?y} becomes: {?x ?x2 ?y} AND {?x2 ?x ?y}
{?x ?y ?x} becomes: {?x ?y ?x2} AND {?x2 ?y ?x}
{?y ?x ?x} becomes: {?y ?x ?x2} AND {?y ?x2 ?x}
and for 3 variables:
{?x ?x ?x} becomes: {?x ?x2 ?x3} AND {?x3 ?x ?x2} AND {?x2 ?x3 ?x}
The values of ?x2 and ?x3 can always be ignored since they are identical to ?x.