|
I have studied the behaviour Regex expression in the classic engine. They check the following conditions and raise errors if they are not true:
- Regex pattern is a string, BSONRegEx or null
- Regex flags is string or null
- If regex has BSONRegEx type and options field in the query is defined, only one of them can be non-empty
- Regex pattern cannot contain null bytes
- Regex flags cannot contain null bytes (even if regex pattern is null)
- Regex pattern must be valid
- Regex flags must be valid
Condition 1 is checked in the SBE tree. If condition 7 is false, there is an assert in VM. Condition 3 is not checked since we do not have BSONRegEx support in SBE yet.
We do not raise an error if conditions 2, 4, 5 or 6 are false. This can be seen only when regex pattern or flags are not constant expressions. When they are constant expressions, these conditions are checked in optimize method of respective expressions.
Also, during the SBE regex expressions building we use getConstantPatternAndOptions method to check some of these conditions. This method is not used in the classic engine and I am not sure it is consistent with classic engine's behaviour.
|