Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-43770

Move fetch after random sort in $sample

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Optimization

      Consider the following aggregation on a uniform collection with a [0,999999] (with an index onĀ {a:1}

      [
      	{
      		"$match" : {
      			"$and" : [
      				{
      					"a" : {
      						"$gte" : 500000
      					}
      				},
      				{
      					"a" : {
      						"$lte" : 700000
      					}
      				}
      			]
      		}
      	},
      	{
      		"$sample" : {
      			"size" : 25
      		}
      	}
      ]
      

      This will examine 200001 documents, but in this case, only the record locator needs to be random sorted and 25 documents fetched after record locators are chosen.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            kevin.arhelger@mongodb.com Kevin Arhelger
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: