{"action":"created","issue":{"url":"https://api.github.com/repos/datajoint/datajoint-python/issues/129","labels_url":"https://api.github.com/repos/datajoint/datajoint-python/issues/129/labels{/name}","comments_url":"https://api.github.com/repos/datajoint/datajoint-python/issues/129/comments","events_url":"https://api.github.com/repos/datajoint/datajoint-python/issues/129/events","html_url":"https://github.com/datajoint/datajoint-python/issues/129","id":95642084,"number":129,"title":"Erroneous handling of projection for relation already restricted by another relation","user":{"login":"eywalker","id":3084661,"avatar_url":"https://avatars.githubusercontent.com/u/3084661?v=3","gravatar_id":"","url":"https://api.github.com/users/eywalker","html_url":"https://github.com/eywalker","followers_url":"https://api.github.com/users/eywalker/followers","following_url":"https://api.github.com/users/eywalker/following{/other_user}","gists_url":"https://api.github.com/users/eywalker/gists{/gist_id}","starred_url":"https://api.github.com/users/eywalker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eywalker/subscriptions","organizations_url":"https://api.github.com/users/eywalker/orgs","repos_url":"https://api.github.com/users/eywalker/repos","events_url":"https://api.github.com/users/eywalker/events{/privacy}","received_events_url":"https://api.github.com/users/eywalker/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-17T11:48:08Z","updated_at":"2015-07-23T16:22:43Z","closed_at":null,"body":"When projecting a relation (call it **A**) that is restricted by another relation (**B**), it results incomplete SQL string if **B** heading contains attributes that are not inside *projected* attributes of **A**. For more concrete example, assume that relation **A** have pk attributes (a, b) and non-pk attributes (x, y, z). Also assume that (x) is a pk attribute in **B**. Given this, following pseudo-code was giving error:\r\n\r\n```\r\n(A & B).project()\r\n```\r\n\r\nThis turns out to be due to recent optimization in `Project` that expanded the restrictions on the argument of project (in this case **A**) if there are no aliasing operation during project. This essentially resulted in the restriction (**B**) to be applied **after** the projection operation, giving (essentially)\r\n\r\n```\r\nA.project() & B\r\n```\r\n\r\nNote that `A.project()` only contains (a, b) and not x, thus resulting in improper restriction by **B** which only contains attribute x. \r\n\r\nI believe that this change was introduced in an attempt to speed up some projections where you could truly expand restrictions: for example, if in above case **B** contained attributes (a,b) instead, then expansion would have worked. However, as this case showed, checking for alias is not enough. I've implemented a compromise where I check for **B**'s heading and see if all attributes of **B** belongs to *projected attributes* for A. If true, then restriction is expanded. Otherwise, `Subquery` is used. It is quite possible that a better optimization can be performed. I just wanted to make sure all were aware of the changes and the reason behind it."},"comment":{"url":"https://api.github.com/repos/datajoint/datajoint-python/issues/comments/124156579","html_url":"https://github.com/datajoint/datajoint-python/issues/129#issuecomment-124156579","issue_url":"https://api.github.com/repos/datajoint/datajoint-python/issues/129","id":124156579,"user":{"login":"dimitri-yatsenko","id":1096169,"avatar_url":"https://avatars.githubusercontent.com/u/1096169?v=3","gravatar_id":"","url":"https://api.github.com/users/dimitri-yatsenko","html_url":"https://github.com/dimitri-yatsenko","followers_url":"https://api.github.com/users/dimitri-yatsenko/followers","following_url":"https://api.github.com/users/dimitri-yatsenko/following{/other_user}","gists_url":"https://api.github.com/users/dimitri-yatsenko/gists{/gist_id}","starred_url":"https://api.github.com/users/dimitri-yatsenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimitri-yatsenko/subscriptions","organizations_url":"https://api.github.com/users/dimitri-yatsenko/orgs","repos_url":"https://api.github.com/users/dimitri-yatsenko/repos","events_url":"https://api.github.com/users/dimitri-yatsenko/events{/privacy}","received_events_url":"https://api.github.com/users/dimitri-yatsenko/received_events","type":"User","site_admin":false},"created_at":"2015-07-23T16:22:42Z","updated_at":"2015-07-23T16:22:42Z","body":"I am fixing this on the development branch.  Please add a very specific example that reproduces the problem."}}