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

  • Home
  • SEARCH
  • 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 8435675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:58:40+00:00 2026-06-10T06:58:40+00:00

I have tables with following structure: — Table structure for table `temp_app` — CREATE

  • 0

I have tables with following structure:

-- Table structure for table `temp_app`
--

CREATE TABLE IF NOT EXISTS `temp_app` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `vid` int(5) NOT NULL,
  `num` varchar(64) NOT NULL,
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `vid` (`vid`),
  KEY `num` (`num`),
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=69509;

-- Table structure for table `inv_flags`
--

CREATE TABLE IF NOT EXISTS `inv_flags` (
  `num` varchar(64) NOT NULL,
  `vid` int(11) NOT NULL,
  `f_special` tinyint(1) NOT NULL, /*0 or 1*/
  `f_inserted` tinyint(1) NOT NULL, /*0 or 1*/
  `f_notinserted` tinyint(1) NOT NULL, /*0 or 1*/
  `userID` int(11) NOT NULL,
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  KEY `num` (`num`),
  KEY `userID` (`userID`),
  KEY `vid` (`vid`),
  KEY `timestamp` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Execution time of the following query is 9 seconds to display 30 records. What is wrong?

SELECT date_format(ifs.`timestamp`,'%y/%m/%d') as `date`
                ,count(DISTINCT ta.num) as inserted /*Unique nums*/
                ,SUM(ifs.f_notinserted) as not_inserted
                ,SUM(ifs.f_special)  as special
                ,count(ta.num) as links /*All nums*/
                from inventory_flags ifs
                LEFT JOIN temp_app ta ON ta.num = ifs.num AND ta.vid = ifs.vid
                WHERE ifs.userID = 3
                GROUP BY date(ifs.`timestamp`) DESC LIMIT 30

EXPLAIN RESULT

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  ifs ref userID  userID  4   const   12153   Using where
1   SIMPLE  ta  ref vid,num num 194 ifs.num 1   
  • 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-10T06:58:41+00:00Added an answer on June 10, 2026 at 6:58 am

    COUNT DISTINCT can sometimes cause rotten performance with MySql. Try this instead:

    select count(*) from (select distinct...
    

    as it can sometimes prevent MySql from writing the entire interim result to disk.

    Here is the MySql bug info:

    http://bugs.mysql.com/bug.php?id=21849

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

Sidebar

Related Questions

I have DB2 table having following structure CREATE TABLE DUMMY ( ID CHARACTER(10) NOT
I'm using EF v1. I have following tables: CREATE TABLE category ( category_id int
I have two database tables with the following structure: actions: action_id int(11) primary key
I have table with following structure and test records: +--------+--------+---------+ | vid | number
I have a table with the following structure id(int) | col1(int) | col2(int) |
I have an SQL table with basically the following structure: PK (int, primary key),
I have 2 tables: The question table with the following structure: id title userid
I have two mysql tables that have the following structure: Table 1: ---ID---------NAME------- ---1-----
I have the following tables, link_books_genres , *table structure -> book_id,genre_id* genres , *table
I have the following 2 tables defined in a SQL Server database: CREATE 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.