Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MySQL slowlog (Server version: 5.7.26 MySQL Community Server):
- # User@Host: librenms[librenms] @ localhost [] Id: 19228
- # Query_time: 6.830290
- # Lock_time: 0.000043
- # Rows_sent: 1
- # Rows_examined: 23752917
- select count(*) as aggregate from `notifications` left join `notifications_attribs` on `notifications_attribs`.`notifications_id` = `notifications`.`notifications_id` where (`notifications_attribs`.`key` = 'sticky' and `notifications_attribs`.`value` = 1) or (not exists (select 1 from `notifications_attribs` where notifications.notifications_id = notifications_attribs.notifications_id and `notifications_attribs`.`user_id` = 123));
- mysql> select count(*) from notifications;
- +----------+
- | COUNT(*) |
- +----------+
- | 52 |
- +----------+
- 1 row in set (0.00 sec)
- mysql> select count(*) from notifications_attribs;
- +----------+
- | COUNT(*) |
- +----------+
- | 893 |
- +----------+
- 1 row in set (0.00 sec)
- mysql> select count(1) as aggregate from `notifications` left join `notifications_attribs` on `notifications_attribs`.`notifications_id` = `notifications`.`notifications_id` where (`notifications_attribs`.`key` = 'sticky' and `notifications_attribs`.`value` = 1) or (not exists (select 1 from `notifications_attribs` where notifications.notifications_id = notifications_attribs.notifications_id and `notifications_attribs`.`user_id` = 123) );
- +-----------+
- | aggregate |
- +-----------+
- | 0 |
- +-----------+
- 1 row in set (7.30 sec)
- mysql> explain extended select count(*) as aggregate from `notifications` left join `notifications_attribs` on `notifications_attribs`.`notifications_id` = `notifications`.`notifications_id` where (`notifications_attribs`.`key` = 'sticky' and `notifications_attribs`.`value` = 1) or (not exists (select 1 from `notifications_attribs` where notifications.notifications_id = notifications_attribs.notifications_id and `notifications_attribs`.`user_id` = 123));
- +----+--------------------+-----------------------+------------+-------+---------------+------------------------------+---------+------+------+----------+----------------------------------------------------+
- | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
- +----+--------------------+-----------------------+------------+-------+---------------+------------------------------+---------+------+------+----------+----------------------------------------------------+
- | 1 | PRIMARY | notifications | NULL | index | NULL | notifications_severity_index | 5 | NULL | 51 | 100.00 | Using index |
- | 1 | PRIMARY | notifications_attribs | NULL | ALL | NULL | NULL | NULL | NULL | 790 | 100.00 | Using where; Using join buffer (Block Nested Loop) |
- | 2 | DEPENDENT SUBQUERY | notifications_attribs | NULL | ALL | NULL | NULL | NULL | NULL | 790 | 1.00 | Using where |
- +----+--------------------+-----------------------+------------+-------+---------------+------------------------------+---------+------+------+----------+----------------------------------------------------+
- 3 rows in set, 3 warnings (0.00 sec)
- mysql> show indexes from notifications_attribs;
- +-----------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
- +-----------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | notifications_attribs | 0 | PRIMARY | 1 | attrib_id | A | 790 | NULL | NULL | | BTREE | | |
- +-----------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- 1 row in set (0.00 sec)
- mysql> CREATE INDEX `notifications_attribs_user_idx` ON `notifications_attribs` (`notifications_id`,`user_id`);
- Query OK, 0 rows affected (0.03 sec)
- Records: 0 Duplicates: 0 Warnings: 0
- mysql> show indexes from notifications_attribs;
- +-----------------------+------------+--------------------------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
- +-----------------------+------------+--------------------------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- | notifications_attribs | 0 | PRIMARY | 1 | attrib_id | A | 790 | NULL | NULL | | BTREE | | |
- | notifications_attribs | 1 | notifications_attribs_user_idx | 1 | notifications_id | A | 51 | NULL | NULL | | BTREE | | |
- | notifications_attribs | 1 | notifications_attribs_user_idx | 2 | user_id | A | 790 | NULL | NULL | | BTREE | | |
- +-----------------------+------------+--------------------------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
- 3 rows in set (0.00 sec)
- mysql> explain extended select count(*) as aggregate from `notifications` left join `notifications_attribs` on `notifications_attribs`.`notifications_id` = `notifications`.`notifications_id` where (`notifications_attribs`.`key` = 'sticky' and `notifications_attribs`.`value` = 1) or (not exists (select 1 from `notifications_attribs` where notifications.notifications_id = notifications_attribs.notifications_id and `notifications_attribs`.`user_id` = 123));
- +----+--------------------+-----------------------+------------+-------+--------------------------------+--------------------------------+---------+-----------------------------------------------+------+----------+-------------+
- | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
- +----+--------------------+-----------------------+------------+-------+--------------------------------+--------------------------------+---------+-----------------------------------------------+------+----------+-------------+
- | 1 | PRIMARY | notifications | NULL | index | NULL | notifications_severity_index | 5 | NULL | 51 | 100.00 | Using index |
- | 1 | PRIMARY | notifications_attribs | NULL | ref | notifications_attribs_user_idx | notifications_attribs_user_idx | 4 | librenms.notifications.notifications_id | 15 | 100.00 | Using where |
- | 2 | DEPENDENT SUBQUERY | notifications_attribs | NULL | ref | notifications_attribs_user_idx | notifications_attribs_user_idx | 8 | librenms.notifications.notifications_id,const | 1 | 100.00 | Using index |
- +----+--------------------+-----------------------+------------+-------+--------------------------------+--------------------------------+---------+-----------------------------------------------+------+----------+-------------+
- 3 rows in set, 3 warnings (0.00 sec)
- mysql> select count(1) as aggregate from `notifications` left join `notifications_attribs` on `notifications_attribs`.`notifications_id` = `notifications`.`notifications_id` where (`notifications_attribs`.`key` = 'sticky' and `notifications_attribs`.`value` = 1) or (not exists (select 1 from `notifications_attribs` where notifications.notifications_id = notifications_attribs.notifications_id and `notifications_attribs`.`user_id` = 123) );
- +-----------+
- | aggregate |
- +-----------+
- | 0 |
- +-----------+
- 1 row in set (0.00 sec)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement