Indexes Flashcards

1
Q

What does B-tree index mean? How does it work?

A

Balanced search tree. These tree contains of root node branch node and leaf node. Branch node contains the biggest number (id) from each leaf node. The B-tree enables the database to find a leaf node quickly. ( because tree deep is equal and quite low (3-4)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Where do we store db data on the system level?

A

In mysql we store data in the files with special extention.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Where do we store indexes on the system level?

A

In index leaf nodes which are stored in a database block or page; that is, the database’s smallest storage unit.

Each leaf nodes connect with each other using a double-linked list ( this list are sorted).
Each leaf node contains several rows with (id and link to the main object ( its physical place) ).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is db index? Why do we need it?

A

Data structure that DB use to find row fast.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does index connect with indexed data?

A

-

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a clustered index?

A

Contains the index and row itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does db index work inside? Why do we think that it can help us improve performance?

A

Searching in a database index is like searching in a printed telephone directory. The key concept is that all entries are arranged in a well-defined order. Finding data in an ordered data set is fast and easy because the sort
order determines each entries position.

We can think about indexes as 2 Excel file ( one to store the whole data, the second to store only all sorted ID inside 2 columns -> id, and link to the cell of the main file (A1,B10,GH123) )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is index leaf node?

A

It’s the smallest block where we store index.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a balanced tree?

A

The structure is a balanced search tree because the tree depth is equal at every position; the distance between root node and leaf nodes is the same everywhere. A balanced tree is a tree where every leaf is on the same distance away from the root than any other leaf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When index doesn’t improve performance?

A

1) When we have too many not unique records
2) The fewer indexes a table has, the better the insert, delete and update performance.
3) When amount of records are small
4) Concatenated index if we searching not but the left column

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How balanced tree works if data is equal?

A

As all leaves are sorted we need to check if we don’t have the same item near.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What steps need to be done to finish the index search?

A

An index lookup requires three steps:

1) the tree traversal;
(2) following the leaf node chain; ( if equal items for example
(3) fetching the table data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is concatenated/composite index?

A

Index which is created on several fields. (also known as multi-column, composite or combined index).

Note that the column order of a concatenated index has great impact on its usability so it must be chosen carefully.The database considers each column according
to its position in the index definition to sort the index entries. The first column is the primary sort criterion and the second column determines the order only if two entries have the same value in the first column and so on.

If we are searching by only the second of the concatenated indexes columns the result will be as we don’t have an index at all.( but for the first one is works)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is function-based index (FBI)?

A

An index whose definition contains functions or expressions is a so-called function-based index (FBI). Instead of copying the column data directly into
the index, a function-based index applies the function first and puts the result into the index.

( For example CREATE INDEX emp_up_name
ON employees (UPPER(last_name)); )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is deterministic function?

A

A deterministic function always returns the same result for the same input parameters whereas a non-deterministic function returns different results for the same input parameters. ( something like clear function)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How would be better to start search by equality? or by range ?

A

index for equality first—then for ranges.

17
Q

What is full-text index?

A

This is an index for full-text search ( for example using LIKE operation for filtering).
Very simplified: They split the text into words and make an index over the words and not the whole text. This works a lot faster for text searches when looking for specific words. ( This kind of index work as search engine and tries to find keyword)
To realize it we use 2 steps b-tree ( first step by keyword, the second by the string itself)

  • We select keywords
  • We remove stopwords
  • We remove words that we use more than (50 % cases)
18
Q

Is it better to create one index for each column or a single index for all columns?

A

The answer is very simple in most cases: one index with multiple columns is better.

19
Q

What is filter predicates?

A

-

20
Q

What is bitmap index?

A

The bitmap structures are not stored persistently but

discarded after statement execution, thus bypassing the problem of the poor write scalability.

21
Q

What is partial indexes?

A

The index only contains the rows that satisfy the where clause. ( for example only for the row which includes specific type )

22
Q

What is a covering index?

A

A covering index is an index that “covers” a query. That is it supplies all information for the query so that SQL Server does not have to touch the base tables. ( Index already contains all information that you need )

When you create an index on T (col1, col2), you have a composite index because the index consists of 2 columns.

Suppose now you have a query like:

SELECT col1, col2
FROM T
WHERE col1 = something AND col2 = something else

For such a query the newly created index could act as covering index, because SQL Server can satisfy the query by just touching the index.

23
Q

What will be work better: index on column that allows NULL or NOT NULL columns?

A
  • NOT NULL columns, try to set not_not if you’re going to add an index on this field.
24
Q

What is hash index?

A

Hash indexes use a form of the hash table data structure. We convert column data with hash function and store value by uniq key.

25
Q

What is a prefixed index?

A

This index allows to index only part of the column value ( For example one first 10 characters)

26
Q

How to select what field should be first for concatenated indexes?

A

For example we have stuff_id and company_id. We need to find how many uniq records we have for each row with these values and select as the first one most uniq.

27
Q

What is SSTable?

A

Sorter string table ( everything is sorten by key )

28
Q

What is LSM tree?

A

A log-structured merge-tree (LSM tree)

  • Writes are stored in an in-memory tree (also known as a memtable).
  • When this tree becomes too large it is flushed to disk (segments ) with the keys in sorted order.
  • When we read we check memory then disk
29
Q

What is Spatial Index?

A

(пространственные индекс) You can use a spatial index for indexing geo-objects - shapes. The spatial index makes it possible to efficiently search for objects that overlap in space. Uses R-tree indexes for realizations.

30
Q

What is R-tree index?

A

The R-tree enables you to index multidimensional objects.

31
Q

What Does Fuzzy Search Mean?

A

A fuzzy search searches for text that matches a term closely instead of exactly. Fuzzy searches help you find relevant results even when the search terms are misspelled.