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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:32:26+00:00 2026-05-11T19:32:26+00:00

I am trying here to basically find users that do have sports & regions

  • 0

I am trying here to basically find users that do have sports & regions targeted by an activity. In the acces [users] table there is around 17K users. Each can have a certain number of sport interests and one region.

There query here look for each users that have one sport & one region at least that are targeted via the activities. Sports can be up to 75 when we select each of em [not quite good with an IN query].

SELECT a.user, pp.courriel
FROM acces a
LEFT JOIN acces_profil_sport ap ON ap.id = a.id
LEFT JOIN profil_perso pp ON pp.id = a.id
WHERE ap.sport_id IN
  (
    SELECT ac.sport_id
    FROM activite_sport ac
    RIGHT JOIN activite a ON a.activite_id = ac.activite_id AND a.is_cron = 1 AND a.cron_processed = 0
   )
  AND pp.region_id IN
  (
    SELECT ar.region_id
    FROM activite_region ar
    RIGHT JOIN activite a ON a.activite_id = ar.activite_id AND a.is_cron = 1 AND a.cron_processed = 0
  )
GROUP BY a.id

If I remove the sport lookup, the query takes arounds 30 secs to run. Otherwise it takes quite forever and use around 99% of the proc with mysql.

Any hints to help that ?

[edit : Table structure]
Acces : id (primary key), user, perso_id (Key/Foreign key to profil_perso[perso_id]) [some-other-fields]
profil_perso : perso_id (primary key) courriel, region_id, id (foreign key to acces[id]) [some other fields]
acces_profil_sport : id/sport_id (dual primary key), niveau_id (dual key with sport_id)

  • 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-11T19:32:26+00:00Added an answer on May 11, 2026 at 7:32 pm

    I suspect your indexes are wrong. If you print out an explain select…, I can better comment on that. Further, I’m curious why you’re doing left / right joins and subselects.

    It seems to me that these should all be normal joins since the two left joins will only work if they exist. If they come up null, you won’t get a row because of the required subselect matching.

    As for the right joins, you need the ar bit there, which isn’t part of the right side. I’d either remove them or make them straight joins as well. I assume since you’re checking for what looks like unprocessed cron work, you want to keep them.

    SELECT a.user, pp.courriel
    FROM acces 
    JOIN acces_profil_sport ap ON ap.id = a.id
    JOIN profil_perso pp ON pp.id = a.id
    JOIN activite_sport ac ON ac.sport_id = ap.sport_id
    JOIN activite a1 ON a.activite_id = ac.activite_id AND a.is_cron = 1 AND a.cron_processed = 0
    JOIN activite_region ar ON ar.region_id = pp.region_id
    JOIN activite a2 ON a.activite_id = ar.activite_id AND a.is_cron = 1 AND a.cron_processed = 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

basically I am trying to model some map brushes that have the following format:
Basically I am trying to restart a service from a php web page. Here
Ok here's what I'm trying to do I want to write a class that
Here's what I'm trying to do, and failing... I have a File model which
Bit of a jquery Newbie here, so go easy. Basically I'm trying to plug
Programming Student here...trying to work on a project but I'm stuck. The project is
What I'm trying to do here is get the headers of a given URL
(see here for the problem I'm trying to solve) How do you get hibernate
Here's a problem I've been trying to solve at work. I'm not a database
Here's the situation: I am trying to launch an application, but the location of

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.