{"action":"created","issue":{"url":"https://api.github.com/repos/randlet/django-listable/issues/6","repository_url":"https://api.github.com/repos/randlet/django-listable","labels_url":"https://api.github.com/repos/randlet/django-listable/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/randlet/django-listable/issues/6/comments","events_url":"https://api.github.com/repos/randlet/django-listable/issues/6/events","html_url":"https://github.com/randlet/django-listable/issues/6","id":118201767,"number":6,"title":" foreign key lookups result in long running query","user":{"login":"xavella","id":15383553,"avatar_url":"https://avatars.githubusercontent.com/u/15383553?v=3","gravatar_id":"","url":"https://api.github.com/users/xavella","html_url":"https://github.com/xavella","followers_url":"https://api.github.com/users/xavella/followers","following_url":"https://api.github.com/users/xavella/following{/other_user}","gists_url":"https://api.github.com/users/xavella/gists{/gist_id}","starred_url":"https://api.github.com/users/xavella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xavella/subscriptions","organizations_url":"https://api.github.com/users/xavella/orgs","repos_url":"https://api.github.com/users/xavella/repos","events_url":"https://api.github.com/users/xavella/events{/privacy}","received_events_url":"https://api.github.com/users/xavella/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-21T15:01:37Z","updated_at":"2016-05-18T12:31:44Z","closed_at":null,"body":"Foreign key lookups result in long running query, even on small data set. \r\n\r\nActually, you may not consider this a bug, depending on your view. Using the Business class and Department class example from the documentation, if you search on field \"business\" (a key linking Department to Business), the code results in a long query; however if you search on field \"business__name\" the query is returned in microseconds.\r\n\r\nExample data models:\r\n```python\r\nclass Business(models.Model):\r\n    name = models.CharField(max_length=255)\r\n\r\nclass Department(models.Model):\r\n    name = models.CharField(max_length=255)\r\n    business = models.ForeignKey(Business)\r\n```\r\nResults in a long running search query: \r\n```python\r\nclass Department(BaseListableView):\r\n    model = models.Department\r\n    fields = (\"business\")\r\n```\r\nresults in a quick search query: \r\n```python\r\nclass Department(BaseListableView):\r\n    model = models.Department\r\n    fields = (\"business__name\")\r\n```"},"comment":{"url":"https://api.github.com/repos/randlet/django-listable/issues/comments/220011771","html_url":"https://github.com/randlet/django-listable/issues/6#issuecomment-220011771","issue_url":"https://api.github.com/repos/randlet/django-listable/issues/6","id":220011771,"user":{"login":"werdnav","id":2734062,"avatar_url":"https://avatars.githubusercontent.com/u/2734062?v=3","gravatar_id":"","url":"https://api.github.com/users/werdnav","html_url":"https://github.com/werdnav","followers_url":"https://api.github.com/users/werdnav/followers","following_url":"https://api.github.com/users/werdnav/following{/other_user}","gists_url":"https://api.github.com/users/werdnav/gists{/gist_id}","starred_url":"https://api.github.com/users/werdnav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/werdnav/subscriptions","organizations_url":"https://api.github.com/users/werdnav/orgs","repos_url":"https://api.github.com/users/werdnav/repos","events_url":"https://api.github.com/users/werdnav/events{/privacy}","received_events_url":"https://api.github.com/users/werdnav/received_events","type":"User","site_admin":false},"created_at":"2016-05-18T12:31:44Z","updated_at":"2016-05-18T12:31:44Z","body":"I'm not entirely sure why, but explicitly specifying search_fields results resolves this issue. For example: \r\n\r\n```\r\nclass Department(BaseListableView):\r\n    model = models.Department\r\n    fields = (\"business\")\r\n    search_fields = {\r\n        \"business\": (\"ID__icontains\",),\r\n    }\r\n```\r\nPossibly because **icontains** accepts a partial match? (i.e. not triggering a db call for each character typed into the UI?)"}}