{"action":"created","issue":{"url":"https://api.github.com/repos/pingcap/tidb/issues/6774","repository_url":"https://api.github.com/repos/pingcap/tidb","labels_url":"https://api.github.com/repos/pingcap/tidb/issues/6774/labels{/name}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/6774/comments","events_url":"https://api.github.com/repos/pingcap/tidb/issues/6774/events","html_url":"https://github.com/pingcap/tidb/issues/6774","id":329900216,"node_id":"MDU6SXNzdWUzMjk5MDAyMTY=","number":6774,"title":"Missing built-in benchmark function","user":{"login":"morgo","id":57982,"node_id":"MDQ6VXNlcjU3OTgy","avatar_url":"https://avatars2.githubusercontent.com/u/57982?v=4","gravatar_id":"","url":"https://api.github.com/users/morgo","html_url":"https://github.com/morgo","followers_url":"https://api.github.com/users/morgo/followers","following_url":"https://api.github.com/users/morgo/following{/other_user}","gists_url":"https://api.github.com/users/morgo/gists{/gist_id}","starred_url":"https://api.github.com/users/morgo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/morgo/subscriptions","organizations_url":"https://api.github.com/users/morgo/orgs","repos_url":"https://api.github.com/users/morgo/repos","events_url":"https://api.github.com/users/morgo/events{/privacy}","received_events_url":"https://api.github.com/users/morgo/received_events","type":"User","site_admin":false},"labels":[{"id":861773132,"node_id":"MDU6TGFiZWw4NjE3NzMxMzI=","url":"https://api.github.com/repos/pingcap/tidb/labels/component/expression","name":"component/expression","color":"fbca04","default":false},{"id":586074134,"node_id":"MDU6TGFiZWw1ODYwNzQxMzQ=","url":"https://api.github.com/repos/pingcap/tidb/labels/for%20new%20contributors","name":"for new contributors","color":"c2e0c6","default":false},{"id":256872089,"node_id":"MDU6TGFiZWwyNTY4NzIwODk=","url":"https://api.github.com/repos/pingcap/tidb/labels/help%20wanted","name":"help wanted","color":"159818","default":true},{"id":256872088,"node_id":"MDU6TGFiZWwyNTY4NzIwODg=","url":"https://api.github.com/repos/pingcap/tidb/labels/type/enhancement","name":"type/enhancement","color":"84b6eb","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-06-06T14:44:51Z","updated_at":"2018-12-25T13:33:32Z","closed_at":null,"author_association":"MEMBER","body":"Please answer these questions before submitting your issue. Thanks!\r\n\r\n1. What did you do?\r\nIf possible, provide a recipe for reproducing the error.\r\n\r\nThe built-in benchmark function in MySQL is useful for testing.  I was hoping to use it to generate load on TiDB so I could test auto-scaling in AWS easily (using CPU as a metric).\r\n\r\n2. What did you expect to see?\r\n\r\n```\r\nmysql57> select benchmark(10000000, md5(rand()));\r\n+----------------------------------+\r\n| benchmark(10000000, md5(rand())) |\r\n+----------------------------------+\r\n|                                0 |\r\n+----------------------------------+\r\n1 row in set (8.79 sec)\r\n```\r\n\r\n3. What did you see instead?\r\n\r\n```\r\ntidb> select benchmark(10000000, md5(rand()));\r\nERROR 1305 (42000): FUNCTION BENCHMARK does not exist\r\n```\r\n\r\n4. What version of TiDB are you using (`tidb-server -V` or run `select tidb_version();` on TiDB)?\r\n\r\n```\r\ntidb> select tidb_version()\\G\r\n*************************** 1. row ***************************\r\ntidb_version(): Release Version: v2.1.0-alpha-4-g13050b4\r\nGit Commit Hash: 13050b4d60ebe2da156af7e15774e28119dae165\r\nGit Branch: master\r\nUTC Build Time: 2018-06-04 02:07:21\r\nGoVersion: go version go1.10.2 linux/amd64\r\nRace Enabled: false\r\nTiKV Min Version: 2.0.0-rc.4.1\r\n1 row in set (0.00 sec)\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/pingcap/tidb/issues/comments/449850874","html_url":"https://github.com/pingcap/tidb/issues/6774#issuecomment-449850874","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/6774","id":449850874,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0OTg1MDg3NA==","user":{"login":"wuudjac","id":6769630,"node_id":"MDQ6VXNlcjY3Njk2MzA=","avatar_url":"https://avatars0.githubusercontent.com/u/6769630?v=4","gravatar_id":"","url":"https://api.github.com/users/wuudjac","html_url":"https://github.com/wuudjac","followers_url":"https://api.github.com/users/wuudjac/followers","following_url":"https://api.github.com/users/wuudjac/following{/other_user}","gists_url":"https://api.github.com/users/wuudjac/gists{/gist_id}","starred_url":"https://api.github.com/users/wuudjac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wuudjac/subscriptions","organizations_url":"https://api.github.com/users/wuudjac/orgs","repos_url":"https://api.github.com/users/wuudjac/repos","events_url":"https://api.github.com/users/wuudjac/events{/privacy}","received_events_url":"https://api.github.com/users/wuudjac/received_events","type":"User","site_admin":false},"created_at":"2018-12-25T13:33:32Z","updated_at":"2018-12-25T13:33:32Z","author_association":"NONE","body":"Say we have this query:\r\n```\r\nselect benchmark(1000000000, length('foo'));\r\n```\r\nIn tidb-server, the argument function will be constant folded by `core.expressionRewriter.Leave()` as a visitor.\r\n\r\nSo, the query will be rewriten like this:\r\n```\r\nselect benchmark(1000000000, 3);\r\n```\r\nMaking the evaluation of `benchmark()` just purely looping a constant. \r\n\r\nIn mysql 5.7,  the argument function is not constant folded, so the execurtion time differs, you can compare duration of these queries:\r\n```\r\nselect benchmark(1000000000, length('foo'));\r\nselect benchmark(1000000000, 3);\r\nselect benchmark(1000000000, sin(123)+sin(456));\r\n```\r\n\r\nIn order to make tidb-server behaves like mysql, I think constant folding needs to be turned off while visiting `benchmark` AST, making `core.expressionRewriter.Leave()` use `expression.NewFunctionBase()` instead of `expression.NewFunction()` in this case.\r\n\r\nHowever, it may change many places where expression rewriter uses `expression.NewFunction()`, and may add a new flag into expression rewriter to act as a trigger, is it necessary to accomplish this? What's your opinion? @morgo @coocood "}}
{"actor":{"display_login":"wuudjac"}}