How and when to update the MySQL index?

I use this SQL query to create an index:

$query = "CREATE INDEX id_index2 ON countries(geoname_id, name)"; 

How to update the index when adding new records?

Should I run a PHP script with an update request in CRON and run it every night?

Is this the best practice for automatically updating the index?

+4
source share
2 answers

Indexes are automatically updated by MySQL when inserting / updating rows. (This may be a performance hit for huge websites, but you probably aren't using huge :). You do not need to do anything after the initial creation.

+9
source

It will automatically update after adding rows. No need to run any update instructions.

+2
source

Source: https://habr.com/ru/post/1304681/


All Articles