1. Data Structures & Database
Database Engine
Search Algorithms
Binary Trees
B-Trees
Indexes
2. Database Engine
Bike Engine (With Gears) Database Engine
Start your bike engine Start your database engine.
Create database objects and run
Change gears to 1st and drive the bike.
applications.
What happens to bike engine if we don’t What happens if we don’t changes gears
change gears? in database? Gears in database???
I need to go fast now. I need to get fast results.
You change gears the from 1st to 2nd and Change gears of a database engine.
3rd as you would like to go fast. ??? don’t have gears in database.
We
Dead Engine Very slow and dead applications.
Root cause: Bad bike rider - User Root cause: Poor database user.
3. Search Algorithms
Let’s go through 2 Algorithms
• Sequential Search
• Binary Search
Database Plans
• Scans
• Seeks
4. Sequential Search
Linear search or Sequential search is a method for finding a
particular value in a list, that consists of checking every one of
its elements, one at a time and in sequence, until the desired
one is found.
Set i to 1.
Repeat this loop:
If i > n, then exit the loop.
If A[i] = x, then exit the loop.
Set i to i + 1.
Return i.
5. Binary Search
• Binary Search or Half-interval search algorithm locates the position of an item in a
sortedarray.Binary search works by comparing an input value to the middle
element of the array. The comparison determines whether the element equals the
input, less than the input or greater. When the element being compared to equals
the input the search stops and typically returns the position of the element. If the
element is not equal to the input then a comparison is made to determine
whether the input is less than or greater than the element. Depending on which it
is the algorithm then starts over but only searching the top or bottom subset of
the array's elements. If the input is not located within the array the algorithm will
usually output a unique value indicating this.
6. Binary Trees
• A binary tree is a tree data structure in which each node has at most
two child nodes, usually distinguished as "left" and "right". Nodes with
children are parent nodes, and child nodes may contain references to their
parents. Outside the tree, there is often a reference to the "root" node
(the ancestor of all nodes), if it exists. Any node in the data structure can
be reached by starting at root node and repeatedly following references to
either the left or right child.
7. B-Trees
B-tree is a tree data structure that keeps data sorted and allows
searches, sequential access, insertions, and deletions. The B-tree is a
generalization of a binary search tree in that a node can have more than
two children. Unlike self-balancing binary search trees, the B-tree is
optimized for systems that read and write large blocks of data. It is
commonly used in databases and filesystems.
9. Index (Database)
A database index is a data structure that improves the speed of data
retrieval operations on a database table at the cost of slower writes and
increased storage space. Indexes can be created using one or
more columns of a database table, providing the basis for both rapid
random lookups and efficient access of ordered records. The disk space
required to store the index is typically less than that required by the table
(since indexes usually contain only the key-fields according to which the
table is to be arranged, and exclude all the other details in the
table), yielding the possibility to store indexes in memory for a table
whose data is too large to store in memory.