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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:56:29+00:00 2026-05-29T22:56:29+00:00

I have inherited some code, the original author is not contactable and I would

  • 0

I have inherited some code, the original author is not contactable and I would be extremely grateful for any assistance as my own MySQL knowledge is not great.

I have the following query that is taking around 4 seconds to execute, there is only around 20,000 rows of data in all the tables combined so I suspect the query could be made more efficient, perhaps by splitting it into more than one query, here it is:

    SELECT SQL_CALC_FOUND_ROWS ci.id AS id, ci.customer AS customer, ci.installer AS installer, ci.install_date AS install_date, ci.registration AS registration, ci.wf_obj AS wf_obj, ci.link_serial AS link_serial, ci.sim_serial AS sim_serial, sc.call_status AS call_status 
    FROM ap_servicedesk.corporate_installs AS ci 
    LEFT JOIN service_calls AS sc ON ci.wf_obj = sc.wf_obj
    WHERE ci.acc_id = 3 
    GROUP BY ci.id
    ORDER BY  link_serial
                asc
    LIMIT 40, 20

Can anyone spot any way to make this more efficient, thanks.

(Some values are set as variables but running the above query in PHPMyAdmin takes ~4secs)

The id column is the primary index.

More Info as requested:

corporate_installs table:

Field       Type    Null    Key Default Extra

id              int(11) NO  PRI NULL    auto_increment
customer        varchar(800)    NO      NULL    
acc_id      varchar(11) NO      NULL    
installer       varchar(50) NO      NULL    
install_date    varchar(50) NO      NULL    
address_name    varchar(30) NO      NULL    
address_street  varchar(40) NO      NULL    
address_city    varchar(30) NO      NULL    
address_region  varchar(30) NO      NULL    
address_post_code   varchar(10) NO      NULL    
latitude            varchar(15) NO      NULL    
longitude           varchar(15) NO      NULL    
registration    varchar(50) NO      NULL    
driver_name         varchar(50) NO      NULL    
vehicle_type    varchar(50) NO      NULL    
make            varchar(50) NO      NULL    
model           varchar(50) NO      NULL    
vin                 varchar(50) NO      NULL    
wf_obj          varchar(50) NO      NULL    
link_serial         varchar(50) NO      NULL    
sim_serial          varchar(50) NO      NULL    
tti_inv_no          varchar(50) NO      NULL    
pro_serial          varchar(50) NO      NULL    
eco_serial          varchar(50) NO      NULL    
eco_bluetooth   varchar(50) NO      NULL    
warranty_expiry varchar(50) NO      NULL    
project_no          varchar(50) NO      NULL    
status          varchar(15) NO      NULL    

service_calls table:

Field           Type           Null Key Default Extra
id                  int(11)     NO      PRI NULL    auto_increment
acc_id          int(15)         NO      NULL    
ciid            int(11)         NO      NULL    
installer_job_no    varchar(50) NO      NULL    
installer_inv_no    varchar(50) NO      NULL    
engineer            varchar(50) NO      NULL    
request_date    varchar(50) NO      NULL    
completion_date varchar(50) NO      NULL    
call_status         varchar(50) NO      NULL    
registration    varchar(50) NO      NULL    
wf_obj          varchar(50) NO      NULL    
driver_name         varchar(50) NO      NULL    
driver_phone    varchar(50) NO      NULL    
team_leader_name    varchar(50) NO      NULL    
team_leader_phone   varchar(50) NO      NULL    
servicing_address   varchar(150)    NO      NULL    
region          varchar(50) NO      NULL    
post_code           varchar(50) NO      NULL    
latitude            varchar(50) NO      NULL    
longitude           varchar(50) NO      NULL    
incident_no         varchar(50) NO      NULL    
service_type    varchar(20) NO      NULL    
fault_description   varchar(50) NO      NULL    
requested_action    varchar(50) NO      NULL    
requested_replacemt varchar(100)    NO      NULL    
fault_detected  varchar(50) NO      NULL    
action_taken    varchar(50) NO      NULL    
parts_used          varchar(50) NO      NULL    
new_link_serial varchar(50) NO      NULL    
new_sim_serial  varchar(50) NO      NULL    

(Apologies for the formatting, I did the best I could)

Let me know if you need more info thanks.

Further info (I did the query again with EXPLAIN):

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  ci  ALL acc_id  NULL    NULL    NULL    7227    Using where; Using temporary; Using filesort
1   SIMPLE  sc  ALL NULL    NULL    NULL    NULL    410 
  • 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-29T22:56:31+00:00Added an answer on May 29, 2026 at 10:56 pm

    Add indices on the two wf_obj columns, the link_serial column (you may also need an index on the acc_id, too).

    Then try this version:

    SELECT ...
    FROM 
          ( SELECT * 
            FROM ap_servicedesk.corporate_installs
            WHERE acc_id = 3 
            ORDER BY link_serial ASC
            LIMIT 60
          ) AS ci 
      LEFT JOIN service_calls AS sc 
        ON sc.PK =                          --- the PRIMARY KEY of the table
        ( SELECT PK
          FROM service_calls AS scm
          WHERE ci.wf_obj = scm.wf_obj
          ORDER BY scm.    --- whatever suits you
          LIMIT 1
        )
    ORDER BY ci.link_serial ASC
    LIMIT 20  OFFSET 40
    

    The ORDER BY scm.SomeColumn is needed not for performance but to get consistent results. Your query as it is, is joining a row from the first table to all related rows of the second table. But the final GROUP BY aggregates all these rows (of the second table), so your SELECT ... sc.call_status picks a more or less random call_status from one of these rows.

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

Sidebar

Related Questions

I have inherited some code: Process p = new ProcessBuilder(/bin/chmod, 777, path).start(); p.waitFor(); Basically,
I have inherited some code (from zip file) from a developer and git initialzed,
I have inherited some HTML code and have been asked to align the two
I have inherited some legacy PHP code what was written back when it was
I have some C# / asp.net code I inherited which has a textbox which
I have inherited some code from a guy whose favorite past time was to
I have inherited some code which involves a scheduled task that writes data (obtained
I have inherited some legacy code which generates a ton of inline styles. The
I have some code I inherited which has a lot of warnings that I
I have inherited some code and am getting an error when I try to

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.