Uploaded image for project: 'Phoenix'
  1. Phoenix
  2. PHOENIX-6420

Wrong result when conditional and regular upserts are passed in the same commit batch

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.0.0, 4.16.0
    • 4.17.0, 5.2.0, 5.1.2
    • None
    • None

    Description

      Consider this example:

      CREATE TABLE T1 (k integer not null primary key, v1 bigint, v2 bigint);
      

      Now consider this batch:

      UPSERT INTO T1 VALUES(0,0,1);
      UPSERT INTO T1 VALUES(0,1,1) ON DUPLICATE KEY UPDATE v1 = v1 + 2;
      commit();
      

      Expected row state: 0, 2, 1

      Actual: 0, 2, 0

      The value of the column (v2) not updated in the conditional expression remains default. It's value should have been the one set in the regular upsert in the batch.

       Now, the row exists. Consider another batch of updates

      UPSERT INTO T1 VALUES(0, 7, 4);
      UPSERT INTO T1 VALUES(0,1,1) ON DUPLICATE KEY UPDATE v1 = v1 + 2;
      commit();
      

      Expected row state: 0,2,1  -> 0, 9, 4

      Actual: 0,2,0 -> 0, 4, 0

      The conditional update expression is evaluated and applied on the row state already committed instead of on the regular update in the same batch. Also, v2 still remains 0 (the default value).

       Now consider the case of a partial regular update following a conditional update:

      UPSERT INTO T1 (k, v2) VALUES(0,100) ON DUPLICATE KEY UPDATE v1 = v1 + 2;
      UPSERT INTO T1 (k, v2) VALUES (0,125);
      commit();
      

      Expected row state: 0, 9, 4 -> 0, 11, 125

      Actual: 0, 4, 0 -> 0, 4, 125

      Only the regular update is applied and the conditional update is completely ignored.

      Attachments

        1. PHOENIX-6420.patch
          44 kB
          Tanuj Khurana

        Issue Links

          Activity

            People

              tkhurana Tanuj Khurana
              tkhurana Tanuj Khurana
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: