[MDEV-3900] Optimizer difference between MySQL and MariaDB with stored functions in WHERE clause of UPDATE or DELETE statements Created: 2012-12-01 Updated: 2013-01-17 Resolved: 2013-01-17 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.0.0, 5.5.28, 5.3.11 |
| Fix Version/s: | 10.0.1, 5.5.29, 5.3.12 |
| Type: | Bug | Priority: | Major |
| Reporter: | Hank Eskin (Inactive) | Assignee: | Timour Katchaounov (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | optimizer | ||
| Environment: |
CentOS 64bit, Ubuntu 11.10 64bit |
||
| Description |
|
I use the built-in functions "to_days(now())" all the time in my application and queries. To save typing, I shortened this in a user-defined function "tdn()" like this: CREATE FUNCTION tdn() RETURNS int(7) DETERMINISTIC RETURN to_days(now()); When I issue an UPDATE or DELETE statement of a large (300 million rows), fully indexed table like this: update <table> set <field>=<value> where daynum=to_days(now()) <plus optional extra criteria> The update uses the index on the "daynum" field to properly update or delete the proper records. but if I do the same thing using my UDF: update <table> set <field>=<value> where daynum=tdn() <plus optional extra criteria> the query does a full table scan. The exact same UPDATE and DELETE queries running on MySQL 5.5.8 both properly use the index using both methods. All equivalent SELECT queries also use the index as expected on both platforms. The problem only occurs when doing and UPDATE or DELETE and my UDF is in the where clause of an indexed field. But only in MaraiDB and not in MySQL. Is there a workaround for this, or is this an optimizer bug? I'm actually running version MariaDB 5.5.27. |
| Comments |
| Comment by Elena Stepanova [ 2012-12-01 ] |
|
Reproducible on current maria/5.3, maria/5.5, maria/10.0. Not reproducible on maria/5.2, mysql/5.6, mysql-5.1. Test case: CREATE FUNCTION tdn() RETURNS int(7) DETERMINISTIC RETURN to_days(now()); CREATE TABLE t1 (pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY, daynum INT, a CHAR(1), INDEX(daynum), INDEX(a)) ENGINE=MyISAM; FLUSH TABLES; --echo # Status before UPDATE UPDATE t1 SET a = '+' WHERE daynum=tdn(); --echo # Status after UPDATE
Output:
Output with TO_DAYS instead of tdn:
|
| Comment by Hank Eskin (Inactive) [ 2012-12-01 ] |
|
Thank you for creating this test case and validating the bug (so I don't have to). |
| Comment by Timour Katchaounov (Inactive) [ 2013-01-17 ] |
|
Pushed to 5.3. |