Uploaded image for project: 'MariaDB MaxScale'
  1. MariaDB MaxScale
  2. MXS-220

LAST_INSERT_ID() query is redirect to slave if function call is in where clause

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.1.1, 1.2.0
    • 1.3.0
    • readwritesplit
    • None

    Description

      Hi,

      If a query contains LAST_INSERT_ID() it should be redirected to master, even if it is in WHERE clause.

      Also another syntax is not redirected to the master: SELECT @id:=LAST_INSERT_ID(); - please let me know if you need a test case for this as well.

      Test case:

      MariaDB [mariadb_test]> create table a (id serial, primary key(id));
      Query OK, 0 rows affected (0.02 sec)
       
      MariaDB [mariadb_test]> insert into a values(null);
      Query OK, 1 row affected (0.00 sec)
       
      MariaDB [mariadb_test]> select @@hostname from a WHERE id=last_insert_id();
      Empty set (0.00 sec)
       
      michaeldg [5:44 PM]
      MariaDB [mariadb_test]> select @@hostname from a WHERE id=last_insert_id() or id=1;
      +------------------------+
      | @@hostname             |
      +------------------------+
      | 203.local |
      +------------------------+
      1 row in set (0.00 sec)
       
      MariaDB [mariadb_test]> select @@hostname, last_insert_id() FROM a WHERE id=last_insert_id();
      +------------------------+------------------+
      | @@hostname             | last_insert_id() |
      +------------------------+------------------+
      | 201.local |                1 |
      +------------------------+------------------+
      1 row in set (0.00 sec)

      201 = master, 203 = slave.

      Please change it so all queries with LAST_INSERT_ID() function call get redirected to master.

      Attachments

        Activity

          michaeldg Michaël de groot created issue -
          markus makela markus makela made changes -
          Field Original Value New Value
          Component/s ReadWriteSplit [ 11613 ]
          markus makela markus makela made changes -
          Affects Version/s 1.1.1 [ 19404 ]
          michaeldg Michaël de groot made changes -
          Description Hi,

          If a query contains LAST_INSERT_ID() it should be redirected to master, even if it is in WHERE clause.

          Test case:
          {code}
          MariaDB [mariadb_test]> create table a (id serial, primary key(id));
          Query OK, 0 rows affected (0.02 sec)

          MariaDB [mariadb_test]> show create table a;
          +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
          | Table | Create Table |
          +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
          | a | CREATE TABLE `a` (
           `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
           PRIMARY KEY (`id`),
           UNIQUE KEY `id` (`id`)
          ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
          +-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
          1 row in set (0.00 sec)

          MariaDB [mariadb_test]> insert into a values(null);
          Query OK, 1 row affected (0.00 sec)

          MariaDB [mariadb_test]> select @@hostname from a WHERE id=last_insert_id();
          Empty set (0.00 sec)

          michaeldg [5:44 PM]
          MariaDB [mariadb_test]> select @@hostname from a WHERE id=last_insert_id() or id=1;
          +------------------------+
          | @@hostname |
          +------------------------+
          | 203.local |
          +------------------------+
          1 row in set (0.00 sec)

          MariaDB [mariadb_test]> select @@hostname, last_insert_id() FROM a WHERE id=last_insert_id();
          +------------------------+------------------+
          | @@hostname | last_insert_id() |
          +------------------------+------------------+
          | 201.local | 1 |
          +------------------------+------------------+
          1 row in set (0.00 sec)
          {code}

          201 = master, 203 = slave.

          Please change it so all queries with LAST_INSERT_ID() function call get redirected to master.
          Hi,

          If a query contains LAST_INSERT_ID() it should be redirected to master, even if it is in WHERE clause.

          Test case:
          {code}
          MariaDB [mariadb_test]> create table a (id serial, primary key(id));
          Query OK, 0 rows affected (0.02 sec)

          MariaDB [mariadb_test]> insert into a values(null);
          Query OK, 1 row affected (0.00 sec)

          MariaDB [mariadb_test]> select @@hostname from a WHERE id=last_insert_id();
          Empty set (0.00 sec)

          michaeldg [5:44 PM]
          MariaDB [mariadb_test]> select @@hostname from a WHERE id=last_insert_id() or id=1;
          +------------------------+
          | @@hostname |
          +------------------------+
          | 203.local |
          +------------------------+
          1 row in set (0.00 sec)

          MariaDB [mariadb_test]> select @@hostname, last_insert_id() FROM a WHERE id=last_insert_id();
          +------------------------+------------------+
          | @@hostname | last_insert_id() |
          +------------------------+------------------+
          | 201.local | 1 |
          +------------------------+------------------+
          1 row in set (0.00 sec)
          {code}

          201 = master, 203 = slave.

          Please change it so all queries with LAST_INSERT_ID() function call get redirected to master.
          michaeldg Michaël de groot made changes -
          Description Hi,

          If a query contains LAST_INSERT_ID() it should be redirected to master, even if it is in WHERE clause.

          Test case:
          {code}
          MariaDB [mariadb_test]> create table a (id serial, primary key(id));
          Query OK, 0 rows affected (0.02 sec)

          MariaDB [mariadb_test]> insert into a values(null);
          Query OK, 1 row affected (0.00 sec)

          MariaDB [mariadb_test]> select @@hostname from a WHERE id=last_insert_id();
          Empty set (0.00 sec)

          michaeldg [5:44 PM]
          MariaDB [mariadb_test]> select @@hostname from a WHERE id=last_insert_id() or id=1;
          +------------------------+
          | @@hostname |
          +------------------------+
          | 203.local |
          +------------------------+
          1 row in set (0.00 sec)

          MariaDB [mariadb_test]> select @@hostname, last_insert_id() FROM a WHERE id=last_insert_id();
          +------------------------+------------------+
          | @@hostname | last_insert_id() |
          +------------------------+------------------+
          | 201.local | 1 |
          +------------------------+------------------+
          1 row in set (0.00 sec)
          {code}

          201 = master, 203 = slave.

          Please change it so all queries with LAST_INSERT_ID() function call get redirected to master.
          Hi,

          If a query contains LAST_INSERT_ID() it should be redirected to master, even if it is in WHERE clause.

          Also another syntax is not redirected to the master: SELECT @id:=LAST_INSERT_ID(); - please let me know if you need a test case for this as well.

          Test case:
          {code}
          MariaDB [mariadb_test]> create table a (id serial, primary key(id));
          Query OK, 0 rows affected (0.02 sec)

          MariaDB [mariadb_test]> insert into a values(null);
          Query OK, 1 row affected (0.00 sec)

          MariaDB [mariadb_test]> select @@hostname from a WHERE id=last_insert_id();
          Empty set (0.00 sec)

          michaeldg [5:44 PM]
          MariaDB [mariadb_test]> select @@hostname from a WHERE id=last_insert_id() or id=1;
          +------------------------+
          | @@hostname |
          +------------------------+
          | 203.local |
          +------------------------+
          1 row in set (0.00 sec)

          MariaDB [mariadb_test]> select @@hostname, last_insert_id() FROM a WHERE id=last_insert_id();
          +------------------------+------------------+
          | @@hostname | last_insert_id() |
          +------------------------+------------------+
          | 201.local | 1 |
          +------------------------+------------------+
          1 row in set (0.00 sec)
          {code}

          201 = master, 203 = slave.

          Please change it so all queries with LAST_INSERT_ID() function call get redirected to master.
          dshjoshi Dipti Joshi (Inactive) made changes -
          Fix Version/s 1.2.1 [ 19400 ]
          markus makela markus makela made changes -
          Affects Version/s 1.2.0 [ 18901 ]
          markus makela markus makela made changes -
          Assignee markus makela [ <markus.makela ]
          markus makela markus makela made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          markus makela markus makela made changes -
          Status In Progress [ 3 ] In Review [ 10002 ]
          markus makela markus makela made changes -
          Status In Review [ 10002 ] Stalled [ 10000 ]
          markus makela markus makela made changes -
          Resolution Fixed [ 1 ]
          Status Stalled [ 10000 ] Closed [ 6 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Fix Version/s 1.3.0 [ 19303 ]
          Fix Version/s 1.2.1 [ 19400 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 70316 ] MariaDB v4 [ 136872 ]

          People

            markus makela markus makela
            michaeldg Michaël de groot
            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.