-
Type:
Improvement
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: Change streams
-
None
-
Query Execution
-
Fully Compatible
-
QE 2025-05-26
-
None
-
3
-
TBD
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
0
Namespace matching in change streams code is currently always performed using BSONRegEx match expressions.
Example:
auto endOfTransactionFilter = BSON("op" << "n" << "o2.endOfTransaction" << BSONRegEx(nsRegex));
The code in change_stream_filter_helpers.cpp has many such examples.
Using regexes for matching the namespace can be overkill for some change stream types.
For example, in single collection change streams the regex match could be replaced by a cheaper $eq match here and here.
Further optimizations are possible here and here.
The code that builds the match expressions relies on the namespace match expressions being regexes. There are 22 currently occurrences of BSONRegEx in change_stream_filter_helpers.cpp.
Instead of relying on regexes, we should make the creation of match expressions more flexible, so that they can handle the current regexes, but will also be able to use cheaper $eq expressions in the future.
For this we can wrap the creation of the namespace match expressions into helper methods, which return a BSONObj. That BSONObj can either contain a BSONRegEx or an $eq match.
This will make it very easy to perform the move to $eq match expressions at some future point in order to improve filter performance.
We should not perform the move to $eq match expressions as part of this PR, because there seem to be subtle behavior differences between regex match expressions and $eq match expressions when the change stream uses specific collations.
So this change should only do the preparation work.
- related to
-
SERVER-105554 Improve change stream namespace matching
-
- Needs Scheduling
-