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

Move fetch after random sort in $sample

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • Query Optimization

    Description

      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.

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            kevin.arhelger@mongodb.com Kevin Arhelger
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated: