DA Assigment 1
DA Assigment 1
1. Define NoSQL databases. What are the primary reasons for the emergence of NoSQL
databases, and in what scenarios are they more suitable than tradi onal rela onal
databases?
Ans. NoSQL databases, or "Not Only SQL" databases, are a class of database management
systems that provide a mechanism for the storage and retrieval of data that uses
unstructured data. These databases are designed to handle large volumes of unstructured,
semi-structured, or structured data, and they provide a flexible, scalable, and high-
performance alterna ve to tradi onal rela onal databases.
1. Schema flexibility: NoSQL databases allow for flexible and dynamic schema design. Unlike
rela onal databases, which enforce a rigid structure, NoSQL databases can handle diverse
data types and structures. This flexibility is par cularly useful in scenarios where the data
model is evolving or uncertain.
2. Scalability: NoSQL databases are o en designed to scale horizontally, meaning they can
handle a growing amount of data by adding more nodes to a distributed system. This makes
them well-suited for applica ons with rapidly increasing data volumes or unpredictable
workloads.
3. Performance: Many NoSQL databases are op mized for specific use cases, providing be er
performance for certain types of queries or data access pa erns compared to tradi onal
rela onal databases. This is especially beneficial in scenarios where low-latency and high-
throughput are cri cal.
4. Big Data and Real- me processing: NoSQL databases are o en used in big data and real-
me processing applica ons where the ability to quickly ingest, process, and analyse large
amounts of data is essen al. They can efficiently handle unstructured and semi-structured
data, which is common in these scenarios.
5. Cost-effec veness: NoSQL databases are o en open-source and can run on commodity
hardware, making them more cost-effec ve than some tradi onal rela onal databases for
certain use cases.
In scenarios where NoSQL databases are more suitable than tradi onal rela onal databases
include:
1. Web and Mobile Applica ons: NoSQL databases are well-suited for web and mobile
applica ons that require flexible and scalable data storage to accommodate varying data
structures and high traffic.
2. Big Data and Analy cs: NoSQL databases are commonly used in big data and analy cs
environments where the ability to store and process large volumes of data quickly is crucial.
3. Content Management Systems (CMS): CMS o en deal with diverse and unstructured data,
making NoSQL databases a good fit for efficiently storing and retrieving content.
4. IoT (Internet of Things) Applica ons: NoSQL databases can handle the large amounts of
data generated by IoT devices, which may have variable data structures and require scalable
and high-performance storage solu ons.
5. Real- me Applica ons: Applica ons that require real- me processing and low-latency
access to data, such as gaming and financial applica ons, can benefit from the performance
characteris cs of NoSQL databases.
It's important to note that the choice between NoSQL and tradi onal rela onal databases
depends on the specific requirements of the applica on. In some cases, a hybrid approach or
a combina on of different database types may be the most suitable solu on.
2. Compare and contrast NoSQL databases with tradi onal rela onal databases. Discuss the
key differences in terms of data models, scalability, and use cases.
- Structured Data Model: Rela onal databases organize data into tables with predefined
schemas, where each row represents a record and each column represents an a ribute.
- ACID Proper es: Transac ons in rela onal databases adhere to ACID proper es (Atomicity,
Consistency, Isola on, Durability), ensuring data integrity and consistency.
NoSQL Databases:
- Flexible Data Model: NoSQL databases support a variety of data models, including
document-oriented, key-value pairs, column-family, and graph formats. This flexibility allows
for dynamic and evolving data structures.
- Eventual Consistency: NoSQL databases may priori ze performance and scalability over
strict consistency, leading to eventual consistency models rather than immediate
consistency.
Scalability:
- Ver cal Scaling: Tradi onal rela onal databases o en scale ver cally by adding more
resources (CPU, RAM) to a single server.
- Complex Scaling: Scaling can be complex, especially for large datasets, and may require
significant planning and down me.
NoSQL Databases:
- Horizontal Scaling: NoSQL databases are designed for horizontal scaling, achieved by adding
more servers to a distributed database cluster.
- Easier Scalability: NoSQL databases are generally more adaptable to dynamic and rapidly
growing datasets, making them well-suited for applica ons with varying workloads.
Use Cases:
- Structured Data: Ideal for applica ons with well-defined and stable data structures.
- Transac ons: Best suited for applica ons where ACID transac ons are cri cal, such as
banking systems.
- Complex Queries: Suitable for scenarios requiring complex queries and joins between
tables.
NoSQL Databases:
- Dynamic Data: Well-suited for applica ons dealing with evolving, dynamic, or semi-
structured data.
- Scalable Web Applica ons: NoSQL databases are commonly used in web and mobile
applica ons that require horizontal scalability and flexibility.
- Big Data and Real- me Analy cs: Suitable for handling large volumes of data and providing
quick access for analy cs.
Examples:
NoSQL Databases:
When to Choose:
- When data is highly structured and rela onships between en es are well-defined.
NoSQL Databases:
3. Explain the four main categories of NoSQL databases: column-oriented stores, key-value
stores, document databases, and graph databases. Provide examples of popular databases
within each category.
Ans. 1. Column-Oriented Stores:
Characteris cs:
Examples:
- Apache Cassandra: A distributed and highly scalable NoSQL database. It provides high
availability and fault tolerance and is commonly used for me-series data and large-scale
distributed applica ons.
- HBase: Built on top of Hadoop, HBase is a distributed, scalable, and consistent key-value
store. It is o en used for sparse data sets, such as those found in big data and analy cs
applica ons.
2. Key-Value Stores:
Characteris cs:
- Fast and efficient for basic read and write opera ons.
Examples:
- Redis: An in-memory data store that supports various data structures (strings, hashes, lists,
sets, etc.). It is known for its speed and is o en used for caching and real- me analy cs.
- Amazon DynamoDB: A fully managed, serverless key-value and document database service
offered by Amazon Web Services (AWS). It is designed for high-performance and scalable
applica ons.
3. Document Databases:
Characteris cs:
- Well-suited for content management systems, e-commerce, and applica ons with evolving
data structures.
Examples:
- MongoDB: A widely used NoSQL database that stores data in JSON-like BSON documents. It
is known for its flexibility, scalability, and ease of development.
Characteris cs:
- Well-suited for scenarios where the rela onships between en es are as important as the
en es themselves.
Examples:
- Neo4j: A highly popular graph database that uses the Cypher query language. It is
commonly used for applica ons involving social networks, fraud detec on, and
recommenda on engines.
- Amazon Neptune: A fully managed graph database service provided by AWS. It supports
both property graph and RDF graph models and is suitable for a variety of graph database
use cases.
1. What is MongoDB, and how does it fit into the NoSQL landscape? Describe its primary
features and advantages.
Ans. MongoDB is a widely used NoSQL database that falls into the category of document-oriented
databases. It is designed to handle large volumes of unstructured or semi-structured data,
providing flexibility, scalability, and ease of development. MongoDB is an open-source, cross-
pla orm database that uses a document-oriented data model, where data is stored in
flexible, JSON-like BSON documents.
- MongoDB stores data in flexible, schema-less documents, typically in BSON (Binary JSON)
format.
- Each document can have a different structure, allowing for dynamic and evolving data
models.
- MongoDB supports a powerful and expressive query language that is similar to JSON. This
makes it easy to query and manipulate data.
3. Dynamic Schema:
- Unlike tradi onal rela onal databases with a fixed schema, MongoDB has a dynamic
schema, which means that fields can be added to documents on the fly.
- MongoDB supports indexes on fields, enabling efficient querying and sor ng of data. This
is crucial for op mizing query performance, especially in large datasets.
5. Scalability:
6. Aggrega on Framework:
- MongoDB supports replica sets, which are copies of the data distributed across mul ple
servers. This ensures data redundancy, fault tolerance, and high availability.
8. Sharding:
- MongoDB can shard data across mul ple servers to distribute the load and improve
scalability. Sharding allows for horizontal scaling of data storage.
9. Geospa al Indexing:
- MongoDB supports geospa al indexing and queries, making it suitable for loca on-based
applica ons.
Advantages of MongoDB:
- MongoDB's dynamic schema allows developers to work with evolving data models
without the constraints of a predefined schema.
2. Scalability:
- MongoDB can scale horizontally to handle large amounts of data and high traffic, making
it suitable for applica ons with growing needs.
- MongoDB can store complex nested structures, arrays, and documents within documents,
providing a rich data representa on.
5. Performance:
2. Define the following MongoDB terms: database, collec on, and document. How does the
structure of MongoDB collec ons differ from tables in a tradi onal rela onal database?
Ans. In MongoDB, the terms "database," "collec on," and "document" represent fundamental
concepts in its data model. Let's define each term and discuss how the structure of
MongoDB collec ons differs from tables in tradi onal rela onal databases:
1. Database:
- Comparison with Rela onal Databases: In the context of MongoDB, a database is similar to
a database in a tradi onal rela onal database management system (RDBMS). It provides a
way to organize and isolate sets of related data.
2. Collec on:
- Comparison with Rela onal Databases (Tables): While collec ons in MongoDB are similar to
tables in rela onal databases in terms of being a container for data, they differ significantly
in terms of schema. In a rela onal database, tables have a fixed schema, meaning that each
row (record) must conform to the defined structure, and the schema is typically enforced
strictly. In MongoDB collec ons, documents can have varying structures within the same
collec on, allowing for a more flexible and dynamic data model.
3. Document:
- Comparison with Rela onal Databases (Rows): While documents are conceptually similar to
rows in rela onal databases, they are more flexible. In MongoDB, documents within a
collec on can have different fields, and fields can be added or removed dynamically. This
flexibility contrasts with the fixed structure of rows in a rela onal table.
Differences in Structure:
1. Schema Flexibility:
- MongoDB collec ons allow for a dynamic and flexible schema where documents within a
collec on can have different structures. This flexibility contrasts with the fixed and rigid
schema enforced by tables in tradi onal rela onal databases.
- In MongoDB, different documents within the same collec on can have different fields.
This allows for more adaptability to changing data requirements compared to the uniform
fields enforced in rela onal database tables.
3. Data Model:
3. Discuss the concept of data types in MongoDB. Provide examples of common data types
used in MongoDB documents.
Ans. In MongoDB, data types refer to the different types of values that can be stored in
documents. MongoDB uses a flexible and rich data model, allowing for the storage of various
data types within its BSON (Binary JSON) documents. Here are some common data types
used in MongoDB documents, along with examples:
1. String:
2. Integer:
- Example: `42`
3. Double:
- Example: `3.14`
4. Boolean:
- Example: `true`
5. Arrays:
- Example: `{ "name": "John", "age": 30, "address": { "city": "New York", "zip": "10001" } }`
7. Null:
- Example: `null`
8. ObjectId:
- Example: `ObjectId("5f63a7f62b844d1a5c4a7f3a")`
9. Date:
- Example: `ISODate("2023-11-25T12:00:00Z")`
- Example: `/^OpenAI/`
12. Timestamp:
1. Explain the importance of configura on in MongoDB. What are some key configura on
op ons that can be customized to op mize a MongoDB deployment?
Ans. Configura on in MongoDB is crucial for op mizing the performance, reliability, and security
of a MongoDB deployment. MongoDB provides a variety of configura on op ons that allow
administrators to fine-tune the behavior of the database to meet the specific requirements
of their applica on and environment. Proper configura on can enhance performance,
ensure data integrity, and provide a secure and efficient deployment. Here are some key
configura on op ons that can be customized to op mize a MongoDB deployment:
1. Storage Engine:
- MongoDB supports mul ple storage engines (e.g., WiredTiger, MMAPv1). The choice of a
storage engine can impact performance, storage efficiency, and concurrency. WiredTiger is
the default storage engine and is o en preferred for most use cases.
2. Caching:
- Configura on of caching se ngs, such as the size of the WiredTiger cache, can
significantly impact query performance. Properly sizing the cache helps MongoDB keep
frequently accessed data in memory, reducing disk I/O.
3. Indexes:
- Proper indexing is crucial for query performance. MongoDB allows the crea on of various
types of indexes (e.g., single-field, compound, text, geo-spa al), and administrators should
strategically choose and create indexes based on the applica on's query pa erns.
4. Journaling:
- MongoDB uses write-ahead logging for durability. The journaling feature ensures that
write opera ons are recorded to a journal before being wri en to the data files. Configuring
the size and write concern for journaling impacts data durability and recovery me.
- For replica sets, configura on op ons include se ng the number of replicas, priority of
nodes, and read preferences. These se ngs affect fault tolerance, read scaling, and the
behaviour of the replica set.
- Sharding distributes data across mul ple servers. Configura on op ons include the
number of shards, shard key selec on, and balancing se ngs. Proper sharding configura on
is cri cal for horizontal scalability.
- MongoDB provides op ons for user authen ca on and authoriza on. Configuring users,
roles, and authen ca on mechanisms (e.g., SCRAM-SHA-256) ensures secure access to the
database.
- Se ngs related to network interfaces, port numbers, and hostname resolu on can be
configured to control network accessibility and communica on between MongoDB
instances.
9. Profiling:
- Profiling se ngs determine the level of detail captured in the database profiler, aiding in
performance analysis and op miza on. Configuring profiling op ons can help iden fy slow
queries and bo lenecks.
10. Log Configura on:
- MongoDB logs provide valuable informa on for monitoring and troubleshoo ng.
Configuring log verbosity, rota on, and des na on (e.g., console, file) helps manage log data
efficiently.
- Configuring resource limits, such as the maximum number of concurrent connec ons,
helps prevent resource exhaus on and ensures the stability of the MongoDB deployment.
- Enabling and configuring monitoring and metrics op ons (e.g., MMS, Ops Manager)
provides insights into the performance and health of the MongoDB deployment.
- Configuring op ons for backup and restore opera ons, such as snapshot intervals and
storage op ons, ensures data resilience and facilitates disaster recovery.
2. Describe the MongoDB shell and its role in interac ng with the MongoDB database.
How can you connect to a MongoDB server using the shell, and what are some common
shell commands?
Ans. The MongoDB shell is a command-line interface that allows users to interact with a
MongoDB database. It provides a JavaScript-based environment where users can execute
commands and queries to perform various opera ons on the database. The MongoDB shell
is a powerful tool for managing databases, collec ons, documents, and running
administra ve tasks.
```bash
mongo
```
- Once in the shell, you can connect to a specific database using the `use` command:
```bash
use your_database_name
```
1. Show Databases:
```javascript
show dbs
```
```javascript
```
3. Insert Document:
```javascript
```
4. Find Documents:
```javascript
```
5. Update Document:
```javascript
```
6. Remove Document:
```javascript
```
7. Aggrega on:
```javascript
```
8. Create Index:
```javascript
```
9. Show Help:
```javascript
help
```
```javascript
exit
```
Ans. Certainly! In MongoDB, you can add documents to a collec on using the `insertOne()`
and `insertMany()` methods. Here's a step-by-step walkthrough for each method with code
examples:
Using `insertOne()`:
1. Connect to MongoDB:
- Ensure that you have a MongoDB server running, and you are connected to it using the
MongoDB shell or a MongoDB driver in your programming language.
2. Select a Database:
- Choose the database where you want to add a document using the `use` command.
```javascript
use your_database_name
```
- Use the `insertOne()` method to add a single document to the collec on.
```javascript
db.your_collec on_name.insertOne({
age: 30,
email: "[email protected]"
})
```
Using `insertMany()`:
1. Connect to MongoDB:
- Ensure that you are s ll connected to the MongoDB server and have selected the
appropriate database.
- Use the `insertMany()` method to add mul ple documents to the collec on.
```javascript
db.your_collec on_name.insertMany([
])
```
A er execu ng the `insertOne()` or `insertMany()` methods, you can verify that the
documents have been added to the collec on by using the `find()` method:
```javascript
db.your_collec on_name.find()
```
This command will display all documents in the specified collec on, allowing you to confirm
the successful inser on of your new documents.
Ans. In MongoDB, upda ng documents is a common opera on that allows you to modify
exis ng records in a collec on. MongoDB provides several methods for upda ng documents,
each serving specific use cases. Three key methods for upda ng documents are
`updateOne()`, `updateMany()`, and the legacy `update()` method. The significance of these
methods lies in their ability to perform precise and bulk updates based on specified filter
criteria.
1. `updateOne()` Method:
Syntax:
```javascript
db.collec on.updateOne(
{ filter_criteria },
```
- `$set`: An update operator that sets the specified fields to the provided values.
Example:
```javascript
db.users.updateOne(
{ $set: { age: 31 } }
```
2. `updateMany()` Method:
The `updateMany()` method updates mul ple documents in a collec on that match
a specified filter. It's useful for performing bulk updates.
Syntax:
```javascript
db.collec on.updateMany(
{ filter_criteria },
```
- `$set`: An update operator that sets the specified fields to the provided values.
Example:
```javascript
db.users.updateMany(
{ $set: { age: 25 } }
```
While `updateOne()` and `updateMany()` are more explicit, the `update()` method is
a legacy method that can be used for both single and mul ple document updates. However,
it's recommended to use the more specific `updateOne()` and `updateMany()` for clarity and
future compa bility.
Syntax:
```javascript
db.collec on.update(
{ filter_criteria },
{ op ons }
```
- `$set`: An update operator that sets the specified fields to the provided values.
- `op ons`: Addi onal op ons, such as `upsert` (creates a new document if no match
is found).
Example:
```javascript
db.users.update(
{ name: "Alice" },
{ $set: { age: 26 } }
```
- Filter Criteria:
- Allows for precise targe ng based on specific field values or condi ons.
- U lize update operators like `$set`, `$inc`, `$push`, etc., to perform specific update
ac ons.
3. What are the considera ons and poten al pi alls when dele ng documents in
MongoDB? Describe the differences between deleteOne() and deleteMany() methods
and when to use each.
Ans. When dele ng documents in MongoDB, it's essen al to consider certain factors to
ensure that the opera on is performed accurately and does not uninten onally affect other
parts of the data. Here are considera ons and poten al pi alls when dele ng documents in
MongoDB, along with an explana on of the differences between the `deleteOne()` and
`deleteMany()` methods:
1. Filter Criteria:
- Be cau ous when specifying the filter criteria for dele on. Ensure that the criteria
accurately iden fy the documents to be deleted and that the filter does not uninten onally
match more documents than intended.
2. Impact on Indexes:
- Dele ons can impact index usage and performance. When dele ng many documents,
indexes may need to be rebuilt, poten ally causing temporary performance degrada on.
3. Data Integrity:
- Dele ng documents should be performed with care to maintain data integrity. Consider
any rela onships between collec ons and ensure that dele ng documents does not violate
referen al integrity.
4. Delete Permissions:
- Ensure that the user execu ng the delete opera on has the necessary permissions to
perform the delete ac on. Unauthorized dele ons can lead to data loss.
- Dele on of documents does not immediately reclaim disk space. MongoDB uses a storage
engine, and space may be reused for new documents. However, explicit ac ons like the
`compact` command may be needed to release unused space.
1. `deleteOne()` Method:
- Syntax:
```javascript
- Use Case:
- Use `deleteOne()` when you want to delete a specific document based on a unique
iden fier or a specific condi on.
2. `deleteMany()` Method:
- Syntax:
```javascript
```
- Use Case:
- Use `deleteMany()` when you want to delete mul ple documents that share a common
condi on.
Examples:
Using `deleteOne()`:
```javascript
``
Using `deleteMany()`:
```javascript
```
- `deleteOne()`:
- Use when you want to delete a single document based on specific criteria.
- Ideal for scenarios where you are certain that only one document should match the filter
criteria.
- `deleteMany()`:
- Use when you want to delete mul ple documents that match a common condi on.
- Suitable for scenarios where you want to perform bulk dele ons based on shared criteria.
Sec on 5: Querying in MongoDB
1. Explain the importance of querying in MongoDB. How do you use the find() method to
retrieve documents that match specific criteria? Provide examples of queries with
different filter condi ons.
Ans. Querying is a fundamental aspect of working with databases, and in MongoDB, the `find()`
method is a primary tool for retrieving documents that match specific criteria. MongoDB
queries allow you to retrieve, filter, and analyze data based on various condi ons. The `find()`
method, along with query operators, provides a powerful and flexible mechanism for
querying MongoDB collec ons.
1. Data Retrieval:
2. Data Filtering:
- Enables the applica on of filters to narrow down results, focusing on the data relevant to
specific requirements.
- Supports sor ng results and projec ng only the necessary fields, op mizing data retrieval
and reducing network overhead.
4. Aggrega on:
- Queries can leverage indexes to efficiently locate and retrieve relevant documents,
enhancing query performance.
The `find()` method in MongoDB is used to query a collec on and retrieve documents that
match a specified set of criteria. It can take a filter object as an argument to specify the
condi ons for matching documents.
Syntax:
```javascript
```
```javascript
```
```javascript
```
```javascript
```
```javascript
// Retrieve documents where the "status" is "ac ve" and "age" is greater than 25
```
```javascript
// Retrieve only the "name" and "email" fields of documents where "status" is "ac ve"
```
```javascript
// Retrieve documents where "status" is "ac ve" and sort by "age" in ascending order
```
```javascript
Querying in MongoDB is essen al for applica ons to retrieve the right data efficiently, and
the `find()` method, along with query operators, provides a flexible and powerful mechanism
to achieve that.
2. Describe how to sort, limit, and skip results in MongoDB queries. What is the purpose of
the sort(), limit(), and skip() methods, and when should they be used?
Ans. In MongoDB, the `sort()`, `limit()`, and `skip()` methods are used to control and manipulate
the results of queries. These methods allow you to specify the order in which documents
should be returned, limit the number of documents returned, and skip a specified number of
documents. Let's explore each of these methods:
1. `sort()` Method:
The `sort()` method is used to specify the order in which the documents should be returned.
It takes a document as an argument, where each field represents a key, and the associated
value indicates the sor ng order (ascending or descending).
Syntax:
```javascript
```
- `order1`, `order2`: Sor ng order (`1` for ascending, `-1` for descending).
Example:
```javascript
// Retrieve documents where "status" is "ac ve" and sort by "age" in ascending order
```
2. `limit()` Method:
The `limit()` method is used to restrict the number of documents returned by a query. It
takes a numerical value as its argument, represen ng the maximum number of documents
to be returned.
Syntax:
```javascript
```
Example:
```javascript
```
3. `skip()` Method:
The `skip()` method is used to skip a specified number of documents and return the
remaining documents. It is o en used in combina on with `limit()` to implement pagina on.
Syntax:
```javascript
```
Example:
```javascript
// Skip the first 10 documents where "status" is "ac ve" and retrieve the next 5
```
1. `sort()` Method:
- When to Use:
- When you want the results to be ordered based on one or more fields.
2. `limit()` Method:
- When to Use:
- When you want to limit the number of documents returned to a specific count.
- Useful for scenarios like pagina on or when dealing with large result sets.
3. `skip()` Method:
- Purpose: Skips a specified number of documents and returns the remaining documents.
- When to Use:
- When implemen ng pagina on, allowing users to navigate through different result
pages.
Notes:
- The order of method chaining is significant. For example, the order of `sort()`, `skip()`, and
`limit()` affects the final result.
- Be cau ous with `skip()` for large result sets, as it may impact performance. Use efficient
pagina on strategies.
- Ensure that the fields used in `sort()` exist in the documents; otherwise, the sor ng may not
produce the expected results.
3. Discuss the concept of indexing in MongoDB. How can indexes be used to op mize
query performance, and what types of indexes are available in MongoDB?
Ans. Indexing is a crucial concept in MongoDB and plays a significant role in op mizing query
performance. An index in MongoDB is a data structure that improves the speed of data
retrieval opera ons on a collec on. By crea ng indexes on specific fields, MongoDB can
quickly locate and access the documents that match the query criteria.
Importance of Indexing:
1. Query Performance:
- Indexes significantly improve the speed of read opera ons, such as queries and
aggrega ons, by allowing MongoDB to locate relevant documents more efficiently.
- Indexes can speed up sor ng and aggrega on opera ons, especially when the fields being
sorted or aggregated are indexed.
3. Covered Queries:
- Indexes enable covered queries where the query can be sa sfied en rely using the index
without needing to access the actual documents.
4. Unique Constraints:
- Indexes can enforce unique constraints on fields, preven ng the inser on of duplicate
values.
5. Text Search:
- MongoDB supports text indexes for efficient text search opera ons.
Crea ng an Index:
In MongoDB, you can create an index using the `createIndex()` method. This method takes a
document that specifies the fields to be indexed and the type of index.
Example:
```javascript
db.users.createIndex({ username: 1 })
```
MongoDB automa cally uses indexes to fulfill queries whenever possible. To check if an
index is used for a specific query, you can use the `explain()` method.
Example:
```javascript
```
1. Single-Field Index:
2. Compound Index:
3. Unique Index:
4. Text Index:
5. Geospa al Index:
6. Wildcard Index:
7. Hashed Index:
8. Par al Index:
Considera ons:
- Indexing Overhead:
- While indexes improve read performance, they can increase write overhead. Each insert,
update, or delete opera on may require updates to the associated indexes.
- Aim for high selec vity to make indexes more efficient. Highly selec ve indexes narrow
down the search space, improving query performance.
- Index Size:
- Larger indexes consume more storage space. Consider the balance between improved
performance and increased storage requirements.
- Upda ng Indexes:
- Regularly monitor and update indexes, especially in cases of high write ac vity or changing
query pa erns.
- Covered Queries:
- Design indexes to make use of covered queries, where the index alone sa sfies the query.