[SERVER-76102] handleRIDRangeScan() sets hasCompatibleCollation wrong in recursive cases Created: 13/Apr/23  Updated: 29/Oct/23  Resolved: 24/Apr/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 6.0.0-rc0, 6.0.6
Fix Version/s: 7.1.0-rc0, 7.0.0-rc1, 6.3.2, 6.0.7

Type: Bug Priority: Major - P3
Reporter: Kevin Cherkauer Assignee: Hana Pearlman
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Problem/Incident
is caused by SERVER-67105 $in queries do not use clustered index Closed
Assigned Teams:
Query Optimization
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v7.0, v6.3, v6.0
Sprint: QO 2023-05-01
Participants:

 Description   

Found by code inspection.

planner_access.h handleRIDRangeScan() calls itself recursively on the branches of AndMatchExpressions, but in setting the output value of collScan->hasCompatibleCollation it neglects to consider the recursions, so the value from whichever recursion happened last is the final value.

The recursions should each have a chance to conjunctively falsify it, i.e. updates should be something like

collScan->hasCompatibleCollation =
    collScan->hasCompatibleCollation && allEltsCollationCompatible;

but instead the first occurrence of this updates it incorrectly (introduced in 7.0.0-rc0 by SERVER-67105 commit https://github.com/mongodb/mongo/commit/9f391ea93fa62f57d6b4576130283d98eec69456 and subsequently backported to 6.0.6):

collScan->hasCompatibleCollation = allEltsCollationCompatible;

and toward the bottom of the function (which is not always reached) there is another incorrect update (introduced in 6.0.0-rc0 by SERVER-60824 commit https://github.com/10gen/mongo/commit/8e4d331e8c20eff3ed50e3d6bb7a1b4a58aa1c16):

// Even if the collations don't match at this point, it's fine,
// because the bounds exclude values that use it
collScan->hasCompatibleCollation = true;

The fix might be to change the first existing update to use && as I suggested above and delete the second existing update, but this suggestion needs validation from a QO expert.

I confirmed with hana.pearlman@mongodb.com that the current code is incorrect. 



 Comments   
Comment by Githook User [ 28/Apr/23 ]

Author:

{'name': 'Hana Pearlman', 'email': 'hana.pearlman@mongodb.com', 'username': 'HanaPearlman'}

Message: SERVER-76102: Fix handleRIDRangeScan to set hasCompatibleCollation when query excludes values of the cluster key affected by collation
Branch: v6.3
https://github.com/mongodb/mongo/commit/7312a723371dde3af3e65432266e4b3d6a63b739

Comment by Githook User [ 28/Apr/23 ]

Author:

{'name': 'Hana Pearlman', 'email': 'hana.pearlman@mongodb.com', 'username': 'HanaPearlman'}

Message: SERVER-76102: Fix handleRIDRangeScan to set hasCompatibleCollation when query excludes values of the cluster key affected by collation
Branch: v7.0
https://github.com/mongodb/mongo/commit/5fd3b5de0b091d373a633325314d49b53e34d245

Comment by Githook User [ 28/Apr/23 ]

Author:

{'name': 'Hana Pearlman', 'email': 'hana.pearlman@mongodb.com', 'username': 'HanaPearlman'}

Message: SERVER-76102: Fix handleRIDRangeScan to set hasCompatibleCollation when query excludes values of the cluster key affected by collation
Branch: v6.0
https://github.com/mongodb/mongo/commit/141684c9113827ad43302f620a8b7504073f4733

Comment by Githook User [ 24/Apr/23 ]

Author:

{'name': 'Hana Pearlman', 'email': 'hana.pearlman@mongodb.com', 'username': 'HanaPearlman'}

Message: SERVER-76102: Fix handleRIDRangeScan to set hasCompatibleCollation when query excludes values of the cluster key affected by collation
Branch: master
https://github.com/mongodb/mongo/commit/856823c7d62275eb279b200d8087a43730f8c31c

Comment by Ana Meza [ 18/Apr/23 ]

nicholas.zolnierz@mongodb.com can someone on your team work on this?

Generated at Thu Feb 08 06:31:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.