[MDEV-6023] size limited index not used even when query len(data) < len(index) Created: 2014-04-04  Updated: 2014-04-04  Resolved: 2014-04-04

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: 5.5.35-galera
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Daniel Black Assignee: Unassigned
Resolution: Not a Bug Votes: 0
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 |
 



 Comments   
Comment by Elena Stepanova [ 2014-04-04 ]

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?

Comment by Daniel Black [ 2014-04-04 ]

nope, you're right - needed data.

invalid.

Generated at Thu Feb 08 07:08:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.