[SERVER-22205] Index bounds are not populated for a compound index with 2dsphere in the end Created: 15/Jan/16  Updated: 19/Apr/16  Resolved: 19/Apr/16

Status: Closed
Project: Core Server
Component/s: Geo, Querying
Affects Version/s: 3.2.3, 3.3.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Alexander Komyagin Assignee: David Storch
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-23065 Geo predicate beneath $elemMatch obje... Closed
Operating System: ALL
Sprint: Query 10 (02/22/16)
Participants:

 Description   

Test data:

db.test.insert({
point: { "type": "MultiPolygon", 
    "coordinates": [
        [
            [[30, 20], [45, 40], [10, 40], [30, 20]]
        ], 
        [
            [[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]
        ]
    ]
},
array: [
{
	value1: 1,
	value2: 2
},
{
	value1: 5,
	value2: 10
}
]
})

Test index:

db.test.ensureIndex({'array.value1':1,'array.value2':1,point:"2dsphere"})

Test query:

db.test.find({ point: {       $geoWithin: {          $geometry: { "type": "MultiPolygon",      "coordinates": [         [             [[30, 20], [45, 40], [10, 40], [30, 20]]         ],          [             [[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]         ]     ]          }       }    },    array: {$elemMatch:{value1:1, value2:2}} }).hint("array.value1_1_array.value2_1_point_2dsphere").explain()

The explain() output has very bad index bounds, which renders the index useless:

				"indexBounds" : {
					"array.value1" : [
						"[MinKey, MaxKey]"
					],
					"array.value2" : [
						"[MinKey, MaxKey]"
					],
					"point" : [
						"[MinKey, MaxKey]"
					]
				}

If I don't use $elemMatch, the results are a bit better, but array.value2 bounds are not set:

db.test.find({ point: {       $geoWithin: {          $geometry: { "type": "MultiPolygon",      "coordinates": [         [             [[30, 20], [45, 40], [10, 40], [30, 20]]         ],          [             [[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]         ]     ]          }       }    },    'array.value1':1, 'array.value2':2 }).hint("array.value1_1_array.value2_1_point_2dsphere").explain()
....
"indexBounds" : {
					"array.value1" : [
						"[1.0, 1.0]"
					],
					"array.value2" : [
						"[MinKey, MaxKey]"
					],
					"point" : [
						"[\"0f200\", \"0f201\")",
						"[\"0f2012\", \"0f2013\")",
						"[\"0f2013\", \"0f2014\")",
						"[\"0f202\", \"0f203\")",
						"[\"0f2030\", \"0f2031\")",
						"[\"0f2031\", \"0f2032\")",
						"[\"0f2112333\", \"0f2112334\")",
						"[\"0f212\", \"0f213\")",
						"[\"0f2130\", \"0f2131\")",
						"[\"0f220\", \"0f221\")",
						"[\"0f221\", \"0f222\")",
						"[\"0f222\", \"0f223\")",
						"[\"0f22311\", \"0f22312\")",
						"[\"0f230\", \"0f231\")",
						"[\"0f231\", \"0f232\")",
						"[\"0f232\", \"0f233\")",
						"[\"2f0000\", \"2f0001\")",
						"[\"2f0003\", \"2f0004\")",
						"[\"2f0010\", \"2f0011\")",
						"[\"2f0011000\", \"2f0011000\"]",
						"[\"2f00110000\", \"2f00110001\")"
					]
				}
...



 Comments   
Comment by David Storch [ 19/Apr/16 ]

Ah, thanks max.hirschhorn, that makes sense.

I have identified this as a duplicate of SERVER-23065, which is currently in code review. I am closing this ticket as a duplicate. Please watch SERVER-23065 for further updates.

CC alex.komyagin

Comment by Max Hirschhorn [ 05/Apr/16 ]

I can reproduce this issue using the script that Dave provided in his earlier comment against MongoDB versions 3.2.3 and 3.3.2. I cannot reproduce the issue after reverting the changes from SERVER-22448.

{
  "queryPlanner" : {
    "plannerVersion" : 1,
    "namespace" : "test.test",
    "indexFilterSet" : false,
    "parsedQuery" : {
      ...
    },
    "winningPlan" : {
      "stage" : "FETCH",
      "filter" : {
        ...
      },
      "inputStage" : {
        "stage" : "IXSCAN",
        "keyPattern" : {
          "array.value1" : 1,
          "array.value2" : 1,
          "point" : "2dsphere"
        },
        "indexName" : "array.value1_1_array.value2_1_point_2dsphere",
        "isMultiKey" : true,
        "isUnique" : false,
        "isSparse" : false,
        "isPartial" : false,
        "indexVersion" : 1,
        "direction" : "forward",
        "indexBounds" : {
          "array.value1" : [
            "[MinKey, MaxKey]"
          ],
          "array.value2" : [
            "[MinKey, MaxKey]"
          ],
          "point" : [
            "[MinKey, MaxKey]"
          ]
        }
      }
    },
    "rejectedPlans" : [ ]
  },
  "serverInfo" : {
    "host" : "gopher-blue",
    "port" : 27017,
    "version" : "3.2.4",
    "gitVersion" : "e2ee9ffcf9f5a94fad76802e28cc978718bb7a30"
  },
  "ok" : 1
}

Comment by David Storch [ 08/Feb/16 ]

alex.komyagin, for now I'm closing as "Cannot Reproduce". Please re-open if you can provide more detailed repro steps.

Best,
Dave

Comment by David Storch [ 02/Feb/16 ]

alex.komyagin, I believe I ran exactly your query against a recent build of the master branch, and I could not reproduce. Here's my script, taken nearly verbatim from the ticket description:

(function() {
    db.test.insert({
      point : {
        "type" : "MultiPolygon",
        "coordinates" : [
          [[ [ 30, 20 ], [ 45, 40 ], [ 10, 40 ], [ 30, 20 ] ]],
          [[ [ 15, 5 ], [ 40, 10 ], [ 10, 20 ], [ 5, 10 ], [ 15, 5 ] ]]
        ]
      },
      array : [ {value1 : 1, value2 : 2}, {value1 : 5, value2 : 10} ]
    });
 
    db.test.ensureIndex({'array.value1': 1,'array.value2': 1, point: "2dsphere"});
 
    var explain = db.test.find({
        point: {$geoWithin: {$geometry: {
            "type": "MultiPolygon",
            "coordinates": [
                [[ [30, 20], [45, 40], [10, 40], [30, 20] ]],
                [[ [15, 5], [40, 10], [10, 20], [5, 10], [15, 5] ]]
            ]
        }}},
        array: {$elemMatch: {value1: 1, value2: 2}}
    }).hint("array.value1_1_array.value2_1_point_2dsphere").explain();
 
    printjson(explain);
})();

This produces index bounds that look correct to me:

					"array.value1" : [
						"[1.0, 1.0]"
					],
					"array.value2" : [
						"[2.0, 2.0]"
					],
					"point" : [
						"[1152921504606846977, 1188950301625810943]",
						"[1206964700135292928, 1206964700135292928]",
						"[1206964700135292929, 1215971899390033919]",
						"[1215971899390033921, 1224979098644774911]",
						"[1224979098644774912, 1224979098644774912]",
						"[1224979098644774913, 1261007895663738879]",
						"[1261007895663738881, 1270015094918479871]",
						"[1270015094918479873, 1279022294173220863]",
						"[1279022294173220864, 1279022294173220864]",
						"[1351079888211148800, 1351079888211148800]",
						"[1355583487838519296, 1355583487838519296]",
						"[1358961187559047168, 1358961187559047168]",
						"[1359805612489179136, 1359805612489179136]",
						"[1359946349977534465, 1360087087465889791]",
						"[1369094286720630784, 1369094286720630784]",
						"[1369094286720630785, 1405123083739594751]",
						"[1405123083739594753, 1414130282994335743]",
						"[1423137482249076736, 1423137482249076736]",
						"[1441151880758558721, 1477180677777522687]",
						"[1477180677777522689, 1513209474796486655]",
						"[1513209474796486656, 1513209474796486656]",
						"[1513209474796486657, 1549238271815450623]",
						"[1560497270883876865, 1562749070697562111]",
						"[1562749070697562112, 1562749070697562112]",
						"[1567252670324932608, 1567252670324932608]",
						"[1585267068834414593, 1621295865853378559]",
						"[1621295865853378561, 1657324662872342527]",
						"[1657324662872342528, 1657324662872342528]",
						"[1657324662872342529, 1693353459891306495]",
						"[4611686018427387905, 4620693217682128895]",
						"[4629700416936869888, 4629700416936869888]",
						"[4638707616191610881, 4647714815446351871]",
						"[4647714815446351873, 4656722014701092863]",
						"[4656722014701092865, 4656757199073181695]",
						"[4656792383445270528, 4656792383445270528]",
						"[4657003489677803520, 4657003489677803520]",
						"[4657847914607935488, 4657847914607935488]",
						"[4661225614328463360, 4661225614328463360]",
						"[4665729213955833856, 4665729213955833856]",
						"[4683743612465315840, 4683743612465315840]"
					]

Could you please provide more detailed repro steps?

Best,
Dave

Generated at Thu Feb 08 03:59:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.