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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:58:35+00:00 2026-05-16T07:58:35+00:00

SELECT count(*) c FROM full_view WHERE verified > ( DATE (NOW()) – INTERVAL 30

  • 0
SELECT count(*) c FROM full_view WHERE verified > ( DATE (NOW()) - INTERVAL 30 DAY)

If I run that query it takes a split second but if I switch the comparison operator around it takes eons. Now the first way the count = 0 and the second way the count = 120000, but if I just count the whole table that also takes microseconds.

But there is something something funky going on because if the query ever does finish it runs super quick thereafter. MySQL is caching the query or something right? Well, I don’t want to depend on caches to make sure the website doesn’t hang.

This seems nonsensical: if it can count everything greater than a certain date quickly, why should it take any longer to count the opposite? Either way it has to look through the whole table right? And all it needs to return is a number so bandwidth shouldn’t be an issue.

Explain on the query:

1, 'SIMPLE', 'b', 'range', 'updated,verified_index', 'updated', '3', '', 28, 'Using where'`    
1, 'SIMPLE', 'l', 'eq_ref', 'PRIMARY', 'PRIMARY', '4', 'xyz_main.b.loc_id', 1, 'Using index'
1, 'SIMPLE', 'f', 'ALL', '', '', '', '', 2214, ''

EDIT:

This may be of some interest, I found this info when I run the query:

Handler_read_rnd_next:

  • 254436689 (when doing less than)
  • 2 (for greater than)

Key_read_requests:
314393 vs 33 (33 is the biggest number for all of the stats when using greater than)

Handler_read_key:
104303 vs 1

Bypassing the view and running the query directly on the main table eliminates the slowness. So what do I need to do to speed it up? The view is essentially like this:

SELECT x, y, z, verified FROM table1 LEFT JOIN table2 on tab2_ID = table2.ID LEFT JOIN table3 on tab3_ID = table3.ID

SOLVED:
Frankie led my in the right direction. The second joined table (the company table) was joined via the full text name of the companies. I only recently decided to add a integer key to that table. The name column was supposed to be indexed but I may have botched that. Anyway I re-organized everything. I converted the foreign key in the main table to match the integer ID of the company table rather than the full company name. I re-indexed those columns in each table, then I updated the view to reflect the new join point. Now it runs instantly in both directions. 🙂 So I guess integer keys were the key. The problem is gone but still, I don’t feel like my original question was really solved.

Thanks for your help guys.

  • 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-05-16T07:58:35+00:00Added an answer on May 16, 2026 at 7:58 am

    Please run the bellow query and post the results.

    EXPLAIN SELECT count(*) c 
    FROM full_view 
    WHERE verified > ( DATE (NOW()) - INTERVAL 30 DAY)
    

    The long forgotten EXPLAIN almost always brings something in! ;)


    Edit 1:
    This is probably the offensive line:

    1, 'SIMPLE', 'f', 'ALL', '', '', '', '', 2214, ''
    

    The ALL there states that there is a FULL table scan.

    You can dig further into the Explain syntax on this diagram.

    Do try to see where the differences go…


    Edit 2:
    This doc will sure make things much clearer on the Explain output. Please check it out.


    Edit 3:
    Step-by-step analys of the explain command.

    1, 'SIMPLE', 'b', 'range', 'updated,verified_index', 'updated', '3', '', 28, 'Using where'`    
    1 - id
    SIMPLE - simple select, not using sub-queries
    b - table name
    range - only rows that are in a given range are retrieved, using an index
    updated,verified_index - are both possible keys
    updated - was the key eventually used
    3 - key lenght
    '' - this is the ref column and would show which columns or constants are compared to the index name in the key column to select rows from the table.
    28 - number of rows mysql believes it must examine to execute the query
    Using where - self explanatory
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, the title bar is owned by the window manager… May 16, 2026 at 11:35 pm
  • Editorial Team
    Editorial Team added an answer Suppose the string you want to insert is the literal… May 16, 2026 at 11:35 pm
  • Editorial Team
    Editorial Team added an answer Actually Objective C has a powerful set of introspection features,… May 16, 2026 at 11:35 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a query which is crossing two tables select count(*) from ingenium.empevt, ingenium.evt
I tried .. SELECT c.* , ( SELECT COUNT( * ) FROM item t
foreach (string str in TestWords) { //spam SqlCommand cmd6 = new SqlCommand(select count from
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { const char *sqlStatement = select count(*) from mytable;
var query = from c in db.Customers select c; query = query.Where(c => c.Orders.Where(o
I created a MySQL view using UNION ALL from two tables so that I
The problem is that the query in question runs very slow when compared to
I have an elementary query that is taking too long to execute even on
with tmp_rows as ( select * from [dbo].[customer] ) select * from tmp_rows; select
We have a view that stores the history of membership plans held by our

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.