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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:19:08+00:00 2026-05-12T09:19:08+00:00

I have the following SQL code: select val.PersonNo, val.event_time, clg.number_dialed from vicidial_agent_log val join

  • 0

I have the following SQL code:

select val.PersonNo,
       val.event_time,
       clg.number_dialed
  from vicidial_agent_log val
         join
       call_log           clg on date_add('1970-01-01 02:00:00', interval clg.uniqueid second) = val.event_time
 order by val.event_time desc
 limit 100;

which executes and returns rows in less than 1 second. However, if I change the straight join to a left outer:

select val.PersonNo,
       val.event_time,
       clg.number_dialed
  from vicidial_agent_log val
         left outer join
       call_log           clg on date_add('1970-01-01 02:00:00', interval clg.uniqueid second) = val.event_time
 order by val.event_time desc
 limit 100;

the query runs forever and uses ~100% of the server’s CPU.

I ran explain on both queries and the first hits the event_time index on vicidial_agent_log, while the second ignores all indexes. There is an index on call_log.uniqueid.

vicidial_agent_log contains ~41,000 rows, call_log contains ~43,000.

So my question is – why is MySQL not hitting the indexes I’ve defined, is there any way to force it to do so, and if not, how can I make this query run at an acceptable speed?

edit

Full solution:

select val.PersonNo,
       val.event_time,
       cl.number_dialed
  from vicidial_agent_log val
         left outer join
       (select date_add('1970-01-01 02:00:00', interval clg.uniqueid second) as 'converted_date',
               number_dialed
          from call_log clg) cl ON cl.converted_date = val.event_time
 order by val.event_time desc
 limit 100;
  • 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-12T09:19:09+00:00Added an answer on May 12, 2026 at 9:19 am

    Using functions in JOIN or WHERE clauses will always cause havoc with indexes. Example:

    DATE_ADD('1970-01-01 02:00:00', INTERVAL clg.uniqueid SECOND)
    

    The database is using the uniqueid index to lookup the values for the conversion, not the comparison to the event_time column in your case. If this were Oracle with PLW errors turned on, you’d be notified about potentially converting away from the data type.

    Such situations should always be handled before the comparison, which means using an inline view to perform the conversion and then join to that result column. IE:

    JOIN (SELECT DATE_ADD('1970-01-01 02:00:00', INTERVAL clg.uniqueid SECOND) 'converted_date'
            FROM CALL_LOG clg) cl ON cl.converted_date = val.event_time
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 240k
  • Answers 240k
  • 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 Class.getResource/getResourceAsStream. In fact a class should always be able to… May 13, 2026 at 7:09 am
  • Editorial Team
    Editorial Team added an answer Here's a possible fix for your problem: <html> <head runat="server">… May 13, 2026 at 7:09 am
  • Editorial Team
    Editorial Team added an answer I would recommend SQLite. It's a full SQL database engine… May 13, 2026 at 7:09 am

Related Questions

I'm not sure whether my SQL code and practise here is any good, so
I have the following T-SQL code (in SQL 2000) which functions correctly: INSERT INTO
I have the following code SELECT tA.FieldName As [Field Name], COALESCE(tO_A.[desc], tO_B.[desc], tO_C.Name, tA.OldVAlue)
I have the following Sql Query that returns the type of results that I

Trending Tags

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

Top Members

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.