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

Incorrect behavior for DELETE statements on a GTT table

    XMLWordPrintable

Details

    • Not for Release Notes
    • Q4/2025 Server Maintenance

    Description

      The first testcase below uses oracle and MariaDB compatible SQL (with some auto-ignored error statements to align instances).

      SET autocommit=0;
      SET SQL_MODE='ORACLE';
       
      CREATE GLOBAL TEMPORARY TABLE gtt (c INT) ON COMMIT PRESERVE ROWS;
       
      INSERT INTO gtt(c) VALUES (1);
      COMMIT;
       
      SELECT COUNT(*) AS ct FROM gtt;
      DELETE FROM gtt WHERE c=1;
      SELECT COUNT(*) AS ct FROM gtt;
       
      -- Cleanup
      TRUNCATE TABLE gtt;
      COMMIT;
      DROP TABLE gtt;
      

      For the second SELECT, on oracle, this leads to:

      oracle

      SQL>
      	CT
      ----------
      	 0
      

      However on MariaDB we see:

      MDEV-35915-6 CS 12.2.0 ed3c63488a1613377d92ee3ade3fe6870e39b4db (Optimized, Clang 21.1.0-20250811) Build 24/09/2025

      12.2.0-opt>SELECT COUNT(*) AS ct FROM gtt;
      +----+
      | ct |
      +----+
      |  1 |
      +----+
      1 row in set (0.000 sec)
      

      Regular temporary tables do not show this issue (MariaDB compatible SQL only):

      SET autocommit=0;
      SET SQL_MODE='ORACLE';
       
      CREATE TEMPORARY TABLE tt (c INT);
       
      INSERT INTO tt(c) VALUES (1);
      COMMIT;
       
      SELECT COUNT(*) AS ct FROM tt;
      DELETE FROM tt WHERE c=1;
      SELECT COUNT(*) AS ct FROM tt;
       
      -- Cleanup
      TRUNCATE TABLE tt;
      COMMIT;
      DROP TABLE tt;
      

      For the second SELECT yields:

      MDEV-35915-6 CS 12.2.0 ed3c63488a1613377d92ee3ade3fe6870e39b4db (Optimized, Clang 21.1.0-20250811) Build 24/09/2025

      12.2.0-opt>SELECT COUNT(*) AS ct FROM tt;
      +----+
      | ct |
      +----+
      |  0 |
      +----+
      1 row in set (0.000 sec)
      

      Nor do regular tables:

      SET autocommit=0;
      SET SQL_MODE='ORACLE';
       
      CREATE TABLE t (c INT);
       
      INSERT INTO t(c) VALUES (1);
      COMMIT;
       
      SELECT COUNT(*) AS ct FROM t;
      DELETE FROM t WHERE c=1;
      SELECT COUNT(*) AS ct FROM t;
       
      -- Cleanup
      TRUNCATE TABLE t;
      COMMIT;
      DROP TABLE t;
      

      For the second SELECT yields:

      MDEV-35915-6 CS 12.2.0 ed3c63488a1613377d92ee3ade3fe6870e39b4db (Optimized, Clang 21.1.0-20250811) Build 24/09/2025

      12.2.0-opt>SELECT COUNT(*) AS ct FROM t;
      +----+
      | ct |
      +----+
      |  0 |
      +----+
      1 row in set (0.000 sec)
      

      Attachments

        Issue Links

          Activity

            People

              nikitamalyavin Nikita Malyavin
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.