Mongodb limited query return field query is slower?
大家讲道理
大家讲道理 2017-05-17 10:04:05
0
1
879

When I directly use find to return all fields, the results are as follows, and the query time is 155

If the return field is limited, the query time will be longer, and the query time is 251

Why? If I limit the fields returned, the query character bytes will be smaller, shouldn't the transmission be faster?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
洪涛

The execution plan you posted mainly reveals the following information:

1. The first execution plan:

Because no index is used, collscan reveals that it is a full collection scan, so you can consider creating an index

2. The second execution plan:

It is still a full collection scan, and documents that meet the conditions are scanned into the memory, and projection is completed in the memory, the specified field is selected, and the field is returned. It seems like this will consume more time.

Although only the specified field is returned, when reading the storage or scanning the entire collection, only the entire documents can be returned. This is probably some basic principles of databases: reading and writing according to documents; additionally, some columnar databases are saved according to columns, which is the situation you imagined; but many databases are saved according to rows or documents. .

If you create a covered index on a specified field and only return the specified field, this is the most efficient, because only scanning the index can return the specified field.

For reference.

Love MongoDB! Have fun!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template