Why Insert statements perform slower on a indexed table?
相关问题
- NOT DISTINCT query in mySQL
- Can I skip certificate verification oracle utl_htt
- Flush single app django 1.9
- how to calculate sum time with data type char in o
- keeping one connection to DB or opening closing pe
相关文章
- node连接远程oracle报错
- oracle 11g expdp导出作业调用失败,提示丢包。
- 执行一复杂的SQL语句效率高,还是执行多少简单的语句效率高
- Use savefig in Python with string and iterative in
- Oracle equivalent of PostgreSQL INSERT…RETURNING *
- Accessing an array element when returning from a f
- Connection pooling vs persist connection mysqli
- Difference between FOR UPDATE OF and FOR UPDATE
An
INSERT
statement has to both add the data to the table data blocks and update any indexes that the table has defined.Clearly, if you have an index, the insert will need to do some more 'work' to update the index as well.
If you need to delete some data at a later stage from the table you inserted into would it not be a good idea to have an index on the table. The extra time taken to insert the data into the table can be compensated by the deletes running faster on an indexed table (if the indexed columns are used in the delete WHERE clause. ????
This is actually the same kind of question as:
This is because when storing your groceries, you want them on a nice, well known position so that it is easier to find them afterwards.
A database has to do the same.
This also means that adding more indexes will further slow down inserts.
It should be clear that you only want to create an index if you will also use it afterwards. If you only create an index and you are not using it afterwards to improve the performance of a query, there's no need to have the index as it will only slow down the inserts, and not improve any query.
Indexes allow you to store more information (in index blocks) about the data which helps retrieving the data easier. Obviously, you are doing additional work initially to benefit later (for selects).