Questions tagged [index]

A database structure that can improve the speed of queries at the cost of disk space and slower inserts/updates. It stores a copy of one or more columns sorted but structures the data differently to allow faster access.

An index can be added to a table to facilitate efficient lookups. If a query predicate is not supported by an index then it will be necessary to scan the entire table to identify rows matching the predicate.

Various data structures can be used for indexing, with particular characteristics. Some commonly used on-disk index structures are:

B-Trees and their variants allow O(log n) lookup times and efficient ordinal, sequential access to records (i.e. the tree can be traversed in order). BTrees are tree structures that hold multiple keys in their nodes, which is efficient for disk access. B-Tree type indexes (the actual structures tend to be variations on the BTree) are supported by most DBMS platforms.

Linear Hash Tables is a method of constructing a hash table that can grow incrementally without requiring the table to be rebuilt as it expands. This feature makes the structure useful for disk indexing. Linear Hash Tables cannot traverse data ordinally, but have O(1) lookup times for a single record.

R-Trees are used for indexing spatial data. Commonly used in purpose built spatial database systems, modern RDBMS platforms often feature spatial indexing capabilities as well.

Bitmap Indexes: Are used for applications such as reporting systems where queries combine searches on a number of low cardinality columns where any column has a small number of distinct values and thus low selectivity. The data structure used in bitmap indexes is very sparse, so it compresses very well with run-length encoding schemes. Index intersection computations can be resolved very quickly with bitmap indexes, so they are very efficient for certain types of quereies. However they cannot be updated incrementally, so they are mainly useful for applications such as data warehouse systems where the data is loaded in batch operations for a subsequent read-only workload.

Related: What does "index" means on RDBMS?

3312 questions
22
votes
7 answers

Where can I find some guidance on index strategies?

Most of us will probably agree that using database indexes is good. Too many indexes and performance can actually be degraded. As a general rule, which fields should be indexed? Which fields should not be indexed? What are the rules for using…
SpecialAgent_W436
  • 385
  • 1
  • 3
  • 9
19
votes
2 answers

SQL INDEX - how it works?

My knowledge of databases and SQL is based in most on university classes. Anyhow, I spent few monts (almost a year) in a company, where I was working with databases. I have read few books and I have taken part in few trainings about databases such…
ruhungry
  • 203
  • 2
  • 9
5
votes
1 answer

Why don't relational databases have read-only indexes on columns?

In many programming language implementations, the compiler will turn on certain optimizations if it knows that a variable will not change after its initial assignment. Wouldn't this stretch to persistent data too? If the database knows that a…
Michael Hewson
  • 213
  • 2
  • 5
4
votes
1 answer

how does multiple column index work in details

if we have a table T1 with columns A,B,C,D,E and an index ( A,B,C) built for it if we a SQL query joining on columns A,B or A,B,C or A, this index can still be used, but if the query is joining on B or C or B,C the index is totally useless I know…
zinking
  • 410
  • 1
  • 5
  • 16
4
votes
5 answers

How much does an index need to narrow the results of a search in order to be useful?

How much does an index need to narrow the results of a search in order to be useful in speeding up queries? Some examples all across the spectrum: A column for storing true/false values obviously has only two unique values. A 'last name' column…
Nathan Long
  • 885
  • 2
  • 9
  • 20
3
votes
1 answer

Query column A, order by B - is index needed if A and B together are the PK?

I have a table (in Postgresql) which has a primary key on columns a and b. I want to do a query: select * from table where a='XXX' order by b; Does the existing primary key serve to help with the performance of that query? Can I improve…
mcarans
  • 133
  • 2
2
votes
0 answers

Do we need index on "order by" if the "where" clause alreday have index ( small data set )

Assume I have a very large table X and I want to run below SQL. select * from table X where type='X1234' order by time; type is not unique and indexed ( with high cardinality), and there are very few rows in one type ( assume 1 - 5 ). Data size of…
user8100646
  • 81
  • 1
  • 4
2
votes
0 answers

Can I read data from a 'hash field' in a legacy Ingres database?

I have been asked to read and present data from the 'hash fields' of an Ingres 2.0 database, which are apparently multiple pieces of data stored together in a single field in various combinations. I know nothing about Ingres 2 and there is no…
1
vote
1 answer

SQL INDEX - how it works?

See this question here: Database Administrators meta My knowledge of databases and SQL is based in most on university classes. Anyhow, I spent few monts (almost a year) in a company, where I was working with databases. I have read few books and I…
ruhungry
  • 203
  • 2
  • 9
1
vote
1 answer

why would rebuild index reduce btree leaf numbers

Rebuilding an index might reduce the number of leaf nodes by about 20% - 30%. The most you can possibly expect from this reduction is 20%-30% for very expensive operations like a FULL INDEX SCAN. The typical INDEX UNIQUE SCAN gain of an index…
zinking
  • 410
  • 1
  • 5
  • 16
1
vote
1 answer

How to index according to a property that is a set/collection using a relational database

I would like to query in O(log N) time against a property that is a collection. How do I set up the indexes for this in a relational database such as MySQL or PostgreSQL? Example: book: { title: "Hitchhiker's Guide to the Galaxy", genre:…
Chris Dutrow
  • 265
  • 3
  • 7
1
vote
0 answers

Database for dictionary storage and querying

I'm looking for a database for the following data storage and query pattern: Data consists of dictionaries - mappings string to string. Queries are also dictionaries. The result of the query is a list of all matching dictionaries, where matching is…
psarka
  • 111
  • 4
0
votes
0 answers

primary index on column having duplicates

must primary index be done over the primary key column? can the primary index be done on a column having duplicates? I searched the textbook but I found it not that clear?
0
votes
1 answer

Best practice on index usage with timestamp

I have a query to find period tasks, it runs calculation and scans the whole table. UPDATE task SET status = ? WHERE cron_hour != 0 AND (status = ? OR status = ?) AND UNIX_TIMESTAMP(NOW()) - end_time > cron_hour * 3600 I think the last condition…
daisy
  • 1,328
  • 3
  • 11
  • 14
0
votes
1 answer

How should i index this?

i always had this question and i hope you can help me with this, how should i index created_at if i need to order results based on date. Example: COMMENTS TABLE: ID (UUID) ENTRY_ID (UUID) USER_ID (UUID) CONTENT FEATURED STATUS CREATED_AT I have…
Angel Vega
  • 11
  • 2
1
2