Questions tagged [indexing]

Indexing data structures is a general technique to improve the speed of data lookups.

The purpose of storing an index is to optimize speed and performance in finding relevant documents for a search query. Without an index, the search process would scan every document in the corpus, which would require considerable time and computing power.

Indexes may benefit both read queries and updates. Many people wrongly believe indexes are only good for read queries. In general, there are three methods of indexing - non-clustered, clustered and cluster.

References:

Top Indexing Questions

By these questions, you will clear your concepts regarding indexing. And you can ask similar questions (not duplicate) with this tag.

33955 questions
237
votes
5 answers

How important is the order of columns in indexes?

I've heard that you should put columns that will be the most selective at the beginning of the index declaration. Example: CREATE NONCLUSTERED INDEX MyINDX on Table1 ( MostSelective, SecondMost, Least ) First off, is what I'm saying…
Abe Miessler
  • 82,532
  • 99
  • 305
  • 486
235
votes
8 answers

How to Remove Array Element and Then Re-Index Array?

I have some troubles with an array. I have one array that I want to modify like below. I want to remove element (elements) of it by index and then re-index array. Is it possible? $foo = array( 'whatever', // [0] 'foo', // [1] 'bar' //…
daGrevis
  • 21,014
  • 37
  • 100
  • 139
234
votes
3 answers

Creating an index on a table variable

Can you create an index on a table variable in SQL Server 2000? i.e. DECLARE @TEMPTABLE TABLE ( [ID] [int] NOT NULL PRIMARY KEY ,[Name] [nvarchar] (255) COLLATE DATABASE_DEFAULT NULL ) Can I create an index on Name?
GordyII
  • 7,067
  • 16
  • 51
  • 69
231
votes
4 answers

Why does PostgreSQL perform sequential scan on indexed column?

Very simple example - one table, one index, one query: CREATE TABLE book ( id bigserial NOT NULL, "year" integer, -- other columns... ); CREATE INDEX book_year_idx ON book (year) EXPLAIN SELECT * FROM book b WHERE b.year > 2009 gives…
Alex Vayda
  • 6,154
  • 5
  • 34
  • 50
229
votes
4 answers

SQL Server Index Naming Conventions

Is there some standard way to name indexes for SQL Server? It seems that the primary key index is named PK_ and non-clustered indexes typically start with IX_. Are there any naming conventions beyond that for unique indexes?
Eric Ness
  • 10,119
  • 15
  • 48
  • 51
228
votes
6 answers

pandas loc vs. iloc vs. at vs. iat?

Recently began branching out from my safe place (R) into Python and and am a bit confused by the cell localization/selection in Pandas. I've read the documentation but I'm struggling to understand the practical implications of the various…
scribbles
  • 4,089
  • 7
  • 22
  • 29
219
votes
3 answers

Can PostgreSQL index array columns?

I can't find a definite answer to this question in the documentation. If a column is an array type, will all the entered values be individually indexed? I created a simple table with one int[] column, and put a unique index on it. I noticed that I…
IamIC
  • 17,747
  • 20
  • 91
  • 154
219
votes
5 answers

How to list indexes created for table in postgres

Could you tell me how to check what indexes are created for some table in postgresql ?
user6023611
217
votes
18 answers

How to find all positions of the maximum value in a list?

I have a list: a = [32, 37, 28, 30, 37, 25, 27, 24, 35, 55, 23, 31, 55, 21, 40, 18, 50, 35, 41, 49, 37, 19, 40, 41, 31] max element is 55 (two elements on position 9 and 12) I need to find on which position(s) the maximum value is…
Bob
  • 10,427
  • 24
  • 63
  • 71
204
votes
8 answers

In Python, how do I index a list with another list?

I would like to index a list with another list like this L = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] Idx = [0, 3, 7] T = L[ Idx ] and T should end up being a list containing ['a', 'd', 'h']. Is there a better way than T = [] for i in Idx: …
Daniel Andrén
  • 2,143
  • 2
  • 14
  • 10
202
votes
9 answers

Get index of selected option with jQuery

I'm a little bit confused about how to get an index of a selected option from a HTML