Hướng dẫn count explain mongodb - đếm giải thích mongodb

Tài liệu về nhà → Hướng dẫn sử dụng MongoDBMongoDB Manual

Trên trang này

  • Giải thích cấu trúc đầu ra
  • Giải thích đầu ra cho MongoDB 5.1 trở lên
  • queryPlanner
  • executionStats
  • serverInfo
  • Thống kê kế hoạch thực thi cho truy vấn với giai đoạn đường ống $lookup
  • Quét bộ sưu tập
  • Truy vấn được bảo hiểm
  • Giao lộ chỉ số
  • $or Biểu thức
  • $sort
    '$lookup': {
    from: ,
    as: ,
    localField: ,
    foreignField:
    },
    totalDocsExamined: ,
    totalKeysExamined: ,
    collectionScans: ,
    indexesUsed: [ , , ..., ],
    nReturned: ,
    executionTimeMillisEstimate:
    0 giai đoạn
  • Sắp xếp giai đoạn

Để trả về thông tin về các kế hoạch truy vấn và thống kê thực thi của các kế hoạch truy vấn, MongoDB cung cấp:

  • Phương pháp

    '$lookup': {
    from: ,
    as: ,
    localField: ,
    foreignField:
    },
    totalDocsExamined: ,
    totalKeysExamined: ,
    collectionScans: ,
    indexesUsed: [ , , ..., ],
    nReturned: ,
    executionTimeMillisEstimate:
    1,

  • phương pháp

    '$lookup': {
    from: ,
    as: ,
    localField: ,
    foreignField:
    },
    totalDocsExamined: ,
    totalKeysExamined: ,
    collectionScans: ,
    indexesUsed: [ , , ..., ],
    nReturned: ,
    executionTimeMillisEstimate:
    2 và

  • lệnh

    '$lookup': {
    from: ,
    as: ,
    localField: ,
    foreignField:
    },
    totalDocsExamined: ,
    totalKeysExamined: ,
    collectionScans: ,
    indexesUsed: [ , , ..., ],
    nReturned: ,
    executionTimeMillisEstimate:
    3.

Quan trọng

  • Chỉ các trường đầu ra quan trọng nhất được hiển thị trên trang này.

  • Đầu ra có thể thay đổi.

  • Một số trường được sử dụng nội bộ và không được ghi lại.

Kết quả

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
3 trình bày các kế hoạch truy vấn như một cây của các giai đoạn. Cấu trúc đầu ra có thể khác nhau dựa trên công cụ truy vấn mà hoạt động sử dụng. Hoạt động có thể sử dụng công cụ truy vấn cổ điển hoặc công cụ truy vấn thực thi dựa trên khe.

Để xem cấu trúc đầu ra có thể khác nhau giữa hai công cụ thực thi, hãy xem các ví dụ sau:

Mỗi giai đoạn vượt qua các tài liệu hoặc khóa chỉ mục kết quả của nó cho nút cha. Các nút lá truy cập vào bộ sưu tập hoặc các chỉ số. Các nút bên trong sử dụng các tài liệu hoặc các khóa chỉ mục xuất phát từ các nút con. Nút gốc chỉ ra giai đoạn mà MongoDB cuối cùng có được kết quả được đặt từ.

Các giai đoạn là mô tả của hoạt động. Ví dụ:

  • '$lookup': {
    from: ,
    as: ,
    localField: ,
    foreignField:
    },
    totalDocsExamined: ,
    totalKeysExamined: ,
    collectionScans: ,
    indexesUsed: [ , , ..., ],
    nReturned: ,
    executionTimeMillisEstimate:
    5 để quét bộ sưu tập

  • '$lookup': {
    from: ,
    as: ,
    localField: ,
    foreignField:
    },
    totalDocsExamined: ,
    totalKeysExamined: ,
    collectionScans: ,
    indexesUsed: [ , , ..., ],
    nReturned: ,
    executionTimeMillisEstimate:
    6 cho các khóa chỉ số quét

  • '$lookup': {
    from: ,
    as: ,
    localField: ,
    foreignField:
    },
    totalDocsExamined: ,
    totalKeysExamined: ,
    collectionScans: ,
    indexesUsed: [ , , ..., ],
    nReturned: ,
    executionTimeMillisEstimate:
    7 để lấy tài liệu

  • '$lookup': {
    from: ,
    as: ,
    localField: ,
    foreignField:
    },
    totalDocsExamined: ,
    totalKeysExamined: ,
    collectionScans: ,
    indexesUsed: [ , , ..., ],
    nReturned: ,
    executionTimeMillisEstimate:
    8 để nhóm các tài liệu

  • '$lookup': {
    from: ,
    as: ,
    localField: ,
    foreignField:
    },
    totalDocsExamined: ,
    totalKeysExamined: ,
    collectionScans: ,
    indexesUsed: [ , , ..., ],
    nReturned: ,
    executionTimeMillisEstimate:
    9 để hợp nhất kết quả từ mảnh vỡ

  • {
    stage : 'AND_SORTED',
    inputStages : [
    {
    stage : 'IXSCAN',
    ...
    },
    {
    stage : 'IXSCAN',
    ...
    }
    ]
    }
    0 để lọc các tài liệu mồ côi từ các mảnh vỡ

Phần này cho thấy đầu ra

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
3 cho MongoDB 5.1 trở lên. Để xem đầu ra giải thích cho các phiên bản cũ của MongoDB, hãy tham khảo tài liệu cho phiên bản đó.

Trường
{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}
22Integer với phiên bản kế hoạch giải thích.

Integer field with the explain planner version.

{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}
3 là:

  • 1 Khi thực thi truy vấn dựa trên khe không được sử dụng.

  • 2 Khi thực hiện truy vấn dựa trên khe được sử dụng.

Mới trong phiên bản 5.1.

{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}
4 Thông tin chi tiết Kế hoạch được chọn bởi Trình tối ưu hóa truy vấn. information details the plan selected by the query optimizer.

Những ví dụ này có thể kết hợp các cấu trúc đầu ra của các công cụ thực hiện dựa trên khe và cổ điển của MongoDB. Họ không có nghĩa là đại diện. Sản lượng của bạn có thể khác nhau đáng kể.

{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}
4Contains Thông tin về việc lựa chọn gói truy vấn của Trình tối ưu hóa truy vấn.

Contains information on the selection of the query plan by the query optimizer.

Chuỗi
{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}
6A chỉ định không gian tên với tên của cơ sở dữ liệu và bộ sưu tập được truy cập bởi truy vấn. Không gian tên có định dạng
{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}
7.

A string that specifies the namespace with the names of the database and the collection accessed by the query. The namespace has the format

{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}
7.

{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}
8

Một boolean chỉ định liệu MongoDB có áp dụng bộ lọc chỉ mục cho hình dạng truy vấn hay không.

{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}
9A chuỗi thập lục phân đại diện cho băm của hình dạng truy vấn và chỉ phụ thuộc vào các hình dạng truy vấn.
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
0 có thể giúp xác định các truy vấn chậm [bao gồm cả bộ lọc truy vấn của các hoạt động ghi] với cùng một hình dạng truy vấn.

A hexadecimal string that represents the hash of the query shape and is dependent only on the query shapes.

{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
0 can help identify slow queries [including the query filter of write operations] with the same query shape.

Ghi chú

Như với bất kỳ hàm băm nào, hai hình dạng truy vấn khác nhau có thể dẫn đến cùng một giá trị băm. Tuy nhiên, sự xuất hiện của các va chạm băm giữa các hình dạng truy vấn khác nhau là không thể.

Để biết thêm thông tin về

{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
0 và
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
2, xem
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
0 và
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
2

{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
5a băm của khóa cho mục nhập bộ đệm kế hoạch liên quan đến truy vấn.

A hash of the key for the plan cache entry associated with the query.

Không giống như

{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}
9,
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
5 là một hàm của cả hình dạng truy vấn và các chỉ mục hiện có cho hình dạng đó. Đó là, nếu các chỉ mục có thể hỗ trợ hình dạng truy vấn được thêm/giảm, giá trị
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
2 có thể thay đổi trong khi giá trị
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
0 sẽ không thay đổi.
{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}
9
, the
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
5
is a function of both the query shape and the currently available indexes for that shape. That is, if indexes that can support the query shape are added/dropped, the
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
2 value may change whereas the
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
0 value would not change.

Để biết thêm thông tin về

{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
0 và
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
2, xem
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
0 và
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
2

{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
5a băm của khóa cho mục nhập bộ đệm kế hoạch liên quan đến truy vấn.

A boolean that indicates that the entire aggregation pipeline operation was optimized away, and instead, fulfilled by a tree of query plan execution stages.

Không giống như

{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}
9,
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
5 là một hàm của cả hình dạng truy vấn và các chỉ mục hiện có cho hình dạng đó. Đó là, nếu các chỉ mục có thể hỗ trợ hình dạng truy vấn được thêm/giảm, giá trị
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
2 có thể thay đổi trong khi giá trị
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
0 sẽ không thay đổi.

db.example.aggregate[[ { $match: { someFlag: true } } ] ]

queryPlanner4A Boolean chỉ ra rằng toàn bộ hoạt động đường ống tổng hợp đã được tối ưu hóa, và thay vào đó, được thực hiện bởi một cây thực hiện kế hoạch truy vấn.

Ví dụ, bắt đầu trong MongoDB 4.2, hoạt động tổng hợp sau đây có thể được thực hiện bằng cách thực hiện Kế hoạch Truy vấn thay vì sử dụng đường ống tổng hợp.

A document that details the plan selected by the query optimizer.

Trường chỉ có mặt nếu giá trị là queryPlanner5 và chỉ áp dụng để giải thích về các hoạt động đường ống tổng hợp. Khi queryPlanner5, vì đường ống được tối ưu hóa, không có thông tin giai đoạn tổng hợp nào xuất hiện trong đầu ra.

A string that denotes the name of the stage.

queryPlanner7A Tài liệu chi tiết kế hoạch được chọn bởi Trình tối ưu hóa truy vấn.

Chuỗi queryPlanner8A biểu thị tên của giai đoạn.

Mỗi giai đoạn bao gồm thông tin cụ thể cho giai đoạn. Ví dụ: giai đoạn
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
6 bao gồm các giới hạn chỉ mục cùng với dữ liệu cụ thể khác cho việc quét chỉ mục. Nếu một giai đoạn có giai đoạn trẻ em hoặc nhiều giai đoạn trẻ em, sân khấu sẽ có executionStats0 hoặc executionStats1.

A document that describes the child stage, which provides the documents or index keys to its parent. The field is present if the parent stage has only one child.

executionStats3an mảng tài liệu mô tả các giai đoạn trẻ em. Các giai đoạn con cung cấp các tài liệu hoặc khóa chỉ mục cho giai đoạn cha mẹ. Trường có mặt nếu giai đoạn cha mẹ có nhiều nút con. Ví dụ: các giai đoạn cho $ hoặc biểu thức hoặc giao điểm chỉ mục tiêu thụ đầu vào từ nhiều nguồn.

An array of documents describing the child stages. Child stages provide the documents or index keys to the parent stage. The field is present if the parent stage has multiple child nodes. For example, stages for $or expressions or index intersection consume input from multiple sources.

Trường này xuất hiện nếu hoạt động sử dụng công cụ thực thi truy vấn cổ điển.

executionStats4A Tài liệu chi tiết về kế hoạch được chọn bởi Trình tối ưu hóa truy vấn. MongoDB trình bày kế hoạch như một cây của các giai đoạn.

A document that details the plan selected by the query optimizer. MongoDB presents the plan as a tree of stages.

Tài liệu này xuất hiện nếu truy vấn sử dụng công cụ truy vấn thực thi dựa trên khe.

Mới trong phiên bản 5.1.

Chuỗi executionStats5A biểu thị tên của giai đoạn.

A string that denotes the name of the stage.

Mỗi giai đoạn bao gồm thông tin cụ thể cho giai đoạn. Ví dụ: giai đoạn

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
6 bao gồm các giới hạn chỉ mục cùng với dữ liệu cụ thể khác cho việc quét chỉ mục.

executionStats7Unique Trường số nguyên xác định từng giai đoạn trong kế hoạch thực hiện. Trường được bao gồm trong tất cả các giai đoạn trong suốt kết quả
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
3.

Unique integer field that identifies each stage in the execution plan. Field is included in all stages throughout the

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
3 results.

Mới trong phiên bản 5.1.

Chuỗi executionStats5A biểu thị tên của giai đoạn.

See executionStats2

Mỗi giai đoạn bao gồm thông tin cụ thể cho giai đoạn. Ví dụ: giai đoạn
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
6 bao gồm các giới hạn chỉ mục cùng với dữ liệu cụ thể khác cho việc quét chỉ mục.

Document with information about the slot based query execution plan tree and stages.

Mới trong phiên bản 5.1.

Chuỗi executionStats5A biểu thị tên của giai đoạn.

Array of candidate plans considered and rejected by the query optimizer. The array can be empty if there were no other candidate plans.

Mỗi giai đoạn bao gồm thông tin cụ thể cho giai đoạn. Ví dụ: giai đoạn

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
6 bao gồm các giới hạn chỉ mục cùng với dữ liệu cụ thể khác cho việc quét chỉ mục.serverInfo3 information details the execution of the winning plan. In order to include executionStats in the results, you must run the explain in either:

  • executionStats7Unique Trường số nguyên xác định từng giai đoạn trong kế hoạch thực hiện. Trường được bao gồm trong tất cả các giai đoạn trong suốt kết quả

    '$lookup': {
    from: ,
    as: ,
    localField: ,
    foreignField:
    },
    totalDocsExamined: ,
    totalKeysExamined: ,
    collectionScans: ,
    indexesUsed: [ , , ..., ],
    nReturned: ,
    executionTimeMillisEstimate:
    3.

  • executionStats9See executionStats2

serverInfo1Document với thông tin về cây thực hiện truy vấn dựa trên khe và các giai đoạn.

serverInfo2Array của các kế hoạch ứng viên được xem xét và từ chối bởi trình tối ưu hóa truy vấn. Mảng có thể trống nếu không có kế hoạch ứng cử viên nào khác.

Contains statistics that describe the completed query execution for the winning plan. For write operations, completed query execution refers to the modifications that would be performed, but does not apply the modifications to the database.

Thông tin đã trả lại serverInfo3 chi tiết về việc thực hiện kế hoạch chiến thắng. Để đưa executionStats vào kết quả, bạn phải chạy giải thích trong một trong hai:

Number of documents that match the query condition. serverInfo8 corresponds to the serverInfo9 field returned by

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
2 in earlier versions of MongoDB.

execStats hoặc

Total time in milliseconds required for query plan selection and query execution. $lookup1 corresponds to the $lookup3 field returned by

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
2 in earlier versions of MongoDB.

chế độ verbosity allplansexecution. Sử dụng chế độ serverInfo5 để bao gồm dữ liệu thực thi một phần được ghi lại trong quá trình lựa chọn kế hoạch.

Number of index entries scanned. $lookup5 corresponds to the $lookup7 field returned by

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
2 in earlier versions of MongoDB.

Những ví dụ này có thể kết hợp các cấu trúc đầu ra của các công cụ thực hiện dựa trên khe và cổ điển của MongoDB. Họ không có nghĩa là đại diện. Sản lượng của bạn có thể khác nhau đáng kể.

Number of documents examined during query execution. Common query execution stages that examine documents are

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
5 and
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
7.

Thống kê serverInfo3Contains mô tả việc thực hiện truy vấn đã hoàn thành cho kế hoạch chiến thắng. Đối với các hoạt động ghi, thực thi truy vấn đã hoàn thành đề cập đến các sửa đổi sẽ được thực hiện, nhưng không áp dụng các sửa đổi cho cơ sở dữ liệu.

serverInfo7Number của các tài liệu phù hợp với điều kiện truy vấn. serverInfo8 tương ứng với trường serverInfo9 được trả về bởi
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
2 trong các phiên bản trước của MongoDB.

Details the completed execution of the winning plan as a tree of stages; i.e. a stage can have an executionStats0 or multiple executionStats1.

$lookup1 Thời gian tính bằng mili giây cần thiết để lựa chọn kế hoạch truy vấn và thực thi truy vấn. $lookup1 tương ứng với trường $lookup3 được trả về bởi

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
2 trong các phiên bản trước của MongoDB.

  • $or5

  • $or6

  • $or7

  • $or8

$lookup5Number của các mục nhập chỉ mục được quét. $lookup5 tương ứng với trường $lookup7 được trả về bởi

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
2 trong các phiên bản trước của MongoDB.

$lookup9 Số tài liệu được kiểm tra trong quá trình thực hiện truy vấn. Các giai đoạn thực thi truy vấn phổ biến kiểm tra các tài liệu là
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
5 và
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
7.

The estimated amount of time in milliseconds for query execution.

Ghi chú

Starting in MongoDB 5.1, the number of times a stage was opened during query execution.

$or2Details Việc thực hiện hoàn thành kế hoạch chiến thắng như một cây của các giai đoạn; tức là một giai đoạn có thể có executionStats0 hoặc nhiều executionStats1.

Starting in MongoDB 5.1, the number of times a stage was closed during query execution.

Bắt đầu từ MongoDB 5.1, một giai đoạn có thể có các giai đoạn đầu vào:

Specifies the number of "work units" performed by the query execution stage. Query execution divides its work into small units. A "work unit" might consist of examining a single index key, fetching a single document from the collection, applying a projection to a single document, or doing a piece of internal bookkeeping.

Trường này xuất hiện nếu hoạt động sử dụng công cụ thực thi truy vấn cổ điển.

Mỗi giai đoạn bao gồm thông tin thực thi cụ thể cho giai đoạn.

The number of times that the query stage suspended processing and saved its current execution state, for example in preparation for yielding its locks.

$or9 Lượng thời gian ước tính tính bằng mili giây để thực hiện truy vấn.

The number of times that the query stage restored a saved execution state, for example after recovering locks that it had previously yielded.

$sort0Starting trong MongoDB 5.1, số lần một giai đoạn được mở trong quá trình thực hiện truy vấn.

Specifies whether the execution stage has reached end of stream:

  • $sort1 khởi động trong MongoDB 5.1, số lần một giai đoạn đã bị đóng trong quá trình thực hiện truy vấn.

  • $sort2Spec chỉ định số lượng "đơn vị công việc" được thực hiện bởi giai đoạn thực thi truy vấn. Truy vấn thực thi chia công việc của nó thành các đơn vị nhỏ. Một "đơn vị làm việc" có thể bao gồm kiểm tra một khóa chỉ mục duy nhất, tìm nạp một tài liệu duy nhất từ ​​bộ sưu tập, áp dụng một phép chiếu cho một tài liệu hoặc thực hiện một phần sổ sách nội bộ.

$sort3 Số lần mà giai đoạn truy vấn đã đình chỉ xử lý và lưu trạng thái thực thi hiện tại của nó, ví dụ như để chuẩn bị cho việc mang lại khóa của nó.

Each executionStats0 can have different fields depending on the value of

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
08. The following table describes possible fields and what stages they can appear in.

Mỗi executionStats0 có thể có một executionStats0 khác như một trường. Xem Giải thích Cấu trúc đầu ra.Explain Output Structure.

Đồng ruộng

Sự mô tả

Giai đoạn áp dụng

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
11

Chỉ định số lượng tài liệu được quét trong giai đoạn thực thi truy vấn.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
5,
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
7

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
14

Đối với các giai đoạn thực thi truy vấn quét một chỉ mục

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
14 là tổng số các khóa trong giới hạn và ngoài giới hạn được kiểm tra trong quá trình quét chỉ mục. Nếu quét chỉ số bao gồm một phạm vi khóa tiếp giáp duy nhất, chỉ cần kiểm tra các khóa trong giới hạn. Nếu các giới hạn chỉ mục bao gồm một số phạm vi chính, quy trình thực thi quét chỉ số có thể kiểm tra các khóa ngoài giới hạn để bỏ qua từ cuối một phạm vi đến đầu tiếp theo.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
6

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
17

Số lượng tài liệu được quét hoặc khóa chỉ mục được kiểm tra trong giai đoạn thực thi truy vấn.

Mới trong phiên bản 5.1.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
5,
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
6

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
20

Số lần chúng tôi phải tìm kiếm con trỏ chỉ mục đến một vị trí mới để hoàn thành việc quét chỉ mục.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
6

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
22

Số lượng gần đúng của các byte trong bộ nhớ tràn vào đĩa trong giai đoạn.

Mới trong phiên bản 5.3.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
8

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
24

Số lượng hồ sơ được sản xuất tràn vào đĩa trong giai đoạn.

Mới trong phiên bản 5.3.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
8

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
26

Số lượng hồ sơ được sản xuất tràn vào đĩa trong giai đoạn.

Mới trong phiên bản 5.3.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
8

Số lượng hồ sơ được sản xuất tràn vào đĩa trong giai đoạn.

Contains partial execution information captured during the plan selection phase for both the winning and rejected plans. The field is present only if

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
3 runs in serverInfo5 verbosity mode.

Cho dù sân khấu đã viết cho đĩa.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
28Contains Thông tin thực thi một phần được ghi lại trong giai đoạn lựa chọn kế hoạch cho cả hai kế hoạch chiến thắng và bị từ chối. Trường chỉ có mặt nếu
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
3 chạy ở chế độ serverInfo5.explain results can include execution statistics for queries that use a $lookup pipeline stage. To include those execution statistics, you must run the explain operation in one of these execution verbosity modes:

  • Mới trong phiên bản 5.0.

  • Các kết quả giải thích có thể bao gồm số liệu thống kê thực thi cho các truy vấn sử dụng giai đoạn đường ống $lookup. Để bao gồm các thống kê thực thi đó, bạn phải chạy hoạt động giải thích trong một trong các chế độ xác thực thực thi này:

execStats

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:

AllPlansExecution

Các trường sau được bao gồm trong kết quả giải thích cho truy vấn $lookup:

Để xem các mô tả cho các trường trong phần $lookup, hãy xem trang $lookup.

Number of documents examined during the query execution.

Các trường khác là:

Number of index keys examined.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
35Number của các tài liệu được kiểm tra trong quá trình thực hiện truy vấn.

Number of times a collection scan occurred during query execution. During a collection scan, each document in a collection is compared to the query predicate. Collection scans occur if no appropriate index exists that covers the query.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
36Number của các phím chỉ số được kiểm tra.

Array of strings with the names of the indexes used by the query.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
37Number của lần quét bộ sưu tập đã xảy ra trong quá trình thực hiện truy vấn. Trong quá trình quét thu thập, mỗi tài liệu trong một bộ sưu tập được so sánh với vị từ truy vấn. Quét thu thập xảy ra nếu không có chỉ số thích hợp tồn tại bao gồm truy vấn.

Number of documents that match the query condition.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
38Array của các chuỗi với tên của các chỉ mục được sử dụng bởi truy vấn.

Estimated time in milliseconds for the query execution.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
39Number của các tài liệu phù hợp với điều kiện truy vấn.

Thời gian

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
40 trong mili giây để thực hiện truy vấn.

Nếu trình lập kế hoạch truy vấn chọn quét thu thập, kết quả giải thích bao gồm giai đoạn

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
5.

Nếu trình lập kế hoạch truy vấn chọn một chỉ mục, kết quả giải thích bao gồm giai đoạn

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
6. Giai đoạn bao gồm thông tin như mẫu khóa chỉ mục, hướng của truyền tải và giới hạn chỉ mục.

Bắt đầu từ MongoDB 5.3, nếu trình lập kế hoạch truy vấn chọn một chỉ mục được phân cụm cho một bộ sưu tập phân cụm, kết quả giải thích bao gồm giai đoạn

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
43. Giai đoạn bao gồm thông tin về khóa chỉ mục được phân cụm và giới hạn chỉ mục.and return the results using only the index keys; i.e. MongoDB does not need to examine documents from the collection to return the results.

Để biết thêm thông tin về thống kê thực thi về quét thu thập, xem Phân tích hiệu suất truy vấn.not a descendant of a

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
7 stage, and in the executionStats, the $lookup9 is $sort9.

Khi một chỉ mục bao gồm một truy vấn, MongoDB đều có thể khớp với các điều kiện truy vấn và trả về kết quả chỉ bằng các khóa chỉ mục; tức là MongoDB không cần kiểm tra các tài liệu từ bộ sưu tập để trả về kết quả.executionStats3 array that details the indexes; e.g.:

{
stage : 'AND_SORTED',
inputStages : [
{
stage : 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
}
]
}

Khi một chỉ số bao gồm một truy vấn, kết quả giải thích có giai đoạn

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
6 không phải là hậu duệ của giai đoạn
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
7 và trong executionStats, $lookup9 là $sort9.executionStats3 array that details the indexes; e.g.:

{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}

Đối với kế hoạch giao lộ chỉ mục, kết quả sẽ bao gồm giai đoạn

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
49 hoặc giai đoạn
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
50 với mảng executionStats3 chi tiết các chỉ mục; ví dụ.:

Nếu MongoDB sử dụng các chỉ mục cho biểu thức $or, kết quả sẽ bao gồm giai đoạn

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
53 với mảng executionStats3 chi tiết các chỉ mục; ví dụ.:

Trong các phiên bản trước của MongoDB,

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
2 đã trả lại mảng
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
56 chi tiết các chỉ mục.

Đồng ruộng

Khi

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
3 được chạy trong chế độ xác thực thực thi hoặc allplansexecution, các giai đoạn $sort
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
0 có đầu ra bổ sung.

Sự mô tả

$sort

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
61

long

Sân khấu

$sort

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
26

boolean

Loại hình

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
0

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
67

long

Số lượng byte ước tính được xử lý trong giai đoạn $sort.

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
0

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
26

boolean

Cho dù giai đoạn $sort đã viết cho đĩa.

Ước tính tổng kích thước của tất cả các tài liệu đầu ra theo giai đoạn

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
0 trong byte.

Nếu MongoDB yêu cầu sử dụng hơn 100 megabyte bộ nhớ hệ thống cho hoạt động sắp xếp chặn, MongoDB trả về lỗi trừ khi truy vấn chỉ định

'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
74 [mới trong MongoDB 4.4].
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
74 cho phép MongoDB sử dụng các tệp tạm thời trên đĩa để lưu trữ dữ liệu vượt quá giới hạn bộ nhớ hệ thống 100 megabyte trong khi xử lý hoạt động sắp xếp chặn.Nếu kế hoạch giải thích không chứa một giai đoạn
'$lookup': {
from: ,
as: ,
localField: ,
foreignField:
},
totalDocsExamined: ,
totalKeysExamined: ,
collectionScans: ,
indexesUsed: [ , , ..., ],
nReturned: ,
executionTimeMillisEstimate:
72 rõ ràng, thì MongoDB có thể sử dụng một chỉ mục để có được thứ tự sắp xếp.

Bài Viết Liên Quan

Chủ Đề