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

SELECT and DELETE/UPDATE return inconsistent row counts with identical WHERE clause

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.6, 10.11, 11.4, 11.8, 12.3, 12.2.2
    • 10.11.17, 11.4.11, 11.8.7, 12.3.2
    • Optimizer
    • OS: Any (Docker container)
      CPU Architecture: Any (x86_64)
      MariaDB version: 12.2.2-MariaDB-ubu2404
    • Not for Release Notes

    Description

      The same WHERE clause produces inconsistent results across different SQL statements.

      • A SELECT COUNT( * ) query returns 4 rows
      • However, executing DELETE or UPDATE with the exact same WHERE condition only affects 1 row

       
      -- SCHEMA
       
      CREATE TABLE orders (
          id          INT,
          user_id     INT,
          amount      DOUBLE,
          status      VARCHAR(20),
          created_at  TIMESTAMP NULL
      );
       
      INSERT INTO orders VALUES
      (1, 1, 100.00, 'paid',    '2022-02-01 09:00:00'),
      (2, 1, 200.50, 'shipped', '2022-02-02 10:00:00'),
      (3, 2, NULL,   'failed',  '2022-02-03 11:00:00'),
      (4, 3, 50.00,  'paid',    '2022-02-04 12:00:00'),
      (5, 5, 999.99, 'paid',    '2022-02-05 13:00:00');
       
      -- TRIGGER SQLs:
       
      SELECT COUNT(*)
      FROM orders
      WHERE LPAD(
              LTRIM('v0px'),
              orders.id
            ) < LEFT('tutl', orders.user_id);
       
      -- RESULT: {4}
       
      DELETE FROM orders
      WHERE LPAD(
              LTRIM('v0px'),
              orders.id
            ) < LEFT('tutl', orders.user_id);
       
      -- affected_rows: {1}
       
      UPDATE orders set 
        id = orders.id, 
        amount = orders.amount
      WHERE LPAD(
              LTRIM('v0px'),
              orders.id
            ) < LEFT('tutl', orders.user_id);
       
      -- affected_rows: {1}
      

      Attachments

        Issue Links

          Activity

            People

              serg Sergei Golubchik
              fmu Jasper Andrew
              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.