Indexes Flashcards
What does B-tree index mean? How does it work?
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)
Where do we store db data on the system level?
In mysql we store data in the files with special extention.
Where do we store indexes on the system level?
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) ).
What is db index? Why do we need it?
Data structure that DB use to find row fast.
How does index connect with indexed data?
-
What is a clustered index?
Contains the index and row itself.
How does db index work inside? Why do we think that it can help us improve performance?
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) )
What is index leaf node?
It’s the smallest block where we store index.
What is a balanced tree?
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
When index doesn’t improve performance?
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 balanced tree works if data is equal?
As all leaves are sorted we need to check if we don’t have the same item near.
What steps need to be done to finish the index search?
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.
What is concatenated/composite index?
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)
What is function-based index (FBI)?
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)); )
What is deterministic function?
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)