MySQL – Generated Columns with Non-Deterministic Functions

MySQLoptimization

ON MySQL 5.7, generated columns are not allowed with non-deterministic function.

The query that I need to optimize is executing on a bulky table.

Where clause is causing a full scan on the table, need to optimize that.

The column is DateTime type, we have to use the unix_timestamp function as per application

WHERE UNIX_TIMESTAMP(Last_Used_Time) > 1540874005

I am trying to convert UNIX_TIMESTAMP(Last_Used_Time) into a generated column but throws an error disallowed function used in the expression.

Any workaround to allow MySQL to use generated/virtual column with unix_timestamp function.

Best Answer

Don't convert the column's value, convert your criterium:

WHERE Last_Used_Time > from_unixtime(1540874005)