{"action":"created","issue":{"url":"https://api.github.com/repos/arangodb/arangodb/issues/1624","labels_url":"https://api.github.com/repos/arangodb/arangodb/issues/1624/labels{/name}","comments_url":"https://api.github.com/repos/arangodb/arangodb/issues/1624/comments","events_url":"https://api.github.com/repos/arangodb/arangodb/issues/1624/events","html_url":"https://github.com/arangodb/arangodb/issues/1624","id":122993349,"number":1624,"title":"Problem with the ternary operator","user":{"login":"Kurtas","id":970983,"avatar_url":"https://avatars.githubusercontent.com/u/970983?v=3","gravatar_id":"","url":"https://api.github.com/users/Kurtas","html_url":"https://github.com/Kurtas","followers_url":"https://api.github.com/users/Kurtas/followers","following_url":"https://api.github.com/users/Kurtas/following{/other_user}","gists_url":"https://api.github.com/users/Kurtas/gists{/gist_id}","starred_url":"https://api.github.com/users/Kurtas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kurtas/subscriptions","organizations_url":"https://api.github.com/users/Kurtas/orgs","repos_url":"https://api.github.com/users/Kurtas/repos","events_url":"https://api.github.com/users/Kurtas/events{/privacy}","received_events_url":"https://api.github.com/users/Kurtas/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/arangodb/arangodb/labels/aql","name":"aql","color":"444444"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-12-18T17:35:19Z","updated_at":"2015-12-23T15:58:40Z","closed_at":"2015-12-23T09:25:32Z","body":"Hi, \r\n\r\n I have following aql where I want first to check IP in vTask collection and if it isn't stored there then I need try to select from other collection.\r\n\r\nIn other words I don't want make a select from both collections, if I have stored IP in vTask, it's not necessary. But Arango always run also second query according to execution plan.\r\n\r\n```\r\nlet tasks=(for task in vTask filter task.ip == '10.67.125.125' return task)\r\nreturn length(tasks) == 0 ? (for l3 in vIntL3 filter l3.ip == '10.67.125.125' return l3) : (tasks)\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/arangodb/arangodb/issues/comments/166930472","html_url":"https://github.com/arangodb/arangodb/issues/1624#issuecomment-166930472","issue_url":"https://api.github.com/repos/arangodb/arangodb/issues/1624","id":166930472,"user":{"login":"jsteemann","id":1423118,"avatar_url":"https://avatars.githubusercontent.com/u/1423118?v=3","gravatar_id":"","url":"https://api.github.com/users/jsteemann","html_url":"https://github.com/jsteemann","followers_url":"https://api.github.com/users/jsteemann/followers","following_url":"https://api.github.com/users/jsteemann/following{/other_user}","gists_url":"https://api.github.com/users/jsteemann/gists{/gist_id}","starred_url":"https://api.github.com/users/jsteemann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsteemann/subscriptions","organizations_url":"https://api.github.com/users/jsteemann/orgs","repos_url":"https://api.github.com/users/jsteemann/repos","events_url":"https://api.github.com/users/jsteemann/events{/privacy}","received_events_url":"https://api.github.com/users/jsteemann/received_events","type":"User","site_admin":false},"created_at":"2015-12-23T15:58:40Z","updated_at":"2015-12-23T15:58:40Z","body":"I think that even though the explain shows the two subqueries being placed on the main level unconditionally, the extra filter inside the true-part subquery should prevent it from being executed:\r\n```(filter isempty for l3 in vIntL3 filter l3.ip == '10.67.125.125' return l3)```\r\n\r\nIn the above if `isempty` is true, then there shouldn't be reads from the vIntL3 collection. You can validate if it reads from it by modifying that part as follows:\r\n```(filter isempty for l3 in vIntL3 filter fail('should not get here!') && l3.ip == '10.67.125.125' l3)```\r\nIf `isempty` is false, then it should not go into the subquery and access the collection. If `isempty` is true, then it should do it of course. The `fail()` function I used is just a quick test to show that the branch is actually executed, because it will make the query abort with the specified message.\r\n\r\nMerry christmas to you too!"}}