DB-12133 Fix predicate packing logic for multiple IN lists MultiProbeScan #5671
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Short Description
Fixes loss of a predicate during packing of useful MultiProbeScan predicates, which may show up in a query as "ERROR 42Y63: Hash join requires an optimizable equijoin predicate", or possibly incorrect results.
Long Description
When we have a tables such as:
create table t1
(a1 int, b1 int, c1 int, primary key (a1, b1, c1));
create table t2
(a2 int, b2 int, c2 int, primary key (a2, b2, c2));
...and a query such as :
select a1, t2.a2 from t1 INNER JOIN t2 on t1.a1=t2.a2
where a1=(SELECT MAX(a2) FROM t2 ) and a1 in (0,1,2)
and b1 in (0,1,2,3,4,5) and c1 in (0,1,2,3,4,5,6,7,8) order by t2.a2;
The 3 IN list predicates may be collected into a usefulPredicates array, along with pushable predicate t1.a1=t2.a2.
The IN list predicates are then combined into one a single multicolumn IN list, and the usefulPredicates is packed into a smaller size, removing the original IN predicates. This logic is faulty and does not increment variable "j" when the source and destination position in usefulPredicates are identical, so the predicate t1.a1=t2.a2 which enables a hashable join is lost:
The solution is to move the incrementing of j outside of the conditional code which skips NoOp assignments.
How to test
The following test case should not error out: