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

size limited index not used even when query len(data) < len(index)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Not a Bug
    • Affects Version/s: 5.5.35-galera
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      When a search is on a 5 character cid, it should be able to use a cid(255) index.

      | CREATE TABLE `cache_data` (
        `cidhash` binary(20) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' COMMENT 'Hash of cid - for quick lookups.',
        `cid` varchar(1024) NOT NULL DEFAULT '' COMMENT 'Cache ID.',
        `data` longblob COMMENT 'A collection of data to cache.',
        `expire` int(11) NOT NULL DEFAULT '0' COMMENT 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
        `created` int(11) NOT NULL DEFAULT '0' COMMENT 'A Unix timestamp indicating when the cache entry was created.',
        `serialized` smallint(6) NOT NULL DEFAULT '0' COMMENT 'A flag to indicate whether content is serialized (1) or not (0).',
        `tags` longtext COMMENT 'Space-separated list of cache tags for this entry.',
        `checksum_invalidations` int(11) NOT NULL DEFAULT '0' COMMENT 'The tag invalidation sum when this entry was saved.',
        `checksum_deletions` int(11) NOT NULL DEFAULT '0' COMMENT 'The tag deletion sum when this entry was saved.',
        PRIMARY KEY (`cidhash`,`cid`(255)),
        KEY `expire` (`expire`),
        KEY `created` (`created`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Storage for the cache API.' |
      
      MariaDB [drupal_dev]> explain extended SELECT cid, data, created, expire, serialized, tags, checksum_invalidations, checksum_deletions FROM cache_data WHERE cidhash = '�D�a?��7���о�U6�' AND cid = 'test1';
      | id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra                                               |
      +------+-------------+-------+------+---------------+------+---------+------+------+----------+-----------------------------------------------------+
      |    1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL |     NULL | Impossible WHERE noticed after reading const tables |
      
      

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            elenst Elena Stepanova added a comment -

            It does if there is anything to find:

            insert into cache_data values 
            ('foo','test1','foo',1,1,1,'foo',1,1),
            ('bar','test2','bar',1,1,1,'bar',1,1);
            
            explain extended SELECT cid, data, created, expire, serialized, tags, checksum_invalidations, checksum_deletions FROM cache_data WHERE cidhash = 'foo\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' AND cid = 'test1';
            
            +------+-------------+------------+-------+---------------+---------+---------+-------------+------+----------+-------+
            | id   | select_type | table      | type  | possible_keys | key     | key_len | ref         | rows | filtered | Extra |
            +------+-------------+------------+-------+---------------+---------+---------+-------------+------+----------+-------+
            |    1 | SIMPLE      | cache_data | const | PRIMARY       | PRIMARY | 787     | const,const |    1 |   100.00 |       |
            +------+-------------+------------+-------+---------------+---------+---------+-------------+------+----------+-------+
            

            Or did you mean something different?

            Show
            elenst Elena Stepanova added a comment - It does if there is anything to find: insert into cache_data values ('foo','test1','foo',1,1,1,'foo',1,1), ('bar','test2','bar',1,1,1,'bar',1,1); explain extended SELECT cid, data, created, expire, serialized, tags, checksum_invalidations, checksum_deletions FROM cache_data WHERE cidhash = 'foo\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' AND cid = 'test1'; +------+-------------+------------+-------+---------------+---------+---------+-------------+------+----------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +------+-------------+------------+-------+---------------+---------+---------+-------------+------+----------+-------+ | 1 | SIMPLE | cache_data | const | PRIMARY | PRIMARY | 787 | const,const | 1 | 100.00 | | +------+-------------+------------+-------+---------------+---------+---------+-------------+------+----------+-------+ Or did you mean something different?
            Hide
            danblack Daniel Black added a comment -

            nope, you're right - needed data.

            invalid.

            Show
            danblack Daniel Black added a comment - nope, you're right - needed data. invalid.

              People

              • Assignee:
                Unassigned
                Reporter:
                danblack Daniel Black
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: