Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-3900

Optimizer difference between MySQL and MariaDB with stored functions in WHERE clause of UPDATE or DELETE statements

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.0.0, 5.5.28, 5.3.11
    • 10.0.1, 5.5.29, 5.3.12
    • None
    • 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>
      or
      delete from <table> 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>
      or
      delete from <table> 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.

      Attachments

        Activity

          heskin Hank Eskin (Inactive) created issue -
          elenst Elena Stepanova made changes -
          Field Original Value New Value
          Priority Critical [ 2 ] Major [ 3 ]
          elenst Elena Stepanova made changes -
          Fix Version/s 10.0.1 [ 11400 ]
          Fix Version/s 5.5.29 [ 12102 ]
          elenst Elena Stepanova made changes -
          Affects Version/s 5.3.11 [ 11700 ]
          Affects Version/s 10.0.0 [ 10000 ]
          elenst Elena Stepanova made changes -
          Assignee Sergei Petrunia [ psergey ]
          elenst Elena Stepanova made changes -
          Environment CentOS 64bit CentOS 64bit, Ubuntu 11.10 64bit
          elenst Elena Stepanova made changes -
          Fix Version/s 5.3.12 [ 12000 ]
          serg Sergei Golubchik made changes -
          Labels optimizer udf update optimizer update
          serg Sergei Golubchik made changes -
          Labels optimizer update optimizer
          serg Sergei Golubchik made changes -
          Summary Optimizer difference between MySQL and MariaDB with user defined functions in WHERE clause of UPDATE or DELETE statements Optimizer difference between MySQL and MariaDB with stored functions in WHERE clause of UPDATE or DELETE statements
          serg Sergei Golubchik made changes -
          Assignee Sergei Petrunia [ psergey ] Timour Katchaounov [ timour ]
          timour Timour Katchaounov (Inactive) made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          sanja Oleksandr Byelkin made changes -
          Assignee Timour Katchaounov [ timour ] Oleksandr Byelkin [ sanja ]
          sanja Oleksandr Byelkin made changes -
          Assignee Oleksandr Byelkin [ sanja ] Timour Katchaounov [ timour ]
          timour Timour Katchaounov (Inactive) made changes -
          Status In Progress [ 3 ] Open [ 1 ]
          timour Timour Katchaounov (Inactive) made changes -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow defaullt [ 25427 ] MariaDB v2 [ 46374 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Workflow MariaDB v2 [ 46374 ] MariaDB v3 [ 64380 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 64380 ] MariaDB v4 [ 146233 ]

          People

            timour Timour Katchaounov (Inactive)
            heskin Hank Eskin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.