Adbms All
Adbms All
SAPID:-60004210126
BRANCH:-COMPUTER ENGINEERING
DIV:-C2 ; BATCH:-1
ADBMS
EXPERIMENT-02
AIM: STIMULATE QUERY OPTIMISATION BY APPLYING SQL QUERY ON YOUR SELECTED DATABASE.
THEORY:
QUERY:
1.234s
ORDER BY SELECT * FROM
SALARIES ORDER BY
SALARY ASC;
1.171 s
OPTIMIZE TABLE
COMMAND RUN
1.765 s
INDEXING:
3.219 s
ORDER BY SELECT * FROM
SALARIES ORDER BY
SALARY ASC;
1.687 s
NESTED QUERY SELECT emp_no,
first_name, last_name, 0.547s
hire_date,birth_date
FROM preksha
WHERE emp_no IN (
SELECT emp_no
FROM salaries
WHERE hire_date >
'1960-06-24'
AND salary > 35000
)
ORDER BY hire_date
DESC
1.953 s
BRANCH:-COMPUTER ENGINEERING
SAPID:-60004210126
DIV:-C2 ; BATCH:- 1
ADBMS
EXPERIMENT-3
AIM:- Perform Query Monitor.
THEORY :-
COMMAND:-
JOIN QUERY :-
SELECT preksha.first_name, preksha.last_name, dept_emp.dept_no
FROM preksha
JOIN dept_emp ON preksha.emp_no = dept_emp.emp_no;
RESULT GRID:
FORM EDITOR:
FIELD TYPES:
QUERY STATISTICS:
EXECUTION PLAN:
CONCLUSION:-
In conclusion,an experiment to perform a query Monitor provided valuable insight into how
we can keep a close watch on the performance of our database queries. By using this tool,
we know how to track,analyze and optimize our database interactions, ensuring our projects
to run smoothly and efficiently.
NAME:-PREKSHA ASHOK PATEL
BRANCH:-COMPUTER ENGINEERING
SAPID:-60004210126
DIV:-C2 ; BATCH:-1
ADBMS
Experiment 4
Aim: Optimize using B and B+ trees.
Theory:-
B-Tree:
A B-Tree (Balanced Tree) is a self-balancing tree data structure that maintains sorted data and
allows searches, insertions, and deletions in logarithmic time. It is designed to keep data
sorted and balanced, ensuring efficient operations even with large datasets. A B-Tree node
contains multiple keys and child pointers, and it is structured in a way that maintains balance
by redistributing keys among nodes during insertions and deletions. This balancing property
helps in optimizing search operations, making B-Trees suitable for use in databases and file
systems.
The main characteristics of a B-Tree include:
• Balanced Structure: All leaf nodes of the tree are at the same level, ensuring a
balanced structure that guarantees logarithmic height.
• Sorted Data: Within each node, keys are stored in sorted order, allowing for efficient
searching through a binary search-like mechanism.
• Node Capacity: Each node in a B-Tree has a maximum and minimum number of keys
it can hold. When a node becomes full, it is split, and the median key is pushed up to
the parent node.
• Child Pointers: Non-leaf nodes have child pointers corresponding to ranges of keys.
These pointers guide the search process.
B-Trees are commonly used in databases to store and manage indices, allowing for rapid
retrieval of records.
B+ Tree:
A B+ Tree is an extension of the B-Tree that optimizes certain aspects, especially for use in
databases and file systems. The key differences lie in the structure of the nodes and the way
keys are stored.
In a B+ Tree:
• Data Storage: Unlike B-Trees, B+ Trees store data only in the leaf nodes. Internal
nodes contain only keys and child pointers, leading to a more efficient use of memory.
• Sequential Access: Leaf nodes are linked in a sequential manner, facilitating range
queries and sequential access to the data.
• Search Operation: Search operations involve navigating down the tree through
internal nodes and finally reaching a leaf node where the desired data is stored.
• Balanced Structure: Similar to B-Trees, B+ Trees maintain a balanced structure,
ensuring logarithmic height and efficient operations.
• Key Range Queries: B+ Trees are particularly well-suited for range queries due to
their sequential leaf node arrangement.
B+ Trees are commonly used in database systems to implement indices, providing efficient
support for various query types, including equality searches and range queries.
Code:
B Tree
from BTrees import IIBTree
import time
t = IIBTree()
insertion_start_time= time.time()
for i in range(1000):
t.update({i: 2*i})
insertion_end_time=time.time()
"milliseconds")
search_start_time = time.time()
if t.has_key(key):
print(t[key])
search_end_time = time.time()
"milliseconds")
Output:
B+ Tree:
import time
tree = BPlusTree('D:/PY_PROJECTS/tmp/bplustree.db',order=50)
for i in range(1000):
data=(2*i).to_bytes(10,'big')
tree[i]=data
start_time=time.time()
for i in range(5):
byte_data=tree.get(data)
int_data=int.from_bytes(byte_data, 'big')
print("Value : ",int_data)
end_time=time.time()
tree.close()
Output
Observation:
Runtime for a single search in B Tree was 0.999 ms while that in B+ Tree was 0.195 ms which proves
that
The B-Tree and B+ Tree data structures are powerful tools for managing sorted data
efficiently. B-Trees excel in scenarios where a balanced structure and sorted data are crucial,
providing logarithmic time complexity for operations. On the other hand, B+ Trees optimize
memory usage and enhance support for range queries, making them particularly well-suited
for database applications. Both tree types play a significant role in improving the
performance of search, insertion, and deletion operations, with B+ Trees offering specific
advantages in certain database-related scenarios.
NAME:-PREKSHA ASHOK PATEL
SAPID:-60004210126
BRANCH:-COMPUTER ENGINEERING
DIV:-C2 ; BATCH:-1
ADBMS
EXPERIMENT-5
AIM:- Implement various types of fragmentation and partitioning
(list,keys,hash and range)
THEORY:
How can we partition the table in MySQL?
We can create a partition in MySQL using the CREATE TABLE or ALTER TABLE statement. Below
is the syntax of creating partition using CREATE TABLE command:
The below is the syntax of creating partition using ALTER TABLE command:
MySQL has mainly six types of partitioning, which are given below:
● RANGE Partitioning
● LIST Partitioning
● COLUMNS Partitioning
● HASH Partitioning
● KEY Partitioning
● Subpartitioning
This partitioning allows us to partition the rows of a table based on column values that fall within a
specified range. The given range is always in a contiguous form but should not overlap each other,
and also uses the VALUES LESS THAN operator to define the ranges.
CODE:
CREATE TABLE Sales ( cust_id INT NOT NULL, name VARCHAR(40),
store_id VARCHAR(20) NOT NULL, bill_no INT NOT NULL,
bill_date DATE PRIMARY KEY NOT NULL, amount DECIMAL(8,2) NOT
NULL)
PARTITION BY RANGE (year(bill_date))(
PARTITION p0 VALUES LESS THAN (2016),
PARTITION p1 VALUES LESS THAN (2017),
PARTITION p2 VALUES LESS THAN (2018),
PARTITION p3 VALUES LESS THAN (2020));
CODE:
OUTPUT:
MySQL HASH Partitioning
This partitioning is used to distribute data based on a predefined number of partitions. In other
words, it splits the table as of the value returned by the user-defined expression. It is mainly used to
distribute data evenly into the partition. It is performed with the PARTITION BY HASH(expr) clause.
Here, we can specify a column value based on the column_name to be hashed and the number of
partitions into which the table is divided.
CODE:
CREATE TABLE Stores2 ( cust_name VARCHAR(40), bill_no
VARCHAR(20) NOT NULL, store_id INT PRIMARY KEY NOT NULL,
bill_date DATE NOT NULL, amount DECIMAL(8,2) NOT NULL
)
PARTITION BY HASH(store_id)
PARTITIONS 4;
OUTPUT:
MySQL COLUMN Partitioning
This partitioning allows us to use the multiple columns in partitioning keys. The purpose of these
columns is to place the rows in partitions and determine which partition will be validated for
matching rows. It is mainly divided into two types:
All Integer Types: TINYINT, SMALLINT, MEDIUMINT, INT (INTEGER), and BIGINT.
String Types: CHAR, VARCHAR, BINARY, and VARBINARY.
DATE and DATETIME data types.
Range Column Partitioning: It is similar to the range partitioning with one difference. It defines
partitions using ranges based on various columns as partition keys. The defined ranges are of
column types other than an integer type.
CODE:
CREATE TABLE test_part (A INT, B CHAR(5), C INT, D INT)
PARTITION BY RANGE COLUMNS(A, B, C)
(PARTITION p0 VALUES LESS THAN (50, 'test1', 100),
PARTITION p1 VALUES LESS THAN (100, 'test2', 200),
PARTITION p2 VALUES LESS THAN (150, 'test3', 300), PARTITION p3
VALUES LESS THAN (MAXVALUE, MAXVALUE, MAXVALUE));
CODE:
CREATE TABLE AgentDetail (
agent_id VARCHAR(10),
agent_name VARCHAR(40),
city VARCHAR(10))
PARTITION BY LIST COLUMNS(agent_id) (
PARTITION pNewyork VALUES IN('A1', 'A2', 'A3'),
PARTITION pTexas VALUES IN('B1', 'B2', 'B3'),
PARTITION pCalifornia VALUES IN ('C1', 'C2', 'C3'));
If the table contains a PRIMARY KEY and we have not specified any column for partition, then
the primary key is used as partitioning key.
CODE:
CODE:
SAPID:-60004210126
BRANCH:-COMPUTER ENGINEERING
DIV:-C2 ; BATCH:-1
ADBMS EXPERIMENT-6
THEORY:-
IMPLEMENTATION:
COORDINATOR
import java.io.IOException;
import
java.net.ServerSocket;
import java.net.Socket;
public class Coordinator {
private static final int COORDINATOR_PORT = 9001;
while (true) {
Socket clientSocket = serverSocket.accept(); new
CoordinatorThread(clientSocket).start();
}
}
}
COORDINATOR.THREAD
import java.io.BufferedReader; import
java.io.IOException; import
java.io.InputStreamReader; import
java.io.PrintWriter;
import java.net.Socket;
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
socket.close();
}
}
OUTPUT:
CONCLUSION:-
NAME:-PREKSHA ASHOK PATEL
SAPID:-60004210126
BRANCH:COMPUTER ENGINEERING
DIV:-C2 ; BATCH:-1
ADBMS
EXPERIMENT NO.-07
THEORY:-
IMPLEMENTATION:
CONCLUSION:-
NAME:-PREKSHA ASHOK PATEL
SAPID:-60004210126
BRANCH:COMPUTER ENGINEERING
DIV:-C2 ; BATCH:-1
ADBMS
EXPERIMENT NO.-08
THEORY:-
IMPLEMENTATION:
CONCLUSION:-
NAME:-PREKSHA ASHOK PATEL
SAPID:-60004210126
BRANCH:-COMPUTER ENGINEERING
DIV:-C2 ; BATCH:-1
ADBMS
EXPERIMENT NO.09
AIM: Procesing spatial and temporal data
THEORY:-
IMPLEMENTATION:
CONCLUSION:-