Port MySQL patch for functions with constant values

Registered by Lee Bieber

This blueprint has been superseded. See the newer blueprint "Port fixes for multiple evaluation of constants from MySQL" for updated plans.

From Jay:

Basically, the fixes are to ensure items in the parsed syntax tree which evaluate to a constant (such as UNIX_TIMESTAMP(constant) are only evaluated once and then cached in the Lex as a Item_cached_xxx object.

The port would be to take the commit and apply it almost as-is to Drizzle, add the associated test cases, and cleanup any non-Drizzle stuff in the commit (pretty minimal).

First come, first served! I can help out any takers on IRC.

-------- Original Message --------
Subject: Re: Functions of constant values
Date: Thu, 03 Dec 2009 18:53:54 +0100
From: Sergei Golubchik <email address hidden>
To: Olivier <email address hidden>
CC: <email address hidden> <email address hidden>
References: <email address hidden> <email address hidden> <email address hidden> <email address hidden> <email address hidden> <00af01ca7371$3687d250$a39776f0$@com> <email address hidden> <email address hidden>

Hi, Olivier!

> Is there a reason to compute some functions of constant values multiple times?

No.

> While debugging, I found unix_timestamp(constant) gets evaluated 3
> times in the (silly) example below (MySQL 5.1.41):
>
> DROP DATABASE IF EXISTS `test`;
> CREATE DATABASE `test`;
> DROP TABLE IF EXISTS `test`.`test`;
> CREATE TABLE `test`.`test` (
> `t` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
> INSERT INTO `test`.`test` VALUES('2009-12-03 14:00:00'),('2009-12-03 14:01:00'),('2009-12-03 14:02:00');
> SELECT * FROM `test`.`test` WHERE unix_timestamp(t) >= unix_timestamp('2009-12-03 14:01:00');
>
> I thought deterministic functions of constant values where always
> optimized away by the query engine? Or this is a bug in
> unix_timestamp()?

The fix was just pushed this week.
http://bugs.mysql.com/33546
http://bugs.mysql.com/47839
http://bugs.mysql.com/41153

It didn't make it into 5.1, but it'll be in the next GA release.

--

Blueprint information

Status:
Complete
Approver:
Jay Pipes
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
Superseded
Series goal:
None
Implementation:
Unknown
Milestone target:
None
Completed by
Lee Bieber

Related branches

Sprints

Whiteboard

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.