I have an sql table foo created like below
Create table
CREATE TABLE foo(id INTEGER, name TEXT) ;
Inserted some data
INSERT INTO foo VALUES(1, 'Alex');
Created INDEX
CREATE INDEX bar_idx ON foo(id) ;
Now Inserted some extra data
INSERT INTO foo VALUES(1, 'Bob');
Does it automatically updatae previously created index in the column ?
2
Answers
Yes, indexes are always kept up-to-date. In the event of bulk changes of a very large number of rows you may want to run REINDEX but that is not normally necessary.
yes if you simply enter data then it will be update but if you insert another row then
You need to explicitly rebuild or reorganise the index to ensure that it reflects the current state of the data.(for better practise)
In your example as you created an index on ‘id’ attribute and later when you inserted another row the index will now be updated
you have to use REINDEX bar_idx;
while it is not necessary to run this