/*** Something like this should have worked in MySQL 5.7 series: ALTER TABLE `workday` ADD `coal_gross` INT(16) UNSIGNED GENERATED ALWAYS AS (COALESCE(`out1`-`in1`, 0)+COALESCE(`out2`-`in2`,0)+COALESCE(`out3`-`in3`,0)+COALESCE(`out4`-`in4`,0)+COALESCE(`out5`-`in5`,0)+COALESCE(`out6`-`in6`,0)) STORED; But current Lightsail Server is installed with MySQL 5.6.39 Going to Implement as Trigger afterUpdates then, maybe not as performant which is the whole point although better than current JIT direct Query implementation ***/ /*** Optimization Strategies: 1. Hardware -- Upgrade Computing Credits tier 2. Software -- Cleanup code, let go unused but executed(?) Before-Redesign2018 helper methods 3. Database -- Optimize: 3.2 Created Generated Stored column for Coalesced Gross number which is used constantly and computed every-time. Use Trigger and Regular Column, see Note above for 5.6.39. 3.3 Create new Indexes for constantly checked FK through relationship queries: workweek_id for workdays and timesheet_id for workweeks. 3.3.1 WorkdayFormdata (currently 56k records.) always searching by FK timesheetFormdata_id 3.3.2 TimesheetFormdata always being searched by extrafield-owner field 3.3.2 Workday (currently 15k records.) always searched by FK workweek_id 3.3.3 Wrokweek (currently 3k records.) always searched by FK timesheet_id 3.3.4 Timesheet (currently 1.5 records.) frequently searched by extrafield, start_date and end_date Execution Log: Re 3.2: ALTER TABLE `workday` ADD `coal_gross` INT UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Updated by Automatic Trigger only' AFTER `task_id6`; RE 3.2: SET NEW.coal_gross = (COALESCE(NEW.out1-NEW.in1, 0)+COALESCE(NEW.out2-NEW.in2,0)+COALESCE(NEW.out3-NEW.in3,0)+COALESCE(NEW.out4-NEW.in4,0)+COALESCE(NEW.out5-NEW.in5,0)+COALESCE(NEW.out6-NEW.in6,0)); NOTE: Tested and Works as expected. NOTE: verify FOR EACH ROW BEGIN _ END notation is indeed not needed. 3.3.1 ALTER TABLE `intappmandb_dev`.`workday_formdata` ADD INDEX `bytfdid` (`id`); 3.3.2 ALTER TABLE `intappmandb_dev`.`timesheet_formdata` ADD INDEX `byextrastateid` (`extrafield`, `state_id`) USING BTREE; 3.3.3 ALTER TABLE `intappmandb_dev`.`workday` ADD INDEX `bydate` (`date`) USING BTREE; 3.3.4 ALTER TABLE `intappmandb_dev`.`workday` ADD INDEX `byworkweekid` (`workweek_id`) USING BTREE; 3.3.5 ALTER TABLE `intappmandb_dev`.`workweek` ADD INDEX `bytimesheetid` (`timesheet_id`) USING BTREE; 3.3.6 ALTER TABLE `intappmandb_dev`.`timesheet` ADD INDEX `byextrafieldstatus` (`extrafield`, `status_id`) USING BTREE; 3.3.7 ALTER TABLE `intappmandb_dev`.`timesheet` ADD INDEX `byownerstatus` (`owner_id`, `status_id`) USING BTREE; 3.3.8 ALTER TABLE `intappmandb_dev`.`timesheet` ADD INDEX `bystartendstatus` (`start_date`, `end_date`, `status_id`) USING BTREE; ***/