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

Incorrect behavior with EXPLAIN

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.6, 10.11, 11.4, 11.8
    • None
    • Optimizer
    • None
    • ubuntu22.04

    Description

      Summary

      EXPLAIN incorrectly executes a stored function when it appears inside a derived table (e.g. SELECT * FROM (SELECT f()) AS t), while the same function is not invoked for EXPLAIN SELECT f();.


      Environment

      • Product: MariaDB (reproduced on 12.3.1)

      Expected behaviour

      • EXPLAIN should only produce a plan and must not evaluate stored functions (except where explicitly documented otherwise).
      • Scalar and derived-table forms should behave consistently: neither should increment a side-effect counter during EXPLAIN.

      Actual behaviour

      Statement @n after EXPLAIN
      EXPLAIN SELECT m(); 0 (correct)
      EXPLAIN SELECT * FROM (SELECT m()) AS t; 1 (incorrect: m() was executed)

      Minimal reproducer (SQL)

      DROP FUNCTION IF EXISTS m;
      DELIMITER //
      CREATE FUNCTION m() RETURNS INT
      DETERMINISTIC
      BEGIN
        SET @n = IFNULL(@n, 0) + 1;
        RETURN 1;
      END//
      DELIMITER ;
       
      SET @n = 0;
      EXPLAIN SELECT m();
      SELECT @n AS n_after_explain_scalar;   -- expected: 0
       
      SET @n = 0;
      EXPLAIN SELECT * FROM (SELECT m()) AS t;
      SELECT @n AS n_after_explain_derived; -- expected: 0; actual: 1
       
      DROP FUNCTION m;
      

      Attachments

        Activity

          People

            mariadb-pavithrapandith Pavithra Pandith
            mu mu
            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.