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

Index not being used, if parameter binding is used in combination with UNION in subquery/view

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.5, 10.6, 10.11, 11.4, 11.7
    • 10.5, 10.6, 10.11, 11.4, 11.7
    • Optimizer
    • None
    • MariaDB: reproduced with 10.x & 11.x, up to 11.5
      OS: any

    Description

      Reproducer query:

      SELECT *
      FROM (
          SELECT * FROM my_table
          UNION ALL
          SELECT * FROM my_table
      ) q
      WHERE q.column_with_index = ?;
      

      I am using PHP to execute this query. Everything works fine when using PDO's emulated parameter bindings. The execution is fast and "EXPLAIN SELECT ..." reveals that the index on column "column_with_index" is being used.

      Things change when I set "PDO::ATTR_EMULATE_PREPARES" to "false": When using MariaDB's native parameter binding protocol, the index is not being used.

      This behavior changes again, depending on the exact parameter binding protocol + charset + database API combination.

      I've posted my question to StackOverflow and somebody suspected this to be a bug in MariaDB.
      The post can be found here: https://stackoverflow.com/q/79245146/1529133

      I've also prepared a reproducer here:
      https://phpize.online/sql/mariadb115/a1c61a1321ba2adfc689bd9e87e75ad9/php/php82/c602157f683d216f384ec3e56833df9b/

      Attachments

        Activity

          People

            psergei Sergei Petrunia
            FeBe95 Felix Bernhard
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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