- What is having in sql?
- What are the possible issues with indexes?
- When using a composite index, under what conditions will the database use it for a query that filters only on a subset of the indexed columns?
- How to verify that an index was used in a query?
- Does it make sense to add an index on a column with a highly skewed distribution to selectively query the minority value?
- Sql works very slowly, what are the possible improvements (the database is MySQL, for example)?
- NoSQL vs SQL Databases
- What are the main types of NoSQL databases, and when is each type most useful?
- OLAP vs OLTP Databases
- By which instruments of DB is ACID supported?
- What is Multi-Version Concurrency Control (MVCC)?
- What is the difference between keyset and offset pagination?
- HAVING filters records that work on summarized GROUP BY results.
- HAVING applies to summarized group records, whereas WHERE applies to individual records.
- Only the groups that meet the HAVING criteria will be returned.
- HAVING requires that a GROUP BY clause is present.
- WHERE and HAVING can be in the same query.
Although indexes are intended to enhance a database's performance, there are times when they should be avoided. The following guidelines indicate when the use of an index should be reconsidered.
- Indexes should not be used on small tables.
- Tables that have frequent, large batch updates or insert operations.
- Indexes should not be used on columns that contain a high number of NULL values.
- Columns that are frequently manipulated should not be indexed.
When using a composite index, under what conditions will the database use it for a query that filters only on a subset of the indexed columns?
The database uses the composite index only if the query filters on a leftmost prefix of the index columns. If the leftmost column is omitted, the index is typically not used for efficient seeks (though some databases offer skip‑scan optimization).
The standard way is to examine the query's execution plan, which reveals the actual operations the database performs. The primary tool is the EXPLAIN command, which you prepend to your query.
Does it make sense to add an index on a column with a highly skewed distribution to selectively query the minority value?
Partial indexes are a powerful tool for optimizing database performance when you consistently query a subset of your data.
- Index All Columns Used in 'where', 'order by', and 'group by' Clauses
- Optimize Like Statements With Union Clause
- Avoid Like Expressions With Leading Wildcards
- Take Advantage of MySQL Full-Text Searches
- Optimize Your Database Schema
- MySQL Query Caching
The four primary NoSQL database types are optimized for specific use cases:
- Key-value: Ideal for fast lookups, session management, real-time bidding, and shopping carts. Examples: Redis, DynamoDB.
- Document: Best for product catalogs, user profiles, and content management. Examples: MongoDB, Couchbase.
- Wide-column / Column-family: Suited for time-series data, real-time analytics (e.g., Sum, Count, Avg), IoT, and recommendation engines. Examples: Cassandra, HBase.
- Graph: Optimal for social networks, fraud detection, logistics, and recommendation engines. Examples: Neo4j, JanusGraph.
- Write-Ahead Logging – records changes before committing (Atomicity, Durability).
- Checkpointing – periodically flushes dirty pages to disk to speed recovery (Durability).
- Locks / MVCC – controls concurrent access to data (Isolation).
- Constraints & Triggers – enforce data integrity rules (Consistency).
MVCC is a database technique that creates a new version of a record instead of overwriting it when updated. This lets readers view the old version while writers update a new version simultaneously without any read/write blocking. It uses timestamps and transaction IDs to maintain consistency, ensuring no transaction ever waits to read an object. The result is increased concurrency and minimized read delays.
- Offset pagination uses
OFFSETandLIMIT. Performance degrades linearly (O(n)) as pages get deeper, and results can be inconsistent if data changes between page loads. - Keyset pagination uses a
WHEREclause on a unique, indexed column. It provides consistent O(1) performance regardless of dataset size and is immune to data changes, but it does not support jumping to random pages.