← Back to team overview

drizzle-discuss team mailing list archive

[Fwd: Re: Functions of constant values]

 

Anybody interested in porting the fixes for this issue into Drizzle?

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.

Cheers,

jay

-------- Original Message --------
Subject: Re: Functions of constant values
Date: Thu, 03 Dec 2009 18:53:54 +0100
From: Sergei Golubchik <serg@xxxxxxxxx>
To: Olivier <och@xxxxxxxxxxxxx>
CC: internals@xxxxxxxxxxxxxxx <internals@xxxxxxxxxxxxxxx>
References: <381204.87969.qm@xxxxxxxxxxxxxxxxxxxxxxxxxxx> <20091201153149.GA3974@janus.mylan> <740929.55959.qm@xxxxxxxxxxxxxxxxxxxxxxxxxxx> <20091201181359.GA30801@janus.mylan> <123903.90936.qm@xxxxxxxxxxxxxxxxxxxxxxxxxxx> <00af01ca7371$3687d250$a39776f0$@com> <40034.85022.qm@xxxxxxxxxxxxxxxxxxxxxxxxxxx> <29950174C01D6949A1C0A924C7FAAB5C02BC73DA93@xxxxxxxxxxxx.local>

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.

Regards / Mit vielen Grüßen,
Sergei

--
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /   Sergei Golubchik <serg@xxxxxxx>
 / /|_/ / // /\ \/ /_/ / /__  Principal Software Engineer/Server Architect
/_/  /_/\_, /___/\___\_\___/  Sun Microsystems GmbH, HRB München 161028
       <___/                  Sonnenallee 1, 85551 Kirchheim-Heimstetten
Geschäftsführer: Thomas Schroeder, Wolfgang Engels, Wolf Frenkel
Vorsitzender des Aufsichtsrates: Martin Häring

--
MySQL Internals Mailing List
For list archives: http://lists.mysql.com/internals
To unsubscribe:    http://lists.mysql.com/internals?unsub=jay@xxxxxxxxx