これinsert
は、ユーザーが写真を撮ってデータベースに保存できるようにするアプリケーションの一部です。データベースに保存されているすべてのファイル名にはかなり具体的な命名規則がありますcase
。これは私のパフォーマンスが遅いことと関係があると思います。データベースにほとんど格納されていない、またはまったく格納されていない に対して newshots
を挿入すると、アプリケーションの実行速度が大幅に向上します。ただし、追加先のデータベースにすでに多くのデータが保存されている場合、パフォーマンスは大幅に低下します。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