这insert
是我的应用程序的一部分,它允许用户拍照并将它们存储在数据库中。存储在数据库中的所有文件名都有一个非常具体的命名约定,这就是为什么我的插入case
语句有如此密集的原因。我猜这与我的表现缓慢有关。当为数据库中存储很少或没有存储shots
的 a插入新时,我的应用程序运行得更快。但是,如果我要添加的内容已经有很多存储在数据库中,那么性能会慢得多。patient
shots
patient
shots
是否有可能加快这一insert
说法?如果是这样,怎么做?我的应用程序是用 PHP 编码的,我正在使用phpMyAdmin
和mysqli
INSERT INTO shot (ID, VISIT_ID, PATIENT_ID ,IMG_FILENAME ,SHRUNK_IMG_FILENAME ,SUBDIR ,SUBSUBDIR ,IMG_FILE_FORMAT ,EYE)
SELECT (
SELECT (max(ID) + 1) FROM SHOT
)
,(
SELECT max(ID) FROM visit WHERE visit.patient_id = " . $_SESSION['id'] ."
)
," . $_SESSION['id'] . "
,(
SELECT CASE
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 100
THEN CONCAT ( '00000000' ,(MAX(shot.ID) + 1) ,'r.jpg' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 1000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 99
THEN CONCAT ( '0000000' ,(MAX(shot.ID) + 1) ,'r.jpg' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 10000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 999
THEN CONCAT ( '000000' ,(MAX(shot.ID) + 1) ,'r.jpg' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 100000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 9999
THEN CONCAT ( '00000' ,(MAX(shot.ID) + 1) ,'r.jpg' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 1000000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 99999
THEN CONCAT ( '0000' ,(MAX(shot.ID) + 1) ,'r.jpg' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 10000000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 999999
THEN CONCAT ( '000' ,(MAX(shot.ID) + 1) ,'r.jpg' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 100000000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 9999999
THEN CONCAT ( '00' ,(MAX(shot.ID) + 1) ,'r.jpg' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 1000000000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 99999999
THEN CONCAT ( '0' ,(MAX(shot.ID) + 1) ,'r.jpg' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 10000000000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 999999999
THEN CONCAT ( (MAX(shot.ID) + 1) ,'r.jpg' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 100000000000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 9999999999
THEN CONCAT ( (MAX(shot.ID) + 1) ,'r.jpg' )
END
)
,(
SELECT CASE
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 100
THEN CONCAT ( '00000000' ,(MAX(shot.ID) + 1) ,'s.bmp' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 1000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 99
THEN CONCAT ( '0000000' ,(MAX(shot.ID) + 1) ,'s.bmp' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 10000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 999
THEN CONCAT ( '000000' ,(MAX(shot.ID) + 1) ,'s.bmp' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 100000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 9999
THEN CONCAT ( '00000' ,(MAX(shot.ID) + 1) ,'s.bmp' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 1000000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 99999
THEN CONCAT ( '0000' ,(MAX(shot.ID) + 1) ,'s.bmp' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 10000000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 999999
THEN CONCAT ( '000' ,(MAX(shot.ID) + 1) ,'s.bmp' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 100000000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 9999999
THEN CONCAT ( '00' ,(MAX(shot.ID) + 1) ,'s.bmp' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 1000000000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 99999999
THEN CONCAT ( '0' ,(MAX(shot.ID) + 1) ,'s.bmp' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 10000000000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 999999999
THEN CONCAT ( (MAX(shot.ID) + 1) ,'s.bmp' )
WHEN ( SELECT MAX(shot.ID) + 1 FROM shot ) < 100000000000
AND ( SELECT MAX(shot.ID) + 1 FROM SHOT ) > 9999999999
THEN CONCAT ( (MAX(shot.ID) + 1) ,'s.bmp' )
END
)
,$SUB
,$ISUB
,'124'
,'0'
FROM SHOT