Importance of Indexes
By not having an index your update statement will have to scan through the whole table. It's the where
condition that is causing the delay.
In general, you should consider adding an index under the following conditions:
Indexes are best used on columns that are frequently used in where
clauses, and in any kind of sorting, such as "order by".
You should also pay attention to whether or not this information will
change frequently, because it will slow down your updates and inserts.
In your specific case, order_number
does not seem like a field that will change.
Reference: https://www.howtoforge.com/when-to-use-indexes-in-mysql-databases
How to create an index
You can create an index in mysql with the create index command.
There are various types of indexes so you may have to decide on which type to use.
Syntax:
CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name
[index_type]
ON tbl_name (key_part,...)
[index_option]
[algorithm_option | lock_option] ...
key_part: {col_name [(length)] | (expr)} [ASC | DESC]
index_option:
KEY_BLOCK_SIZE [=] value
| index_type
| WITH PARSER parser_name
| COMMENT 'string'
| {VISIBLE | INVISIBLE}
index_type:
USING {BTREE | HASH}
algorithm_option:
ALGORITHM [=] {DEFAULT | INPLACE | COPY}
lock_option:
LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE}
Example - Adding a Simple Index:
ALTER TABLE `your_table_name` ADD INDEX order_number_index(`order_number`)
Example - Adding an Index and specifying type:
create index order_number_indexon your_table_name(order_number) using HASH;
or
create index order_number_indexon your_table_name(order_number) using BTREE;
Note: Supported index types change depending on the storage engine.
See Table 13.1 Index Types Per Storage Engine
in create-index documentation.
References: