Hi, all. I’m experiencing strange issue in MySQL.
I have 2 tables in database,
oc_ocfilter_option_value_to_product | CREATE TABLE `oc_ocfilter_option_value_to_product` (
`ocfilter_option_value_to_product_id` int(11) NOT NULL AUTO_INCREMENT,
`product_id` int(11) NOT NULL,
`option_id` int(11) NOT NULL,
`value_id` bigint(20) NOT NULL,
`slide_value_min` decimal(15,4) NOT NULL DEFAULT '0.0000',
`slide_value_max` decimal(15,4) NOT NULL DEFAULT '0.0000',
PRIMARY KEY (`ocfilter_option_value_to_product_id`),
UNIQUE KEY `option_id_value_id_product_id` (`option_id`,`value_id`,`product_id`),
KEY `slide_value_min_slide_value_max` (`slide_value_min`,`slide_value_max`),
KEY `product_id` (`product_id`)
) ENGINE=InnoDB AUTO_INCREMENT=802118 DEFAULT CHARSET=utf8
oc_product_option_value | CREATE TABLE `oc_product_option_value` (
`product_option_value_id` int(11) NOT NULL AUTO_INCREMENT,
`product_option_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`option_id` int(11) NOT NULL,
`option_value_id` int(11) NOT NULL,
`quantity` int(3) NOT NULL,
`subtract` tinyint(1) NOT NULL,
`price` decimal(15,4) NOT NULL,
`price_prefix` varchar(1) NOT NULL,
`points` int(8) NOT NULL,
`points_prefix` varchar(1) NOT NULL,
`weight` decimal(15,8) NOT NULL,
`weight_prefix` varchar(1) NOT NULL,
`optsku` varchar(64) DEFAULT NULL,
PRIMARY KEY (`product_option_value_id`),
KEY `option_value_id` (`option_value_id`),
KEY `product_id` (`product_id`),
KEY `optsku` (`optsku`),
KEY `optsku_2` (`optsku`),
KEY `product_option_id` (`product_option_id`),
KEY `optsku_3` (`optsku`)
) ENGINE=InnoDB AUTO_INCREMENT=222740 DEFAULT CHARSET=utf8
When I try to execute query
mysql> delete FROM oc_ocfilter_option_value_to_product WHERE option_id IN(SELECT option_id FROM oc_product_option_value WHERE quantity < '1');
it freezes. But the SELECT executes pretty fast:
mysql> select * FROM oc_ocfilter_option_value_to_product WHERE option_id IN(SELECT option_id FROM oc_product_option_value WHERE quantity < '1');
Empty set (0.02 sec)
SELECT subquesry returns approx 13000 rows with only two values:
mysql> SELECT option_id, count( option_id) FROM oc_product_option_value WHERE quantity < '1' group by option_id;
+-----------+-------------------+
| option_id | count( option_id) |
+-----------+-------------------+
| 15 | 6621 |
| 16 | 6395 |
+-----------+-------------------+
2 rows in set (0.02 sec)
I have already tried to use ‘DISTINCT’ in subquery, but no luck.
delete FROM oc_ocfilter_option_value_to_product WHERE option_id IN(SELECT distinct option_id FROM oc_product_option_value WHERE quantity < '1');
It reproduces on MySQL 5.6 and 5.7. Does someone know what the root of that issue?