twisted1919
Administrator
Staff member@Jean-Claude CHRISTOPHE - can you please run an EXPLAIN on that query?
mysql> explain SELECT COUNT(DISTINCT t.subscriber_id) as counter FROM `mw_list_subscriber` `t` LEFT JOIN `mw_list_field_value` `fieldValues434` ON (`fieldValues434`.`subscriber_id`=`t`.`subscriber_id`) WHERE ((t.list_id='15') AND (t.status='confirmed') AND ( (`fieldValues434`.`field_id` = 434 AND (CAST(`fieldValues434`.`value` AS UNSIGNED) = 0 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 3 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 4) ) ))\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: t
type: ref
possible_keys: PRIMARY,fk_list_subscriber_list1_idx,list_email,status_last_updated,list_id_status
key: list_id_status
key_len: 49
ref: const,const
rows: 5331149
Extra: Using where; Using index
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: fieldValues434
type: ref
possible_keys: fk_list_field_value_list_field1_idx,fk_list_field_value_list_subscriber1_idx,field_subscriber,field_id_value
key: field_subscriber
key_len: 8
ref: const,mailwizz.t.subscriber_id
rows: 1
Extra: Using where
2 rows in set (0.00 sec)
SELECT COUNT(DISTINCT t.subscriber_id) as counter FROM `mw_list_subscriber` `t` LEFT JOIN `mw_list_field_value` `fieldValues434` ON (`fieldValues434`.`subscriber_id`=`t`.`subscriber_id`) WHERE ((t.list_id='15') AND (t.status='confirmed') AND ( (`fieldValues434`.`field_id` = 434 AND (CAST(`fieldValues434`.`value` AS UNSIGNED) = 0 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 3 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 4) ) ))
SELECT COUNT(*) as counter FROM `mw_list_subscriber` `t` LEFT JOIN `mw_list_field_value` `fieldValues434` ON (`fieldValues434`.`subscriber_id`=`t`.`subscriber_id`) WHERE ((t.list_id='15') AND (t.status='confirmed') AND ( (`fieldValues434`.`field_id` = 434 AND (CAST(`fieldValues434`.`value` AS UNSIGNED) = 0 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 3 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 4) ) ))
mysql> SELECT COUNT(DISTINCT t.subscriber_id) as counter FROM `mw_list_subscriber` `t` LEFT JOIN `mw_list_field_value` `fieldValues434` ON (`fieldValues434`.`subscriber_id`=`t`.`subscriber_id`) WHERE ((t.list_id='15') AND (t.status='confirmed') AND ( (`fieldValues434`.`field_id` = 434 AND (CAST(`fieldValues434`.`value` AS UNSIGNED) = 0 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 3 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 4) ) ));
+---------+
| counter |
+---------+
| 4716831 |
+---------+
1 row in set, 65535 warnings (43.98 sec)
mysql> SELECT COUNT(*) as counter FROM `mw_list_subscriber` `t` LEFT JOIN `mw_list_field_value` `fieldValues434` ON (`fieldValues434`.`subscriber_id`=`t`.`subscriber_id`) WHERE ((t.list_id='15') AND (t.status='confirmed') AND ( (`fieldValues434`.`field_id` = 434 AND (CAST(`fieldValues434`.`value` AS UNSIGNED) = 0 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 3 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 4) ) ));
+---------+
| counter |
+---------+
| 4716831 |
+---------+
1 row in set, 65535 warnings (27.87 sec)
SELECT COUNT(*) from `mw_list_field_value` `fieldValues434` WHERE `fieldValues434`.`field_id` = 434 AND (CAST(`fieldValues434`.`value` AS UNSIGNED) = 0 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 3 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 4)
mysql> SELECT COUNT(*) from `mw_list_field_value` `fieldValues434` WHERE `fieldValues434`.`field_id` = 434 AND (CAST(`fieldValues434`.`value` AS UNSIGNED) = 0 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 3 OR CAST(`fieldValues434`.`value` AS UNSIGNED) = 4);
+----------+
| COUNT(*) |
+----------+
| 4734102 |
+----------+
1 row in set, 65535 warnings (4.89 sec)
SELECT COUNT(*) from `mw_list_field_value` `fieldValues434` WHERE `fieldValues434`.`field_id` = 434 AND (`fieldValues434`.`value` = 0 OR `fieldValues434`.`value` = 3 OR `fieldValues434`.`value` = 4);
SELECT COUNT(*) from `mw_list_field_value` `fieldValues434` WHERE `fieldValues434`.`field_id` = 434 AND `fieldValues434`.`value` IN(0, 3, 4);
mysql> SELECT COUNT(*) from `mw_list_field_value` `fieldValues434` WHERE `fieldValues434`.`field_id` = 434 AND (`fieldValues434`.`value` = 0 OR `fieldValues434`.`value` = 3 OR `fieldValues434`.`value` = 4);
+----------+
| COUNT(*) |
+----------+
| 4734100 |
+----------+
1 row in set, 270 warnings (4.62 sec)
mysql> SELECT COUNT(*) from `mw_list_field_value` `fieldValues434` WHERE `fieldValues434`.`field_id` = 434 AND `fieldValues434`.`value` IN(0, 3, 4);
+----------+
| COUNT(*) |
+----------+
| 4734100 |
+----------+
1 row in set, 268 warnings (4.36 sec)
mysql> SELECT count(*) FROM mw_list_field_value;
+-----------+
| count(*) |
+-----------+
| 128174741 |
+-----------+
1 row in set (2 min 13.76 sec)
Kindly Check my Previous Post We solved this problem
We have 11 Million Records and Dashboard loads amazingly fast..