Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How and when to update a MySQL index?

I'm using this SQL query to create an index:

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

How do I update the index when new entries are added?

Should I run a PHP script with the update query in CRON and run it every night?

Is this best practice for automated index updating?

like image 321
never_had_a_name Avatar asked Dec 23 '22 04:12

never_had_a_name


2 Answers

Indexes are updated by MySQL automatically as you insert/update rows. (This may be a performance hitter for huge websites, but you probably aren't running a huge one :).) You don't need to do anything after the initial creation.

like image 89
Amy B Avatar answered Jan 04 '23 08:01

Amy B


It will be automatically updated after adding rows, No need to run any update statements.

like image 26
Wael Dalloul Avatar answered Jan 04 '23 08:01

Wael Dalloul