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

Anonymous BEGIN NOT ATOMIC block ignores PATH and raises ERROR 1046 without a current database

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Duplicate
    • 12.3.3
    • N/A
    • Server
    • None
    • Linux x86_64
    • Not for Release Notes

    Description

      An unqualified procedure call resolves through an explicit PATH when issued directly without a current database, but the same call inside an anonymous BEGIN NOT ATOMIC block fails with ERROR 1046 (3D000): No database selected. This was reproduced on MariaDB 12.3.3.

      Trigger

      Save the following as test.sql:

      CREATE DATABASE routines;
      CREATE PROCEDURE routines.get_marker() SELECT 7 AS marker;
      CREATE DATABASE scratch;
      USE scratch;
      DROP DATABASE scratch;
      SET PATH 'routines';
      SELECT DATABASE() IS NULL AS no_current_database;
      CALL get_marker();
      DELIMITER //
      BEGIN NOT ATOMIC
        CALL get_marker();
      END//
      DELIMITER ;

      Run test.sql in a MariaDB client session. Creating, selecting, and dropping scratch deliberately leaves the session without a current database before PATH is set.

      The direct call resolves get_marker through PATH and returns 7, but the anonymous block then fails:

      no_current_database
      1
      marker
      7
       
      --------------
      BEGIN NOT ATOMIC
        CALL get_marker();
      END
      --------------
       
      ERROR 1046 (3D000): No database selected

      Controls

      After the trigger, reconnect so that this runs in a new client session, then execute the following as control.sql:

      CREATE DATABASE scratch;
      USE scratch;
      DROP DATABASE scratch;
      SET PATH 'routines';
      DELIMITER //
      BEGIN NOT ATOMIC
        CALL routines.get_marker();
      END//
      DELIMITER ;
      USE routines;
      DELIMITER //
      BEGIN NOT ATOMIC
        CALL get_marker();
      END//
      DELIMITER ;

      Both control blocks succeed and return 7:

      marker
      7
      marker
      7

      The qualified call shows that anonymous block syntax and procedure execution work without a current database. The second call shows that the unqualified block call works when a current database is selected. With PATH 'routines' set, the unqualified call in the trigger should likewise resolve get_marker and return 7 instead of requiring a current database.

      This occurs when an anonymous compound statement calls a procedure through an explicit PATH while the session has no current database.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              noob liu
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.