Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9147339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:57:52+00:00 2026-06-17T10:57:52+00:00

1.query is taking around 10mins to 1 hr to execute. 2.due to this we

  • 0

1.query is taking around 10mins to 1 hr to execute.
2.due to this we are getting load spikes frequently.
3.please help me to rewrite the query.
4.also help me to improve the performance of query.

Query with explain plan

   explain select count(*) 
      from t_event eve 
 left join t_event_element_rel rel on rel.event_id = eve.id 
 left join t_object object on eve.create_object_id = object.id 
 left join t_keyword keyword on  rel.element_id = keyword.id and rel.element_type_id = 1 
 left join t_target_url targeturl on  rel.element_id = targeturl.id and rel.element_type_id = 2 
 where eve.domain_id = 522



+----+-------------+-----------+--------+-------------------------+-------------------------+---------+----------------------------+--------+-------------+
| id | select_type | table     | type   | possible_keys           | key                     | key_len | ref                        | rows   | Extra       |
+----+-------------+-----------+--------+-------------------------+-------------------------+---------+----------------------------+--------+-------------+
|  1 | SIMPLE      | eve       | ref    | domain_id_event_type_cd | domain_id_event_type_cd | 4       | const                      | 243430 |             |
|  1 | SIMPLE      | rel       | ref    | FK_event                | FK_event                | 4       | company.eve.id             |      2 |             |
|  1 | SIMPLE      | user      | eq_ref | PRIMARY                 | PRIMARY                 | 4       | company.eve.create_user_id |      1 | Using index |
|  1 | SIMPLE      | keyword   | ref    | id                      | id                      | 4       | company.rel.element_id     |      1 | Using index |
|  1 | SIMPLE      | targeturl | ref    | id                      | id                      | 4       | company.rel.element_id     |      1 | Using index |
+----+-------------+-----------+--------+-------------------------+-------------------------+---------+----------------------------+--------+-------------+
5 rows in set (0.45 sec)

Table structure:

mysql> show create table t_event_element_rel\G
*************************** 1. row ***************************
       Table: t_event_element_rel
Create Table: CREATE TABLE `t_event_element_rel` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `element_type_id` int(11) NOT NULL,
  `event_id` int(11) NOT NULL,
  `element_id` int(11) NOT NULL,
  `element_desc` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_event` (`event_id`),
  KEY `element_type_id_element_id` (`element_type_id`,`element_id`)
) ENGINE=InnoDB AUTO_INCREMENT=45901159 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

mysql> show create table t_object\G
*************************** 1. row ***************************
       Table: t_object
Create Table: CREATE TABLE `t_object` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `is_admin` int(11) DEFAULT NULL,
  `phone` varchar(50) DEFAULT NULL,
  `company` varchar(255) DEFAULT NULL,
  `last_login` datetime DEFAULT NULL,
  `state` int(11) DEFAULT NULL,
  `validate_code` varchar(50) DEFAULT NULL,
  `has_login` smallint(6) DEFAULT NULL COMMENT 'if null or 0 then hasn''t login, first time login',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1304 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)


mysql> show create table t_event\G
*************************** 1. row ***************************
       Table: t_event
Create Table: CREATE TABLE `t_event` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `create_user_id` int(11) DEFAULT NULL,
  `event_create_date` date DEFAULT NULL,
  `event_type_cd` int(11) NOT NULL,
  `event_desc` varchar(512) NOT NULL,
  `IsGlobalEvent` int(2) DEFAULT NULL,
  `event_start_date` datetime NOT NULL,
  `event_end_date` datetime NOT NULL,
  `job_id` int(11) DEFAULT NULL,
  `domain_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `event_user_FK` (`create_user_id`),
  KEY `domain_id_event_type_cd` (`domain_id`,`event_type_cd`)
) ENGINE=InnoDB AUTO_INCREMENT=8586007 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

mysql> show create table t_keyword\G
*************************** 1. row ***************************
       Table: t_keyword
Create Table: CREATE TABLE `t_keyword` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `keyword_name` varchar(255) DEFAULT NULL,
  `keyword_value` varchar(255) DEFAULT NULL,
  `type` int(11) DEFAULT NULL,
  `description` varchar(2000) DEFAULT NULL,
  `own_domain_id` int(11) DEFAULT NULL,
  `rank_check` int(11) DEFAULT NULL,
  `rank1` int(11) DEFAULT NULL COMMENT 'yesterday rank value',
  `rank2` int(11) DEFAULT NULL COMMENT 'the day before yesterday rank value',
  `rank3` int(11) DEFAULT NULL COMMENT 'special date rank for overstock.com',
  `yesterday_entrances` int(11) DEFAULT NULL COMMENT 'yesterday entrances',
  `week_entrances` int(11) DEFAULT NULL COMMENT '7 days entrances',
  `current_ctr` float(16,4) DEFAULT NULL COMMENT 'Current CTR',
  `monthly_search_volume` int(11) DEFAULT NULL COMMENT 'Most Recent Month search volume',
  `avg_monthly_search_volume` int(11) DEFAULT NULL COMMENT 'avg_monthly_search_volume',
  `traffic_increase` int(11) DEFAULT NULL COMMENT 'Traffic Increase',
  `rank_improvement` int(11) DEFAULT NULL COMMENT 'Rank Improvement',
  `rank_update_date` date DEFAULT NULL COMMENT 'rank be updated for Special Date',
  `top_rank_targeturl_id` int(11) DEFAULT NULL,
  `frequency` int(10) DEFAULT '1' COMMENT '1: daily, 2: weekly, 3: monthly',
  `score` float DEFAULT NULL,
  `create_date` datetime DEFAULT NULL,
  `bing_rank1` int(10) DEFAULT NULL,
  `bing_rank2` int(10) DEFAULT NULL,
  `yesterday_bing_entrances` int(11) DEFAULT NULL,
  `bing_rank_improvement` int(11) DEFAULT NULL,
  KEY `id` (`id`),
  KEY `keyword_name` (`keyword_name`),
  KEY `own_domain_id` (`own_domain_id`,`rank_check`),
  KEY `rank_check` (`rank_check`)
) ENGINE=InnoDB AUTO_INCREMENT=670267018 DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (`rank_check`)
(PARTITION p0 VALUES LESS THAN (0) ENGINE = InnoDB,
 PARTITION p1 VALUES LESS THAN (1) ENGINE = InnoDB,
 PARTITION p2 VALUES LESS THAN (2) ENGINE = InnoDB,
 PARTITION pEOW VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
1 row in set (0.00 sec)

mysql> show create table t_target_url\G
*************************** 1. row ***************************
       Table: t_target_url
Create Table: CREATE TABLE `t_target_url` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `own_domain_id` int(11) DEFAULT NULL,
  `url` varchar(2000) NOT NULL,
  `create_date` datetime DEFAULT NULL,
  `friendly_name` varchar(255) DEFAULT NULL,
  `section_name_id` int(11) DEFAULT NULL,
  `type` int(11) DEFAULT NULL,
  `status` int(11) DEFAULT NULL,
  `week_entrances` int(11) DEFAULT NULL COMMENT 'last 7 days entrances',
  `week_bounces` int(11) DEFAULT NULL COMMENT 'last 7 days bounce',
  `canonical_url_id` int(11) DEFAULT NULL COMMENT 'the primary URL ID, NOT allow canonical of canonical',
  KEY `id` (`id`),
  KEY `urlindex` (`url`(255)),
  KEY `own_domain_id_type_status` (`own_domain_id`,`type`,`status`),
  KEY `canonical_url_id` (`canonical_url_id`),
  KEY `type` (`type`,`status`)
) ENGINE=InnoDB AUTO_INCREMENT=237034388 DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (`type`)
(PARTITION p0 VALUES LESS THAN (0) ENGINE = InnoDB,
 PARTITION p1 VALUES LESS THAN (1) ENGINE = InnoDB,
 PARTITION p2 VALUES LESS THAN (2) ENGINE = InnoDB,
 PARTITION pEOW VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
1 row in set (0.01 sec)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:57:53+00:00Added an answer on June 17, 2026 at 10:57 am

    The first line of your EXPLAIN shows a lot of rows for domain_id_event_type_cd, which is a compound index, yet in your query you only search on a part of the index (eve.domain_id = xxx). So unless domain 522 really has 243K entries, you can cut down on this by adding an index solely for domain_id.

    Also, it seems you are trying to do an OR search by using rel.element_type_id as a “switch” for referencing different types of data. Since you are only interested in the count, I suggest you split the query in two parts, then add the results. This will cut down on the LEFT JOINS. You can even add the results within MySQL:

    SELECT (SELECT COUNT (*) FROM ….) + (SELECT COUNT (*) FROM …)

    (You do know you can abuse SELECT to do math, don’t you?)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below query is taking long time to execute around 2mins please help me how
I have this query which is taking around 40-50 seconds to load SELECT members.latitude,
My query is taking very long time around 1hr. 2.due to this it was
I have this query that, due to the number of records, is taking several
I'm trying to optimize a query which is taking around 6 seconds to execute.
I have simple insert into.. query which is taking around 40 seconds to execute.
I have this query which is a dependant query and taking much execution time
I am having this Linq To SQL query which is taking Customer Category from
We have a query that is taking around 5 sec on our production system,
The following query is taking more than 20 seconds to execute on a table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.