Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Covered Index?

I've just heard the term covered index in some database discussion - what does it mean?

like image 804
Martynnw Avatar asked Sep 15 '08 10:09

Martynnw


People also ask

What is a Covered index SQL Server?

When an index contains all the columns needed to satisfy a query, it is called a covering index. Including strategic columns in a nonclustered index can ensure that the most frequent queries can be satisfied entirely from the index without the need for key lookups into the clustered index.

What is the difference between composite index and covering index?

when we create index then we can mention multiple column name and that is called composite index but when we create cover index then we create index on one column and for cover index we mention other column in include function.

What is made faster by a covering index?

A covering index is a non-clustered index which includes all columns referenced in the query and therefore, the optimizer does not have to perform an additional lookup to the table in order to retrieve the data requested. As the data requested is all indexed by the covering index, it is a faster operation.

What is covering index in Postgres?

A covering index is a fantastic query performance optimization. An index covers a query when the index has all the data needed to execute the query, so the server can retrieve the query's data without reading any rows or documents.


2 Answers

A covering index is an index that contains all of, and possibly more, the columns you need for your query.

For instance, this:

SELECT * FROM tablename WHERE criteria 

will typically use indexes to speed up the resolution of which rows to retrieve using criteria, but then it will go to the full table to retrieve the rows.

However, if the index contained the columns column1, column2 and column3, then this sql:

SELECT column1, column2 FROM tablename WHERE criteria 

and, provided that particular index could be used to speed up the resolution of which rows to retrieve, the index already contains the values of the columns you're interested in, so it won't have to go to the table to retrieve the rows, but can produce the results directly from the index.

This can also be used if you see that a typical query uses 1-2 columns to resolve which rows, and then typically adds another 1-2 columns, it could be beneficial to append those extra columns (if they're the same all over) to the index, so that the query processor can get everything from the index itself.

Here's an article: Index Covering Boosts SQL Server Query Performance on the subject.

like image 60
Lasse V. Karlsen Avatar answered Oct 04 '22 01:10

Lasse V. Karlsen


Covering index is just an ordinary index. It's called "covering" if it can satisfy query without necessity to analyze data.

example:

CREATE TABLE MyTable (   ID INT IDENTITY PRIMARY KEY,    Foo INT )   CREATE NONCLUSTERED INDEX index1 ON MyTable(ID, Foo)  SELECT ID, Foo FROM MyTable -- All requested data are covered by index 

This is one of the fastest methods to retrieve data from SQL server.

like image 36
aku Avatar answered Oct 04 '22 01:10

aku