fdb-record-layer
fdb-record-layer copied to clipboard
Union comparison key for union merge can contain duplicates after #2557
It looks like after #2557, there's now a possibility that we get problems with the plan ordering key for an in-union plan containing FanOut key expressions. This can happen in a scenario like:
RecordQuery.newBuilder()
.setRecordType(type)
.where(Query.or(
Query.field("repeated").oneOfThem().matches(Query.field("foo").equalsParameter(p1)),
Query.field("repeated").oneOfThem().matches(Query.field("foo").equalsParameter(p2))
))
.build()
If there's an index on field("repeated", FanType.FanOut).nest("foo"), then this index can be selected, with two legs being unioned together. We previously were rejecting that plan because of an "unordered distinct" meaning that we wouldn't have enough information to select the ordering key, but with #2557, we started selecting this index with a plan ordering key that still contained the repeated field (though perhaps it doesn't need to). This results in a runtime exception with the message "Should evaluate to single key only" coming from a call to evaulateSingleton in the union execution logic.