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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:25:40+00:00 2026-06-08T07:25:40+00:00

I am having issues with an InnoDB mysql database. E.g., I have two tables,

  • 0

I am having issues with an InnoDB mysql database. E.g., I have two tables, events and events_artists with the following architecture:

events:
id (PK)
host_id
date

events_artists:
id (PK)
event_id
artist_id

The table events has about 100,000 entries, events_artists holds about 150,000.

One of the things I have to do is check for entries in the table events that are not referred to in the table events_artists. To do that, in another post I have received the query

SELECT * FROM events WHERE id IS NULL OR id NOT IN (SELECT event_id FROM events_artists)

From the logic, this query looks good to me. However, it is just extremely slow. I let it run for one hour now, and still no result. Something has to be wrong there.

I am grateful for any help on how to optimize this!

Thanks

Charles

SOLUTION FOUND

The following query makes the statement much faster:

SELECT * 
FROM events a
     LEFT JOIN events_artists b
     ON a.id = b.event_id
     WHERE b.event_id IS NULL;

However, the main speed boost was adding foreign keys. I had to remove them in the interim for some duplicate search and added them back now, which increases speed a lot. While the query took more than an hour before, it only takes one second now.

Thank you!

Charles

  • 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-08T07:25:42+00:00Added an answer on June 8, 2026 at 7:25 am

    To get faster results you should avoid using sub-query. Alternatively you can try using LEFT JOIN to get records which are in events but not in events_artists.

    Visit Visual explanation of joins

    SELECT * 
    FROM events a
         LEFT JOIN events_artists b
             ON a.id = b.event_id
    WHERE b.event_id IS NULL;
    

    Also make sure that you have index on columns id and event_id for faster query execution.

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

Sidebar

Related Questions

I having issues exporting a GridView to Excel for some reason. I have two
Having issues with screen progress. I have a screen displaying information from a database.
Im having issues trying to join a table twice. I have 3 tables: Users,
I am having issues with my Rails 3.1 app. I have two controllers &
MySQL Server version: 5.0.95 Tables All: InnoDB I am having an issue with a
Im having issues getting this to work, maybe its not even possible? I have
I'm having issues parsing some XML using DefaultHandler2. My XML takes the following form:
I having issues getting Django to work with settings.py at different location I have
I have been having issues calling a background image in my CSS file. The
im having issues with the following interface and a class: public interface IRelated {

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.