Description
The following SQL statement fails with an exception com.apple.foundationdb.record.RecordCoreException: Missing binding for __const_CONSTANT
:
select * from t1 where a like ‘a’
— now, the above statement is cached
— so the execution of the same statement
— should be pulled from the plan cache …
select * from t1 where a like ‘a’
— THROWS: Missing binding for __const_CONSTANT
There is a bug in the way the LIKE
clause is handled during query normalization. When normalizing the query, the LIKE
clause is not visited, so the literal like
pattern is not extracted and left in the normalized form. This is acceptable, as long as the same behavior is applied during plan generation. However, this is the root cause of the problem: the plan generator extracts the pattern into a ConstantObjectValue
. This mismatch causes the above error when we attempt to execute the cached physical plan. Since the plan expects a COV
, but the AST normalizer did not extract it away from the query, the execution of the cached query fails with the missing reference: Missing binding for __const_CONSTANT
.
We should either avoid pulling the pattern in both the AST normalizer and the plan generator, or avoid extracting it in both, i.e., the behavior should be aligned.