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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:48:21+00:00 2026-06-12T19:48:21+00:00

I am writing a SQL query which requires highly optimized solution, so as to

  • 0

I am writing a SQL query which requires highly optimized solution, so as to not timeout. But I have got no idea of how to continuously optimize the following SQL query:

select distinct j.job,f.path,p.path 
from fixes f, jobs j, paths p where f.job=j.id and p.id =f.path 
and (p.path like '//Tools/Web/%' or p.path = '//Tools/Web');

I have created indexes on the following fields(essentially everything):

  • jobs.id
  • jobs.job
  • paths.path
  • paths.id
  • fixes.job
  • fixes.path

In each of the "fixes", "jobs", "paths" table there are ~50,000 rows, and current timeout is 6 min

The ‘explain’ command shows the following information, try to deciphering

1   SIMPLE  j   index   PRIMARY         job     62   (null)    73226    Using index; Using temporary
1   SIMPLE  f   ref     path,job        job     8    j.id      825  
1   SIMPLE  p   eq_ref  PRIMARY,path    PRIMARY 8    f.path    1        Using where

The table creation statements for the ‘paths’ table:

CREATE TABLE `paths` (
   `id` bigint(20) NOT NULL AUTO_INCREMENT,
   `path` varchar(250) NOT NULL,
   PRIMARY KEY (`id`),
   UNIQUE KEY `path` (`path`),
 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
  • 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-12T19:48:23+00:00Added an answer on June 12, 2026 at 7:48 pm

    Wouldn’t this get the same results?

    select distinct j.job,f.path,p.path  
    from fixes f
    join  jobs j on  f.job=j.id 
    join  paths p  on p.id =f.path  
    where p.path like '//Tools/Web%' 
    

    OR is almost always a costly feature.

    You could also try a Union Query, they are often faster than an OR.

    select  j.job,f.path,p.path  
    from fixes f
    join  jobs j on  f.job=j.id 
    join  paths p  on p.id =f.path  
    where p.path like '//Tools/Web/%' 
    union 
    select  j.job,f.path,p.path  
    from fixes f
    join  jobs j on  f.job=j.id 
    join  paths p  on p.id =f.path  
    where  p.path = '//Tools/Web'); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing sql query and i have issue which i cannot fix. I'm trying
I am writing an SQL query which involves finding if timestamp falls in particular
I'm writing a Transact-SQL query which involves several UNIONS where, where the datatype of
In SQL Server are these things possible Writing a select query which references tables
I have a datatable which contains all these records (see SQL query). Instead of
I am writing an SQL query which will return a list of auctions a
I am writing an SQL query in which that I will need to perform
I have this query which works but when I try to write the equivalent
I'm writing a SQL query in SQL Server in which I need to replace
I'm writing an sql query on three tables which finds and displays categories and

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.