Collections:
BENCHMARK() - Repeating Expression Evaluation
How to evaluate an expression repeatedly for benchmark testing using the BENCHMARK() function?
✍: FYIcenter.com
BENCHMARK(count, exp) is a MySQL built-in function that
evaluates an expression repeatedly for benchmark testing
and returns 0.
For example:
SELECT BENCHMARK(1000000, AES_ENCRYPT('hello','goodbye')); -- +----------------------------------------------------+ -- | BENCHMARK(1000000, AES_ENCRYPT('hello','goodbye')) | -- +----------------------------------------------------+ -- | 0 | -- +----------------------------------------------------+ -- 1 row in set (0.39 sec) SELECT BENCHMARK(1000000, AES_ENCRYPT('hello','goodbye')); -- +----------------------------------------------------+ -- | BENCHMARK(1000000, AES_ENCRYPT('hello','goodbye')) | -- +----------------------------------------------------+ -- | 0 | -- +----------------------------------------------------+ -- 1 row in set (0.41 sec)
Note that the input expression can be a SELECT statement as long as it returns one row with one column. For example,
SELECT BENCHMARK(1000000, (SELECT name FROM mysql.help_topic LIMIT 1)); -- +-----------------------------------------------------------------+ -- | BENCHMARK(1000000, (SELECT name FROM mysql.help_topic LIMIT 1)) | -- +-----------------------------------------------------------------+ -- | 0 | -- +-----------------------------------------------------------------+ 1 row in set (0.03 sec) SELECT BENCHMARK(1000000, (SELECT * FROM mysql.help_topic LIMIT 1)); ERROR 1241 (21000): Operand should contain 1 column(s) SELECT BENCHMARK(1000000, (SELECT name FROM mysql.help_topic)); ERROR 1242 (21000): Subquery returns more than 1 row CREATE TABLE MyTable (id INTEGER, count INTEGER); SELECT BENCHMARK(100, (INSERT INTO MyTable VALUES(1,1))); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTO MyTable VALUES(1,1)))' at line 1
Reference information of the BENCHMARK() function:
BENCHMARK(count, exp): int Evaluates an expression repeatedly for benchmark testing. Arguments, return value and availability: count: Required. The number of time to evaluate the expression. exp: Required. The expression to be executed. int: Return value. 0 if evaluations are performed successfully. Available since MySQL 4.0.
⇒ CONNECTION_ID() - Thread ID of Current Connection
⇐ MySQL Functions on System Information
2024-07-17, 749🔥, 2💬
Popular Posts:
How To Create a Table Index in Oracle? If you have a table with a lots of rows, and you know that on...
Where to find MySQL database server tutorials? Here is a collection of tutorials, tips and FAQs for ...
What Is the Difference Between GETDATE() and GETUTCDATE() in SQL Server Transact-SQL? The difference...
Can Date and Time Values Be Converted into Integers in SQL Server Transact-SQL? Can date and time va...
How To Use DATEADD() Function in SQL Server Transact-SQL? DATEADD() is a very useful function for ma...