24 lines
838 B
SQL
24 lines
838 B
SQL
-- SQL Script: Index zur sick-Tabelle hinzufügen
|
|
-- Verbessert die Performance beim Abrufen von Krankheitseinträgen
|
|
-- Ausführen mit: mysql -u root -p timeclock < add-sick-index.sql
|
|
|
|
-- Index für user_id und first_day (für effiziente Abfragen nach User und Datum)
|
|
-- Prüfe zuerst ob der Index bereits existiert
|
|
SELECT COUNT(*) INTO @index_exists
|
|
FROM information_schema.statistics
|
|
WHERE table_schema = DATABASE()
|
|
AND table_name = 'sick'
|
|
AND index_name = 'idx_sick_user_first_day';
|
|
|
|
SET @sql = IF(@index_exists = 0,
|
|
'CREATE INDEX idx_sick_user_first_day ON sick (user_id, first_day DESC)',
|
|
'SELECT "Index idx_sick_user_first_day existiert bereits" AS Info'
|
|
);
|
|
|
|
PREPARE stmt FROM @sql;
|
|
EXECUTE stmt;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
SELECT 'Index idx_sick_user_first_day erfolgreich erstellt oder bereits vorhanden.' AS Status;
|
|
|