Question :
We are having trouble with simple updates on a single table taking a long time. The table contains ~40 Million rows.
and the job runs every day that truncates the table and inserts new data from other sources in that table.
Here is the table:
CREATE TABLE temp (
NO int(4) NOT NULL AUTO_INCREMENT,
DATE1 date DEFAULT NULL,
CODE int(4) DEFAULT NULL,
TYPE varchar(20) DEFAULT NULL,
SCODE int(4) DEFAULT NULL,
Nature varchar(25) DEFAULT NULL,
UNITS decimal(19,4) DEFAULT NULL,
BNITS decimal(19,4) DEFAULT NULL,
DRECD double DEFAULT '0',
FNO varchar(50) DEFAULT NULL,
FLAG varchar(5) DEFAULT NULL,
MBAL double DEFAULT NULL,
PBAL double DEFAULT NULL,
MTotalBal double DEFAULT NULL,
PLNOT decimal(19,4) DEFAULT NULL,
PLBOOK decimal(19,4) DEFAULT NULL,
AGE int(4) DEFAULT NULL,
RETABS decimal(19,4) DEFAULT NULL,
RETAGR decimal(19,4) DEFAULT NULL,
INDEX1 decimal(19,4) DEFAULT NULL,
RETINDEXABS decimal(19,4) DEFAULT NULL,
RetIndexCAGR decimal(19,4) DEFAULT NULL,
CURRAMT decimal(19,4) DEFAULT NULL,
GLOSSLT decimal(19,4) DEFAULT NULL,
GLOSSST decimal(19,4) DEFAULT NULL,
UNITSFORDIVID decimal(19,4) DEFAULT NULL,
factor double DEFAULT NULL,
LNav double DEFAULT '10',
Date2 date DEFAULT NULL,
IType int(4) DEFAULT NULL,
Rate double DEFAULT NULL,
CurrAmt double DEFAULT NULL,
IndexVal double DEFAULT NULL,
LatestIndexVal double DEFAULT NULL,
Field int(4) DEFAULT NULL,
C_Code int(4) DEFAULT NULL,
B_Code int(4) DEFAULT NULL,
Rm_Code int(4) DEFAULT NULL,
Group_Name varchar(100) DEFAULT NULL,
Type1 varchar(20) DEFAULT NULL,
Type2 varchar(20) DEFAULT NULL,
IsOnline tinyint(3) unsigned DEFAULT NULL,
SFactor double DEFAULT NULL,
OS_Code int(4) DEFAULT NULL,
PRIMARY KEY (NO),
KEY SCODE (SCODE),
KEY C_Code (C_Code),
KEY TYPE (TYPE),
KEY OS_Code (OS_Code),
KEY LNav (LNav),
KEY IDX_1 (AGE,Type2),
KEY DATE1 (DATE1)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
note: the reason for having this many indexes is we have many selects coming ahead in SP that will decrease the table scans.
UPDATE Temp
INNER JOIN SchDate ON Temp.Sch_Code = SchDate.Sch_Code
SET LatestNav = NavRs, NavDate = LDate ;
-- SchDate table contain 41K record
UPDATE Temp
SET Age = DATEDIFF(NAVDATE, TR_DATE),
CurrAmt = (LatestNav * Units),
PL_Notional = (UNITS * (LatestNav - Rate)),
Divd_Recd = 0;
here is my.cnf for reference
[client]
port=3307
max_execution_time = 0
local_infile = 1
[mysql]
no-beep
[mysqld]
port=3307
#skip-locking
#skip-name-resolve
default_authentication_plugin=mysql_native_password
wait_timeout = 300
interactive_timeout = 300
default-storage-engine=INNODB
sql-mode="NO_ENGINE_SUBSTITUTION,ANSI_QUOTES"
max_execution_time = 0
innodb_autoinc_lock_mode = 0
group_concat_max_len=153600
skip-log-bin
log_bin_trust_function_creators = 1
#expire_logs_days = 3
local_infile = 1
skip-log-bin
### Cache/Buffer Related Parameters ###
table_open_cache=1024000
open_files_limit=2048000
key_buffer_size=2147483648
#myisam_max_sort_file_size=1G
#myisam_sort_buffer_size=512M
#myisam_repair_threads=1
# General and Slow logging.
log-output=FILE
#general-log=0
#general_log_file="E:MysqlMySQL Server 8.0Data2016SERVER.log"
#slow-query-log=1
#slow_query_log_file="E:MysqlMySQL Server 8.0Data2016SERVER-slow.log"
long_query_time=100
# Thread Specific Values
sort_buffer_size=2147483648
read_buffer_size=2147483648
read_rnd_buffer_size=1073741824
join_buffer_size=1073741824
thread_cache_size=600
bulk_insert_buffer_size=4294967296
### Mysql Directory & Tables ###
datadir="E:MysqlDataData"
Answer :