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

ROW_COUNT() after REPLACE of duplicit row returns 1

    XMLWordPrintable

Details

    Description

      On table with single unique index:

      CREATE TABLE `test` (
        `id` int(11) NOT NULL,
        `value` int(11) NOT NULL,
        UNIQUE KEY `id` (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci
      

      ROW_COUNT() returns allways 1, even for duplicate rows:

      REPLACE INTO test VALUES (1,1); SELECT ROW_COUNT(); REPLACE INTO test VALUES (1,1); SELECT ROW_COUNT();
      Query OK, 1 row affected (0.000 sec)
       
      +-------------+
      | ROW_COUNT() |
      +-------------+
      |           1 |
      +-------------+
      1 row in set (0.000 sec)
       
      Query OK, 1 row affected (0.000 sec)
       
      +-------------+
      | ROW_COUNT() |
      +-------------+
      |           1 |
      +-------------+
      1 row in set (0.000 sec)
      

      On table with multiple indexes:

      CREATE TABLE `test` (
        `id` int(11) NOT NULL,
        `value` int(11) NOT NULL,
        UNIQUE KEY `id` (`id`),
        UNIQUE KEY `value` (`value`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci
      

      ROW_COUNT() returns correct result according to documentation (1 and then 2):

      REPLACE INTO test VALUES (1,1); SELECT ROW_COUNT(); REPLACE INTO test VALUES (1,1); SELECT ROW_COUNT();
      Query OK, 1 row affected (0.000 sec)
       
      +-------------+
      | ROW_COUNT() |
      +-------------+
      |           1 |
      +-------------+
      1 row in set (0.000 sec)
       
      Query OK, 2 rows affected (0.000 sec)
       
      +-------------+
      | ROW_COUNT() |
      +-------------+
      |           2 |
      +-------------+
      1 row in set (0.000 sec)
      

      Attachments

        Activity

          People

            sanja Oleksandr Byelkin
            matesstar Martin Tomec
            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.