我们正在运行一个使用 PHP 创建的基于 Web 的医院系统。由于数据库的大小,该系统最初很快,但现在它变得很慢。
以下是一个示例查询
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
如您所见,我们查询的大小(称它们为未优化)显示了患者、医生、所接受的服务、他来自什么时间和哪个公司。所以现在我们创建了在一段时间内确实有帮助的索引,但现在速度又变慢了。在 localhost 上运行系统会导致结果在大约 15 秒后出现,而在实时系统上,它会超时。
您能否提出任何提高速度的方法以及如何实现它们。
仅供参考,每个表中的行如下:
- 患者应用程序详细信息 - 195k
- 患者 - 34k
- 员工 - 200
- 部门服务 - 700
- 提供者 - 2800
谢谢