{"action":"created","issue":{"url":"https://api.github.com/repos/cockroachdb/cockroach/issues/10109","repository_url":"https://api.github.com/repos/cockroachdb/cockroach","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/10109/labels{/name}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/10109/comments","events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/10109/events","html_url":"https://github.com/cockroachdb/cockroach/issues/10109","id":184242621,"number":10109,"title":"sql: inconsistent comparisons of NaN","user":{"login":"eisenstatdavid","id":3858570,"avatar_url":"https://avatars.githubusercontent.com/u/3858570?v=3","gravatar_id":"","url":"https://api.github.com/users/eisenstatdavid","html_url":"https://github.com/eisenstatdavid","followers_url":"https://api.github.com/users/eisenstatdavid/followers","following_url":"https://api.github.com/users/eisenstatdavid/following{/other_user}","gists_url":"https://api.github.com/users/eisenstatdavid/gists{/gist_id}","starred_url":"https://api.github.com/users/eisenstatdavid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eisenstatdavid/subscriptions","organizations_url":"https://api.github.com/users/eisenstatdavid/orgs","repos_url":"https://api.github.com/users/eisenstatdavid/repos","events_url":"https://api.github.com/users/eisenstatdavid/events{/privacy}","received_events_url":"https://api.github.com/users/eisenstatdavid/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-20T14:18:09Z","updated_at":"2016-10-20T14:57:12Z","closed_at":null,"body":"The issue on my mind at present is the following inconsistency between sorting and scanning an index, but in general, we're not handling NaN comparisons very well.\r\n\r\n```\r\nroot@:26257> CREATE DATABASE foo;\r\nCREATE DATABASE\r\nroot@:26257> CREATE TABLE foo.bar (baz INT PRIMARY KEY, quux FLOAT);\r\nCREATE TABLE\r\nroot@:26257> INSERT INTO foo.bar VALUES (1, 0/0), (2, -1), (3, 1), (4, 0/0);\r\nINSERT 4\r\nroot@:26257> SELECT quux FROM foo.bar ORDER BY quux;\r\n+------+\r\n| quux |\r\n+------+\r\n| NaN  |\r\n|   -1 |\r\n|    1 |\r\n| NaN  |\r\n+------+\r\n(4 rows)\r\nroot@:26257> CREATE INDEX splat ON foo.bar (quux);\r\nCREATE INDEX\r\nroot@:26257> SELECT quux FROM foo.bar ORDER BY quux;\r\n+------+\r\n| quux |\r\n+------+\r\n| NaN  |\r\n| NaN  |\r\n|   -1 |\r\n|    1 |\r\n+------+\r\n(4 rows)\r\n```"},"comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments/255130661","html_url":"https://github.com/cockroachdb/cockroach/issues/10109#issuecomment-255130661","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/10109","id":255130661,"user":{"login":"petermattis","id":6201335,"avatar_url":"https://avatars.githubusercontent.com/u/6201335?v=3","gravatar_id":"","url":"https://api.github.com/users/petermattis","html_url":"https://github.com/petermattis","followers_url":"https://api.github.com/users/petermattis/followers","following_url":"https://api.github.com/users/petermattis/following{/other_user}","gists_url":"https://api.github.com/users/petermattis/gists{/gist_id}","starred_url":"https://api.github.com/users/petermattis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermattis/subscriptions","organizations_url":"https://api.github.com/users/petermattis/orgs","repos_url":"https://api.github.com/users/petermattis/repos","events_url":"https://api.github.com/users/petermattis/events{/privacy}","received_events_url":"https://api.github.com/users/petermattis/received_events","type":"User","site_admin":false},"created_at":"2016-10-20T14:57:11Z","updated_at":"2016-10-20T14:57:11Z","body":"Yeah, `DFloat.Compare` is almost certainly doing the wrong thing:\r\n\r\n```\r\nfunc TestDFloatCompare(t *testing.T) {\r\n\tnan := DFloat(math.NaN())\r\n\ttestdata := []struct {\r\n\t\ta DFloat\r\n\t\tb DFloat\r\n\t}{\r\n\t\t{nan, 1},\r\n\t\t{nan, nan},\r\n\t\t{1, nan},\r\n\t}\r\n\tfor _, d := range testdata {\r\n\t\tfmt.Printf(\"(%v).Compare(%v) == %d\\n\",\r\n\t\t\td.a, d.b, d.a.Compare(&d.b))\r\n\t}\r\n}\r\n```\r\n\r\n```\r\n=== RUN   TestDFloatCompare\r\n(NaN).Compare(1) == 0\r\n(NaN).Compare(NaN) == 0\r\n(1).Compare(NaN) == 0\r\n```\r\n\r\nThis argues for making the ordering of NaNs deterministic in `DFloat.Compare`."}}
{"actor":{"display_login":"petermattis"}}