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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:09:55+00:00 2026-06-15T01:09:55+00:00

Stumped on this query, it searches an important table which contains about 213k rows.

  • 0

Stumped on this query, it searches an important table which contains about 213k rows. The purpose of the query is to report traffic data for a month. The amount of traffic for each day of that month. And sum of a decimal value for each day. This query is ran frequently so I need to optimize it to the best possible. Currently takes avg. 2 seconds..

SQL Fiddle: http://sqlfiddle.com/#!2/171f5/3/0

All suggestions will be greatly appreciated! Thank you.

Query:

SELECT `date_day`, COUNT(*) AS num, SUM(decval) AS sum_decval FROM (`tbl_traffic`)
WHERE `uuid` = '1' AND `date_year` = '2012' AND `date_month` = '11'
GROUP BY `date_day`;

Explain Result:

id: 1
select_type: SIMPLE
table: adb1_analytics
type: ref
possible_keys: keys1,keys2,keys3
key: keys1
key_len: 7
ref: const,const,const
rows: 106693
Extra: Using where
1 row in set (0.13 sec)

Table structure:

CREATE TABLE IF NOT EXISTS `tbl_traffic` (
  `id` int(100) unsigned NOT NULL AUTO_INCREMENT,
  `uuid` int(100) unsigned NOT NULL,
  `country` char(2) CHARACTER SET latin1 DEFAULT NULL,
  `browser` varchar(50) CHARACTER SET latin1 DEFAULT NULL,
  `platform` varchar(50) CHARACTER SET latin1 DEFAULT NULL,
  `referrer` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `decval` decimal(15,5) NOT NULL,
  `date_year` smallint(4) unsigned NOT NULL,
  `date_month` tinyint(2) unsigned NOT NULL,
  `date_day` tinyint(2) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `keys1` (`uuid`,`date_year`,`date_month`,`date_day`),
  KEY `keys2` (`date_year`,`date_month`,`referrer`),
  KEY `keys3` (`date_year`,`date_month`,`country`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
  • 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-15T01:09:57+00:00Added an answer on June 15, 2026 at 1:09 am

    Use count(id) and add keys on date_day and decval.
    A covering key over both fields might be even better

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

Sidebar

Related Questions

This one really has me stumped. I have a documents table which hold info
Guys I'm stumped on this one, I have a large table with 100,000 rows
I'm stumped with this query. I have a deal table with deals for different
java.lang.UnsupportedOperationException: This operation is not supported on Query Results at org.datanucleus.store.query.AbstractQueryResult.contains(AbstractQueryResult.java:250) at java.util.AbstractCollection.retainAll(AbstractCollection.java:369) at
I'm rather stumped about the best way to build a Django query that checks
I'm going to get some real-world data the best I can for this query
I have this LINQ query which returns the indexes of all the items in
Okay, I am stumped with this one. I have a table in my database
Im stumped by this simple query because its one I have not tried before.
This has got me completely stumped: print_r($json); echo json_encode($json); output: Array ( [query] =>

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.