{"action":"created","issue":{"url":"https://api.github.com/repos/pingcap/tidb/issues/4236","repository_url":"https://api.github.com/repos/pingcap/tidb","labels_url":"https://api.github.com/repos/pingcap/tidb/issues/4236/labels{/name}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/4236/comments","events_url":"https://api.github.com/repos/pingcap/tidb/issues/4236/events","html_url":"https://github.com/pingcap/tidb/pull/4236","id":251177550,"number":4236,"title":"expression: Support more types when getting default flen and decimal","user":{"login":"breeswish","id":1916485,"avatar_url":"https://avatars3.githubusercontent.com/u/1916485?v=4","gravatar_id":"","url":"https://api.github.com/users/breeswish","html_url":"https://github.com/breeswish","followers_url":"https://api.github.com/users/breeswish/followers","following_url":"https://api.github.com/users/breeswish/following{/other_user}","gists_url":"https://api.github.com/users/breeswish/gists{/gist_id}","starred_url":"https://api.github.com/users/breeswish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/breeswish/subscriptions","organizations_url":"https://api.github.com/users/breeswish/orgs","repos_url":"https://api.github.com/users/breeswish/repos","events_url":"https://api.github.com/users/breeswish/events{/privacy}","received_events_url":"https://api.github.com/users/breeswish/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-08-18T08:38:47Z","updated_at":"2017-08-24T06:04:41Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/4236","html_url":"https://github.com/pingcap/tidb/pull/4236","diff_url":"https://github.com/pingcap/tidb/pull/4236.diff","patch_url":"https://github.com/pingcap/tidb/pull/4236.patch"},"body":"Fix https://github.com/pingcap/tidb/issues/4233\r\n\r\nThis PR needs at least 3 LGTM to merge.\r\n\r\n- Added more default flen / decimal.\r\n- Fixed incorrect REVERSE() return type.\r\n- Fixed incorrect ABS() return type for FLOAT / DOUBLE parameter.\r\n- Fixed incorrect IF / IFNULL type inference: when the decimal of one of the parameter is unspecified, the return decimal should be unspecified.\r\n- Fixed incorrect type inference for some functions: when one of the parameter is a kind of string, its decimal should be treated as unspecified.\r\n- Fixed incorrect decimal / flen in CREATE TABLE.\r\n- Unified default decimal / flen in CAST.\r\n- Fixed `NULLIF(param1, param2)` inconsistent behavior with `IF(param1 = param2, NULL, param1)`.\r\n- Fixed incorrect field name printing:\r\n   - For int types like INT / TINY / BIT and char types like CHAR / VARCHAR, the flen is always printed.\r\n   - For FLOAT / DOUBLE, the flen and decimal is printed only when decimal is specified.\r\n   - For TEXT / BLOB / ..., the flen and decimal is NEVER printed.\r\n- Fixed a bunch of incorrect flen / decimal in typeinfer_test.\r\n\r\n~~TODO: We have a bunch of tests to fix.~~ Fixed\r\n\r\n~~TODO: might need to fix mysql-test.~~ Fixed\r\n\r\n---\r\n\r\n\r\nAfter merging this PR, there are still two primary issues causing our FLEN / DECIMAL inference being incorrect:\r\n\r\n1. We do not differentiate \"significant digit\" and \"display length\" previously. For example, when creating table using `DECIMAL(10, 3)`, the sigificant digit is 10 and the display length is 12 (10 sigificant digit + 1 sign + 1 dot). They are totally mixed together and both of them are stored in `Flen`. Even worse, some of the code treat them as \"significant digit\" and other as \"display length\". Other types like `DATETIME`, `FLOAT`, `DOUBLE` have this issue as well.\r\n\r\n2. We do not assign correct Flen / Decimal in `types.NewFieldType` (we set both of them to -1) so that during the calculation Flen / Decimal might be incorrect."},"comment":{"url":"https://api.github.com/repos/pingcap/tidb/issues/comments/324541863","html_url":"https://github.com/pingcap/tidb/pull/4236#issuecomment-324541863","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/4236","id":324541863,"user":{"login":"zz-jason","id":5268763,"avatar_url":"https://avatars0.githubusercontent.com/u/5268763?v=4","gravatar_id":"","url":"https://api.github.com/users/zz-jason","html_url":"https://github.com/zz-jason","followers_url":"https://api.github.com/users/zz-jason/followers","following_url":"https://api.github.com/users/zz-jason/following{/other_user}","gists_url":"https://api.github.com/users/zz-jason/gists{/gist_id}","starred_url":"https://api.github.com/users/zz-jason/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zz-jason/subscriptions","organizations_url":"https://api.github.com/users/zz-jason/orgs","repos_url":"https://api.github.com/users/zz-jason/repos","events_url":"https://api.github.com/users/zz-jason/events{/privacy}","received_events_url":"https://api.github.com/users/zz-jason/received_events","type":"User","site_admin":false},"created_at":"2017-08-24T06:04:41Z","updated_at":"2017-08-24T06:04:41Z","body":"@XuHuaiyu PTAL"}}
{"actor":{"display_login":"zz-jason"}}