{"action":"opened","issue":{"url":"https://api.github.com/repos/lykahb/groundhog/issues/57","repository_url":"https://api.github.com/repos/lykahb/groundhog","labels_url":"https://api.github.com/repos/lykahb/groundhog/issues/57/labels{/name}","comments_url":"https://api.github.com/repos/lykahb/groundhog/issues/57/comments","events_url":"https://api.github.com/repos/lykahb/groundhog/issues/57/events","html_url":"https://github.com/lykahb/groundhog/issues/57","id":148123412,"number":57,"title":"Query performance (table indexes are ignored)","user":{"login":"nhenezi","id":1262435,"avatar_url":"https://avatars.githubusercontent.com/u/1262435?v=3","gravatar_id":"","url":"https://api.github.com/users/nhenezi","html_url":"https://github.com/nhenezi","followers_url":"https://api.github.com/users/nhenezi/followers","following_url":"https://api.github.com/users/nhenezi/following{/other_user}","gists_url":"https://api.github.com/users/nhenezi/gists{/gist_id}","starred_url":"https://api.github.com/users/nhenezi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhenezi/subscriptions","organizations_url":"https://api.github.com/users/nhenezi/orgs","repos_url":"https://api.github.com/users/nhenezi/repos","events_url":"https://api.github.com/users/nhenezi/events{/privacy}","received_events_url":"https://api.github.com/users/nhenezi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-13T17:05:43Z","updated_at":"2016-04-13T17:05:43Z","closed_at":null,"body":"Hello,\r\n\r\nplease take a look at `equalsOperator a b` for Postgresql: https://github.com/lykahb/groundhog/blob/6d2f68129109330e6e0d0c3d98f03e791ee7a741/groundhog-postgresql/Database/Groundhog/Postgresql.hs#L66\r\n\r\n`a IS NOT DISTINCT FROM b` always ignores indexes, which makes queries on large table quite expensive\r\n\r\n\r\n```\r\ntestdb=# explain ANALYZE UPDATE \"public\".\"test_table\" SET \"status\"='Something' WHERE \"id\" IS NOT DISTINCT FROM 468029;                                                                          \r\n                                                     QUERY PLAN                                                     \r\n--------------------------------------------------------------------------------------------------------------------\r\n Update on test_table  (cost=0.00..59080.88 rows=1 width=87) (actual time=544.271..544.271 rows=0 loops=1)\r\n   ->  Seq Scan on test_table  (cost=0.00..59080.88 rows=1 width=87) (actual time=105.891..543.881 rows=1 loops=1)\r\n         Filter: (NOT (id IS DISTINCT FROM 468029))\r\n         Rows Removed by Filter: 2139457\r\n Total runtime: 544.308 ms\r\n(5 rows)\r\n```\r\n\r\nCompared to a query using index:\r\n```\r\ntestdb=# explain ANALYZE UPDATE \"public\".\"test_table\" SET \"status\"='Something' WHERE \"id\"=468029;                                                                                               \r\n                                                             QUERY PLAN                                                              \r\n-------------------------------------------------------------------------------------------------------------------------------------\r\n Update on test_table  (cost=0.43..8.45 rows=1 width=87) (actual time=0.069..0.069 rows=0 loops=1)\r\n   ->  Index Scan using test_table_pkey on test_table  (cost=0.43..8.45 rows=1 width=87) (actual time=0.034..0.035 rows=1 loops=1)\r\n         Index Cond: (id = 468029)\r\n Total runtime: 0.116 ms\r\n(4 rows)\r\n```\r\n\r\n\r\nI understand that from Haskell perspective `Nothing == Nothing`, but SQL standard (and postgresql) doesn't consider any two `NULL` values equal.\r\ncb3adcaa65b743a2dab338ffced84a2005de0213 (from 2011) introduced `IS NOT DISTINCT` as equals operator. Is there any other reason (except `NULL` behavior) that requires use `IS NOT DISTINCT` (or `<>`, `<=>` in `mysql`/`sqlite`)?\r\n\r\nWould you be open to fixing this?\r\nI'm new to the groundhog codebase, so I'm not sure what would be the best way to fix this. Do you have any suggestions?\r\n\r\n\r\nIn any case, thank you for this awesome library - keep up the good work!"}}