Difference between revisions of "Databases"

From Bitnami MediaWiki
Jump to navigation Jump to search
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
===Background and Invention===
 
===Background and Invention===
−
;What The Fuck is a Transaction?  
+
;Resources
 +
* [https://www.analyticsvidhya.com/blog/2020/10/sql-vs-nosql-databases-a-key-concept-every-data-engineer-should-know/ SQL vs. NoSQL]
 +
* [https://www.analyticsvidhya.com/blog/2020/08/a-beginners-guide-to-cap-theorem-for-data-engineering/ A beginner's guide to the CAP theorem]
 +
* Article on [https://www.sqlshack.com/learn-sql-foreign-key/ foreign keys]
 +
 
 +
 
 +
 
 +
;What The Hell is a Transaction?  
 
A '''database transaction''' is a unit of work done within a DBMS against a database, and treated independently from other transactions. They serve two purposes:
 
A '''database transaction''' is a unit of work done within a DBMS against a database, and treated independently from other transactions. They serve two purposes:
 
# Provide reliable units of work that permit failure recovery and maintain database consistency even under system failure, if execution stops and leaves multiple operations uncompleted
 
# Provide reliable units of work that permit failure recovery and maintain database consistency even under system failure, if execution stops and leaves multiple operations uncompleted
 
# Provide isolation between programs accessing a database concurrently
 
# Provide isolation between programs accessing a database concurrently
−
Generally, any change or potential change in a database is a transaction.  
+
Generally, any change--threatened or actual--in a database is a transaction. Other types
 +
 
  
 
;ACID  
 
;ACID  
Line 12: Line 20:
 
* Isolation: must not affect other transactions
 
* Isolation: must not affect other transactions
 
* Durable: must be written to persistent storage
 
* Durable: must be written to persistent storage
 +
  
 
;CAP Theorem
 
;CAP Theorem
Line 18: Line 27:
 
# Availability: Every request receives a (non-error) response, without the guarantee it contains the most recent write
 
# Availability: Every request receives a (non-error) response, without the guarantee it contains the most recent write
 
# Partition tolerance: The system continues to operate despite an arbitrary number of messages being dropped by the network between nodes
 
# Partition tolerance: The system continues to operate despite an arbitrary number of messages being dropped by the network between nodes
 +
* For example, MongoDB leans away from availability while Cassandra is weaker on consistency<ref>testbook</ref>
 +
 +
===RDBMS===
 +
In 2020, the five most popular database systems were MySQL, PostgreSQL, Microsoft SQL Server, SQLite, and MongoDB (NoSQL). (Here's a list from Wikipedia of databases that [https://en.wikipedia.org/wiki/Comparison_of_relational_database_management_systems no one has ever heard of.])
 +
* MySQL began in 1995 using IBM's ISAM (indexed sequential access method) engine. In ISAM one uses an API directly to search indices to find records in files, whereas a relational database uses a query optimizer to select indices automatically. Cutting edge products like dBase and Microsoft Access still use it. MySQL's alternative offering is now (in addition to MyISAM) InnoDB. Neither ISAM nor MyISAM is ''transactional''. InnoDB became default in MySQL 8.0 and [https://dev.mysql.com/doc/refman/8.0/en/innodb-introduction.html here] are the details.
 +
* PostgreSQL dates back to the 80s at UC Berkeley but was born in 1996. It features ACID transactions and views, materialized views, triggers, foreign keys and stored procedures. MVCC (multi-version concurrency control) eliminates the need for read-locks and ensures ACID. It supports full serializability. Supports B-tree and hash table indices as well as generalized search trees (GiST), generalized inverted indices (GIN), space-partitioned GiST, and block range indices (BRIN). This variety of indexing facilitates things like the PostGIS project which stores geographic information.
 +
* Microsoft sucks and SQLite is exactly what its name says.
 +
 +
===NoSQL===
 +
NoSQL databases come in a few flavors, whose names you should know: wide-column, key-value, document-based, graph, columnar. So you've heard of some, here are a few.  The leaders are MongoDB (doc), Cassandra (distributed columnar), ElasticSearch (full-text search),DynamoDB (key-value),
 +
* Document: MongoDB, Redis, AMZN DynamoDB, CouchbaseServer, MongoDB Atlas (GCP), Google Cloud Firestore
 +
* Graph: Redis, OrientDB, ArangoDB, Azure CosmosDB, Neo4j
 +
* Key-value: AMZN DynamoDB, Redis, Couchbase Server
 +
* Object: IBM Db2, Oracle Database Cloud, InterSystemsIRIS, Google Cloud Storage for Firebase
 +
* Columnar: Cassandra, HBase, Scylla

Latest revision as of 16:20, 23 February 2021

Background and Invention[edit]

Resources


What The Hell is a Transaction?

A database transaction is a unit of work done within a DBMS against a database, and treated independently from other transactions. They serve two purposes:

  1. Provide reliable units of work that permit failure recovery and maintain database consistency even under system failure, if execution stops and leaves multiple operations uncompleted
  2. Provide isolation between programs accessing a database concurrently

Generally, any change--threatened or actual--in a database is a transaction. Other types


ACID

Transactions must follow the ACID paradigm:

  • Atomicity: must be atomic, that is complete in its entirety or have no effect
  • Consistency: must conform to existing constraints in the database
  • Isolation: must not affect other transactions
  • Durable: must be written to persistent storage


CAP Theorem

Only two of the following three can be guaranteed for a distributed data store

  1. Consistency: Every read receives the most recent write, or an error
  2. Availability: Every request receives a (non-error) response, without the guarantee it contains the most recent write
  3. Partition tolerance: The system continues to operate despite an arbitrary number of messages being dropped by the network between nodes
  • For example, MongoDB leans away from availability while Cassandra is weaker on consistency<ref>testbook</ref>

RDBMS[edit]

In 2020, the five most popular database systems were MySQL, PostgreSQL, Microsoft SQL Server, SQLite, and MongoDB (NoSQL). (Here's a list from Wikipedia of databases that no one has ever heard of.)

  • MySQL began in 1995 using IBM's ISAM (indexed sequential access method) engine. In ISAM one uses an API directly to search indices to find records in files, whereas a relational database uses a query optimizer to select indices automatically. Cutting edge products like dBase and Microsoft Access still use it. MySQL's alternative offering is now (in addition to MyISAM) InnoDB. Neither ISAM nor MyISAM is transactional. InnoDB became default in MySQL 8.0 and here are the details.
  • PostgreSQL dates back to the 80s at UC Berkeley but was born in 1996. It features ACID transactions and views, materialized views, triggers, foreign keys and stored procedures. MVCC (multi-version concurrency control) eliminates the need for read-locks and ensures ACID. It supports full serializability. Supports B-tree and hash table indices as well as generalized search trees (GiST), generalized inverted indices (GIN), space-partitioned GiST, and block range indices (BRIN). This variety of indexing facilitates things like the PostGIS project which stores geographic information.
  • Microsoft sucks and SQLite is exactly what its name says.

NoSQL[edit]

NoSQL databases come in a few flavors, whose names you should know: wide-column, key-value, document-based, graph, columnar. So you've heard of some, here are a few. The leaders are MongoDB (doc), Cassandra (distributed columnar), ElasticSearch (full-text search),DynamoDB (key-value),

  • Document: MongoDB, Redis, AMZN DynamoDB, CouchbaseServer, MongoDB Atlas (GCP), Google Cloud Firestore
  • Graph: Redis, OrientDB, ArangoDB, Azure CosmosDB, Neo4j
  • Key-value: AMZN DynamoDB, Redis, Couchbase Server
  • Object: IBM Db2, Oracle Database Cloud, InterSystemsIRIS, Google Cloud Storage for Firebase
  • Columnar: Cassandra, HBase, Scylla