{"action":"created","issue":{"url":"https://api.github.com/repos/slamdata/slamengine/issues/621","labels_url":"https://api.github.com/repos/slamdata/slamengine/issues/621/labels{/name}","comments_url":"https://api.github.com/repos/slamdata/slamengine/issues/621/comments","events_url":"https://api.github.com/repos/slamdata/slamengine/issues/621/events","html_url":"https://github.com/slamdata/slamengine/issues/621","id":57962305,"number":621,"title":"mongodb: (performance) match should be pushed ahead of map-reduce op if it can't be inlined","user":{"login":"mossprescott","id":6147371,"avatar_url":"https://avatars.githubusercontent.com/u/6147371?v=3","gravatar_id":"","url":"https://api.github.com/users/mossprescott","html_url":"https://github.com/mossprescott","followers_url":"https://api.github.com/users/mossprescott/followers","following_url":"https://api.github.com/users/mossprescott/following{/other_user}","gists_url":"https://api.github.com/users/mossprescott/gists{/gist_id}","starred_url":"https://api.github.com/users/mossprescott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mossprescott/subscriptions","organizations_url":"https://api.github.com/users/mossprescott/orgs","repos_url":"https://api.github.com/users/mossprescott/repos","events_url":"https://api.github.com/users/mossprescott/events{/privacy}","received_events_url":"https://api.github.com/users/mossprescott/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/slamdata/slamengine/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-17T18:30:47Z","updated_at":"2015-02-17T18:56:08Z","closed_at":null,"body":"As a rule, we should always attempt to do filtering *before* map-reduce whenever possible\r\n\r\nFor example, in `select length(name) from foo where a=b`, the comparison cannot be handled by a simple selector, but could be done with project/match. Instead the planner currently produces this sequence, which inlines the comparison into SimpleMap. The result is an unnecessarily large, slow map-reduce.\r\n\r\n```\r\nChain\r\n├─ $Read(foo)\r\n├─ $SimpleMap\r\n│  ╰─ JsMacro({\r\n│             \"0\": _.name.length,\r\n│             \"__tmp0\": _.a === _.b\r\n│           })\r\n├─ $Match\r\n│  ╰─ Selector(Doc)\r\n│     ╰─ Selector(BsonField.Name(\"__tmp0\") -> Eq(Bool(true)))\r\n╰─ $Project\r\n   ├─ Name(0 -> $0)\r\n   ╰─ ExcludeId\r\n```\r\n\r\nOddly, in the similar query `select length(name) from foo where a=1`, the $match op *does* end up before the $simpleMap, and ends up getting inlined into the map-reduce command anyway."},"comment":{"url":"https://api.github.com/repos/slamdata/slamengine/issues/comments/74727380","html_url":"https://github.com/slamdata/slamengine/issues/621#issuecomment-74727380","issue_url":"https://api.github.com/repos/slamdata/slamengine/issues/621","id":74727380,"user":{"login":"sellout","id":33031,"avatar_url":"https://avatars.githubusercontent.com/u/33031?v=3","gravatar_id":"","url":"https://api.github.com/users/sellout","html_url":"https://github.com/sellout","followers_url":"https://api.github.com/users/sellout/followers","following_url":"https://api.github.com/users/sellout/following{/other_user}","gists_url":"https://api.github.com/users/sellout/gists{/gist_id}","starred_url":"https://api.github.com/users/sellout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sellout/subscriptions","organizations_url":"https://api.github.com/users/sellout/orgs","repos_url":"https://api.github.com/users/sellout/repos","events_url":"https://api.github.com/users/sellout/events{/privacy}","received_events_url":"https://api.github.com/users/sellout/received_events","type":"User","site_admin":false},"created_at":"2015-02-17T18:56:08Z","updated_at":"2015-02-17T18:56:08Z","body":"Ah, we only force SPBs earlier when the input expressions can be inlined into the `$match`, IE, `DocField`s."}}