EntityFrameworkCore icon indicating copy to clipboard operation
EntityFrameworkCore copied to clipboard

dbContext.DBSet.FirstOrDefault(e => e.FirstName == "xx") missing filter in MongoQueryable

Open IvanZheng opened this issue 7 years ago • 5 comments

zooDbContext.Employees .FirstOrDefault(e => e.FirstName == "xx") will retrieve all records from employees collection in mongodb.

Reproduce step:

  1. Open mongo shell and use the command "db.setProfilingLevel(2)" to open the query profiler.
  2. Execute zooDbContext.Employees .FirstOrDefault(e => e.FirstName == "xx") in test case.
  3. Use db.system.profile.find().sort({$natural:-1}) to view the profiler data. From the profiler data, we can see there is no filter or pipeline in the command.

`

{
"op" : "command",
"ns" : "zooDb.employees",
"command" : {
    "aggregate" : "employees",
    "pipeline" : [],
    "cursor" : {},
    "$db" : "zooDb",
    "lsid" : {
        "id" : UUID("5854cdca-ee1e-44d2-8098-5d1ae3ed06a3")
    }
},
"keysExamined" : 0,
"docsExamined" : 2,
"cursorExhausted" : true,
"numYield" : 0,
"locks" : {
    "Global" : {
        "acquireCount" : {
            "r" : NumberLong(4)
        }
    },
    "Database" : {
        "acquireCount" : {
            "r" : NumberLong(2)
        }
    },
    "Collection" : {
        "acquireCount" : {
            "r" : NumberLong(2)
        }
    }
},
"nreturned" : 2,
"responseLength" : 422,
"protocol" : "op_msg",
"millis" : 0,
"planSummary" : "COLLSCAN",
"ts" : ISODate("2018-12-11T09:05:25.129Z"),
"client" : "127.0.0.1",
"allUsers" : [],
"user" : ""

}

`

IvanZheng avatar Dec 11 '18 09:12 IvanZheng

@crhairr, Can you reproduce this issue?

IvanZheng avatar Dec 20 '18 02:12 IvanZheng

I'm still working on the sub-document update issue. I did some preliminary tests and my local logs show queries going through.

crhairr avatar Dec 20 '18 03:12 crhairr

If your tests are OK, please provide the code or commit to the repo so that I can verify it on my computer. Thanks!

IvanZheng avatar Dec 20 '18 05:12 IvanZheng

I've been working on a substantial re-write of the metadata tracking system. In the process, I think I may have found part of the issue which is that certain layers of the EF Core query system result in overriding the underlying query provider a basic enumerating provider. I've seen where in some cases, the entire query can be detached from the underlying provider, resulting in enumerating the entire collection from the DB and filtering in-memory on the client.

I've started some changes to address this. I need to finish the current set of changes, and then I can work on things like being able to log the effective query and testing that the correct query goes to the server.

crhairr avatar Feb 06 '19 05:02 crhairr

After I finally dealt with the issues that were wrong with the owned/complex EntityType models, I got started on this and found that I have to rewrite a substantial amount of the query processing code in order to get Includes to work correctly and to work around navigation injections for owned documents. I have a branch where everything but the includes are working, but I'm still working on getting the Include compiler finalized.

crhairr avatar Mar 02 '19 06:03 crhairr