{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/2460","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/2460/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/2460/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/2460/events","html_url":"https://github.com/aspnet/EntityFramework/issues/2460","id":90703299,"number":2460,"title":"Find/Single issue inefficient SQL","user":{"login":"GSPP","id":12032350,"avatar_url":"https://avatars.githubusercontent.com/u/12032350?v=3","gravatar_id":"","url":"https://api.github.com/users/GSPP","html_url":"https://github.com/GSPP","followers_url":"https://api.github.com/users/GSPP/followers","following_url":"https://api.github.com/users/GSPP/following{/other_user}","gists_url":"https://api.github.com/users/GSPP/gists{/gist_id}","starred_url":"https://api.github.com/users/GSPP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GSPP/subscriptions","organizations_url":"https://api.github.com/users/GSPP/orgs","repos_url":"https://api.github.com/users/GSPP/repos","events_url":"https://api.github.com/users/GSPP/events{/privacy}","received_events_url":"https://api.github.com/users/GSPP/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-06-24T15:07:21Z","updated_at":"2015-06-24T17:47:40Z","closed_at":null,"body":"Find issues SQL like this:\r\n\r\n```\r\nexec sp_executesql N'SELECT TOP (2) \r\n    [Extent1].[ID] AS [ID], \r\n    [Extent1].[Name] AS [Name]\r\n    FROM [dbo].[Customers] AS [Extent1]\r\n    WHERE [Extent1].[ID] = @p0',N'@p0 int',@p0=7\r\n```\r\n\r\nThe TOP 2 is unnecessary.\r\n\r\nEntity Framework should either recognize that there is a filter on a unique key or it should special-case for Find.\r\n\r\nThis really is a minor problem. But the TOP 2 shows up in the execution plan for SQL Server so that this is not exactly zero runtime cost.\r\n\r\nThe same issue applies to code like `db.Orders.Single(o => o.CustomerID == customerID)`.\r\n\r\nJust wanted to create an issue for this so that you can track it as a work item. Certainly not top priority."},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/114953317","html_url":"https://github.com/aspnet/EntityFramework/issues/2460#issuecomment-114953317","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/2460","id":114953317,"user":{"login":"divega","id":1253414,"avatar_url":"https://avatars.githubusercontent.com/u/1253414?v=3","gravatar_id":"","url":"https://api.github.com/users/divega","html_url":"https://github.com/divega","followers_url":"https://api.github.com/users/divega/followers","following_url":"https://api.github.com/users/divega/following{/other_user}","gists_url":"https://api.github.com/users/divega/gists{/gist_id}","starred_url":"https://api.github.com/users/divega/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/divega/subscriptions","organizations_url":"https://api.github.com/users/divega/orgs","repos_url":"https://api.github.com/users/divega/repos","events_url":"https://api.github.com/users/divega/events{/privacy}","received_events_url":"https://api.github.com/users/divega/received_events","type":"User","site_admin":false},"created_at":"2015-06-24T17:47:40Z","updated_at":"2015-06-24T17:47:40Z","body":"@vossad01 Nothing in my mental model of how databases work tells me that there should be a significant difference. However ad-hoc testing shows that without the TOP 2 is 6 times faster :smile: "}}