{"action":"created","issue":{"url":"https://api.github.com/repos/BaseXdb/basex/issues/1231","labels_url":"https://api.github.com/repos/BaseXdb/basex/issues/1231/labels{/name}","comments_url":"https://api.github.com/repos/BaseXdb/basex/issues/1231/comments","events_url":"https://api.github.com/repos/BaseXdb/basex/issues/1231/events","html_url":"https://github.com/BaseXdb/basex/issues/1231","id":123619919,"number":1231,"title":"Possible optimizer bug when referencing collections from within predicates","user":{"login":"JensErat","id":628441,"avatar_url":"https://avatars.githubusercontent.com/u/628441?v=3","gravatar_id":"","url":"https://api.github.com/users/JensErat","html_url":"https://github.com/JensErat","followers_url":"https://api.github.com/users/JensErat/followers","following_url":"https://api.github.com/users/JensErat/following{/other_user}","gists_url":"https://api.github.com/users/JensErat/gists{/gist_id}","starred_url":"https://api.github.com/users/JensErat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JensErat/subscriptions","organizations_url":"https://api.github.com/users/JensErat/orgs","repos_url":"https://api.github.com/users/JensErat/repos","events_url":"https://api.github.com/users/JensErat/events{/privacy}","received_events_url":"https://api.github.com/users/JensErat/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-23T08:22:51Z","updated_at":"2015-12-23T08:29:28Z","closed_at":null,"body":"As described in the [Stack Overflow question _XPath: What does the «/» operator at the beginning of a rooted path expression exactly match?_](http://stackoverflow.com/q/34424079/695343), it seems BaseX' behavior regarding predicates and collections is a little bit surprising.\r\n\r\n## Example Input\r\n\r\nTwo files in a folder forming a collection later:\r\n\r\n- `/foo/myDocs/1.xml`: `<root myAtt=\"one\"/>`\r\n- `/foo/myDocs/2.xml`: `<root myAtt=\"two\"/>`\r\n\r\n## The Issue\r\n\r\nRunning a query\r\n\r\n    collection('/tmp/myDocs')[/root/@myAtt = 'one']\r\n\r\nresulting in\r\n\r\n    <root myAtt=\"one\"/>\r\n    <root myAtt=\"two\r\n\r\nto filter the documents still returns both `<root/>` nodes in BaseX, not in Saxon, which only returns the first document:\r\n\r\n    <root myAtt=\"one\"/>\r\n\r\nBaseX is optimizing this to\r\n\r\n    ((db:open-pre(\"myDocs\",0), ...))[((db:open-pre(\"myDocs\",0), ...)/*:root/@*:myAtt = \"one\")]\r\n\r\nand replaces the implicit `root(.)` call with the internal `db-open-pre` statement returning the collection. To me, this looks like an optimizer issue.\r\n\r\n### Using an explicit root call\r\n\r\nConsidering the `/` and `root()` semantics, I would expect this merely to have the meaning of\r\n\r\n    collection('/tmp/myDocs')[root(.)/root/@myAtt = 'one']\r\n\r\nwith the optimized query\r\n\r\n    ((db:open-pre(\"myDocs\",0), ...))[(root(.)/root/@myAtt = \"one\")]\r\n\r\nreturning\r\n\r\n    <root myAtt=\"one\"/>\r\n\r\nwhich would mean the documents contained in the collection will be tested one by one.\r\n\r\n### Enforcing a self-step\r\n\r\nEnforcing an explicit self-step also resolves the issue:\r\n\r\n    collection('/tmp/myDocs')/self::node()[/root/@myAtt = 'one']\r\n\r\nreturning the expected\r\n\r\n    <root myAtt=\"one\"/>\r\n"},"comment":{"url":"https://api.github.com/repos/BaseXdb/basex/issues/comments/166832974","html_url":"https://github.com/BaseXdb/basex/issues/1231#issuecomment-166832974","issue_url":"https://api.github.com/repos/BaseXdb/basex/issues/1231","id":166832974,"user":{"login":"ChristianGruen","id":196589,"avatar_url":"https://avatars.githubusercontent.com/u/196589?v=3","gravatar_id":"","url":"https://api.github.com/users/ChristianGruen","html_url":"https://github.com/ChristianGruen","followers_url":"https://api.github.com/users/ChristianGruen/followers","following_url":"https://api.github.com/users/ChristianGruen/following{/other_user}","gists_url":"https://api.github.com/users/ChristianGruen/gists{/gist_id}","starred_url":"https://api.github.com/users/ChristianGruen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChristianGruen/subscriptions","organizations_url":"https://api.github.com/users/ChristianGruen/orgs","repos_url":"https://api.github.com/users/ChristianGruen/repos","events_url":"https://api.github.com/users/ChristianGruen/events{/privacy}","received_events_url":"https://api.github.com/users/ChristianGruen/received_events","type":"User","site_admin":false},"created_at":"2015-12-23T08:29:28Z","updated_at":"2015-12-23T08:29:28Z","body":"Thanks for the detailed explanation; I agree."}}