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 9046969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:47:20+00:00 2026-06-16T11:47:20+00:00

Below query is taking long time to execute around 2mins please help me how

  • 0
  1. Below query is taking long time to execute around 2mins please help me how to improve performance of this query.
  2. so our requirement is to get result within 2 to 3secs.
  3. query is using indexes also.
  4. but it was performing more scan.

query:

select max(`log_date`)
from `top_competitor_summary_entity`
where
  own_domain_id = 4
  and keyword_top1_count > 0
  and (grouptag_id = 0 OR grouptag_id is null);

Expalin Plan:

+----+-------------+-------------------------------+------+--------------------------------------+------------------------+---------+-------+---------+-------------+
| id | select_type | table                         | type | possible_keys                        | key                    | key_len | ref   | rows    | Extra       |
+----+-------------+-------------------------------+------+--------------------------------------+------------------------+---------+-------+---------+-------------+
|  1 | SIMPLE      | top_competitor_summary_entity | ref  | own_domain_id,own_domain_id_log_date | own_domain_id_log_date | 4       | const | 2100128 | Using where |
+----+-------------+-------------------------------+------+--------------------------------------+------------------------+---------+-------+---------+-------------+
1 row in set (0.66 sec)

Table structure:

mysql> show create table top_competitor_summary_entity\G
*************************** 1. row ***************************
       Table: top_competitor_summary_entity
Create Table: CREATE TABLE `top_competitor_summary_entity` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `domain` varchar(255) NOT NULL COMMENT 'competitor domain name',
  `own_domain_id` int(11) NOT NULL,
  `keyword_top10_count` int(11) DEFAULT NULL,
  `keyword_top3_count` int(11) DEFAULT NULL,
  `keyword_top1_count` int(11) DEFAULT NULL,
  `keyword_top10_search_volume` bigint(20) DEFAULT NULL,
  `keyword_top3_search_volume` bigint(20) DEFAULT NULL,
  `keyword_top1_search_volume` bigint(20) DEFAULT NULL,
  `url_top10_count` int(11) DEFAULT NULL
    COMMENT 'how many competitor url in Top 10',
  `log_date` date DEFAULT NULL,
  `grouptag_id` int(11) DEFAULT '0',
  `keyword_top10_count_bing` int(11) DEFAULT '0',
  `keyword_top10_count_yahoo` int(11) DEFAULT '0',
  `keyword_top3_count_bing` int(11) DEFAULT '0',
  `keyword_top3_count_yahoo` int(11) DEFAULT '0',
  `keyword_top1_count_bing` int(11) DEFAULT '0',
  `keyword_top1_count_yahoo` int(11) DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `own_domain_id` (`own_domain_id`),
  KEY `domain_own_domain_id_log_date` (`domain`,`own_domain_id`,`log_date`),
  KEY `own_domain_id_log_date` (`own_domain_id`,`log_date`)
) ENGINE=InnoDB AUTO_INCREMENT=680592051 DEFAULT CHARSET=utf8
1 row in set (0.09 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-16T11:47:21+00:00Added an answer on June 16, 2026 at 11:47 am

    The query itself is so simple that I don’t think there’s anything you could possibly do to it to make it faster by modifying it. Still I would be curious whether using “IsNull(grouptag_id, 0) = 0” would make any difference whatsoever. I doubt it, but it might be fun to see if it shaves anything off.

    I think the real problem is that there are probably a ton of records that have an own_domain_id value of 4, and you don’t have indexes for the other fields in the where clause. You can create individual indexes for them and/or if you want to create an index that’s specifically tailored to this query then create one that keys on all 4 of the fields referenced.

    Some other observations:

    If it would be a possibility to change your code to deal with null values (perhaps just treat them as 0’s) then you could get rid of the default values you’re placing in most those fields and make them null instead. If not many fields actually have a value of 0 than this wouldn’t do much, but if a lot of fields are set to 0 than this would cause the table to take up less space on disk which would translate to less time to scan the table.

    You could also partition the table either horizontally or vertically.

    Horizontally: You could take all the top1 fields and put them in a top1 table, all the top3 fields and put them in a top3 table, etc. Alternatively, you might do all the yahoo in one table and all bing in another table; or perhaps all the count fields in one table and all the search fields in another. If you find yourself usually only need one set of fields at a time then this would reduce the search time, but if you usually end up grabbing all the fields in most your queries then of course it wouldn’t really help.

    Vertically: This one is probably a lot more work than it’s worth, but you could split the records in your table over multiple tables and put them on multiple hard disks and query them all at the same time asynchronously. I’ve always wondered if Google does something along these lines.

    I also notice you’re using a bigint for your id which is 8 bytes, as opposed to just an int which is only 4 bytes. If you think you will realistically be handling multiple billions of records at some point then bigint is obviously the way to go, but otherwise you could shrink your database by about a 100 megabytes which will also have the effect of making your searches marginally faster. And there’s no reason you can’t make it an int now and change it back to a bigint later if that becomes necessary.

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

Sidebar

Related Questions

We have a query that is taking around 5 sec on our production system,
I have a query that is taking way too long to execute (4 seconds)
The below given code of is taking infinitely long time to load in a
I have the below query which is taking 2 seconds to execute as there
One of the query (given below) is taking 90+ seconds to execute. It returns
I'm using below mentioned query with about 400,000 records in each table its taking
I have below query I am trying to show message 'No SubSource for this
Can anyone help or provide me with some suggestions for the below query. I
When trying to execute this query my mysql server cpu usage goes to 100%
I am using the below query to return the names of artists which appear

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.