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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:35:24+00:00 2026-06-11T10:35:24+00:00

We are running a hospital system which is web based created in PHP. The

  • 0

We are running a hospital system which is web based created in PHP. The system was initially fast due to small size of the database but now it has become slow.

The following is an example query

select pa.id, pa.date as date, pa.visitno, pa.receiptno, pa.debitnoteno, pad.id as padid,
 pad.serviceid as serviceid, pad.waitno, pa.paytype, s.id as doctorid, s.fullname as
 doctorname, p.id as patientid, p.name as patient, p.regno, p.age, p.gender, p.doc,
 p.department, p.telno, p.address, pa.ins_prov_id, ip.name as provider,
 pa.sicksheet_billcode as billcode, ds.id as serviceid, ds.name as servicename, ds.departid
 as departid, ds.servicetype as servicetype, pad.charge, pad.status as status, ts.id as
 timeslotid, ts.name as timeslot, pad.treatment, sd.anesthesiologist, sd.hospitalcharge,
 sd.anesthcharge from patientappointments as pa
INNER JOIN patientappdetails as pad ON pa.id = pad.patappid 
INNER JOIN patients as p ON pa.patid = p.id 
INNER JOIN staffs as s ON pad.doctorid = s.id 
LEFT JOIN departmentalservices as ds ON pad.serviceid = ds.id 
LEFT JOIN insproviders as ip ON pa.ins_prov_id = ip.id 
LEFT JOIN timeslots as ts ON pad.timeslotid = ts.id 
LEFT JOIN surgerydetails as sd ON sd.appdetid = pad.id 
where 1 = 1 and pa.date >= '01.Jul.2012' and ds.departgroupid = 16 and pad.charge != 0

As you can see the size of our queries (call them un-optimized) which shows the patient, doctor, service taken, what time and which ins company he came from. So now we created indexes that did help for a while but now again the speed has become slow. Running the system on localhost results in around 15 secs for the result to appear while on the live system, it times out.

Can you suggest any method to improve the speed and exactly how to implement them.

Just FYI, rows in each table are as follows:

  • patientappdetails – 195k
  • patients – 34k
  • staffs – 200
  • departmentalservices – 700
  • insproviders – 2800

Thank you

  • 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-11T10:35:26+00:00Added an answer on June 11, 2026 at 10:35 am

    Well, lets start with the indexes.
    I assume you have created an index for patienappointments.date and that is of the clustered kind. I also assume you have an index on ds.departgroupid.
    You’re missing the size of several tables, but i’m gonna guess that those left joins are the culprits.
    The query execution plan should yield some interesting results (if you can post it here it may help dispel some doubts). If you dont have an index on the date field you are facing a sequential table scan (reading the whole table) and that is really bad. Also check those left joins since one of them is probably messing the query plan.

    As a rule of thumb i’d do this:

    1. Run the query with the inner joins only, and test the time it takes
    2. Get a query plan for that and see if it can be optimized (by adding indexes mostly)
    3. Run the query of step 1 with the WHERE statement
    4. Query plan and optimization
    5. Add the left joins one at the time
    6. Query plan and optimization

    And so forth…

    Even so maybe your query ends up taking a lot of time in that case there are two things you can do

    1. Add more hardware (it never hurts to have more memory and better disks)
    2. Based on the input of the optimization, split the query into smaller parts using temporal tables son the optimizer can speed up the good parts.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running an MVC web site that calls a WCF service. Site and service on
Running Windows PHP 4.4.2 \cli\php.exe fails with an error Cannot find php4ts.dll if the
Running on MySQL 5.5.9 with InnoDB. I created the following trigger: CREATE TRIGGER TRIGGER_Products_Insert
Running my play framework small app I get the following exception: ... Caused by:
running: ruby 1.9.3p0 with Rails 3.2.1 Trying to use rspec but when I try
Running Linux (Ubuntu 11.10), the same regular expression works in JavaScript, but fails when
Running a gwtp-sample-basic-spring app in Eclipse, I see the welcome page, but after some
Running Safari 5.05. This CSS is looks fine in Chrome and Firefox, but when
Running Apache/PHP on this PC. I am using Eclipse >> Export Java > JAR
Running the following query using PDO (Actually, I use prepared statements but same problem)

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.