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

UUID v7 are compared incorrectly

    XMLWordPrintable

Details

    Description

      create table t1 (id uuid, model_value char(10));
      insert t1 values ('0189f81d-498e-72f8-b0fa-246d7be1adb1', '30'),
                       ('0189f81d-335c-71c7-a620-3f093ccc39c3', '29'),
                       ('0189f81d-2f49-72fa-8ed9-4bd2fe509e59', '28'),
                       ('0189f81d-2ae6-7204-b694-84602a2560c7', '27'),
                       ('0189f81d-2620-717b-b873-1829f25a4d53', '26'),
                       ('0189f81c-f940-7161-9c48-9677e11bc40c', '25'),
                       ('0189f81c-d4cf-71c1-93f1-ddd005eadb8b', '24'),
                       ('0189f81c-d07f-7143-8c8b-b19457138aef', '23'),
                       ('0189f81c-cbec-707d-9b45-b007920b5ef6', '22'),
                       ('0189f81c-c795-71d0-bc3f-8b7b74abe044', '21'),
                       ('0189f81c-c33d-7100-a39c-80ea40a090fc', '20'),
                       ('0189f81c-bf35-70a0-a288-8d80473bc015', '19'),
                       ('0189f81c-baf8-718a-870c-cd41e677c3f4', '18'),
                       ('0189f81c-b5f1-721d-b135-22c38153aab6', '17'),
                       ('0189f81c-b011-71cd-bf2a-d6be3cea6dd7', '16'),
                       ('0189f81c-9934-721f-90dc-05a65a79f4b6', '15'),
                       ('0189f81c-94d6-733d-9953-2addf3a83be4', '14'),
                       ('0189f81c-9016-71a6-a340-ec300186a4d9', '13'),
                       ('0189f81c-8bca-73c9-8ffb-225a39a5dc49', '12'),
                       ('0189f81c-868b-71d1-830e-9b4ae08aa782', '11'),
                       ('0189f81c-8219-731a-b648-0e19e64d0ec0', '10'),
                       ('0189f81c-7e01-710a-91ce-49e62163fa29', '9'),
                       ('0189f81c-7a05-724e-a7e1-9baf65a91ecb', '8'),
                       ('0189f81c-75b8-7223-bd6f-b60601be3aa1', '7'),
                       ('0189f81c-71fc-7303-b850-4538b119c5fc', '6'),
                       ('0189f81c-6e06-71a3-a47a-664a606b08d2', '5'),
                       ('0189f81c-6a38-710e-8730-8babd48c28f4', '4'),
                       ('0189f81c-650e-7171-b962-045cc4033000', '3'),
                       ('0189f81c-4eff-70c7-a361-caffaf2c0666', '2'),
                       ('0189f81c-49e9-7279-8087-9f8e25730957', '1');
      select id, model_value from t1 where id < '0189f81c-c795-71d0-bc3f-8b7b74abe044' order by id desc;
      select id, model_value from t1 where concat(id) < '0189f81c-c795-71d0-bc3f-8b7b74abe044' order by id desc;
      drop table t1;
      

      because it compares segments backwards independently from the version:

      template <bool force_swap>
      class UUID: public FixedBinTypeStorage<MY_UUID_SIZE, MY_UUID_STRING_LENGTH>
      {
        ...
        // Compare two in-memory values
        static int cmp(const LEX_CSTRING &a, const LEX_CSTRING &b)
        {
          DBUG_ASSERT(a.length == binary_length());
          DBUG_ASSERT(b.length == binary_length());
          int res;
          if ((res= segment(4).cmp_memory(a.str, b.str)) ||
              (res= segment(3).cmp_memory(a.str, b.str)) ||
              (res= segment(2).cmp_memory(a.str, b.str)) ||
              (res= segment(1).cmp_memory(a.str, b.str)) ||
              (res= segment(0).cmp_memory(a.str, b.str)))
            return  res;
          return 0;
        }
        ...
      }
      

      Attachments

        Issue Links

          Activity

            People

              serg Sergei Golubchik
              serg Sergei Golubchik
              Votes:
              1 Vote for this issue
              Watchers:
              3 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.