Not deterministic function in WHERE or ON condition

Bug #1608028 reported by arcadius
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Percona Server moved to https://jira.percona.com/projects/PS
New
Undecided
Unassigned

Bug Description

DBMS doesn't use index when comparing its column(s) with not deterministic function.

-- Create sample table:
DROP TABLE IF EXISTS `t`;
CREATE TABLE IF NOT EXISTS `t` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

-- Fill it:
INSERT INTO `t` VALUES
(), (), (), (), (), (), (), (), (), (),
(), (), (), (), (), (), (), (), (), (),
(), (), (), (), (), (), (), (), (), (),
(), (), (), (), (), (), (), (), (), (),
(), (), (), (), (), (), (), (), (), (),
(), (), (), (), (), (), (), (), (), (),
(), (), (), (), (), (), (), (), (), (),
(), (), (), (), (), (), (), (), (), (),
(), (), (), (), (), (), (), (), (), (),
(), (), (), (), (), (), (), (), (), ();

-- DETERMINISTIC fixes issue, but READS SQL DATA or NO SQL don't:
DROP FUNCTION IF EXISTS `f`;
DELIMITER $$
CREATE FUNCTION `f`() RETURNS int(10) unsigned
NO SQL
BEGIN
   RETURN 1;
END $$
DELIMITER ; $$

-- OK:
-- id select_type table type possible_keys key key_len ref rows Extra
-- 1 SIMPLE t const PRIMARY PRIMARY 4 const 1 Using index
DESCRIBE SELECT *
FROM t FORCE INDEX (PRIMARY)
WHERE id = 1;

-- BAD. In fact, key PRIMARY is not used:
-- id select_type table type possible_keys key key_len ref rows Extra
-- 1 SIMPLE t index NULL PRIMARY 4 NULL 100 Using where; Using index
DESCRIBE SELECT *
FROM t FORCE INDEX (PRIMARY)
WHERE id = f();

Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PS-3498

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.