I have a query with a JOIN on three tables that is taking a very long time to run. I created an index on one of my tables for the foreign key (user\_shared\_url\_id) and two columns (event\_result, enabled) in the WHERE clause, so it's an index of three columns total. There seems to be no different from when I simply use an index of the foreign key (user\_shared\_url\_id). The other two tables are using single column indexes. My users table has about 20,000 rows, but the other two tables are quite large, with ~20 million rows. I can't get a query that takes less than a minute or so to finish. Can anyone think of any potential optimizations I can make to speed this up? Are there other indexes or improvements to my custom index that I can work with?

The tables:

```

 CREATE TABLE `users` (
  `user_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `roles` varchar(500) DEFAULT NULL,
  `first_name` varchar(200) DEFAULT NULL,
  `last_name` varchar(100) DEFAULT NULL,
  `org_id` int(11) unsigned NOT NULL,
  `user_email` varchar(100) NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`user_id`),
  KEY `org_id` (`org_id`),
  KEY `status` (`status`),
  KEY `org_id_user_id` (`org_id`,`user_id`)
) ENGINE=MyISAM AUTO_INCREMENT=162524 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC

 CREATE TABLE `user_shared_urls` (
  `user_id` int(11) unsigned NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `user_shared_url_id` int(11) NOT NULL AUTO_INCREMENT,
  `target_url` text,
  PRIMARY KEY (`user_shared_url_id`),
  KEY `user_id` (`user_id`),
  KEY `user_id_usu_id` (`user_id`,`user_shared_url_id`)
) ENGINE=InnoDB AUTO_INCREMENT=62449105 DEFAULT CHARSET=utf8 |

 CREATE TABLE `user_share_events` (
  `user_share_event_id` int(11) NOT NULL AUTO_INCREMENT,
  `event_result` tinyint(1) unsigned DEFAULT NULL,
  `user_shared_url_id` int(11) NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`user_share_event_id`),
  KEY `user_shared_url_id` (`user_shared_url_id`),
  KEY `usuid_enabled_result` (`user_shared_url_id`,`enabled`,`event_result`)
) ENGINE=InnoDB AUTO_INCREMENT=35067339 DEFAULT CHARSET=utf8 |

```

My indexes:

```
CREATE INDEX org_id_user_id ON users(org_id, user_id);
CREATE INDEX user_id_usu_id ON user_shared_urls(user_id, user_shared_url_id);
CREATE INDEX usuid_enabled_result ON user_share_events(user_shared_url_id,enabled,event_result);

```

My query:

```
SELECT
    users.user_id,
    users.user_email "user_email",
    users.roles "role",
    CONCAT(users.first_name, ' ', users.last_name) "name",
    usus.target_url
FROM
    users
    JOIN user_shared_urls usus ON usus.user_id = users.user_id
    JOIN user_share_events uses ON usus.user_shared_url_id = uses.user_shared_url_id 
WHERE
    users.org_id = 1523
    AND
    uses.enabled = '1'
    AND
    uses.event_result = 1

```

Explain output of the above query:

```
+----+-------------+-------+------+----------------------------------------------------------------------------------+--------------------+---------+--------------------------------+------+-------------+
| id | select_type | table | type | possible_keys                                                                    | key                | key_len | ref                            | rows | Extra       |
+----+-------------+-------+------+----------------------------------------------------------------------------------+--------------------+---------+--------------------------------+------+-------------+
|  1 | SIMPLE      | users | ref  | PRIMARY,org_id,org_id_user_id                                                    | org_id             | 4       | const                          | 1235 | NULL        |
|  1 | SIMPLE      | usus  | ref  | PRIMARY,user_id,user_id_usu_id                                                   | user_id_usu_id     | 4       | luster.users.user_id           |  213 | NULL        |
|  1 | SIMPLE      | uses  | ref  | user_shared_url_id,user_and_service,result_service_occurred,usuid_enabled_result | user_shared_url_id | 4       | luster.usus.user_shared_url_id |    1 | Using where |
+----+-------------+-------+------+----------------------------------------------------------------------------------+--------------------+---------+--------------------------------+------+-------------+
3 rows in set (0.00 sec)

```