Not deterministic function in WHERE or ON condition
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();
Percona now uses JIRA for bug reports so this bug report is migrated to: https:/ /jira.percona. com/browse/ PS-3498