Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
MySQL UDF microtime
C
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
compiled_linux
compiled_mac
README.md
license.txt
mysql_udf_microtime.c

README.md

MySQL-udf-microtime

Microtime in MySQL 5.5.*

A User-Defined Function For Mysql 5.5.* that adds microtime support.

How does it scale up to other MySQL time functions?

100,000,000 executions with BENCHMARK() on 2.7GHz Intel Core i5 with Local MySQL 5.5.29:

SELECT BENCHMARK(100000000,NOW()); -- 1.64s
SELECT BENCHMARK(100000000,UNIX_TIMESTAMP()); -- 1.81s
SELECT BENCHMARK(100000000,MICROTIME()); -- 30.1s
SELECT BENCHMARK(100000000,SYSDATE()); -- 148s

About

MySQL-udf-microtime is based on UDFs "udf_microtime" by Vincent Sweeney And "now_usec" by Baron Schwartz, With additional thanks to Justin Swanhart.

All Feedback is appreciated - Feel free to contact me on Twitter.

Download

You can download the precompiled mysql_udf_microtime.so UDF file:

Install

  1. Once you have mysql_udf_microtime.so you need to find out where your mysql installation's plugin directory is located:

    mysql> SHOW VARIABLES LIKE 'plugin_dir';
  2. Move mysql_udf_microtime.so into the plugin_dir.

  3. Create a function named "microtime" pointing to the correct SONAME:

    mysql> CREATE FUNCTION microtime RETURNS REAL SONAME 'mysql_udf_microtime.so';
  4. Test that the function is working:

    mysql> SELECT MICROTIME();
    +-------------------+
    | microtime()       |
    +-------------------+
    | 1381691615.417104 |
    +-------------------+
    1 row in set (0.00 sec)

Compile From Source

You can Downloade the source file mysql_udf_microtime.c and compile it yourself:

Mac Dependencies

  1. Mysql 5.5.*
  2. g++ compiler (included in xcode via additional 'Command Line Tools' download)

Compiling on Mac

Download the source file mysql_udf_microtime.c, cd into its directory and then run:

g++ -Wall -bundle -bundle_loader /usr/local/mysql/bin/mysqld -o mysql_udf_microtime.so `/usr/local/mysql/bin/mysql_config --cflags` mysql_udf_microtime.c

mysql_udf_microtime.so should be created in your current directory.

Linux Dependencies

  1. Mysql 5.5.*
  2. gcc compiler

Compiling on Linux

Download the source file mysql_udf_microtime.c, cd into its directory and then run:

gcc -fPIC -Wall -I/usr/include/mysql -shared -o mysql_udf_microtime.so mysql_udf_microtime.c

mysql_udf_microtime.so should be created in your current directory.

Uninstalling

  1. In Mysql run:
    mysql> DROP FUNCTION microtime;
  2. delete the mysql_udf_microtime.so from the plugin_dir (the one from the installation)

License

This UDF is open source and free to use for anyone under the MIT license.

Something went wrong with that request. Please try again.