Pergunta

I'm working in Sql Server 2005. I have an event log table that tracks user actions, and I want to make sure that inserts into the table are as fast as possible. Currently the table doesn't have any indexes. Does adding a single non-clustered index slow down inserts at all? Or is it only clustered indexes that slow down inserts? Or should I just add a clustered index and not worry about it?

Foi útil?

Solução

Indexes, clustered or non-clustered,will always slow down inserts as SQL has to maintain both the table and index. This slowdown is in an "absolute" sense and you may not notice it. I would add whatever indexes are necessary to retrieve your data.

Outras dicas

Yes, any index will take a little bit of time to keep up to date when doing INSERT, UPDATE, DELETE operations. The more indices you have, the more time we're talking about.

But ultimately it depends on what's more important to you - good query performance (then add indices as needed), or good insert performance (then have as few indices as possible).

Which operation do you perform more often??

This is because each secondary index in MySQL (and any other database engine) is a separate pool of storage, typically organised as some type of B-tree.

These pools of storage contain index records that have the indexed values and some type of pointer to the base table record. In MySQL’s case, this pointer is the PRIMARY KEY of the base table.

Every time you INSERT or DELETE a record, these index storage areas will have new records added or deleted. If you UPDATE a record - and the UPDATE involves an indexed column, the relevant index storage pool has to have its record updated as well.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top