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

Support ON DUPLICATE KEY construct

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 4.9.0
    • None
    • None

    Description

      To support inserting a new row only if it doesn't already exist, we should support the "on duplicate key" construct for UPSERT. With this construct, the UPSERT VALUES statement would run atomically and would thus require a read before write which would obviously have a negative impact on performance. For an example of similar syntax , see MySQL documentation at http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html

      See this discussion for more detail: https://groups.google.com/d/msg/phoenix-hbase-user/Bof-TLrbTGg/68bnc8ZcWe0J. A related discussion is on PHOENIX-2909.

      Initially we'd support the following:

      1. This would prevent the setting of VAL to 0 if the row already exists:
        UPSERT INTO T (PK, VAL) VALUES ('a',0) 
        ON DUPLICATE KEY IGNORE;
        
      2. This would increment the valueS of COUNTER1 and COUNTER2 if the row already exists and otherwise initialize them to 0:
        UPSERT INTO T (PK, COUNTER1, COUNTER2) VALUES ('a',0,0) 
        ON DUPLICATE KEY UPDATE COUNTER1 = COUNTER1 + 1, COUNTER2 = COUNTER2 + 1;
        

      So the general form is:

      UPSERT ... VALUES ... [ ON DUPLICATE KEY [IGNORE | UPDATE <column>=<expression>, ...] ]
      

      The following restrictions will apply:

      • The <column> may not be part of the primary key constraint - only KeyValue columns will be allowed.
      • This new clause cannot be used with
        • Immutable tables since the whole point is to atomically update a row in place which isn't allowed for immutable tables.
        • Transactional tables because these use optimistic concurrency as their mechanism for consistency and isolation.

      Attachments

        1. PHOENIX-6_4.x-HBase-0.98.patch
          110 kB
          James R. Taylor
        2. PHOENIX-6_v2.patch
          107 kB
          James R. Taylor
        3. PHOENIX-6_v3.patch
          111 kB
          James R. Taylor
        4. PHOENIX-6_v4.patch
          112 kB
          James R. Taylor
        5. PHOENIX-6_v5.patch
          113 kB
          James R. Taylor
        6. PHOENIX-6_wip1.patch
          40 kB
          James R. Taylor
        7. PHOENIX-6_wip2.patch
          63 kB
          James R. Taylor
        8. PHOENIX-6_wip3.patch
          71 kB
          James R. Taylor
        9. PHOENIX-6_wip4.patch
          95 kB
          James R. Taylor
        10. PHOENIX-6.patch
          5 kB
          James R. Taylor

        Activity

          People

            jamestaylor James R. Taylor
            jamestaylor James R. Taylor
            Votes:
            2 Vote for this issue
            Watchers:
            12 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: